Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kateinoigakukun opened this issue Jun 2, 2022 · 1 comment
Labels

Comments

@kateinoigakukun
Copy link
Member

kateinoigakukun commented Jun 2, 2022

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.

@llvmbot
Copy link
Member

llvmbot commented Jun 2, 2022

@llvm/issue-subscribers-lld-wasm

kateinoigakukun added a commit to kateinoigakukun/llvm-project that referenced this issue Jun 3, 2022
As well as ELF linker does, retain all data segments named X referenced
through `__start_X` or `__stop_X`.

This fixes llvm#55839
MaxDesiatov pushed a commit to swiftlang/swift-package-manager that referenced this issue Jul 10, 2022
…ns (#5638)

Now wasm-ld strips data segments referenced through __start/__stop symbols
during GC, and it removes Swift metadata sections like swift5_protocols
We should add support of SHF_GNU_RETAIN-like flag for __attribute__((retain))
to LLVM and wasm-ld. For now, just disable section GC for Wasm target.

Context:
llvm/llvm-project#55839
https://reviews.llvm.org/D126950#3558050
kateinoigakukun added a commit to swiftwasm/swift-package-manager that referenced this issue Jul 10, 2022
…ns (swiftlang#5638)

Now wasm-ld strips data segments referenced through __start/__stop symbols
during GC, and it removes Swift metadata sections like swift5_protocols
We should add support of SHF_GNU_RETAIN-like flag for __attribute__((retain))
to LLVM and wasm-ld. For now, just disable section GC for Wasm target.

Context:
llvm/llvm-project#55839
https://reviews.llvm.org/D126950#3558050
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants