bazel-contrib / bazel-contrib/toolchains_llvm
builtin-libc++ not working on macos
- Dominant language
- Starlark
- Stars
- 371
- Forks
- 283
- Avg merge
- 1d 55m
- Merged PRs (30d)
- 25
Description
I've configure a barebones llvm toolchain via:
```
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
llvm.toolchain(
cxx_standard = {"": "c++23"},
stdlib = {"": "builtin-libc++"},
llvm_version = "21.1.6",
)
use_repo(llvm, "llvm_toolchain")
register_toolchains("@llvm_toolchain//:all")
```
However when linking my application it appears to be using the system libc++ not the one from the toolchain as it is unable to find symbols used by the version of the standard library, in particular: `undefined symbol: std::__1::__hash_memory`.
I verified with:
`nm -gU /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libc++.tbd 2>/dev/null | grep __hash_memory` and `nm -gU bazel-whenufree/external/toolchains_llvm++llvm+llvm_toolchain_llvm/lib/libc++.a 2>/dev/null | grep __hash_memory` that the symbol is only present in the builtin version of libc++.
Looking in the link params file I see this snippet which looks off to me, I would expect the order in which search paths are added to have the builtin library ahead of the system library so it is preferred:
```
#... more
-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib
-lc++
-lc++abi
-Bdynamic
-Lexternal/toolchains_llvm++llvm+llvm_toolchain_llvm/lib
# ... more
```
Moving the `-Lexternal/toolchains_llvm++llvm+llvm_toolchain_llvm/lib` above the first line allows the program to link and run.
Contributor guide
Research direction
Start with the llvm.bzl extension and the generated link params from the configuration shown, then trace how macOS SDK and builtin-libc++ library paths are ordered. Reproduce the link using the provided toolchain settings and verify that the builtin library path precedes the SDK path so the application resolves __hash_memory.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100