[RFC PATCH 09/10] arm: discard all .dyn* sections

Sam Edwards
2023-05-21T12:35:28Z

This makes the output ELF friendlier to llvm-objcopy, which
otherwise complains about discarding .dynsym when it's
(potentially) referenced by .rel.dyn.

Since u-boot doesn't actually make use of a dynamic linker,
and these sections are only here because we're building --pie,
it's best to discard what we don't need.

Signed-off-by: Sam Edwards <CFSworks@gmail.com>
---

arch/arm/cpu/u-boot.lds | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds
index 8cdf08a730..bd4650bd86 100644
--- a/arch/arm/cpu/u-boot.lds
+++ b/arch/arm/cpu/u-boot.lds
@@ -235,10 +235,13 @@ SECTIONS
*/
/DISCARD/ : { *(.gnu.version*) }

- .dynsym _image_binary_end : { *(.dynsym) }
- .dynbss : { *(.dynbss) }
- .dynstr : { *(.dynstr*) }
- .dynamic : { *(.dynamic*) }
+ /*
+ * Not needed at runtime: relocations are done directly on .rel.dyn,
+ * and we're self-relocating so we don't need compatibility with an
+ * external dynamic linker.
+ */
+ /DISCARD/ : { *(.dyn*) }
+
.plt : { *(.plt*) }
.interp : { *(.interp*) }
.gnu.hash : { *(.gnu.hash) }
--
2.39.2