Open
Description
Creating a follow-up ticket for #53 based on the discussion there.
Reproducer of what we're seeing based on the tests in [1] and [2]:
cat > test.c << '!'
__attribute__((section(".a")))
__attribute__((aligned(64)))
int foo(void) { return 1; }
__attribute__((section(".b")))
__attribute__((aligned(128)))
int bar(void) { return 2; }
!
cat > script.t << '!'
MEMORY {
VMA_REGION (rwx) : ORIGIN = 0x1000, LENGTH = 0x1000
LMA_REGION (rwx) : ORIGIN = 0x3fc0, LENGTH = 0x1000
}
SECTIONS {
.a : ALIGN_WITH_INPUT {
begin = .;
*(.a)
} > VMA_REGION AT > LMA_REGION
.b : ALIGN_WITH_INPUT {
*(.b)
end = .;
} > VMA_REGION AT > LMA_REGION
}
!
clang --target=riscv32-unknown-elf -Oz -c test.c
riscv32-unknown-elf-ld.bfd -T script.t test.o -o ld.a.out
riscv-link -T script.t test.o -o eld.a.out
Output snippets:
$ llvm-objdump --headers ld.a.out
...
1 .a 00000004 00001000 00003fc0 TEXT
2 .b 00000004 00001080 00004040 TEXT
...
$ llvm-objdump --headers eld.a.out
...
1 .a 00000004 00001000 00003fc0 TEXT
2 .b 00000004 00001080 00004000 TEXT
...
I think the memcpy scenario mentioned in [1] is roughly similar to what Zephyr uses ALIGN_WITH_INPUT for, but I need to double check that. Will update here later.
Links:
[1] https://binutils.sourceware.narkive.com/MTsXxI3t/patch-ld-add-align-with-input-output-section-attribute
[2] https://archive.fosdem.org/2024/events/attachments/fosdem-2024-2340-linker-scripts-in-lld-and-how-they-compare-with-gnu-ld/slides/22752/Fosdem_linker_scripts_2024_uG7XLOI.pdf (see slide 30)