[llvm-bugs] [Bug 40327] New: On Darwin, thread_local variables generate symbols that don't respect -fvisibility=hidden

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jan 15 15:49:14 PST 2019


https://bugs.llvm.org/show_bug.cgi?id=40327

            Bug ID: 40327
           Summary: On Darwin, thread_local variables generate symbols
                    that don't respect -fvisibility=hidden
           Product: clang
           Version: trunk
          Hardware: PC
                OS: MacOS X
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: vlad at tsyrklevich.net
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

(This is taken from a bug on the Chromium bugtracker: https://crbug.com/829078)

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.

https://reviews.llvm.org/D4109 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 https://bugs.llvm.org/show_bug.cgi?id=19989.

Prior to that https://reviews.llvm.org/rL180941 and then
https://reviews.llvm.org/rL210632 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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190115/437ca3cf/attachment.html>


More information about the llvm-bugs mailing list