mold
mold copied to clipboard
Mold 2.40.1 produces broken binary when statically linking with libc++ but not libc
Hi,
The following setup to build a C++ application with a statically linked libc++ but dynamically linked libc works with GNU ld/gold, and LLVM lld but produces a binary which segfaults in _start when using mold.
To reproduce:
> clang++ hello.cpp -fuse-ld=mold -stdlib=libc++ -nostdlib++ -Wl,--push-state,-Bstatic -lc++ -lc++abi -Wl,--pop-state
> ./a.out
Segmentation fault (core dumped)
hello.cpp is about what you would expect:
#include <iostream>
int main()
{
std::cout<<"Hello libc++!\n";
}
When I replace -fuse-ld=mold with -fuse-ld=ld, -fuse-ld=lld or -fuse-ld=gold the problem seems to fix itself.
And here are the versions of mold and clang:
> mold -v
mold 2.40.1 (96c798d7be595d833f3f7d33ca32fd43f2731b89; compatible with GNU ld)
> clang++ -v
clang version 20.1.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/13.3.1
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/14.3.1
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/15.1.1
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.3.1
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/14.3.1
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.1.1
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.1.1
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
Hopefully this is enough to reproduce the issue. Thanks!