[clang] [ARM] Forbid use of TLS with execute-only (PR #124806)

Oliver Stannard via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 28 09:56:34 PST 2025


https://github.com/ostannard created https://github.com/llvm/llvm-project/pull/124806

Thread-local code generation requires constant pools because most of the relocations needed for it operate on data, so it cannot be used with -mexecute-only (or -mpure-code, which is aliased in the driver).

Without this we hit an assertion in the backend when trying to generate a constant pool.

>From 2a1fb2ed2a91cf0a3da2c24b7e4c68fd5fc81751 Mon Sep 17 00:00:00 2001
From: Oliver Stannard <oliver.stannard at arm.com>
Date: Tue, 28 Jan 2025 17:49:42 +0000
Subject: [PATCH] [ARM] Forbid use of TLS with execute-only

Thread-local code generation requires constant pools because most of the
relocations needed for it operate on data, so it cannot be used with
-mexecute-only (or -mpure-code, which is aliased in the driver).

Without this we hit an assertion in the backend when trying to generate
a constant pool.
---
 clang/lib/Basic/Targets/ARM.cpp        |  2 ++
 clang/test/Sema/arm-execute-only-tls.c | 10 ++++++++++
 2 files changed, 12 insertions(+)
 create mode 100644 clang/test/Sema/arm-execute-only-tls.c

diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 0fd5433a76402e..5aa2baeb81b731 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -608,6 +608,8 @@ bool ARMTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
       HasBTI = 1;
     } else if (Feature == "+fullbf16") {
       HasFullBFloat16 = true;
+    } else if (Feature == "+execute-only") {
+      TLSSupported = false;
     }
   }
 
diff --git a/clang/test/Sema/arm-execute-only-tls.c b/clang/test/Sema/arm-execute-only-tls.c
new file mode 100644
index 00000000000000..b17ff450cb74d1
--- /dev/null
+++ b/clang/test/Sema/arm-execute-only-tls.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple arm-none-eabi                               -fsyntax-only -verify=default      %s
+// RUN: %clang_cc1 -triple arm-none-eabi -target-feature +execute-only -fsyntax-only -verify=execute-only %s
+
+// default-no-diagnostics
+
+/// Thread-local code generation requires constant pools because most of the
+/// relocations needed for it operate on data, so it cannot be used with
+/// -mexecute-only (or -mpure-code, which is aliased in the driver).
+
+_Thread_local int t; // execute-only-error {{thread-local storage is not supported for the current target}}



More information about the cfe-commits mailing list