llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.32k stars 12.11k forks source link

[WebAssembly][lld] excessive undefined symbol errors when building a shared library #103592

Open yamt opened 3 months ago

yamt commented 3 months ago

after 22b7b84860d39da71964c9b329937f2ee1d875ba, wasm-ld complains on undefined symbols when building -shared/-pie. it's nice.

however, it even complains on symbols which are expected to be provided/imported by wasm-ld itself. (eg. __heap_base) i consider it a bug.

i saw it while buliding wasi-libc: https://github.com/WebAssembly/wasi-libc/pull/526

a smaller recipe to reproduce: https://github.com/yamt/garbage/tree/master/wasm/ld-shared

with:

clang version 20.0.0git (https://github.com/llvm/llvm-project.git c31ac810910ac87531de636ea508abec6e29e8ff)

spacetanuki% ./test.sh

+ CC=/Volumes/PortableSSD/llvm/build/bin/clang
+ /Volumes/PortableSSD/llvm/build/bin/clang -o liba.so -nostdlib -shared -mexception-handling -fPIC -fvisibility=default -Wl,--no-entry a.c
wasm-ld: warning: creating shared libraries, with -shared, is not yet stable
wasm-ld: error: /var/folders/74/hw1sphgx0lv63q6pq_n5grw00000gn/T/a-7ab945.o: undefined symbol: __heap_base
wasm-ld: error: /var/folders/74/hw1sphgx0lv63q6pq_n5grw00000gn/T/a-7ab945.o: undefined symbol: __heap_end
wasm-ld: error: /var/folders/74/hw1sphgx0lv63q6pq_n5grw00000gn/T/a-7ab945.o: undefined symbol: __cpp_exception
wasm-ld: error: /var/folders/74/hw1sphgx0lv63q6pq_n5grw00000gn/T/a-7ab945.o: undefined symbol: __c_longjmp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
llvmbot commented 3 months ago

@llvm/issue-subscribers-lld-wasm

Author: YAMAMOTO Takashi (yamt)

after 22b7b84860d39da71964c9b329937f2ee1d875ba, wasm-ld complains on undefined symbols when building -shared/-pie. it's nice. however, it even complains on symbols which are expected to be provided/imported by wasm-ld itself. (eg. __heap_base) i consider it a bug. i saw it while buliding wasi-libc: https://github.com/WebAssembly/wasi-libc/pull/526 a smaller recipe to reproduce: https://github.com/yamt/garbage/tree/master/wasm/ld-shared with: ``` clang version 20.0.0git (https://github.com/llvm/llvm-project.git c31ac810910ac87531de636ea508abec6e29e8ff) ``` spacetanuki% ./test.sh ``` + CC=/Volumes/PortableSSD/llvm/build/bin/clang + /Volumes/PortableSSD/llvm/build/bin/clang -o liba.so -nostdlib -shared -mexception-handling -fPIC -fvisibility=default -Wl,--no-entry a.c wasm-ld: warning: creating shared libraries, with -shared, is not yet stable wasm-ld: error: /var/folders/74/hw1sphgx0lv63q6pq_n5grw00000gn/T/a-7ab945.o: undefined symbol: __heap_base wasm-ld: error: /var/folders/74/hw1sphgx0lv63q6pq_n5grw00000gn/T/a-7ab945.o: undefined symbol: __heap_end wasm-ld: error: /var/folders/74/hw1sphgx0lv63q6pq_n5grw00000gn/T/a-7ab945.o: undefined symbol: __cpp_exception wasm-ld: error: /var/folders/74/hw1sphgx0lv63q6pq_n5grw00000gn/T/a-7ab945.o: undefined symbol: __c_longjmp clang: error: linker command failed with exit code 1 (use -v to see invocation) ```