[llvm-bugs] [Bug 43696] New: wasm-ld satisfies weak external from archive

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Oct 16 12:56:56 PDT 2019


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: unassignedbugs at nondot.org
          Reporter: dan433584 at gmail.com
                CC: llvm-bugs at lists.llvm.org, sbc at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191016/52b40e20/attachment-0001.html>


More information about the llvm-bugs mailing list