<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/91711>91711</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
thin LTO + wasm + _Thread_local + -pthread doesn't work well
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
yamt
</td>
</tr>
</table>
<pre>
a test code: https://github.com/yamt/garbage/tree/1deee3044926115ca949e4cc7056da819c118663/lto3
symptom:
```shell
spacetanuki% ./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)
spacetanuki%
```
the same program works ok with -flto=full and w/o lto.
the same symptom with clang from LLVM 46435ac19e09039fb146fa6c12da0e640a66d435
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vc2O4zYTfBr60pBAUT-WDjp41uuTBwPMDL4PORktsmUxpkSDpMbrtw8oOTtJsMltFzBMosmuKjer2-i9Pk9ELSufWLnf4BwG69o7jmHTWXVvEQL5ANIqYvkOhhCunuU7Jg5MHM46DHOXSjsycYg5MYauwzMxcQiO4pIpIsp5UTSiyrJSYlM0VEi55WWlsM4amWV1VeVMHEywOeN7xnfrt7-P12DHyLdGK75-_EDGPO5cUVLAab5oJkpImTh0szYq9cMjSTzBly8s3zOxZeJgr1HlDb1OvLokQqQ8puiJiYM0OJ0hefGQ9CZYlu_DoCdIrmFwhAqSgO5MAW7ox1wkC8h65CP4d7qfRwOJBEzlr6IaUU-_iG2hsoCpXenincSoaDpyzrq4SRI_oCOVjDRadwftQWmPxtgbKejuYIJNw3iFjiTOnkAvXDDZ6ODxqg0puOkwABNbDHbUMj4cWBcD3WwuD-QY7AnD7Min_67nQRe3joyVGLSd4PX0_93b8-n56_PL62-n3X7_eno_vp3ejl-fQOIUxXQEsycFeEY9-QCTnZL34xv4-9hZA6zi36LRfz7xgwn09KmBZESL2Gnn_Spiedm_S9DThVws64iTgh4_i0vf9DoxIAMm6vgQyQcEC54I9PTx0MtE88MW_kev_3UghIHA40hwdfbscISbdRcP9rIS_-m6fjYGoqpbNOxSrR-iPObLmryat3d2hOPxf89QVEVeoswa4g3Pm77LiqrHSmZCIaeq4FhVqsjLFXOj2lw1eYMbarNtVuairot6M7Qi29YlNkS5KkpZqVxV267qe87LXJSF2uhWcFHwMuO8zgpep7LnRd2XTVGKWlVlzwpOI2qTGvMxptadN9r7mdom22bZxmBHxi_zW4iJbrAcMiHiOHdtzEm6-exZwY32wX-iBB0MtUuHHt9fIPZ39NqyOb0vbXmK3jJL5HsTK0t-YmIbluLDjYzZzM60__HXECkfS3J19neScYYsQj0Th-WH_BEAAP__hBcP0g">