[lld] d51f74a - [lld][WebAssembly] Error on import of TLS symbols in shared libraries

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 20 12:36:39 PDT 2021


Author: Sam Clegg
Date: 2021-07-20T12:36:03-07:00
New Revision: d51f74acdf3950628b90320dae9a169762ad225c

URL: https://github.com/llvm/llvm-project/commit/d51f74acdf3950628b90320dae9a169762ad225c
DIFF: https://github.com/llvm/llvm-project/commit/d51f74acdf3950628b90320dae9a169762ad225c.diff

LOG: [lld][WebAssembly] Error on import of TLS symbols in shared libraries

In https://reviews.llvm.org/D102044 we made exporting a TLS symbol
into an error, but we also want to error on import.

See https://github.com/emscripten-core/emscripten/issues/14461

Differential Revision: https://reviews.llvm.org/D106385

Added: 
    lld/test/wasm/tls-import.s

Modified: 
    lld/wasm/Relocations.cpp

Removed: 
    


################################################################################
diff  --git a/lld/test/wasm/tls-import.s b/lld/test/wasm/tls-import.s
new file mode 100644
index 0000000000000..cce45f5fbaac5
--- /dev/null
+++ b/lld/test/wasm/tls-import.s
@@ -0,0 +1,23 @@
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
+# RUN: not wasm-ld -shared --experimental-pic --shared-memory -o %t.wasm %t.o 2>&1 | FileCheck %s
+
+# CHECK: error: {{.*}}.o: TLS symbol is undefined, but TLS symbols cannot yet be imported: `foo`
+
+.globl _start
+_start:
+  .functype _start () -> ()
+  i32.const foo at TLSREL
+  drop
+  end_function
+
+.section  .custom_section.target_features,"",@
+  .int8 3
+  .int8 43
+  .int8 7
+  .ascii  "atomics"
+  .int8 43
+  .int8 11
+  .ascii  "bulk-memory"
+  .int8 43
+  .int8 15
+  .ascii "mutable-globals"

diff  --git a/lld/wasm/Relocations.cpp b/lld/wasm/Relocations.cpp
index 9313e30d805da..1dca6d621b262 100644
--- a/lld/wasm/Relocations.cpp
+++ b/lld/wasm/Relocations.cpp
@@ -146,6 +146,15 @@ void scanRelocations(InputChunk *chunk) {
               " cannot be used against symbol " + toString(*sym) +
               "; recompile with -fPIC");
         break;
+      case R_WASM_MEMORY_ADDR_TLS_SLEB:
+      case R_WASM_MEMORY_ADDR_TLS_SLEB64:
+        if (!sym->isDefined()) {
+          error(toString(file) +
+                ": TLS symbol is undefined, but TLS symbols cannot yet be "
+                "imported: `" +
+                toString(*sym) + "`");
+        }
+        break;
       case R_WASM_TABLE_INDEX_I32:
       case R_WASM_TABLE_INDEX_I64:
       case R_WASM_MEMORY_ADDR_I32:


        


More information about the llvm-commits mailing list