Issue 150739
Summary lld mingw undefined weak symbol, --wrap, import library, and relocation results in garbage pointer
Labels lld, lld:COFF
Assignees
Reporter jeremyd2019
    There are several moving parts here that seem to be necessary to reproduce this, so bear with me.  This is an attempt to reduce something from a more complicated situation inside Cygwin startup code.

testreal.c
```c
void foo (void)
{ }
```

testweak.c
```c
void __wrap_foo (void)
{ }

extern __attribute__ ((weak)) void foo (void) __asm__ ("__real_foo");

void (*bar)(void) = &foo;

int main (void)
{
        return !!bar;
}
```

```
clang -shared -o testreal.dll -Wl,-out-implib,testreal.a testreal.c -Wl,--wrap,foo
clang -o testweak testweak.c testreal.a -fuse-ld=lld -Wl,--wrap,foo
```

With lld running testweak returns 1, with bfd it returns 0.  If you inspect the pointer in a debugger, it is garbage with lld.
```
Thread 1 hit Breakpoint 1, 0x00007ff7a3da146f in main ()
(gdb) p (void *)bar
$1 = (void *) 0x7ff663da0000
```

If you remove the dynamicbase flag (so the testweak.exe does not need to be relocated) it returns 0 with lld
```
clang -o testweak testweak.c testreal.a -Wl,--wrap,foo -fuse-ld=lld -Wl,--disable-dynamicbase
```

Tested with x86_64-w64-mingw32 and x86_64-pc-cygwin targets

@mstorsjo @kikairoya @tyan0
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to