<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 - IR Linking of GlobalAliases does not preserve thread_local attribute"
href="https://bugs.llvm.org/show_bug.cgi?id=46297">46297</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>IR Linking of GlobalAliases does not preserve thread_local attribute
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>Core LLVM classes
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>itay.bookstein@nextsilicon.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>When trying to compile the following code under LTO with a low optimization
level (--lto-O0, for instance), a link error is encountered (relative
relocation against absolute symbol).
This is a bug in the IR linking process whereby the ThreadLocalMode attribute
of GlobalAliases is not copied properly. The bug is masked in higher
optimization levels (uncomment --lto-O2) due to GlobalAlias resolution (uses of
the alias are replaced with uses of the aliasee).
May be related to PR33846.
//
// main.c
//
#define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))
extern __thread int tlsvar attribute_tls_model_ie;
extern __thread int tlsvar2 attribute_tls_model_ie;
void foo()
{
tlsvar2 = 5;
}
//
// tlsvar.c
//
#define attribute_hidden __attribute__ ((visibility ("hidden")))
#define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))
__thread int tlsvar attribute_tls_model_ie;
extern __thread int tlsvar2 __attribute__ ((alias ("tlsvar")))
attribute_hidden attribute_tls_model_ie;
//
// build.sh
//
#!/bin/bash -eu
_CC="clang-10"
_LTO_OPT="-Xlinker --lto-O0"
#_LTO_OPT="-Xlinker --lto-O2"
${_CC} -fPIC -flto -c main.c -o main.c.o
${_CC} -fPIC -flto -c tlsvar.c -o tlsvar.c.o
${_CC} -fPIC -flto -shared ${_LTO_OPT} -fuse-ld=lld main.c.o tlsvar.c.o -o main</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>