Lld automatically hide symbols with __ prefix?

Hello everyone, first time posting here. I’ve a question regarding how LLD handle symbols with __ prefix, which appears to be different from GNU linker. I’m trying to statically link another llvm project compiler-rt into a shared library. The functions in libclang_rt are Global Function:

nm /Users/khu/miniconda3/envs/rt/lib/clang/14.0.6/lib/darwin/libclang_rt.osx.a | grep ___divtc3
0000000000000000 T ___divtc3

However, if I try to export the ___divtc3 symbol, LLD warns me of hidden symbol:

❯ clang++ -dynamiclib -o dummy.dylib  -L/Users/khu/miniconda3/envs/rt/lib -Wl,-search_paths_first  /Users/khu/miniconda3/envs/rt/lib/clang/14.0.6/lib/darwin/libclang_rt.osx.a  -Wl,-exported_symbol,___divtc3
ld: warning: cannot export hidden symbol ___divtc3 from /Users/khu/miniconda3/envs/rt/lib/clang/14.0.6/lib/darwin/libclang_rt.osx.a(divtc3.c.o)

Some more context here…Statically link compiler-rt by oliverhu · Pull Request #986 · numba/llvmlite · GitHub, thanks in advance!

That symbol is very likely hidden in the static library as well. nm -m will give you additional information on the symbol, and it’ll be marked private_extern if it’s hidden.

You’re right… thanks!

/Users/khu/miniconda3/envs/rt/lib/clang/14.0.6/lib/darwin/libclang_rt.osx.a(divtc3.c.o):
0000000000000000 (__TEXT,__text) private external ___divtc3
                 (undefined) external _logbl
                 (undefined) external _scalbnl
1 Like