Closed
Description
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.
extern const char __start_foo_md;
extern const char __stop_foo_md;
// referenced through __start_/__stop_ symbols
__attribute__((__section__("foo_md")))
char FOO_MD[] = "bar";
int main(void) {
printf("__start_foo_md = %p, __stop_foo_md = %p\n", &__start_foo_md, & __stop_foo_md);
return 0;
}
$ clang -target wasm32-unknown-unknown main.c -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: WebAssembly/wasi-libc#296
I'll make a patch to address this issue.