Bug 27377

Summary: /usr/bin/ld.bfd: section .note.ABI-tag VMA [0000000000400190,00000000004001af] overlaps section .bss VMA [00000000000adc00,00000000004af3ff]
Product: binutils Reporter: Martin Liska <martin.liska>
Component: ldAssignee: Alan Modra <amodra>
Status: RESOLVED NOTABUG    
Severity: normal CC: matz, sam
Priority: P2    
Version: 2.37   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Martin Liska 2021-02-08 16:17:29 UTC
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
Comment 1 Alan Modra 2021-02-09 12:31:38 UTC
-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.
Comment 2 Michael Matz 2021-02-10 15:13:56 UTC
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)
Comment 3 Alan Modra 2021-02-10 22:36:59 UTC
Yes, changing -Ttext was exactly what Ian and Daniel wanted a long time ago..
https://sourceware.org/pipermail/binutils/2009-January/058886.html