emscripten-core / emscripten-core/emscripten
em++: error: undefined exported symbol: "_LLVMAddSymbol" [-Wundefined] [-Werror]
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
# Bug
I'm trying to build LLVM (plus some subprojects) and I'm getting this error no matter what I do:
```
em++: error: undefined exported symbol: "_LLVMAddSymbol" [-Wundefined] [-Werror]
```
I don't think it's super important what [this function is/does](https://github.com/llvm/llvm-project/blob/6ec8c4351cfc1d0627d1633b02ea787bd29c77d8/llvm/include/llvm-c/Support.h#L65) but it is in fact unused in the LLVM codebase itself **and it is part of LLVM's C API**. So it's in a header somewhere and wrapped in `extern "C"` and etc.
The full link line is
```
/eudsl/scripts/llvm_wasm/.pyodide_build/pywasmcross_symlinks/c++ -fPIC -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wno-pass-failed -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wundef -Werror=mismatched-tags -Werror=global-constructors -O3 -DNDEBUG -sALLOW_TABLE_GROWTH -sASSERTIONS -sWASM_BIGINT -Wl,--color-diagnostics -Wl,--gc-sections -shared -Wl,-soname,libmlir_c_runner_utils.so -o lib/libmlir_c_runner_utils.so tools/mlir/lib/ExecutionEngine/CMakeFiles/mlir_c_runner_utils.dir/CRunnerUtils.cpp.o tools/mlir/lib/ExecutionEngine/CMakeFiles/mlir_c_runner_utils.dir/SparseTensorRuntime.cpp.o lib/libMLIRSparseTensorRuntime.a lib/libLLVMSupport.a lib/libmlir_float16_utils.so -lrt -lm lib/libLLVMDemangle.a
```
Here's the utterly baffling part:
```shell
(venv) root@b0a8b42982ce:/eudsl# /emsdk/upstream/bin/llvm-nm scripts/llvm_wasm/build/lib/libLLVMSupport.a | grep -C3 LLVMAddSymbol
scripts/llvm_wasm/build/lib/libLLVMSupport.a:blake3_neon.c.o: no symbols
scripts/llvm_wasm/build/lib/libLLVMSupport.a:AutoConvert.cpp.o: no symbols
DynamicLibrary.cpp.o:
0000000c d .L.str
00000e68 T LLVMAddSymbol
00000da2 T LLVMLoadLibraryPermanently
00000e5d T LLVMSearchForAddressOfSymbol
```
i.e., the symbol is in `lib/libLLVMSupport.a` I believe (the leading `_` prefix notwithstanding).
# Things I've tried
Mostly toggling `LLVM_ENABLE_PIC` (i.e., `-fPIC`) and `LLVM_BUILD_STATIC`. I also tried various permutations of `-sERROR_ON_UNDEFINED_SYMOLS=0` and finally landed on `-Wno-undefined` which does silence the error **but just kicks the can down the road** (the shlib fails to load).
I also tried commenting out the decl of that function in its header and that just uncovers more such unused decls in headers - naturally it's not practical to patch all of these out...
# Version info
This is happening on `4.0.9`:
```
(venv) root@b0a8b42982ce:/eudsl# emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.9 (bbf1caa6e24f64fca9eb6a13a9e02d3f42123e77)
clang version 21.0.0git (https:/github.com/llvm/llvm-project 2f05451198e2f222ec66cec4892ada0509519290)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /emsdk/upstream/bin
```
The other baffling part is I can actually successfully do all what I'm trying to do on `3.1.58`. I haven't tried bisecting but something broke somewhere along the line 🤷.
# Related
Possibly related to https://github.com/emscripten-core/emscripten/issues/21516 but the issue identifies `3.1.52` as the source while like I said I have a working build on `3.1.58` 🤷.
Contributor guide
Assessment
This issue has not been assessed yet.