[U-Boot] [PATCH] MIPS: add .padding section to linker script

Daniel Schwierzeck daniel.schwierzeck at gmail.com
Wed Oct 29 18:50:56 CET 2014


Commit 79fd7e649e287228a1445820a72f7dd33baedb96

    MIPS: always keep all sections in u-boot ELF binary.

    Always keep all sections in u-boot ELF binary. Move all unneeded
    sections after _end to avoid allocating space in the final binary.
    Also remove .deadcode section which is now obsolete.

removed section .deadcode because the original symptoms were not
visible anymore. Unfortuneatly the binutils bug still exists.

The size of .rel.dyn section is often bigger than needed for all
entries. But objcopy only allocates space as much as required for all
reloc entries. Thus there is a gap between the last entry and
__rel_dyn_end in u-boot.bin. If u-boot is booted from RAM (e.g. in
SPL scenarios) that area could contain garbage data which could lead
to CPU exceptions during relocation.

Signed-off-by: Gabor Juhos <juhosg at openwrt.org>
Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck at gmail.com>

---

 arch/mips/config.mk      |  2 +-
 arch/mips/cpu/u-boot.lds | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/arch/mips/config.mk b/arch/mips/config.mk
index a2d07af..f7be8f7 100644
--- a/arch/mips/config.mk
+++ b/arch/mips/config.mk
@@ -55,4 +55,4 @@ PLATFORM_LDFLAGS		+= -G 0 -static -n -nostdlib $(ENDIANNESS)
 PLATFORM_RELFLAGS		+= -ffunction-sections -fdata-sections
 LDFLAGS_FINAL			+= --gc-sections -pie
 OBJCOPYFLAGS			+= -j .text -j .rodata -j .data -j .got
-OBJCOPYFLAGS			+= -j .u_boot_list -j .rel.dyn
+OBJCOPYFLAGS			+= -j .u_boot_list -j .rel.dyn -j .padding
diff --git a/arch/mips/cpu/u-boot.lds b/arch/mips/cpu/u-boot.lds
index e504ea7..7d71c11 100644
--- a/arch/mips/cpu/u-boot.lds
+++ b/arch/mips/cpu/u-boot.lds
@@ -61,6 +61,24 @@ SECTIONS
 		__rel_dyn_end = .;
 	}
 
+	.padding : {
+		/*
+		 * Workaround for a binutils feature (or bug?).
+		 *
+		 * The GNU ld from binutils puts the dynamic relocation
+		 * entries into the .rel.dyn section. Sometimes it
+		 * allocates more dynamic relocation entries than it needs
+		 * and the unused slots are set to R_MIPS_NONE entries.
+		 *
+		 * However the size of the .rel.dyn section in the ELF
+		 * section header does not cover the unused entries, so
+		 * objcopy removes those during stripping.
+		 *
+		 * Create a small section here to avoid that.
+		 */
+		LONG(0xFFFFFFFF)
+	}
+
 	_end = .;
 
 	.bss __rel_dyn_start (OVERLAY) : {
-- 
2.1.1



More information about the U-Boot mailing list