You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How to reproduce:
I had gcc 8.3.0, but I suppose that it's reproducible on newer versions of it;
mold 1.11.0 (d4d93d7), but I suppose that it's reproducible on newer versions of it.
Let's generate an .o file with a lot of sections. For example,
Then, let's compile each .cpp file with generating an extra section per data/function definition(/home/mkornaukhov/mold contains symlink ld -> /usr/bin/mold):
mold: fatal: total.o: common local symbol?
collect2: error: ld returned 1 exit status
Meanwhile ld and lld handle it and fail when they cannot find main function.
I did some research:
Let's look at symbol table:
$ readelf -s total.o | grep " COM"
65522: 0000000000000000 0 SECTION LOCAL DEFAULT COM
131058: 0000000000000000 0 SECTION LOCAL DEFAULT COM
196594: 0000000000000000 0 SECTION LOCAL DEFAULT COM
262130: 0000000000000000 0 SECTION LOCAL DEFAULT COM
Mold creates entries of type SECTION with LOCAL binding and st_shndx equal to 65522 (= 0xfff2 = COM).
It's interesting that each entry of this pattern is equal to 0xfff2(=65522) modulo 0x10000(=65536).
Let's look at section header table:
$ readelf -S total.o | head -n1
There are 300118 section headers, starting at offset 0x1af5548
$ readelf -S total.o | grep "\[65522\]"
[65522] .data._ZL13static PROGBITS 0000000000000000 002ed964
I found out that in case of sections number is greater (or equal) than 65522 (reserved index for SHN_COMMON) mold creates incorrect entries in symbol table, mentioned above.
The text was updated successfully, but these errors were encountered:
It looks like because there are just too many entries in the section header table that some entries indices are so large they overlap with the reserved header indices when writing the section table. As per linux elf format manpages
Maybe mold can add a check to not put symbols at those indices?
How to reproduce:
I had gcc 8.3.0, but I suppose that it's reproducible on newer versions of it;
mold 1.11.0 (d4d93d7), but I suppose that it's reproducible on newer versions of it.
Let's generate an
.o
file with a lot of sections. For example,Then, let's compile each
.cpp
file with generating an extra section per data/function definition(/home/mkornaukhov/mold
contains symlinkld -> /usr/bin/mold
):And then, let's collect all
.o
files in single.o
file:g++ -B/home/mkornaukhov/mold file*.o -r -nostdlib -ffunction-sections -fdata-sections -o total.o
After that, let's try to compile an executable:
There's error:
Meanwhile
ld
andlld
handle it and fail when they cannot findmain
function.I did some research:
Let's look at symbol table:
Mold creates entries of type
SECTION
withLOCAL
binding andst_shndx
equal to 65522 (= 0xfff2 =COM
).It's interesting that each entry of this pattern is equal to 0xfff2(=65522) modulo 0x10000(=65536).
Let's look at section header table:
I found out that in case of sections number is greater (or equal) than 65522 (reserved index for
SHN_COMMON
) mold creates incorrect entries in symbol table, mentioned above.The text was updated successfully, but these errors were encountered: