<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - ThinLTO undefined ref due to imported DIGlobalVariable reference at -O0"
href="https://llvm.org/bugs/show_bug.cgi?id=30774">30774</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>ThinLTO undefined ref due to imported DIGlobalVariable reference at -O0
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>3.9
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</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>tejohnson@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>jbc.engelen@gmail.com, llvm-bugs@lists.llvm.org, mehdi.amini@apple.com, peter@pcc.me.uk, tejohnson@google.com
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Johan reported an issue hit using the 3.9 compiler and ThinLTO, when building
with -O0 -g. The issue occurs when importing from a module with a const global
variable - while we don't import the global variable definition, we do import
the debug metadata, and in the 3.9 timeframe the DIGlobalVariable metadata
still contained a reference to the associated GlobalVariable. At -O2 the GV
declaration is eliminated as is the reference from the DIGlobalVariable, but at
-O0 we get an undefined reference linker error.
This doesn't occur at head due to pcc's change to reverse the
GlobalVariable/DIGlobalVariable edge (<a href="https://reviews.llvm.org/rL281284">https://reviews.llvm.org/rL281284</a>).
In reality, we shouldn't bother doing any importing at -O0 - inlining is
disabled, so this is just wasted work. My plan is to disable importing and
other ThinLTO optimizations at -O0, both in trunk and in 3.9 (which will fix
this 3.9 issue).
To reproduce:
$ cat global_main.c
extern int foo();
int main() {
return foo();
}
$ cat global.c
const int foobar = 10;
int foo() {
return 1;
}
$ clang -c -O2 global.c global_main.c -flto=thin -g
$ clang global.o global_main.o -flto=thin -g -O0
/tmp/lto-llvm-14880f.o(.debug_info+0x6f): error: undefined reference to
'foobar'
clang-3.9: error: linker command failed with exit code 1 (use -v to see
invocation)</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>