llvm / llvm/llvm-project

Can't build working `libc++.dylib` with `lld` on macOS

Open
#179,328 1 comment 2 reactions 0 assignees View on GitHub
build-problem libc++ platform:macos
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

In macOS builds, [here](https://github.com/llvm/llvm-project/blob/63195d3d7a8bde05590f91a38398f986bb4265b2/libcxxabi/src/CMakeLists.txt#L243), we use `reexported_symbols_list` to make sure that `libc++abi` symbols are re-exported from `libc++`. However, this option is [not yet implemented](https://github.com/llvm/llvm-project/blob/d0e98909d28be377408b1e52fa35423a2236036c/lld/MachO/Options.td#L631) in `lld`. When we try to build `libc++.dylib` with `lld` built from source, this warns about the option not being implemented and creates a `dylib` that causes any loading binaries to crash on load due to missing symbols that were meant to be re-exported (e.g., `__cxa_pure_virtual`).

It seems that libc++ _only_ builds right now with Apple's `ld`, preventing two-stage builds from working on macOS.

Not sure how to fix this, but I noticed that `lld` does re-export when we use `exported_symbols_list`, perhaps we could detect LLD being enabled and then use `exported_symbols_list` rather than `reexported_symbols_list` in that case?

Contributor guide

Open the contributing guide

Research direction

Start with libcxxabi/src/CMakeLists.txt at the reexported_symbols_list option and compare it with lld/MachO/Options.td, where that option is marked unimplemented. Build libc++.dylib with lld and verify that the resulting library re-exports the required libc++abi symbols, such as __cxa_pure_virtual, without load-time crashes.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp, macos
Domain
build-system, compilers, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.