Merge patch series "Update linker scripts to ensure appended device tree is correctly aligned"

Tom Rini <trini@konsulko.com> says:

This series builds on top of what Beleswar Padhi did in [1]. While
there's still discussion about the mkimage related parts, the linker
portion appears to the reliable path forward. An alternative that I had
mentioned before, and was part of previous discussions on this topic[2]
is in the end I believe not reliable enough. While we can take an output
file and pad it to where we think it needs to be, ultimately the linker
needs to place the symbol where we want it and if that isn't where we
pad to, we have a different problem. So what this series does (but each
commit message elaborates on the arch-specific linker scripts being
inconsistent) is make sure the linker script will place the required
symbol at 8-byte alignment, and then also use an ASSERT to fail the
build if this would not be true due to some unforseen event.

[1]: https://lore.kernel.org/u-boot/20260112101102.1417970-1-b-padhi@ti.com/
[2]: https://source.denx.de/u-boot/u-boot/-/issues/30

Link: https://lore.kernel.org/r/20260115222828.3931345-1-trini@konsulko.com
This commit is contained in:
Tom Rini
2026-01-20 10:19:48 -06:00
34 changed files with 143 additions and 41 deletions

View File

@@ -1583,7 +1583,7 @@ binary_size_check: u-boot-nodtb.bin FORCE
map_size=$(shell cat u-boot.map | \
awk ' \
/_image_copy_start/ { start = $$1 } \
/_image_binary_end/ { end = $$1 } \
/_image_binary_end/ { end = $$1;exit } \
END { \
if (start != "" && end != "") \
print end " " start; \

View File

@@ -30,8 +30,10 @@ SECTIONS
.rodata : { *(SORT_BY_ALIGNMENT(.rodata*)) } >.sram
. = ALIGN(4);
.data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
. = ALIGN(4);
.data : {
*(SORT_BY_ALIGNMENT(.data*))
. = ALIGN(8);
} >.sram
__image_copy_end = .;
_end = .;
@@ -44,3 +46,5 @@ SECTIONS
__bss_end = .;
} >.sdram
}
ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");

View File

@@ -45,7 +45,7 @@ SECTIONS
. = ALIGN(4);
__bss_start = .;
*(.bss*)
. = ALIGN(4);
. = ALIGN(8);
__bss_end = .;
}
@@ -62,3 +62,6 @@ SECTIONS
.gnu : { *(.gnu*) }
.ARM.exidx : { *(.ARM.exidx*) }
}
ASSERT(_image_binary_end % 8 == 0, \
"_image_binary_end must be 8-byte aligned for device tree");

View File

@@ -31,9 +31,9 @@ SECTIONS
. = ALIGN(4);
__u_boot_list : {
KEEP(*(SORT(__u_boot_list*)));
. = ALIGN(8);
} > .sram
. = ALIGN(4);
__image_copy_end = .;
_end = .;
_image_binary_end = .;
@@ -47,3 +47,6 @@ SECTIONS
__bss_end = .;
} > .sdram
}
ASSERT(_image_binary_end % 8 == 0, \
"_image_binary_end must be 8-byte aligned for device tree");

View File

@@ -40,9 +40,9 @@ SECTIONS
. = ALIGN(4);
__u_boot_list : {
KEEP(*(SORT(__u_boot_list*)));
. = ALIGN(8);
} > .sram
. = ALIGN(4);
__image_copy_end = .;
_end = .;
_image_binary_end = .;
@@ -56,3 +56,6 @@ SECTIONS
__bss_end = .;
} > .sdram
}
ASSERT(_image_binary_end % 8 == 0, \
"_image_binary_end must be 8-byte aligned for device tree");

View File

@@ -52,9 +52,9 @@ SECTIONS
__u_boot_list : {
. = ALIGN(8);
KEEP(*(SORT(__u_boot_list*)));
. = ALIGN(8);
} >.sram
. = ALIGN(8);
__image_copy_end = .;
_end = .;
_image_binary_end = .;
@@ -89,5 +89,7 @@ SECTIONS
#endif
}
ASSERT(_image_binary_end % 8 == 0, \
"_image_binary_end must be 8-byte aligned for device tree");
ASSERT(ADDR(.bss) % 8 == 0, \
".bss must be 8-byte aligned");

View File

@@ -146,6 +146,7 @@ SECTIONS
__rel_dyn_start = .;
*(.rela*)
__rel_dyn_end = .;
. = ALIGN(8);
}
_end = .;
@@ -175,3 +176,5 @@ SECTIONS
#include "linux-kernel-image-header-vars.h"
#endif
}
ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");

View File

@@ -51,9 +51,9 @@ SECTIONS
__rel_dyn_start = .;
*(.rel*)
__rel_dyn_end = .;
. = ALIGN(8);
}
. = ALIGN(8);
_image_binary_end = .;
_end = .;
@@ -80,6 +80,9 @@ ASSERT(__image_copy_end - __image_copy_start <= (IMAGE_MAX_SIZE), \
"SPL image too big");
#endif
ASSERT(_image_binary_end % 8 == 0, \
"_image_binary_end must be 8-byte aligned for device tree");
#if defined(CONFIG_SPL_BSS_MAX_SIZE)
ASSERT(__bss_end - __bss_start <= (CONFIG_SPL_BSS_MAX_SIZE), \
"SPL image BSS too big");

View File

@@ -164,6 +164,7 @@ SECTIONS
__rel_dyn_start = .;
*(.rel*)
__rel_dyn_end = .;
. = ALIGN(8);
}
_end = .;
@@ -192,3 +193,6 @@ SECTIONS
/DISCARD/ : { *(.ARM.exidx*) }
/DISCARD/ : { *(.gnu.linkonce.armexidx.*) }
}
ASSERT(_image_binary_end % 8 == 0, \
"_image_binary_end must be 8-byte aligned for device tree");

View File

@@ -59,6 +59,7 @@ SECTIONS
__rel_dyn_start = .;
*(.rel*)
__rel_dyn_end = .;
. = ALIGN(8);
} > .nor
_end = .;
@@ -79,6 +80,9 @@ ASSERT(__image_copy_end - __image_copy_start <= (IMAGE_MAX_SIZE), \
"SPL image too big");
#endif
ASSERT(_image_binary_end % 8 == 0, \
"_image_binary_end must be 8-byte aligned for device tree");
#if defined(CONFIG_SPL_BSS_MAX_SIZE)
ASSERT(__bss_end - __bss_start <= (CONFIG_SPL_BSS_MAX_SIZE), \
"SPL image BSS too big");

View File

@@ -29,9 +29,11 @@ SECTIONS
.data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
. = ALIGN(4);
__u_boot_list : { KEEP(*(SORT(__u_boot_list*))) } > .sram
__u_boot_list : {
KEEP(*(SORT(__u_boot_list*)))
. = ALIGN(8);
} > .sram
. = ALIGN(4);
__image_copy_end = .;
_end = .;
_image_binary_end = .;
@@ -51,6 +53,9 @@ ASSERT(__image_copy_end - __start <= (IMAGE_MAX_SIZE), \
"SPL image too big");
#endif
ASSERT(_image_binary_end % 8 == 0, \
"_image_binary_end must be 8-byte aligned for device tree");
#if defined(CONFIG_SPL_BSS_MAX_SIZE)
ASSERT(__bss_end - __bss_start <= (CONFIG_SPL_BSS_MAX_SIZE), \
"SPL image BSS too big");

View File

@@ -36,9 +36,11 @@ SECTIONS
.data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
. = ALIGN(4);
__u_boot_list : { KEEP(*(SORT(__u_boot_list*))) } > .sram
__u_boot_list : {
KEEP(*(SORT(__u_boot_list*)))
. = ALIGN(8);
} > .sram
. = ALIGN(4);
__image_copy_end = .;
_end = .;
_image_binary_end = .;
@@ -52,3 +54,6 @@ SECTIONS
__bss_end = .;
} >.sdram
}
ASSERT(_image_binary_end % 8 == 0, \
"_image_binary_end must be 8-byte aligned for device tree");

View File

@@ -55,3 +55,6 @@ SECTIONS
__bss_end = .;
} >.sdram
}
ASSERT(_image_binary_end % 8 == 0, \
"_image_binary_end must be 8-byte aligned for device tree");

View File

@@ -42,9 +42,9 @@ SECTIONS
__u_boot_list : {
. = ALIGN(8);
KEEP(*(SORT(__u_boot_list*)));
. = ALIGN(8);
}
. = ALIGN(8);
__image_copy_end = .;
_end = .;
_image_binary_end = .;
@@ -69,6 +69,9 @@ ASSERT(__image_copy_end - __image_copy_start < (CONFIG_TPL_MAX_SIZE), \
"TPL image too big");
#endif
ASSERT(_image_binary_end % 8 == 0, \
"_image_binary_end must be 8-byte aligned for device tree");
#if defined(CONFIG_TPL_BSS_MAX_SIZE)
ASSERT(__bss_end - __bss_start < (CONFIG_TPL_BSS_MAX_SIZE), \
"TPL image BSS too big");

View File

@@ -39,10 +39,9 @@ SECTIONS
. = ALIGN(4);
__u_boot_list : {
KEEP(*(SORT(__u_boot_list*)));
. = ALIGN(8);
} > .sram
. = ALIGN(4);
_image_binary_end = .;
_end = .;
@@ -62,3 +61,6 @@ SECTIONS
/DISCARD/ : { *(.interp*) }
/DISCARD/ : { *(.gnu*) }
}
ASSERT(_image_binary_end % 8 == 0, \
"_image_binary_end must be 8-byte aligned for device tree");

View File

@@ -66,6 +66,7 @@ SECTIONS
__rel_dyn_start = .;
*(.rel*)
__rel_dyn_end = .;
. = ALIGN(8);
}
_end = .;
@@ -98,3 +99,5 @@ SECTIONS
/DISCARD/ : { *(.ARM.exidx*) }
/DISCARD/ : { *(.gnu.linkonce.armexidx.*) }
}
ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");

View File

@@ -69,28 +69,27 @@ SECTIONS
__ex_table : { *(__ex_table) }
__stop___ex_table = .;
. = ALIGN(8);
. = ALIGN(4);
__init_begin = .;
.text.init : { *(.text.init) }
.data.init : { *(.data.init) }
. = ALIGN(8);
. = ALIGN(4);
__init_end = .;
. = ALIGN(8);
. = ALIGN(4);
__rel_dyn_start = .;
.rela.dyn : {
*(.rela.dyn)
}
__rel_dyn_end = .;
. = ALIGN(8);
__dyn_sym_start = .;
.dynsym : {
.dynsym ALIGN(4) : {
__dyn_sym_start = .;
*(.dynsym)
__dyn_sym_end = .;
. = ALIGN(8);
}
__dyn_sym_end = .;
. = ALIGN(8);
_end = .;
__bss_start = .;
@@ -100,9 +99,11 @@ SECTIONS
*(.bss*)
*(.sbss*)
*(COMMON)
. = ALIGN(8);
. = ALIGN(4);
_ebss = .;
}
__bss_end = . ;
PROVIDE (end = .);
}
ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");

View File

@@ -50,7 +50,7 @@ SECTIONS
*(.bss)
*(.bss.*)
*(COMMON)
. = ALIGN(4);
. = ALIGN(8);
__bss_end = .;
}
_end = . ;
@@ -61,3 +61,6 @@ SECTIONS
ASSERT(_end - _start <= (CONFIG_SPL_MAX_FOOTPRINT), \
"SPL image plus BSS too big");
#endif
ASSERT(_image_binary_end % 8 == 0, \
"_image_binary_end must be 8-byte aligned for device tree");

View File

@@ -67,8 +67,10 @@ SECTIONS
*(.scommon)
*(.bss*)
*(COMMON)
. = ALIGN(4);
. = ALIGN(8);
__bss_end = .;
}
_end = . ;
}
ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");

View File

@@ -27,16 +27,17 @@ SECTIONS
.data : {
*(SORT_BY_ALIGNMENT(.data*))
*(SORT_BY_ALIGNMENT(.sdata*))
. = ALIGN(8);
} > .spl_mem
#if defined(CONFIG_SPL_DM) || defined(CONFIG_SPL_LOADER_SUPPORT)
. = ALIGN(4);
__u_boot_list : {
KEEP(*(SORT(__u_boot_list*)));
. = ALIGN(8);
} > .spl_mem
#endif
. = ALIGN(4);
__image_copy_end = .;
__image_copy_len = __image_copy_end - __text_start;
@@ -123,3 +124,6 @@ SECTIONS
*(.eh_frame)
}
}
ASSERT(_image_binary_end % 8 == 0, \
"_image_binary_end must be 8-byte aligned for device tree");

View File

@@ -54,9 +54,9 @@ SECTIONS
LONG(0xFFFFFFFF);
FILL(0);
. += CONFIG_MIPS_RELOCATION_TABLE_SIZE - 4;
. = ALIGN(8);
}
. = ALIGN(8);
_end = .;
.bss __rel_start (OVERLAY) : {
@@ -140,3 +140,5 @@ SECTIONS
*(.eh_frame)
}
}
ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");

View File

@@ -60,8 +60,8 @@ SECTIONS
*(.sdata)
*(.sdata.*)
*(.gnu.linkonce.s.*)
. = ALIGN(8);
}
. = ALIGN(4);
_edata = .;
PROVIDE (edata = .);
@@ -124,3 +124,5 @@ SECTIONS
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
}
ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");

View File

@@ -56,6 +56,7 @@ SECTIONS
* _end - This is end of u-boot.bin image.
* dtb will be appended here to make u-boot-dtb.bin
*/
. = ALIGN(8);
_end = .;
. = ALIGN(4096);
@@ -77,3 +78,5 @@ SECTIONS
PROVIDE (end = .);
}
ENTRY(_start)
ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");

View File

@@ -78,7 +78,7 @@ SECTIONS
__init_begin = .;
.text.init : { *(.text.init) }
.data.init : { *(.data.init) }
. = ALIGN(4);
. = ALIGN(8);
__init_end = .;
_end = .;
@@ -119,3 +119,5 @@ SECTIONS
__bss_end = . ;
PROVIDE (end = .);
}
ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");

View File

@@ -43,6 +43,7 @@ SECTIONS
__binman_sym_start = .;
KEEP(*(SORT(.binman_sym*)));
__binman_sym_end = .;
. = ALIGN(8);
} > .spl_mem
_end = .;
@@ -56,3 +57,6 @@ SECTIONS
__bss_end = .;
} > .bss_mem
}
ASSERT(_image_binary_end % 8 == 0, \
"_image_binary_end must be 8-byte aligned for device tree");

View File

@@ -73,10 +73,9 @@ SECTIONS
__dyn_sym_start = .;
*(.dynsym)
__dyn_sym_end = .;
. = ALIGN(8);
}
. = ALIGN(8);
_end = .;
.bss : {
@@ -86,3 +85,5 @@ SECTIONS
__bss_end = .;
}
}
ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");

View File

@@ -25,9 +25,13 @@ SECTIONS
*(_u_boot_sandbox_getopt_start)
KEEP(*(_u_boot_sandbox_getopt))
*(_u_boot_sandbox_getopt_end)
. = ALIGN(8);
}
_image_binary_end = .;
}
INSERT AFTER .data;
ASSERT(_image_binary_end % 8 == 0, \
"_image_binary_end must be 8-byte aligned for device tree");

View 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) : {

View 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

View 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");

View File

@@ -72,6 +72,7 @@ SECTIONS
* _end - This is end of u-boot.bin image.
* dtb will be appended here to make u-boot-dtb.bin
*/
. = ALIGN(8);
_end = .;
. = ALIGN(4096);
@@ -93,3 +94,5 @@ SECTIONS
PROVIDE (end = .);
}
ENTRY(_start)
ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");

View File

@@ -72,6 +72,7 @@ SECTIONS
* _end - This is end of u-boot.bin image.
* dtb will be appended here to make u-boot-dtb.bin
*/
. = ALIGN(8);
_end = .;
. = ALIGN(4096);
@@ -93,3 +94,5 @@ SECTIONS
PROVIDE (end = .);
}
ENTRY(_start)
ASSERT(_end % 8 == 0, "_end must be 8-byte aligned for device tree");

View File

@@ -43,6 +43,7 @@ SECTIONS
__rel_dyn_start = .;
*(.rel*)
__rel_dyn_end = .;
. = ALIGN(8);
} >.sram
__image_copy_end = .;
@@ -58,3 +59,6 @@ SECTIONS
__bss_end = .;
} >.sdram
}
ASSERT(_image_binary_end % 8 == 0, \
"_image_binary_end must be 8-byte aligned for device tree");

View File

@@ -48,7 +48,10 @@ SECTIONS
. = ALIGN(4);
__bss_start = .;
*(.bss*)
. = ALIGN(4);
. = ALIGN(8);
__bss_end = .;
} >.sram
}
ASSERT(__bss_end % 8 == 0, \
"__bss_end must be 8-byte aligned for device tree");