This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Set the priority of STB_GNU_UNIQUE the same as STB_WEAK
ClosedPublic

Authored by MaskRay on Feb 27 2022, 7:10 PM.

Details

Summary

In GCC -fgnu-unique output, STB_GNU_UNIQUE symbols are always defined relative
to a section in a COMDAT group. Currently other cannot be STB_GNU_UNIQUE for
valid input, so this patch is NFC.

If we switch to the model that ignores COMDAT resolution when performing symbol
resolution (D120626), this will fix bogus `relocation refers to a symbol in a
discarded section` errors when mixing -fno-gnu-unique objects with -fgnu-unique
objects.

Diff Detail

Event Timeline

MaskRay created this revision.Feb 27 2022, 7:10 PM
MaskRay requested review of this revision.Feb 27 2022, 7:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 27 2022, 7:10 PM
peter.smith added inline comments.Feb 28 2022, 10:07 AM
lld/ELF/Symbols.cpp
511

Compare is probably a bit generic a name. I think it is only called from resolveDefined(). Perhaps shouldReplace.

536

Presumably an existing STB_GNU_UNIQUE is also preferred over an incoming STB_WEAK because if it exists it must have come from a prevailing COMDAT?

May be worth adding that to the comment?

lld/test/ELF/comdat-binding.s
13

If I've understood this run, we've got a prevailing group from w.o so we'd expect to see the STB_WEAK symbol and not the STB_GLOBAL. Although looking at reason the code was added (to stop a STB_GNU_UNIQUE from a non prevailing group replacing a STB_WEAK), I'm wondering why as return !isGlobal() && other.isGlobal(); would imply that it should. Perhaps I need to understand https://reviews.llvm.org/D120626 first?

MaskRay updated this revision to Diff 411838.Feb 28 2022, 10:31 AM
MaskRay marked 2 inline comments as done.

improve comment

MaskRay added inline comments.Feb 28 2022, 10:33 AM
lld/ELF/Symbols.cpp
511

Change separately

lld/test/ELF/comdat-binding.s
13

If I've understood this run, we've got a prevailing group from w.o so we'd expect to see the STB_WEAK symbol and not the STB_GLOBAL.

Yes.

This will be changed after D120626 when we ignore COMDAT resolution when deciding whether an incoming Defined replaces an existing Defined. The existing-weak-incoming-global case is the new code cannot handle but fortunately this doesn't happen in the wild.

Thanks I'll try and look at D120626 tomorrow.

This revision was not accepted when it landed; it landed in state Needs Review.Mar 14 2022, 12:00 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 14 2022, 12:00 PM