[libcxx-commits] [PATCH] D81190: [libc++] Link against libatomic when it is found

Loïc Yhuel via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jul 22 10:25:49 PDT 2021


loic.yhuel added a comment.

In D81190#2896925 <https://reviews.llvm.org/D81190#2896925>, @ldionne wrote:

> Does this commit not work on your system? It has been working on our Linux bots since it was committed.

I don't remember if I found a case which needed the library.
My question was more : on which system does linking `libc++` with `libatomic` help ?

If the platform doesn't need libatomic for the particular usecase, then the `-latomic` for `libc++.so` means the commit triggers a load a `libatomic.so` at runtime.
So the commit wouldn't break anything, but it would add a useless dependency.

But if libatomic is actually required, I think there must be a `-latomic` when linking the binary which uses the symbols (then also linking `libc++.so` with it doesn't change anything).
On Linux, when linking an executable (or a shared library with `-Wl,--no-undefined`), the linker checks all symbols referenced in the object files are actually resolved by the direct dependencies.
So while loading `libatomic.so` indirectly would be enough to resolve the symbols at runtime, on Linux at least the linker would mandate a direct link anyway.

> Regarding adding `-latomic` to the linker script, I don't know that we actually want to do that. I think the Clang driver should probably be the one to pass the correct `-latomic` or `-l<library-for-builtins>` depending on what builtin library we're using.

The idea of a using the linker script was that any user of libc++.so would automatically link to `libatomic.so` when it's required (but not if it isn't), as if it were specified as `-Wl,--push-state -Wl,--as-needed -latomic -Wl,--pop-state`.
This would even apply to gcc using libc++ for example.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81190



More information about the libcxx-commits mailing list