[PATCH] D77512: [ELF] Add --warn-backrefs-exclude=<glob>

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 5 13:21:34 PDT 2020


MaskRay created this revision.
MaskRay added reviewers: grimar, psmith, ruiu.
Herald added subscribers: llvm-commits, arichardson, aprantl, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

D45195 <https://reviews.llvm.org/D45195> added --warn-backrefs to detect

- certain input orders which GNU ld either errors ("undefined reference") or has different resolution semantics
- (byproduct) some latent multiple definition problems (-ldef1 -lref -ldef2) which I call "linking sandwich problems".

When an archive appears more than once (-ldef -lref -ldef), lld and GNU
ld may have the same resolution but --warn-backrefs may warn. This is
not uncommon. For example, currently lld itself has such a problem:

  liblldCommon.a liblldCOFF.a ... liblldCommon.a
    _ZN3lld10DWARFCache13getDILineInfoEmm in liblldCOFF.a refers to liblldCommon.a(DWARF.cpp.o)
  libLLVMSupport.a also appears twice and has a similar warning

glibc has such problems. It is somewhat destined because of its separate
libc/libpthread/... and arbitrary grouping. The situation is getting
improved over time but I have seen:

  -lc __isnanl references -lm
  -lc _IO_funlockfile references -lpthread

There are also various issues in interaction with other runtime
libraries such as libgcc_eh and libunwind:

  -lc __gcc_personality_v0 references -lgcc_eh
  -lpthread __gcc_personality_v0 references -lgcc_eh
  -lpthread _Unwind_GetCFA references -lunwind

To facilitate deployment of --warn-backrefs, add --warn-backrefs-exclude= so that
certain known issues (which may be inpractical to fix) can be whitelisted.

Deliberate choices:

- J<"warn-backrefs-exclude="> instead of Eq<"warn-backrefs">. This option is lld specific. We don't need to follow the lax parsing rule of other GNU ld compatible options.
- Not a comma-separated list (--warn-backrefs-exclude=liba.a,libb.a). -Wl, splits the argument at commas so we cannot use commas. --export-dynamic-symbol is similar.
- Not in the style of `--warn-backrefs='*' --warn-backrefs=-liba.a`. We just need exclusion, not inclusion. For easier build system integration, we should avoid order dependency. With the current scheme, we enable --warn-backrefs, and indivial libraries can add --warn-backrefs-exclude=<glob> to their LDFLAGS.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77512

Files:
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/Options.td
  lld/ELF/Symbols.cpp
  lld/docs/ld.lld.1
  lld/test/ELF/warn-backrefs.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77512.255191.patch
Type: text/x-patch
Size: 6132 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200405/d8919d13/attachment.bin>


More information about the llvm-commits mailing list