<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 --- - “illegal thread-local reference to regular symbol” error on a TLS variable"
href="https://llvm.org/bugs/show_bug.cgi?id=25821">25821</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>“illegal thread-local reference to regular symbol” error on a TLS variable
</td>
</tr>
<tr>
<th>Product</th>
<td>lld
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</td>
</tr>
<tr>
<th>OS</th>
<td>MacOS X
</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>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>joel.cornett@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Linking fails with the message "illegal thread-local reference to regular
symbol" when attempting to create a dylib which references an external TLS
variable declared with `__thread`.
In `foo.cc`:
extern __thread int x;
void foo() { ++x; }
The compile step is (this works fine):
$CXX -stdlib=libc++ -std=c++11 -fvisibility=hidden -fPIC -o foo.cc.o -c
foo.cc
The linking step (where the error is thrown):
$CXX -stdlib=libc++ -std=c++11 -fvisibility=hidden -dynamiclib
-Wl,-undefined,dynamic_lookup -o libfoo.dylib foo.cpp.o
Now this works fine in gcc (5 and 4.9.3) on the same platform. I understand
there are differences in the implementation of `__thread`, but I cannot find
any documentation addressing this specific issue anywhere, so I assume this is
a bug.
Version info:
$ $CXX --version
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
$ ld -v
@(#)PROGRAM:ld PROJECT:ld64-253.9
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h
armv6m armv7k armv7m armv7em (tvOS)
LTO support using: Apple LLVM 7.0.2 (clang-700.1.81)</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>