[ELF] Avoid wrapping unreferenced lazy symbols
authorShoaib Meenai <smeenai@fb.com>
Wed, 2 Feb 2022 07:59:50 +0000 (23:59 -0800)
committerShoaib Meenai <smeenai@fb.com>
Sat, 5 Feb 2022 02:09:37 +0000 (18:09 -0800)
commit997f2a56dea16a8b0a8827ca00cbaa21fbcd2338
tree2f0d60e40efe6aeed93c50bac86b8ca2841f63d2
parent34de63c37fa968048cc09cb46371fd8a3bef0c4d
[ELF] Avoid wrapping unreferenced lazy symbols

There's a couple of motivations here:
* LLD 12 (which I was originally testing with) was adding an undefined
  symbol to the symbol table if you attempted to wrap an unreferenced
  lazy symbol, which would later break `--no-allow-shlib-undefined`. LLD
  on main actually produces a weak undefined symbol, so this doesn't
  break anyway, but it's cleaner to not have the weak undefined symbol
  as well. The new behavior also matches bfd and gold.
* PROVIDE in a linker script referencing a wrapped symbol would think
  that an otherwise-unreferenced lazy symbol which was wrapped was
  actually referenced, and therefore proceed with the definition, which
  goes against expectations. The new behavior also matches bfd and gold.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D118756
lld/ELF/Driver.cpp
lld/test/ELF/wrap-lazy.test [new file with mode: 0644]