[clang] [Driver] Normalize the baremetal handling of libc++ and runtimes (PR #101259)
Petr Hosek via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 1 09:57:31 PDT 2024
================
@@ -382,38 +382,6 @@ void BareMetal::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
}
}
-void BareMetal::AddCXXStdlibLibArgs(const ArgList &Args,
- ArgStringList &CmdArgs) const {
- switch (GetCXXStdlibType(Args)) {
- case ToolChain::CST_Libcxx:
- CmdArgs.push_back("-lc++");
- if (Args.hasArg(options::OPT_fexperimental_library))
- CmdArgs.push_back("-lc++experimental");
- CmdArgs.push_back("-lc++abi");
----------------
petrhosek wrote:
The problem with the current implementation is that it assumes that libc++abi is used as the C++ ABI library, but libc++ supports [a number of different C++ ABI library implementations](https://github.com/llvm/llvm-project/blob/c7c5e05389292da7e5a87e3d1d3ef08021911a53/libcxx/CMakeLists.txt#L234), including `none` which may be desirable for some of the baremetal use cases and we use it in some of our embedded targets.
There are two solutions for pulling in the right C++ ABI library without needing to explicitly pass `-lc++abi` to the linker that are already used by other platforms:
1. Replace `libc++.so` and `libc++.a` with an input linker script that pulls in the right C++ ABI library; libc++ build can [generate one for `libc++.so`](https://github.com/llvm/llvm-project/blob/c7c5e05389292da7e5a87e3d1d3ef08021911a53/libcxx/CMakeLists.txt#L266), this could be extended to support `libc++.a` if needed.
2. You can merge `libc++abi.a` into `libc++.a` so you don't need a separate `-lc++abi`, [this is already supported by libc++ build](https://github.com/llvm/llvm-project/blob/c7c5e05389292da7e5a87e3d1d3ef08021911a53/libcxx/CMakeLists.txt#L244).
The advantage of either of these solutions is that Clang driver can remain agnostic to which C++ ABI library the vendor built libc++ against.
@smithp35 Would it be feasible to migrate your toolchain to use either of these solutions?
https://github.com/llvm/llvm-project/pull/101259
More information about the cfe-commits
mailing list