[PATCH] D143619: [llvm][codegen] Disallow default Emulated TLS for RISCV

Paul Kirth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 9 10:10:06 PST 2023


paulkirth updated this revision to Diff 496167.
paulkirth added a comment.

Add supportsEmulatedTLS API, and try to minimize test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143619/new/

https://reviews.llvm.org/D143619

Files:
  lld/test/ELF/lto/riscv-no-emutls.ll
  llvm/include/llvm/TargetParser/Triple.h


Index: llvm/include/llvm/TargetParser/Triple.h
===================================================================
--- llvm/include/llvm/TargetParser/Triple.h
+++ llvm/include/llvm/TargetParser/Triple.h
@@ -950,9 +950,15 @@
              isOSBinFormatDXContainer());
   }
 
+  /// Tests whether the target supports emulated tls
+  bool supportsEmulatedTLS() const {
+    return !isRISCV64();
+  }
+
   /// Tests whether the target uses emulated TLS as default.
   bool hasDefaultEmulatedTLS() const {
-    return isAndroid() || isOSOpenBSD() || isWindowsCygwinEnvironment();
+    return supportsEmulatedTLS() &&
+           (isAndroid() || isOSOpenBSD() || isWindowsCygwinEnvironment());
   }
 
   /// Tests whether the target uses -data-sections as default.
Index: lld/test/ELF/lto/riscv-no-emutls.ll
===================================================================
--- /dev/null
+++ lld/test/ELF/lto/riscv-no-emutls.ll
@@ -0,0 +1,36 @@
+; Test that on targets w/ default emulated TLS, that pass doesn't run in LTO
+
+; RUN: opt -module-summary < %s -o %t.bc --mtriple=riscv64-unknown-linux-android10000
+; RUN: ld.lld --plugin-opt=-debug-pass=Structure %t.bc -o /dev/null --no-undefined -shared 2>&1 | FileCheck %s --allow-empty
+
+; Ensure the backend pass we want to avoid doesn't run: LowerEmuTLSPass
+; so we check for its output under pass structure
+; CHECK-NOT: Add __emutls_
+
+; Also check that we don't end up creating thread_locals that are undefined in
+; the final link. This used to happen because the LowerEmuTLSPass would be added
+; when targeting platforms with default emulated TLS, even on riscv64, despite
+; the lack of emulated TLS support.
+; CHECK-NOT: error: undefined symbol: Mem
+
+target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
+
+%struct.Memory = type { i32, i32 }
+
+ at Mem = internal thread_local global ptr null, align 8
+
+; Give a bogus definition to satisfy the linker
+define ptr @__tls_get_addr(ptr nonnull) {
+  ret ptr null
+}
+
+define void @baz(i32 noundef signext %n) {
+entry:
+  %loc = inttoptr i64 66 to ptr
+  %threadlocal = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @Mem)
+  store ptr %loc, ptr %threadlocal, align 8
+
+  ret void
+}
+
+declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143619.496167.patch
Type: text/x-patch
Size: 2283 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230209/240dd2d9/attachment.bin>


More information about the llvm-commits mailing list