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

Paul Kirth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 8 18:02:24 PST 2023


paulkirth created this revision.
paulkirth added reviewers: hiraditya, phosek, MaskRay, jrtc27.
Herald added subscribers: luke, VincentWu, ormris, vkmr, frasercrmck, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, steven_wu, edward-jones, zzheng, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, arichardson, emaste.
Herald added a project: All.
paulkirth requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead, eopXD.
Herald added a project: LLVM.

Based on  https://github.com/llvm/llvm-project/issues/59500, and further
discussion on https://reviews.llvm.org/D102527, it seems that we will
not support Emulated TLS for RISCV in LLVM. In these cases, we should
avoid setting defaults for a feature we will not support.

This also avoids some trouble when using LTO on targets that would
normally default to emulated TLS, since it can be challenging to
propagate frontend flags like `-fno-emulated-tls` correctly.


Repository:
  rG LLVM Github Monorepo

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
@@ -952,7 +952,8 @@
 
   /// Tests whether the target uses emulated TLS as default.
   bool hasDefaultEmulatedTLS() const {
-    return isAndroid() || isOSOpenBSD() || isWindowsCygwinEnvironment();
+    return !isRISCV64() &&
+           (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,55 @@
+; Test that on targets w/ default emulated TLS, that pass doesn't run in LTO
+
+; RUN: split-file %s %t
+
+; RUN: opt -module-summary %t/a.ll -o %t/a.bc --mtriple=riscv64-unknown-linux-android10000
+; RUN: opt -module-summary %t/b.ll -o %t/b.bc --mtriple=riscv64-unknown-linux-android10000
+; RUN: ld.lld --plugin-opt=-debug-pass=Structure %t/a.bc %t/b.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.
+; CHECK-NOT: error: undefined hidden symbol: Mem
+; CHECK-NOT: error: undefined hidden symbol: __tls_get_addr
+
+;--- a.ll
+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) #0 {
+  ret ptr null
+}
+
+define void @baz(i32 noundef signext %n) #0 {
+entry:
+  %call = call ptr @create()
+  %0 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @Mem)
+  store ptr %call, ptr %0, align 8
+
+  ret void
+}
+
+declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #1
+
+declare ptr @create() #0
+
+attributes #0 = { mustprogress noinline nounwind "frame-pointer"="all"  }
+attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
+
+;--- b.ll
+target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
+
+define ptr @create() #0 {
+entry:
+  ret ptr inttoptr (i64 66 to ptr)
+}
+
+attributes #0 = { mustprogress noinline nounwind "frame-pointer"="all"  }
+


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


More information about the llvm-commits mailing list