[clang] [clang][darwin] armv6m Firmware crashes spilling the TLS wrapper (PR #213595)
Ian Anderson via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 2 22:31:55 PDT 2026
https://github.com/ian-twilightcoder created https://github.com/llvm/llvm-project/pull/213595
Thread local storage isn't universally supported on all architectures. Only enable it for the ones that are known to support it.
rdar://183822457
>From 721787316a8eb1cf0f4e1099cffcc6a018bb04ef Mon Sep 17 00:00:00 2001
From: Ian Anderson <iana at apple.com>
Date: Sun, 2 Aug 2026 22:28:00 -0700
Subject: [PATCH] [clang][darwin] armv6m Firmware crashes spilling the TLS
wrapper
Thread local storage isn't universally supported on all architectures. Only enable it for the ones that are known to support it.
rdar://183822457
---
clang/lib/Basic/Targets/OSTargets.h | 23 +++++++++++++++++++++--
clang/test/Sema/darwin-tls.c | 3 +++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h
index e3343ca3e1902..fb5c17cefc004 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -110,8 +110,27 @@ class LLVM_LIBRARY_VISIBILITY DarwinTargetInfo
// No TLS on DriverKit.
} else if (Triple.isXROS())
this->TLSSupported = true;
- else if (Triple.isAppleFirmware())
- this->TLSSupported = true;
+ else if (Triple.isAppleFirmware()) {
+ if (Triple.isAArch64() || Triple.isARM())
+ this->TLSSupported = true;
+ else if (Triple.isThumb()) {
+ switch (Triple.getSubArch()) {
+ case llvm::Triple::NoSubArch:
+ case llvm::Triple::ARMSubArch_v4t:
+ case llvm::Triple::ARMSubArch_v5:
+ case llvm::Triple::ARMSubArch_v5te:
+ case llvm::Triple::ARMSubArch_v6:
+ case llvm::Triple::ARMSubArch_v6k:
+ case llvm::Triple::ARMSubArch_v6m:
+ // Thumb-1 doesn't support TLS.
+ break;
+
+ default:
+ this->TLSSupported = true;
+ break;
+ }
+ }
+ }
this->MCountName = "\01mcount";
}
diff --git a/clang/test/Sema/darwin-tls.c b/clang/test/Sema/darwin-tls.c
index 2a3d6871cd88c..ddae9011d9c42 100644
--- a/clang/test/Sema/darwin-tls.c
+++ b/clang/test/Sema/darwin-tls.c
@@ -15,6 +15,9 @@
// RUN: %clang_cc1 -fsyntax-only -Wno-error=implicit-int -triple i386-apple-watchos3.0-simulator %s 2>&1 | FileCheck %s --check-prefix TLS
// RUN: %clang_cc1 -fsyntax-only -Wno-error=implicit-int -triple arm64-apple-xros %s 2>&1 | FileCheck %s --check-prefix TLS
// RUN: %clang_cc1 -fsyntax-only -Wno-error=implicit-int -triple arm64-apple-xros-simulator %s 2>&1 | FileCheck %s --check-prefix TLS
+
+// RUN: not %clang_cc1 -fsyntax-only -triple thumbv6m-apple-firmware %s 2>&1 | FileCheck %s --check-prefix NO-TLS
+// RUN: %clang_cc1 -fsyntax-only -Wno-error=implicit-int -triple thumbv7em-apple-firmware %s 2>&1 | FileCheck %s --check-prefix TLS
// RUN: %clang_cc1 -fsyntax-only -Wno-error=implicit-int -triple arm64-apple-firmware %s 2>&1 | FileCheck %s --check-prefix TLS
More information about the cfe-commits
mailing list