]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
x86: Update linker scripts to ensure appended device tree is aligned
authorTom Rini <trini@konsulko.com>
Thu, 15 Jan 2026 22:19:40 +0000 (16:19 -0600)
committerTom Rini <trini@konsulko.com>
Tue, 20 Jan 2026 18:07:24 +0000 (12:07 -0600)
With commit 0535e46d55d7 ("scripts/dtc: Update to upstream version
v1.7.2-35-g52f07dcca47c") it is now a fatal error to U-Boot if our
device tree is not 8-byte aligned. In commit 85f586035d75 ("ARM: OMAP2+:
Pad SPL binary to 8-byte alignment before DTB") Beleswar Padhi explains
that we must have ALIGN(x) statements inside of a section to ensure that
padding is included and not simply that the linker address counter is
incremented. To that end, this patch:
- Rewrite the '.rel.dyn' (u-boot.lds) to follow modern practices, and
  include the 8-byte alignment at the end of the section.
- Expands the '.dynamic' section (u-boot-64.lds) to be more readable
  when adding a second statement to the section.
- Aligns the final section before _end (for U-Boot) or _image_binary_end
  or __bss_end (for xPL phases) by 8-bytes by adding '. = ALIGN(8);' to
  the final section before the symbol or changing an existing ALIGN(4)
  statement.
- Ensure that we do have alignment by adding an ASSERT so that when not
  aligned we fail to link (and explain why).

Signed-off-by: Tom Rini <trini@konsulko.com>
arch/x86/cpu/u-boot-64.lds
arch/x86/cpu/u-boot-spl.lds
arch/x86/cpu/u-boot.lds

index 00a6d8691211a4fa6ff7a97539e2c49d394aaa21..0c353c5d740178d6c0c9fe97338532e70089e02f 100644 (file)
@@ -86,9 +86,11 @@ SECTIONS
        __rel_dyn_end = .;
        . = ALIGN(4);
 
-       .dynamic : { *(.dynamic) }
+       .dynamic : {
+               *(.dynamic)
+               . = ALIGN(8);
+       }
 
-       . = ALIGN(4);
        _end = .;
 
        .bss __rel_dyn_start (OVERLAY) : {
index 50b4b1608552721473f768a12cb3d20f249206fc..57cdce6d7515212c478481e0b78ff4f5d9b0a3c7 100644 (file)
@@ -68,7 +68,7 @@ SECTIONS
                __bss_start = .;
                *(.bss*)
                *(COM*)
-               . = ALIGN(4);
+               . = ALIGN(8);
                __bss_end = .;
        }
        __bss_size = __bss_end - __bss_start;
@@ -97,3 +97,11 @@ SECTIONS
 #endif
 
 }
+
+ASSERT(_image_binary_end % 8 == 0, \
+       "_image_binary_end must be 8-byte aligned for device tree");
+
+#if !CONFIG_IS_ENABLED(SEPARATE_BSS)
+ASSERT(__bss_end % 8 == 0, \
+       "__bss_end must be 8-byte aligned for device tree");
+#endif
index c418ff44aa086ab1aae4a27209d126b3274970f1..ea070acd6a15a4f6349e7af06c6640887d4d4559 100644 (file)
@@ -79,13 +79,12 @@ SECTIONS
        . = ALIGN(4);
        .dynsym : { *(.dynsym*) }
 
-       . = ALIGN(4);
-       __rel_dyn_start = .;
-       .rel.dyn : {
+       .rel.dyn ALIGN(4) : {
+               __rel_dyn_start = .;
                *(.rel*)
+               __rel_dyn_end = .;
+               . = ALIGN(8);
        }
-       __rel_dyn_end = .;
-       . = ALIGN(4);
        _end = .;
 
        .bss __rel_dyn_start (OVERLAY) : {
@@ -120,3 +119,5 @@ SECTIONS
 #endif
 
 }
+
+ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");