Skip to content

[wasm-ld] --gc-sections shouldn't strip data segments in input objects referenced by start/stop symbols #55839

Closed
@kateinoigakukun

Description

@kateinoigakukun

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions