[llvm-bugs] [Bug 38105] New: LTO builds fail when dllimport functions are called locally

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jul 9 08:10:33 PDT 2018


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

            Bug ID: 38105
           Summary: LTO builds fail when dllimport functions are called
                    locally
           Product: new-bugs
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: dmajor at mozilla.com
                CC: llvm-bugs at lists.llvm.org, llvm at inglorion.net,
                    rnk at google.com, tejohnson at google.com

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)

-- 
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/20180709/bfb32d41/attachment.html>


More information about the llvm-bugs mailing list