[ELF] Don't change binding to STB_WEAK for an undefined specified by -u
authorFangrui Song <i@maskray.me>
Wed, 7 Oct 2020 15:45:24 +0000 (08:45 -0700)
committerFangrui Song <i@maskray.me>
Thu, 8 Oct 2020 15:31:34 +0000 (08:31 -0700)
commitdb1988f038843ad047fdab5b9f818306b06ea80a
treeb7de2cf72d59eef5a2c9b5912a502fba8aef114c
parentb57451b011d39f5a36a8cd6236a49c47692ee89c
[ELF] Don't change binding to STB_WEAK for an undefined specified by -u

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.

Reviewed By: grimar

Differential Revision: https://reviews.llvm.org/D88945
lld/ELF/Driver.cpp
lld/test/ELF/weak-undef-lib.s