-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Description
Bugzilla Link | 38105 |
Resolution | FIXED |
Resolved on | Jul 23, 2018 15:35 |
Version | unspecified |
OS | Windows NT |
Reporter | LLVM Bugzilla Contributor |
CC | @pcc,@rnk |
Extended Description
When a function is declared dllimport but called directly (i.e. in the same binary), a non-LTO build will issue a warning but still succeed (same as MSVC). LTO and ThinLTO builds fail with linkage complaints.
This is preventing Firefox's use of LTO on Windows: https://bugzilla.mozilla.org/show_bug.cgi?id=1448976
clang version 7.0.0 (trunk 336407)
$ cat a.cpp
__declspec(dllimport) int foo();
int main() { return foo(); }
$ cat b.cpp
int foo() { return 42; }
$ cat test.sh
#!/bin/bash
rm -rf *.obj *.exe
clang-cl $FLAG -O2 -c a.cpp b.cpp
lld-link -nodefaultlib -entry:main a.obj b.obj
$ ./test.sh
lld-link.exe: warning: a.obj: locally defined symbol imported: ?foo@@yahxz (defined in b.obj) [LNK4217]
$ FLAG=-flto ./test.sh
Global is external, but doesn't have external or weak linkage!
i32 ()* @"?foo@@yahxz"
LLVM ERROR: Broken module found, compilation aborted!
$ FLAG=-flto=thin ./test.sh
lld-link.exe: error: undefined symbol: ?foo@@yahxz
referenced by lto.tmp:(main)