<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/84364>84364</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[WebAssembly]: `__attribute__((used))` doesn't preserve symbol
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
sunfishcode
</td>
</tr>
</table>
<pre>
It appears `__attribute__((used))` doesn't cause a symbol to be preserved in the final output, on Wasm. Similarly, functions with an `export_name` are not preserved, even though it also has `no_dead_strip` in the output.
Specifically, here's a C testcase where everything is prefixed with "abc" for easy grepping:
```c
__attribute__((export_name("abc-red")))
static void abc_apple(void) {}
__attribute__((used))
static void abc_pear(void) {}
void abc_banana(void) {}
__attribute__((export_name("abc-green")))
void abc_grape(void) {}
```
`abc_apple`, `abc_pear`, and `abc_grape` are all marked with `no_dead_strip`, as expected:
```
$ clang -S -o - test.c | grep no_dead_strip
.no_dead_strip abc_apple
.no_dead_strip abc_pear
.no_dead_strip abc_grape
.no_dead_strip __indirect_function_table
```
However, the only function that gets preserved is `abc_grape`:
```sh
$ clang test.c -o test.wasm
$ wasm-tools print test.wasm | grep abc
(func $abc_grape (;6;) (type 2)
(export "abc-green" (func $abc_grape))
```
So it appears wasm-ld is not honoring no_dead_strip.
I can reproduce with with the clang packages in [wasi-sdk](https://github.com/WebAssembly/wasi-sdk/releases/tag/wasi-sdk-21) and with a build from current wasi-sdk and llvm git sources.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVU1v4j4T_zTmMgIFJ0A4cNgWoWfPPewxmjiTxE8dO_I4pXz7v5ykQFu20kpRION5-_3mxcisG0t0EJsnsTkucAit8wcebK25Va6iRemqy-F3AOx7Qs8gtklRYAhel0OgohAyFzIfmCoh9_HZJlA5YivkLoDCgQkQ-NKVzkBwUBL0npj8G1WgLYSWoNYWDbgh9EMQ8hmchT_I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