Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang++-libc++ with clang6 and libcxxabi does support thread_local #231

Closed
PlacidBox opened this issue Jul 25, 2018 · 4 comments
Closed

Comments

@PlacidBox
Copy link

I've been upgrading some company internal projects to use a clang6 toolchain, and discovered that the fix in #208 is causing boost::fiber to not build since it thinks thread_local isn't available.

I can successfully build and run the test case in boost_no_cxx11_thread_local.ipp when i import it in to the project (we're using cmake). This is with the compiler flags:

cxx:
-stdlib=libc++ -fPIE -pthread -std=c++1z

link:
-stdlib=libc++ -static-libstdc++ -Wl,-Bstatic -lc++abi -Wl,-Bdynamic -pthread 

Checking the symbols against the debian 8 prebuilts from http://releases.llvm.org/

clang 6:
> nm -C libc++abi.so | grep __cxa_thread
0000000000027350 T __cxa_thread_atexit
                 U __cxa_thread_atexit_impl@@GLIBC_2.18

clang 5:
> nm -C libc++abi.so | grep __cxa_thread
000000000003c020 T __cxa_thread_atexit
                 U __cxa_thread_atexit_impl@@GLIBC_2.18

clang 3.4 on ubuntu trusty, via apt-get install clang libc++-dev libc++abi-dev:
> nm -CD ./usr/lib/x86_64-linux-gnu/libc++abi.so | grep __cxa_thread
<no results>

So it seems that clang3's libc++abi didn't have support for __cxa_thread_atexit, but newer versions do by deferring to glibc's implementation.

The feature check should probably be changed to detect the clang version?

This may not work 100% of the time though, since it depends on what standard library is being linked in and if libcxxabi is being linked in. Based on the commit llvm-mirror/libcxxabi@3f7b370 more recent versions of clang will attempt to provide a fallback in libcxxabi if glibc does not have an implementation, so perhaps require a very recent version of clang?

@PlacidBox
Copy link
Author

Did some digging and that commit to libcxxabi looks like it was included in clang4. Here's the patch I'm currently using. It might break some users that aren't using libcxxabi though.. not really too sure on the best way to handle this.

--- boost/config/stdlib/libcpp.hpp	2018-07-26 10:09:30.091065048 +1000
+++ boost/config/stdlib/libcpp.hpp	2018-07-26 10:14:24.641990321 +1000
@@ -113,10 +113,16 @@
 #  define BOOST_NO_CXX11_THREAD_LOCAL
 #endif
 
-#if defined(__linux__) && !defined(BOOST_NO_CXX11_THREAD_LOCAL)
+#if defined(__linux__) && _LIBCPP_VERSION < 4000 && !defined(BOOST_NO_CXX11_THREAD_LOCAL)
 // After libc++-dev is installed on Trusty, clang++-libc++ almost works,
 // except uses of `thread_local` fail with undefined reference to
 // `__cxa_thread_atexit`.
+//
+// clang's libc++abi provides an implementation by deferring to the glibc
+// implementation, which may or may not be available (it is not on Trusty).
+// clang 4's libc++abi will provide an implementation if one is not in glibc
+// though, so thread local support should work with clang 4 and above as long
+// as libc++abi is linked in.
 #  define BOOST_NO_CXX11_THREAD_LOCAL
 #endif
 

@jzmaddock
Copy link
Collaborator

Confirmed as working with Ubuntu clang-6 packages at least.

@jzmaddock
Copy link
Collaborator

Spoke too soon.... failed CI testing with clang-5. Updating the CI tests and waiting for them to cycle...

@jzmaddock jzmaddock reopened this Aug 4, 2018
@jzmaddock
Copy link
Collaborator

CI is passing now, not sure if we have all the wrinkles sorted, but it's better than it was.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants