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

thin LTO + wasm + _Thread_local + -pthread doesn't work well #91711

Open yamt opened 6 months ago

yamt commented 6 months ago

a test code: https://github.com/yamt/garbage/tree/1deee3044926115ca949e4cc7056da819c118663/lto3

symptom:

% ./build.sh
+ CC='/opt/wasi-sdk-22.0/bin/clang -Os -flto=thin -pthread -target wasm32-wasi-threads'
+ /opt/wasi-sdk-22.0/bin/clang -Os -flto=thin -pthread -target wasm32-wasi-threads -c a.c
+ /opt/wasi-sdk-22.0/bin/clang -Os -flto=thin -pthread -target wasm32-wasi-threads -c main.c
+ /opt/wasi-sdk-22.0/bin/clang -Os -flto=thin -pthread -target wasm32-wasi-threads main.o a.o
wasm-ld: error: --shared-memory is disallowed by lto.tmp because it was not compiled with 'atomics' or 'bulk-memory' features.
wasm-ld: error: lto.tmp: relocation R_WASM_MEMORY_ADDR_TLS_SLEB cannot be used against non-TLS symbol `x`
wasm-ld: error: lto.tmp: relocation R_WASM_MEMORY_ADDR_TLS_SLEB cannot be used against `x` in non-TLS section: .bss
clang: error: linker command failed with exit code 1 (use -v to see invocation)
% 

the same program works ok with -flto=full and w/o LTO.

the same symptom with Clang from LLVM 46435ac19e09039fb146fa6c12da0e640a66d435

EugeneZelenko commented 6 months ago

@teresajohnson

teresajohnson commented 6 months ago

@MaskRay since this is coming from lld