This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Don't change binding to STB_WEAK for an undefined specified by -u
ClosedPublic

Authored by MaskRay on Oct 6 2020, 10:13 PM.

Details

Summary

Similar to D66992.
In GNU ld, a -u specified symbol is a STB_DEFAULT undefined.
It cannot be changed to STB_WEAK by a later STB_WEAK undefined in a regular object file.

The behavior is consistent with our model because -u means "we need to fetch a lazy definition".
It should not be altered just because there is also a STB_WEAK undefined.

Note, our -u semantics are still different from GNU ld (https://github.com/ClangBuiltLinux/linux/issues/515):
we don't force the specified symbol to appear in .symtab This is a deliberate decision.

Diff Detail

Event Timeline

MaskRay created this revision.Oct 6 2020, 10:13 PM
MaskRay requested review of this revision.Oct 6 2020, 10:13 PM
grimar added inline comments.Oct 7 2020, 12:48 AM
lld/test/ELF/weak-undef-lib.s
23

Perhaps, CHECK1 -> CHECK-UNDEF or just UNDEF.

27

Show binding?

troyj added a subscriber: troyj.Oct 7 2020, 7:14 AM
troyj added a comment.Oct 7 2020, 7:26 AM

This patch fixes the problem that I encountered downstream linking -u foo a.o b.a where foo is weak in a.o and provided in b.a.

MaskRay updated this revision to Diff 296697.Oct 7 2020, 8:45 AM
MaskRay marked an inline comment as done.

Improve tests

MaskRay marked an inline comment as done.Oct 7 2020, 8:45 AM
MaskRay edited the summary of this revision. (Show Details)Oct 7 2020, 8:55 AM
grimar accepted this revision.Oct 8 2020, 1:57 AM

LGTM

This revision is now accepted and ready to land.Oct 8 2020, 1:57 AM
This revision was landed with ongoing or failed builds.Oct 8 2020, 8:31 AM
This revision was automatically updated to reflect the committed changes.