[PATCH] D53796: [libcxx] Use AS_NEEDED command for linker script inputs

Petr Hosek via Phabricator reviews at reviews.llvm.org
Sat Oct 27 19:31:20 PDT 2018


phosek added inline comments.


================
Comment at: libcxx/utils/gen_link_script.py:73
     # information.
-    contents = "INPUT(%s %s)" % (linked_libcxx, ' '.join(public_libs))
+    contents = "INPUT(AS_NEEDED(%s %s))" % (linked_libcxx, ' '.join(public_libs))
     print("GENERATING SCRIPT: '%s' as file %s" % (contents, symlink_file))
----------------
MaskRay wrote:
> I don't understand the intention here.
> 
> If the user passes `-lc++` without `--as-needed` before, the user expects to see a `DT_NEEDED` entry for `libc++.so.1`. But with this change. the `DT_NEEDED` entry will not appear.
> 
> (In lld, `libc++abi.so.1` resolves undefined symbols in `libc++.so.1` so it will always be needed (`SharedFile::IsNeeded == true`).)
Passing `-lc++` doesn't imply `DT_NEEDED` because `-lc++` may refer to different things, for example if you only have static library (i.e. `libc++.a`), passing `-lc++` won't create any `DT_NEEDED` entries.

Implementation of the library gets to decide whether its ABI requires `DT_NEEDED` for users that do not link in any symbols. This is a worthwhile optimization since the implementation does have any initializer-time side-effects or weak symbol overrides that are intended to affect the behavior of a program that doesn't have an undefined reference to a libc++ or libc++abi.


Repository:
  rCXX libc++

https://reviews.llvm.org/D53796





More information about the libcxx-commits mailing list