The test-case is taken from grub2: $ cat 1.c int main() { return 0; } $ cat 2.S .bss .space (1 << 22) $ gcc 1.c 2.S -Wl,-N -Wl,-Ttext,0 -static -Wl,--build-id=none -fuse-ld=bfd /usr/bin/ld.bfd: section .note.ABI-tag VMA [0000000000400190,00000000004001af] overlaps section .bss VMA [00000000000adc00,00000000004af3ff] collect2: error: ld returned 1 exit status I believe ld should not make the 2 sections to overlap. gold is even worse, it crashes: $ gcc 1.c 2.S -Wl,-N -Wl,-Ttext,0 -static -Wl,--build-id=none -fuse-ld=gold /usr/bin/ld.gold: internal error in set_offset, at ../../gold/output.cc:4780 collect2: error: ld returned 1 exit status
-Ttext 0 is asking to place the .text section at address zero. Assuming you're playing with x86_64, the -N script starts laying out the text segment at 0x400000. So a number of sections are placed there after allowing for headers. Then we reset to address zero for .text and place a number of sections there, and since .bss is so large, its vma overlaps the first section, .note.ABI-tag. Not a bug, you asked for overlapping sections. I suspect grub2 should be using -Wl,-Ttext-segment,0.
Hah, -Ttext-segment indeed. When I was looking at this ( https://bugzilla.opensuse.org/show_bug.cgi?id=1181741 ), I idly thought that it would be better if -Ttext would do something else than the traditional .text section moving (for ELF formats), without realizing that this already exists :-) (For better or worse -Ttext is used by basically everything that wants something similar like grub, but what they _actually_ want is the behaviour of -Ttext-segment)
Yes, changing -Ttext was exactly what Ian and Daniel wanted a long time ago.. https://sourceware.org/pipermail/binutils/2009-January/058886.html