[Bug lto/96385] [8/9/10/11 Regression] GCC generates separate debug info with undefined symbols without relocations
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96385 --- Comment #17 from CVS Commits --- The master branch has been updated by Richard Biener : https://gcc.gnu.org/g:b32c5d0b72fda2588b4e170e75a9c64e4bf266c7 commit r11-2506-gb32c5d0b72fda2588b4e170e75a9c64e4bf266c7 Author: Richard Biener Date: Mon Aug 3 15:05:37 2020 +0200 lto/96385 - avoid unused global UNDEFs in debug objects Unused global UNDEFs can have side-effects in some circumstances so the following patch avoids them by treating them the same as other to be discarded DEFs - make them local. 2020-08-03 Richard Biener PR lto/96385 libiberty/ * simple-object-elf.c (simple_object_elf_copy_lto_debug_sections): Localize global UNDEFs and reuse the prevailing name.
[Bug lto/96385] [8/9/10/11 Regression] GCC generates separate debug info with undefined symbols without relocations
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96385 --- Comment #16 from Alan Modra --- It looks fine to me, assuming you don't need to keep any of these undefined symbols.
[Bug lto/96385] [8/9/10/11 Regression] GCC generates separate debug info with undefined symbols without relocations
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96385 Richard Biener changed: What|Removed |Added CC||amodra at gcc dot gnu.org --- Comment #15 from Richard Biener --- I also wonder if the result of the patch, 34: 0 NOTYPE WEAK HIDDEN 1 t.c.5958f17d 35: 0 NOTYPE WEAK HIDDEN UND t.c.5958f17d 36: 0 NOTYPE WEAK HIDDEN UND t.c.5958f17d 37: 0 NOTYPE WEAK HIDDEN UND t.c.5958f17d is in any way "safer" from an ELF perspective (not so much GNU ld since we've dealt with Solaris and HP-UX linker issues in the past). Alan, you fiddled with this earlier so any comments?
[Bug lto/96385] [8/9/10/11 Regression] GCC generates separate debug info with undefined symbols without relocations
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96385 --- Comment #14 from Richard Biener --- Note the symbol table entry should be "unused" (if there's anything like that). At least ld usually treats it like so. IIRC I left those dangling because UNDEFs into the copied .debug_info section are bogus - and I did not want to parse relocation sections to see where it is referenced from (otherwise I'd assert for such UNDEFs). I know it's all a bit awkward but originally this was supposed to be a temporary measure until ld + plugin API understands how to only partly claim an object and make ld link the original .gnu.debuglto_ prefixed debug-info sections unchanged into the final object ... So you basically found a case where ld does _not_ treat the UNDEF as "unused". In case that is not a bug in ld I am not really understanding how the bug manifests which means I have a hard time creating a testcase for GCCs LTO testsuite :/ Now the patch itself should be quite safe (we shouldn't be left with any global UNDEFs). But I'm curious if it resolves a "real" bug...
[Bug lto/96385] [8/9/10/11 Regression] GCC generates separate debug info with undefined symbols without relocations
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96385 --- Comment #13 from Richard Biener --- (In reply to Richard Biener from comment #12) > (In reply to H.J. Lu from comment #10) > > (In reply to H.J. Lu from comment #8) > > > The original pr26324a.o debug info contains reference to xxx. But > > > reference > > > to xxx has been removed by LTO. simple_object_copy_lto_debug_sections > > > fails > > > to remove the un-referenced symbol, xxx, from symbol table. > > > > The alternative is to ask linker to handle it: > > > > https://sourceware.org/pipermail/binutils/2020-July/112673.html > > The bug is we create the reference in the first place. Oh, I see. So we had multiple choices for "pruning" symbols from the symbol table during simple_object_copy_lto_debug_sections and factoring in HP-UX and Solaris (sic!...) emptying UND symbol names didn't work out. So we do now if (discard) { /* Make discarded symbols undefined and unnamed in case it is local. */ int bind = ELF_ST_BIND (*st_info); int other = STV_DEFAULT; if (bind == STB_LOCAL) { /* Make discarded local symbols unnamed and defined in the first prevailing section. */ ELF_SET_FIELD (type_functions, ei_class, Sym, ent, st_name, Elf_Word, 0); ELF_SET_FIELD (type_functions, ei_class, Sym, ent, st_shndx, Elf_Half, sh_map[first_shndx]); } else { /* Make discarded global symbols hidden weak undefined and sharing a name of a prevailing symbol. */ bind = STB_WEAK; other = STV_HIDDEN; ELF_SET_FIELD (type_functions, ei_class, Sym, ent, st_name, Elf_Word, prevailing_name_idx); ELF_SET_FIELD (type_functions, ei_class, Sym, ent, st_shndx, Elf_Half, SHN_UNDEF); } *st_other = other; *st_info = ELF_ST_INFO (bind, STT_NOTYPE); ELF_SET_FIELD (type_functions, ei_class, Sym, ent, st_value, Elf_Addr, 0); ELF_SET_FIELD (type_functions, ei_class, Sym, ent, st_size, Elf_Word, 0); } but somehow the else path isn't triggered(?). Note that all we try to avoid is the need to rewrite relocation sections if we really would prune symbols rather than NULL-ifying them somehow. You can trace history as to how the above code morphed with various bugs in the past... Hmm, we don't treat SHN_UNDEF any special here - I guess we could at most make all of them WEAK ... the following should address this. diff --git a/libiberty/simple-object-elf.c b/libiberty/simple-object-elf.c index c62d5bba551..7c9d492f6a4 100644 --- a/libiberty/simple-object-elf.c +++ b/libiberty/simple-object-elf.c @@ -1467,6 +1467,11 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj, && st_shndx < shnum && pfnret[st_shndx - 1] == -1) discard = 1; + /* We also need to remove global UNDEFs which can +cause link fails later. */ + else if (st_shndx == SHN_UNDEF + && ELF_ST_BIND (*st_info) == STB_GLOBAL) + discard = 1; if (discard) {
[Bug lto/96385] [8/9/10/11 Regression] GCC generates separate debug info with undefined symbols without relocations
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96385 Richard Biener changed: What|Removed |Added Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot gnu.org --- Comment #12 from Richard Biener --- (In reply to H.J. Lu from comment #10) > (In reply to H.J. Lu from comment #8) > > The original pr26324a.o debug info contains reference to xxx. But reference > > to xxx has been removed by LTO. simple_object_copy_lto_debug_sections fails > > to remove the un-referenced symbol, xxx, from symbol table. > > The alternative is to ask linker to handle it: > > https://sourceware.org/pipermail/binutils/2020-July/112673.html The bug is we create the reference in the first place.
[Bug lto/96385] [8/9/10/11 Regression] GCC generates separate debug info with undefined symbols without relocations
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96385 H.J. Lu changed: What|Removed |Added Summary|GCC generates separate |[8/9/10/11 Regression] GCC |debug info with undefined |generates separate debug |symbols without relocations |info with undefined symbols ||without relocations --- Comment #11 from H.J. Lu --- GCC 7.3.1 is OK: [hjl@gnu-cfl-2 pr26324]$ make /usr/gcc-7.3.1-x32/bin/gcc -B./ -O2 -g -flto -ffat-lto-objects -c -o pr26324a.o pr26324a.c /usr/gcc-7.3.1-x32/bin/gcc -B./ -O2 -g -fPIC -c -o pr15146c.o pr15146c.c /usr/gcc-7.3.1-x32/bin/gcc -B./ -O2 -g -fPIC -c -o pr15146b.o pr15146b.c /usr/gcc-7.3.1-x32/bin/gcc -B./ -shared -o pr15146b.so pr15146b.o /usr/gcc-7.3.1-x32/bin/gcc -B./ -shared -o pr15146c.so pr15146c.o pr15146b.so /usr/gcc-7.3.1-x32/bin/gcc -B./ -O2 -g -o x -Wl,-R,. \ -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed pr26324a.o pr15146c.so ./x PASS [hjl@gnu-cfl-2 pr26324]$