Issue 84364
Summary [WebAssembly]: `__attribute__((used))` doesn't preserve symbol
Labels new issue
Assignees
Reporter sunfishcode
    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.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to