https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104617
Bug ID: 104617 Summary: Bug in handling of 64k+ sections Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: jakub at gcc dot gnu.org CC: marxin at gcc dot gnu.org Target Milestone: --- When foo1.c is: #define A(n) int foo1##n(void) { return 1##n; } #define B(n) A(n##0) A(n##1) A(n##2) A(n##3) A(n##4) A(n##5) A(n##6) A(n##7) A(n##8) A(n##9) #define C(n) B(n##0) B(n##1) B(n##2) B(n##3) B(n##4) B(n##5) B(n##6) B(n##7) B(n##8) B(n##9) #define D(n) C(n##0) C(n##1) C(n##2) C(n##3) C(n##4) C(n##5) C(n##6) C(n##7) C(n##8) C(n##9) #define E(n) D(n##0) D(n##1) D(n##2) D(n##3) D(n##4) D(n##5) D(n##6) D(n##7) D(n##8) D(n##9) E(0) E(1) E(2) D(30) D(31) C(320) C(321) C(322) C(323) C(324) C(325) B(3260) B(3261) B(3262) B(3263) A(32640) A(32641) A(32642) and I compile it like: ./xgcc -B ./ -c -g -fpic -ffat-lto-objects -flto -O0 -o foo1.o foo1.c -ffunction-sections ./xgcc -B ./ -shared -g -fpic -flto -O0 -o foo1.so foo1.o /tmp/ccTW8mBm.debug.temp.o: file not recognized: file format not recognized If I add -save-temps, and readelf -WS foo1.o.debug.temp.o I see various errors: readelf: foo1.o.debug.temp.o: Warning: Section 2 has an out of range sh_link value of 65321 readelf: foo1.o.debug.temp.o: Warning: Section 5 has an out of range sh_link value of 65321 readelf: foo1.o.debug.temp.o: Warning: Section 10 has an out of range sh_link value of 65323 There are 13 section headers, starting at offset 0x40: readelf: foo1.o.debug.temp.o: Warning: [ 2]: Link field (65321) should index a symtab section. readelf: foo1.o.debug.temp.o: Warning: [ 5]: Link field (65321) should index a symtab section. readelf: foo1.o.debug.temp.o: Warning: [10]: Link field (65323) should index a string section. Section Headers: [Nr] Name Type Address Off Size ES Flg Lk Inf Al [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 [ 1] .debug_info PROGBITS 0000000000000000 000380 057ac7 00 0 0 1 [ 2] .rela.debug_info RELA 0000000000000000 057e48 0bf4c0 18 I 65321 1 8 [ 3] .debug_abbrev PROGBITS 0000000000000000 117308 00002f 00 0 0 1 [ 4] .debug_line PROGBITS 0000000000000000 117337 000036 00 0 0 1 [ 5] .rela.debug_line RELA 0000000000000000 117370 000048 18 I 65321 4 8 [ 6] .debug_str PROGBITS 0000000000000000 1173b8 04fbb7 01 MS 0 0 1 [ 7] .debug_line_str PROGBITS 0000000000000000 166f6f 00001c 01 MS 0 0 1 [ 8] .comment PROGBITS 0000000000000000 166f8b 00002b 01 MS 0 0 1 [ 9] .note.GNU-stack PROGBITS 0000000000000000 166fb6 000000 00 0 0 1 [10] .symtab SYMTAB 0000000000000000 166fb8 23dfa8 18 65323 65315 8 [11] .strtab STRTAB 0000000000000000 3a4f60 04fb36 00 0 0 1 [12] .shstrtab STRTAB 0000000000000000 3f4a96 000097 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), l (large), p (processor specific) The sh_link fields containing 65321 looks to be a bug, it should be 10 instead. 65323 should be 11 (index of .strtab), 65315 is probably ok (that is how many STB_LOCAL symbols are in .symtab).