<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 - On Darwin, thread_local variables generate symbols that don't respect -fvisibility=hidden"
href="https://bugs.llvm.org/show_bug.cgi?id=40327">40327</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>On Darwin, thread_local variables generate symbols that don't respect -fvisibility=hidden
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>MacOS X
</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>C++11
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>vlad@tsyrklevich.net
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>(This is taken from a bug on the Chromium bugtracker: <a href="https://crbug.com/829078">https://crbug.com/829078</a>)
On Darwin, compiling the following test program with -fvisibility=hidden
generates an output with a default visibility symbol.
$ cat test.cc
thread_local int tls_global = 42;
int& global() {
return tls_global;
}
$ clang -fPIC -shared -std=c++11 test.cc -fvisibility=hidden
$ nm | grep global
0000000000000f90 t __Z6globalv
0000000000000fa0 T __ZTW10tls_global # visibility=hidden does not work here
0000000000001000 s _tls_global
0000000000001018 s _tls_global$tlv$init
On other platforms the thread wrapper function '__ZTW10tls_global' has hidden
visibility. TL variables use a different ABI on Darwin. On other platforms the
TL variable is emitted with whatever visibility it's declared with and the
thread wrapper function has hidden visibility. Darwin prefers to expose the
thread wrapper function so the TL variable is given internal linkage and the
thread wrapper is not given hidden visibility. Because -fvisibility=hidden only
applies hidden visibility to declarations taken from test.cc and not to
intermediates generated by the compiler the thread wrapper function is output
with default visibility. On other platforms, the thread wrapper would have
hidden visibility and -fvisibility=hidden would override the default visibility
for that variable's symbol.
<a href="https://reviews.llvm.org/D4109">https://reviews.llvm.org/D4109</a> introduces the change to not mark thread wrapper
funcs hidden on Darwin (to correctly handle cross-DSO references.) It's a fix
for this unreferenced bug report <a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED FIXED - Change introduced in r207451 broke thread_local on Darwin"
href="show_bug.cgi?id=19989">https://bugs.llvm.org/show_bug.cgi?id=19989</a>.
Prior to that <a href="https://reviews.llvm.org/rL180941">https://reviews.llvm.org/rL180941</a> and then
<a href="https://reviews.llvm.org/rL210632">https://reviews.llvm.org/rL210632</a> are the changes that mark TL variables
internal on Darwin.
I'm not sure yet how to fix this as I've not even looked into how
constructors/destructors work for thread_local variables. If the TL variable
were not marked with internal linkage (so that it always has hidden visibility)
in CodeGenModule, we could copy the TL variable's visibility and apply it to
the thread wrapper. Perhaps we could delay marking the variable's linkage until
we generate its wrapper it in the ItaniumCXXABI code.</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>