[PATCH 4/8] asm-generic: memory_layout: define __keep_symbolref()
Ahmad Fatoum
a.fatoum at pengutronix.de
Sun Oct 23 23:57:12 PDT 2022
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 at 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
More information about the barebox
mailing list