<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - LTO builds fail when dllimport functions are called locally"
href="https://bugs.llvm.org/show_bug.cgi?id=38105">38105</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>LTO builds fail when dllimport functions are called locally
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>dmajor@mozilla.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, llvm@inglorion.net, rnk@google.com, tejohnson@google.com
</td>
</tr></table>
<p>
<div>
<pre>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:
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1448976">https://bugzilla.mozilla.org/show_bug.cgi?id=1448976</a>
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
<span class="quote">>>> referenced by lto.tmp:(main)</span ></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>