[PATCH] D119630: [WebAssembly] Use GeneralDynamic TLS for exception handling builtins.

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 13 06:56:30 PST 2022


sbc100 updated this revision to Diff 408256.
sbc100 added a comment.

- rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119630

Files:
  lld/test/wasm/relocation-bad-tls.s
  lld/wasm/Relocations.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
  llvm/test/CodeGen/WebAssembly/lower-em-exceptions.ll
  llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll


Index: llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
===================================================================
--- llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
+++ llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
@@ -10,8 +10,8 @@
 @global_var = global i32 0, align 4
 ; NO-TLS-DAG: __THREW__ = external global [[PTR]]
 ; NO-TLS-DAG: __threwValue = external global [[PTR]]
-; TLS-DAG: __THREW__ = external thread_local(localexec) global i32
-; TLS-DAG: __threwValue = external thread_local(localexec) global i32
+; TLS-DAG: __THREW__ = external thread_local global i32
+; TLS-DAG: __threwValue = external thread_local global i32
 @global_longjmp_ptr = global void (%struct.__jmp_buf_tag*, i32)* @longjmp, align 4
 ; CHECK-DAG: @global_longjmp_ptr = global void (%struct.__jmp_buf_tag*, i32)* bitcast (void ([[PTR]], i32)* @emscripten_longjmp to void (%struct.__jmp_buf_tag*, i32)*)
 
Index: llvm/test/CodeGen/WebAssembly/lower-em-exceptions.ll
===================================================================
--- llvm/test/CodeGen/WebAssembly/lower-em-exceptions.ll
+++ llvm/test/CodeGen/WebAssembly/lower-em-exceptions.ll
@@ -9,8 +9,8 @@
 @_ZTIc = external constant i8*
 ; NO-TLS-DAG: __THREW__ = external global [[PTR]]
 ; NO-TLS-DAG: __threwValue = external global i32
-; TLS-DAG: __THREW__ = external thread_local(localexec) global [[PTR]]
-; TLS-DAG: __threwValue = external thread_local(localexec) global i32
+; TLS-DAG: __THREW__ = external thread_local global [[PTR]]
+; TLS-DAG: __threwValue = external thread_local global i32
 
 ; Test invoke instruction with clauses (try-catch block)
 define void @clause() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
@@ -422,7 +422,7 @@
   // shared-memory module, which we don't want to be responsible for.
   auto *Subtarget = TM.getSubtargetImpl();
   auto TLS = Subtarget->hasAtomics() && Subtarget->hasBulkMemory()
-                 ? GlobalValue::LocalExecTLSModel
+                 ? GlobalValue::GeneralDynamicTLSModel
                  : GlobalValue::NotThreadLocal;
   GV->setThreadLocalMode(TLS);
   return GV;
Index: lld/wasm/Relocations.cpp
===================================================================
--- lld/wasm/Relocations.cpp
+++ lld/wasm/Relocations.cpp
@@ -112,6 +112,11 @@
       break;
     case R_WASM_MEMORY_ADDR_TLS_SLEB:
     case R_WASM_MEMORY_ADDR_TLS_SLEB64:
+      if (!sym->isDefined()) {
+        error(toString(file) + ": relocation " + relocTypeToString(reloc.Type) +
+              " cannot be used against an undefined symbol `" + toString(*sym) +
+              "`");
+      }
       // In single-threaded builds TLS is lowered away and TLS data can be
       // merged with normal data and allowing TLS relocation in non-TLS
       // segments.
Index: lld/test/wasm/relocation-bad-tls.s
===================================================================
--- lld/test/wasm/relocation-bad-tls.s
+++ lld/test/wasm/relocation-bad-tls.s
@@ -6,6 +6,8 @@
   .functype _start () -> ()
   i32.const foo at TLSREL
   i32.const bar at TLSREL
+  i32.const baz at TLSREL
+  drop
   drop
   drop
   end_function
@@ -24,3 +26,4 @@
 
 # CHECK: relocation R_WASM_MEMORY_ADDR_TLS_SLEB cannot be used against `foo` in non-TLS section: .data
 # CHECK: relocation R_WASM_MEMORY_ADDR_TLS_SLEB cannot be used against `bar` in non-TLS section: .bss
+# CHECK: relocation R_WASM_MEMORY_ADDR_TLS_SLEB cannot be used against an undefined symbol `baz`


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119630.408256.patch
Type: text/x-patch
Size: 3722 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220213/fc979cdd/attachment.bin>


More information about the llvm-commits mailing list