From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 4/8] asm-generic: memory_layout: define __keep_symbolref()
Date: Mon, 24 Oct 2022 08:57:12 +0200 [thread overview]
Message-ID: <20221024065716.1215046-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20221024065716.1215046-1-a.fatoum@pengutronix.de>
When multiple PBL entry points are built as part of a multi-image build,
the link process will be conducted multiple times, each with a different
entry point and then linker garbage collection will take care to remove
any unreferenced sections. Sometimes, we want to keep sections around,
even if they are unreferenced in code, because the linker will place
them at a location, where they can fulfill their purpose without being
referenced explicitly.
Examples are the barebox IMD entries, which attach image meta-data to
barebox or the stack setup prologue which is inserted at the start of
the image to work around lack of __attribute__((naked)) support on
ARM64.
So far, these sections were kept around by either a call to an external
function, which worked because we don't employ LTO or via
barrier_data(ptr), which in its <linux/compiler-gcc.h> implementation
generates a load from the supplied ptr. Improve readability, by defining
a new __keep_symbolref() that describes what it is supposed to do and
does just that: Keep a symbol reference alive as long as the code
surrounding it is not eliminated as dead code.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/include/asm/barebox-arm.h | 2 +-
include/asm-generic/memory_layout.h | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/arch/arm/include/asm/barebox-arm.h b/arch/arm/include/asm/barebox-arm.h
index 47d20b6b04ea..68a9610398cc 100644
--- a/arch/arm/include/asm/barebox-arm.h
+++ b/arch/arm/include/asm/barebox-arm.h
@@ -141,7 +141,7 @@ static inline unsigned long arm_mem_barebox_image(unsigned long membase,
#define ____emit_entry_prologue(name, instr, ...) do { \
static __attribute__ ((unused,section(".text_head_prologue_" __stringify(name)))) \
const u32 __entry_prologue[] = {(instr), ##__VA_ARGS__}; \
- barrier_data(__entry_prologue); \
+ __keep_symbolref(__entry_prologue); \
} while(0)
#define __emit_entry_prologue(name, instr1, instr2, instr3, instr4, instr5) \
diff --git a/include/asm-generic/memory_layout.h b/include/asm-generic/memory_layout.h
index 5cfd2a43a056..7593e18da151 100644
--- a/include/asm-generic/memory_layout.h
+++ b/include/asm-generic/memory_layout.h
@@ -23,4 +23,11 @@
#define MALLOC_SIZE CONFIG_MALLOC_SIZE
#define STACK_SIZE CONFIG_STACK_SIZE
+/*
+ * This generates a useless load from the specified symbol
+ * to ensure linker garbage collection doesn't delete it
+ */
+#define __keep_symbolref(sym) \
+ __asm__ __volatile__("": :"r"(&sym) :)
+
#endif /* __ASM_GENERIC_MEMORY_LAYOUT_H */
--
2.30.2
next prev parent reply other threads:[~2022-10-24 6:58 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-24 6:57 [PATCH 0/8] ARM64: rewrite ENTRY_FUNCTION_WITHSTACK in assembly Ahmad Fatoum
2022-10-24 6:57 ` [PATCH 1/8] ARM64: cpu: select HAVE_PBL_MULTI_IMAGES globally Ahmad Fatoum
2022-10-24 6:57 ` [PATCH 2/8] ARM64: asm: define ENTRY_FUNCTION in terms of ENTRY_FUNCTION_WITHSTACK Ahmad Fatoum
2022-10-24 6:57 ` [PATCH 3/8] pbl: have linker define __pbl_board_entry alias Ahmad Fatoum
2022-10-24 6:57 ` Ahmad Fatoum [this message]
2022-10-24 6:57 ` [PATCH 5/8] ARM64: asm: rewrite ENTRY_FUNCTION(_WITHSTACK) fully in assembly Ahmad Fatoum
2022-10-24 8:55 ` Sascha Hauer
2022-10-24 10:02 ` Ahmad Fatoum
2022-10-24 12:11 ` [PATCH] fixup! " Ahmad Fatoum
2022-10-24 6:57 ` [PATCH 6/8] ARM64: asm: drop __barebox_arm_head Ahmad Fatoum
2022-10-24 6:57 ` [PATCH 7/8] ARM: asm: cleanup 32-bit entry points Ahmad Fatoum
2022-10-24 6:57 ` [PATCH 8/8] Documentation: devel: porting: bring it up-to-date Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221024065716.1215046-5-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox