[PATCH] D108006: [lld][ELF] Add --no-search-static-libs-for-shlib-undefined flag

Pirama Arumuga Nainar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 23 22:49:24 PDT 2021


pirama added a comment.

> For the Android problem, it looks like a workaround as well. Do you know why gold linked executables were fine when Android was still using gold?

This worked with gold because static libraries were always ahead of shared libraries in the linker input list.

To preface, I _am_ trying to replace static libs with shared libraries for the failing cases.  In the past, we only considered adding the closure for the static library to the failing cases which quickly got out of hand.  Replacing with shared libraries doesn't cause any bloat but there may be other constraints with vendor libraries and tests which force them to use the static library variant instead of the shared variant.

However, I don't agree that the static linker should consider/handle static libraries and shared libraries equivalently.  Like discussed earlier, `DT_NEEDED` makes defining undefined symbols in shared libraries a "soft" requirement.  OTOH, if all shared libraries are built with `--no-undefined`, the linker is __not__ required at all to include any definition of undef symbols from shared libraries to produce a working program.  Each shared library defines its own closure via DT_NEEDED.

With a single-pass linker, not defining undefs from shared libraries can be achieved with linker input ordering.  With lld, IIUC, we should do the following to achieve this:

  `ld.lld --start-lib <objects> <static-libs> --end-lib <shared-libs> --warn-backrefs`

If this is correct, does it make sense to add a flag to opt into this behavior?  In particular, the flag name `--warn-backrefs` doesn't capture the fact that lld is not trying to resolve some references at all in this configuration.  Such a flag would be more general than the one proposed here and is probably less confusing (and have more users than just Android).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108006/new/

https://reviews.llvm.org/D108006



More information about the llvm-commits mailing list