https://bugs.llvm.org/show_bug.cgi?id=43696

            Bug ID: 43696
           Summary: wasm-ld satisfies weak external from archive
           Product: lld
           Version: unspecified
          Hardware: Other
                OS: other
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: wasm
          Assignee: unassignedb...@nondot.org
          Reporter: dan433...@gmail.com
                CC: llvm-bugs@lists.llvm.org, s...@chromium.org

wasm-ld (in LLVM 9.0) is pulling in symbols from an archive to satisfy weak
external references, which is different from what ELF linkers do, and precludes
a common use case.

Consider this testcase:

```c
#include <stdio.h>

extern int x __attribute__((weak));

int main(void) {
    if (&x) {
        printf("we have x: %d\n", x);
    }
    return 0;
}
```

This shouldn't cause `x` to be linked by itself, because `x` is weak, even if
`x` is available in an archive library. But if I create an archive library
containing this:

```c
int x = 42;
```

then `x` does get linked.

With the above snippets in a.c and b.c respectively, this command-line
reproduces the issue with wasi-sdk (clang configured to target wasm32 by
default):

$ clang -c b.c && llvm-ar crs b.a b.o && clang a.c b.a -Wl,-y,x
/tmp/a-5e48c9.o: reference to x
b.a: lazy definition of x

For comparison, on an ELF target, I get this:

$ clang -c b.c && llvm-ar crs b.a b.o && clang a.c b.a -Wl,-y,x
/tmp/a-4c66f3.o: reference to x

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to