LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 25821 - “illegal thread-local reference to regular symbol” error on a TLS variable
Summary: “illegal thread-local reference to regular symbol” error on a TLS variable
Status: RESOLVED WONTFIX
Alias: None
Product: lld
Classification: Unclassified
Component: MachO (show other bugs)
Version: unspecified
Hardware: Macintosh MacOS X
: P normal
Assignee: Unassigned LLVM Bugs
URL: http://stackoverflow.com/q/34212217/1...
Keywords: build-problem
Depends on:
Blocks:
 
Reported: 2015-12-14 09:40 PST by Joel Cornett
Modified: 2021-02-19 16:01 PST (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joel Cornett 2015-12-14 09:40:50 PST
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)
Comment 1 Sean Silva 2016-06-26 17:56:51 PDT
Moving to more specific "MachO" LLD component (instead of generic "All Bugs").
Comment 2 Jez Ng 2021-02-19 16:01:56 PST
Closing this as it applies to the old iteration of LLD-MachO which is not being developed. (The new one is named `ld64.lld.darwinnew`, and will be receiving active feature development and bug fixes.)