summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2022-10-24 08:57:12 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2022-10-26 06:21:19 +0200
commiteee1b8846b0788c866dabf04e85742a48662455f (patch)
tree178b7ed2e44ae9b391a1fac801a500553ede543f
parent392ef1e9c0e27e5abc75fc41176ad0f25016921a (diff)
downloadbarebox-eee1b8846b0788c866dabf04e85742a48662455f.tar.gz
barebox-eee1b8846b0788c866dabf04e85742a48662455f.tar.xz
asm-generic: memory_layout: define __keep_symbolref()
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> Link: https://lore.barebox.org/20221024065716.1215046-5-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--arch/arm/include/asm/barebox-arm.h2
-rw-r--r--include/asm-generic/memory_layout.h7
2 files changed, 8 insertions, 1 deletions
diff --git a/arch/arm/include/asm/barebox-arm.h b/arch/arm/include/asm/barebox-arm.h
index 47d20b6b04..68a9610398 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 5cfd2a43a0..7593e18da1 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 */