So this enables the code. It makes -femulated-tls the default,
otherwise it will generated TLS relocations that we can't handle yet.
It is possible to specify -fno-emulated-tls if you really want to
generate those.
A trivial example program that modifies the variable in one thread and
prints it in another seems to work as expected.
Note that the libcompiler_rt implementation unconditionally references
some symbols in libpthread. So linking with -lpthread is mandatory.
GCC 4.9 uses weak references, so -lpthread isn't needed there.
Perhaps those functions should move to libc. Or we can make the
libcompiler_rt code a bit smarter.
Also note that the libcompiler_rt implementation offers the choice
between posix_memalign() and normal malloc(). With this diff it uses
malloc(). Perhaps otto@ has an opinion what's better here?
Index: gnu/llvm/tools/clang/lib/Basic/Targets.cpp
===================================================================
RCS file: /cvs/src/gnu/llvm/tools/clang/lib/Basic/Targets.cpp,v
retrieving revision 1.7
diff -u -p -r1.7 Targets.cpp
--- gnu/llvm/tools/clang/lib/Basic/Targets.cpp 14 Mar 2017 08:11:34 -0000
1.7
+++ gnu/llvm/tools/clang/lib/Basic/Targets.cpp 7 May 2017 15:25:08 -0000
@@ -549,8 +549,6 @@ protected:
public:
OpenBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
: OSTargetInfo<Target>(Triple, Opts) {
- this->TLSSupported = false;
-
switch (Triple.getArch()) {
default:
case llvm::Triple::x86:
Index: gnu/llvm/tools/clang/lib/Driver/Tools.cpp
===================================================================
RCS file: /cvs/src/gnu/llvm/tools/clang/lib/Driver/Tools.cpp,v
retrieving revision 1.10
diff -u -p -r1.10 Tools.cpp
--- gnu/llvm/tools/clang/lib/Driver/Tools.cpp 24 Jan 2017 08:39:08 -0000
1.10
+++ gnu/llvm/tools/clang/lib/Driver/Tools.cpp 7 May 2017 15:25:09 -0000
@@ -5370,7 +5370,8 @@ void Clang::ConstructJob(Compilation &C,
Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
// Emulated TLS is enabled by default on Android, and can be enabled manually
// with -femulated-tls.
- bool EmulatedTLSDefault = Triple.isAndroid() ||
Triple.isWindowsCygwinEnvironment();
+ bool EmulatedTLSDefault = Triple.isAndroid() || Triple.isOSOpenBSD() ||
+ Triple.isWindowsCygwinEnvironment();
if (Args.hasFlag(options::OPT_femulated_tls, options::OPT_fno_emulated_tls,
EmulatedTLSDefault))
CmdArgs.push_back("-femulated-tls");
Index: lib/libcompiler_rt/Makefile
===================================================================
RCS file: /cvs/src/lib/libcompiler_rt/Makefile,v
retrieving revision 1.7
diff -u -p -r1.7 Makefile
--- lib/libcompiler_rt/Makefile 17 Apr 2017 15:53:21 -0000 1.7
+++ lib/libcompiler_rt/Makefile 7 May 2017 15:25:09 -0000
@@ -64,6 +64,7 @@ GEN_SRCS= absvdi2 \
divti3 \
divtf3 \
divxc3 \
+ emutls \
enable_execute_stack \
eprintf \
extendsfdf2 \