[clang] [Cygwin] Enable TLS on Cygwin target (PR #138618)

via cfe-commits cfe-commits at lists.llvm.org
Mon May 5 18:02:10 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-driver

Author: Tomohiro Kashiwada (kikairoya)

<details>
<summary>Changes</summary>

Cygwin environment and toolchain supports EMUTLS.

>From https://cygwin.com/git/?p=newlib-cygwin.git;a=blob;f=config/tls.m4;hb=HEAD#l118,

```
$ LANG=C gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/15/lto-wrapper.exe Target: x86_64-pc-cygwin
Configured with: (snip)
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 15.0.1 20250406 (experimental) (GCC)

$ echo '__thread int a; int b; int main() { return a = b; }' | gcc -S -xc -o- - | grep __emutls_get_address
        call    __emutls_get_address
        .def    __emutls_get_address;   .scl    2;      .type   32;     .endef
```

---
Full diff: https://github.com/llvm/llvm-project/pull/138618.diff


2 Files Affected:

- (modified) clang/lib/Basic/Targets/X86.h (-1) 
- (modified) clang/test/Driver/emulated-tls.cpp (+6) 


``````````diff
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 194f3faef1be3..2f6fb33a7b597 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -965,7 +965,6 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_64TargetInfo : public X86_64TargetInfo {
   CygwinX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
       : X86_64TargetInfo(Triple, Opts) {
     this->WCharType = TargetInfo::UnsignedShort;
-    TLSSupported = false;
   }
 
   void getTargetDefines(const LangOptions &Opts,
diff --git a/clang/test/Driver/emulated-tls.cpp b/clang/test/Driver/emulated-tls.cpp
index 3ee901a835858..431105bdfdf45 100644
--- a/clang/test/Driver/emulated-tls.cpp
+++ b/clang/test/Driver/emulated-tls.cpp
@@ -8,6 +8,8 @@
 // RUN:   | FileCheck -check-prefix=NOEMU %s
 // RUN: %clang -### --target=i686-pc-cygwin %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=EMU %s
+// RUN: %clang -### --target=x86_64-pc-cygwin %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=EMU %s
 // RUN: %clang -### --target=i686-pc-openbsd %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=EMU %s
 
@@ -17,6 +19,8 @@
 // RUN: | FileCheck -check-prefix=EMU %s
 // RUN: %clang -### -target i686-pc-cygwin %s -fno-emulated-tls -femulated-tls 2>&1 \
 // RUN: | FileCheck -check-prefix=EMU %s
+// RUN: %clang -### -target x86_64-pc-cygwin %s -fno-emulated-tls -femulated-tls 2>&1 \
+// RUN: | FileCheck -check-prefix=EMU %s
 // RUN: %clang -### -target i686-pc-openbsd %s -fno-emulated-tls -femulated-tls 2>&1 \
 // RUN: | FileCheck -check-prefix=EMU %s
 
@@ -26,6 +30,8 @@
 // RUN: | FileCheck -check-prefix=NOEMU %s
 // RUN: %clang -### -target i686-pc-cygwin %s -femulated-tls -fno-emulated-tls 2>&1 \
 // RUN: | FileCheck -check-prefix=NOEMU %s
+// RUN: %clang -### -target x86_64-pc-cygwin %s -femulated-tls -fno-emulated-tls 2>&1 \
+// RUN: | FileCheck -check-prefix=NOEMU %s
 // RUN: %clang -### -target i686-pc-openbsd %s -femulated-tls -fno-emulated-tls 2>&1 \
 // RUN: | FileCheck -check-prefix=NOEMU %s
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/138618


More information about the cfe-commits mailing list