<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 - [ThinLTO] externally visible linkonce_odr object is incorrectly internalized"
href="https://bugs.llvm.org/show_bug.cgi?id=41645">41645</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[ThinLTO] externally visible linkonce_odr object is incorrectly internalized
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</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>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>eleviant@accesssoftek.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Symbol with linkonce_odr linkage whose prevailing definition is in regular
object file can be incorrectly internalized by ThinLTO.
Steps to reproduce:
1) Create following C++ source files (struct.h, main.cpp, init.cpp)
// File: struct.h
template <class T>
struct Singleton {
static __attribute__((noinline)) T& getInstance() throw() {
static T instance;
return instance;
}
};
struct S : public Singleton<S> {
long a = 0;
};
static inline S* getS() {
S& os = S::getInstance();
return os.a ? &os : nullptr;
}
// File: main.cpp
#include "struct.h"
void init();
int main() {
init();
return getS()->a;
}
// File: init.cpp
#include "struct.h"
void init() {
S::getInstance().a = 1;
}
2) Compile init.cpp to regular object
clang -c init.cpp
3) Compile main.cpp in thin LTO mode
clang -c -flto=thin main.cpp
4) Link program. It is important that init.o goes before main.o in command line
params
clang -flto=thin -fuse-ld=lld init.o main.o
5) Run a.out. Program will crash because getS() returns zero in main function.
This happens because static instance variable is incorrectly internalized by
thin LTO, so finally init and main functions access two different copies of it.</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>