[PATCH] D124056: [ELF] Fix wrapping symbols produced during LTO codegen

Shoaib Meenai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 19 18:26:05 PDT 2022


smeenai created this revision.
smeenai added a reviewer: MaskRay.
Herald added subscribers: ormris, StephenFan, steven_wu, hiraditya, arichardson, inglorion, emaste.
Herald added a project: All.
smeenai requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

We were previously not correctly wrapping symbols that were only
produced during LTO codegen and unreferenced before then, or symbols
only referenced from such symbols. The root cause was that we weren't
marking the wrapped symbol as used if we only saw the use after LTO
codegen, leading to the failed wrapping.

Fix this by explicitly tracking whether a symbol will become referenced
after wrapping is done. We can use this property to tell LTO to preserve
such symbols, instead of overload isUsedInRegularObj for this purpose.
Since we're now not setting isUsedInRegularObj for all symbols which
will be wrapped, its value at the time of performing the wrapping in the
symbol table will accurately reflect whether the symbol was actually
used in an object (including in an LTO-generated object), and we can
propagate that value to the wrapped symbol and thereby ensure we wrap
correctly.

This incorrect wrapping was the only scenario I was aware of where we
produced an invalid PLT relocation, which D123985 <https://reviews.llvm.org/D123985> started diagnosing,
and with it fixed, we lose the test for that diagnosis. I think it's
worth keeping the diagnosis though, in case we run into other issues in
the future which would be caught by it.

Fixes PR50675.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124056

Files:
  lld/ELF/Driver.cpp
  lld/ELF/LTO.cpp
  lld/ELF/SymbolTable.cpp
  lld/ELF/Symbols.h
  lld/test/ELF/invalid-plt-relocation.test
  lld/test/ELF/lto/wrap-unreferenced-before-codegen.test

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124056.423780.patch
Type: text/x-patch
Size: 9940 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220420/885d7619/attachment.bin>


More information about the llvm-commits mailing list