This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Use pthread instead of thread_local to support more runtimes.
ClosedPublic

Authored by sammccall on Jan 31 2018, 8:39 AM.

Details

Summary

thread_local has nice syntax and semantics, but requires __cxa_thread_atexit,
and some not-ancient runtime libraries don't provide it.
The clang-x86_64-linux-selfhost-modules buildbot is one example :-)

It works on windows, and the other platforms clang-tools-extra supports should
all have the relevant pthread API. So we just use that if it's available,
falling back to thread_local (so if a platform has neither, we'll fail to link).

The fallback should really be the other way, that would require cmake changes.

Diff Detail

Repository
rL LLVM

Event Timeline

sammccall created this revision.Jan 31 2018, 8:39 AM
This revision is now accepted and ready to land.Feb 1 2018, 12:48 AM
This revision was automatically updated to reflect the committed changes.

Is there some way to figure out what's going on in clang-x86_64-linux-selfhost-modules?

I believe there should be no linux builders which are missing this function -- it was added to libgcc in 4.8, and we don't support older versions, so I think missing this function on a linux build must be a misconfiguration of some sort.

This breaks compilation for me on Gentoo's clang-9999.ebuild

The following patch fixes things for me

commit a4c071b16bbbc84bbb960000d90b51bed8a12127 (HEAD -> master)
Author: Mike Lothian <mike@fireburn.co.uk>
Date:   Tue Feb 6 09:55:41 2018 +0000

    [clangd] Fix include to use Clang's config.h

    This fixes:

    [clangd] Use pthread instead of thread_local to support more runtimes.

diff --git a/clangd/Context.cpp b/clangd/Context.cpp
index 23006778..aed832f4 100644
--- a/clangd/Context.cpp
+++ b/clangd/Context.cpp
@@ -8,7 +8,7 @@
 //===---------------------------------------------------------------------===//

 #include "Context.h"
-#include "llvm/Config/config.h"
+#include "clang/Config/config.h"
 #include <cassert>

 // The thread-local Context is scoped in a function to avoid init-order issues.