<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/55839>55839</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[wasm-ld] --gc-sections shouldn't strip data segments in input objects referenced by start/stop symbols
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kateinoigakukun
</td>
</tr>
</table>
<pre>
wasm-ld mis-strips live data segments referenced by start/stop symbols.
The linker should keep data segments if any symbol in an object file, which contains the data segment, is referenced and start/stop symbols for the segment are referenced.
For the following case, it works with ELF lld, but doesn't with wasm-ld due to the mis-stripping.
```c
// in foo.c, which is archived as libfoo.a
__attribute__((__section__("foo_md")))
char FOO_MD[] = "bar";
void foo_func(void) {}
// in main.c, which links foo via -lfoo
#include <stdio.h>
extern const char __start_foo_md;
extern const char __stop_foo_md;
extern void foo_func(void);
int main(void) {
printf("__start_foo_md = %p, __stop_foo_md = %p\n", &__start_foo_md, & __stop_foo_md);
foo_func();
return 0;
}
```
```console
$ clang -target wasm32-unknown-unknown -c foo.c && llvm-ar cr libfoo.a foo.o
$ clang -target wasm32-unknown-unknown main.c -lfoo -L. -fuse-ld=lld
wasm-ld: error: /tmp/main-c796ab.o: undefined symbol: __start_foo_md
wasm-ld: error: /tmp/main-c796ab.o: undefined symbol: __stop_foo_md
```
Discussion with @sbc100: https://github.com/WebAssembly/wasi-libc/pull/296
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVcuOozoQ_RqyKRERCHksWHR3JqsZzWakWSJjCvDE2Mg2nZu_v2UgnYB6ru5IEzkBU-XinFOPFLq8ZVdm21CW0AobWmdEZ0GKd4SSOQYW6xaVs2CwQoOKYwnFDaxjxgXx2Trdgb21hZZ2HUSnIHoZf380SFHUBQ3YRvcU_oLYLWKKCpi6TedBKNqBLn4hd1AJiUH8BtdG8Aa4Vo4JZcE1c1ze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