Skip to content

Commit

Permalink
elfloader/linker: Fix arithmetic in the linker script
Browse files Browse the repository at this point in the history
Linker's operators precedence [1] which follows C makes "+" higher than
shifting "<<". Thus, ". + CONFIG_MAX_NODES" will be shifted by 12 in this
case, which is wrong and is not the intended behavior.
In lld (which properly implements C's operators precedence, unlike ld.bfd),
the arithmetic results in a significant value.

The outcome is either a huge ELF file size, or a linking error
(e.g., relocation R_AARCH64_ADR_PREL_PG_HI21 out of range).

This commit fixes the arithmetic and uses += which is more portable.

[1] https://sourceware.org/binutils/docs/ld.html

Sponsored by: DARPA.

Signed-off-by: Hesham Almatary <[email protected]>
  • Loading branch information
heshamelmatary committed Jan 15, 2024
1 parent 76236d3 commit db8d245
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion elfloader-tool/src/arch-arm/linker.lds
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ SECTIONS
.bss (NOLOAD) : {
. = ALIGN(0x1000);
core_stack_alloc = .;
. = . + CONFIG_MAX_NUM_NODES * 1 << 12;
. += CONFIG_MAX_NUM_NODES * (1 << 12);
core_stack_alloc_end = .;
_bss = .;
*(.bss)
Expand Down

0 comments on commit db8d245

Please sign in to comment.