[PATCH] D93554: [lld][WebAssembly] Fix for TLS + --relocatable

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 13 07:49:27 PST 2021


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

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93554

Files:
  lld/test/wasm/tls-no-shared.s
  lld/test/wasm/tls.s
  lld/wasm/Driver.cpp
  lld/wasm/InputFiles.cpp
  lld/wasm/Writer.cpp


Index: lld/wasm/Writer.cpp
===================================================================
--- lld/wasm/Writer.cpp
+++ lld/wasm/Writer.cpp
@@ -284,7 +284,7 @@
     log(formatv("mem: {0,-15} offset={1,-8} size={2,-8} align={3}", seg->name,
                 memoryPtr, seg->size, seg->alignment));
 
-    if (seg->name == ".tdata") {
+    if (!config->relocatable && seg->name == ".tdata") {
       if (config->sharedMemory) {
         auto *tlsSize = cast<DefinedGlobal>(WasmSym::tlsSize);
         setGlobalPtr(tlsSize, seg->size);
Index: lld/wasm/InputFiles.cpp
===================================================================
--- lld/wasm/InputFiles.cpp
+++ lld/wasm/InputFiles.cpp
@@ -123,6 +123,7 @@
   case R_WASM_MEMORY_ADDR_REL_SLEB64:
   case R_WASM_MEMORY_ADDR_I32:
   case R_WASM_MEMORY_ADDR_I64:
+  case R_WASM_MEMORY_ADDR_TLS_SLEB:
   case R_WASM_FUNCTION_OFFSET_I32:
   case R_WASM_FUNCTION_OFFSET_I64:
     return reloc.Addend;
Index: lld/wasm/Driver.cpp
===================================================================
--- lld/wasm/Driver.cpp
+++ lld/wasm/Driver.cpp
@@ -639,7 +639,7 @@
     WasmSym::stackPointer->markLive();
   }
 
-  if (config->sharedMemory) {
+  if (config->sharedMemory && !config->relocatable) {
     WasmSym::tlsBase = createGlobalVariable("__tls_base", true);
     WasmSym::tlsSize = createGlobalVariable("__tls_size", false);
     WasmSym::tlsAlign = createGlobalVariable("__tls_align", false);
Index: lld/test/wasm/tls.s
===================================================================
--- lld/test/wasm/tls.s
+++ lld/test/wasm/tls.s
@@ -73,8 +73,8 @@
 # RUN: wasm-ld -no-gc-sections --shared-memory --max-memory=131072 --no-entry -o %t.wasm %t.o
 # RUN: obj2yaml %t.wasm | FileCheck %s
 
-# RUN: wasm-ld -no-gc-sections --shared-memory --max-memory=131072 --no-merge-data-segments --no-entry -o %t.wasm %t.o
-# RUN: obj2yaml %t.wasm | FileCheck %s
+# RUN: wasm-ld -no-gc-sections --shared-memory --max-memory=131072 --no-merge-data-segments --no-entry -o %t2.wasm %t.o
+# RUN: obj2yaml %t2.wasm | FileCheck %s
 
 # CHECK:      - Type:            GLOBAL
 # CHECK-NEXT:   Globals:
@@ -163,3 +163,32 @@
 # Expected body of tls_align:
 #   global.get 3
 #   end
+
+
+# Also verify TLS usage with --relocatable
+# RUN: wasm-ld --relocatable -o %t3.wasm %t.o
+# RUN: obj2yaml %t3.wasm | FileCheck %s --check-prefix=RELOC
+
+# RELOC:       - Type:            IMPORT
+# RELOC-NEXT:    Imports:
+# RELOC-NEXT:      - Module:          env
+# RELOC-NEXT:        Field:           __tls_base
+# RELOC-NEXT:        Kind:            GLOBAL
+# RELOC-NEXT:        GlobalType:      I32
+# RELOC-NEXT:        GlobalMutable:   true
+# RELOC-NEXT:      - Module:          env
+# RELOC-NEXT:        Field:           __tls_align
+# RELOC-NEXT:        Kind:            GLOBAL
+# RELOC-NEXT:        GlobalType:      I32
+# RELOC-NEXT:        GlobalMutable:   false
+
+# RELOC:         GlobalNames:
+# RELOC-NEXT:      - Index:           0
+# RELOC-NEXT:        Name:            __tls_base
+# RELOC-NEXT:      - Index:           1
+# RELOC-NEXT:        Name:            __tls_align
+# RELOC-NEXT:    DataSegmentNames:
+# RELOC-NEXT:      - Index:           0
+# RELOC-NEXT:        Name:            .tdata
+# RELOC-NEXT:      - Index:           1
+# RELOC-NEXT:        Name:            .bss.no_tls
Index: lld/test/wasm/tls-no-shared.s
===================================================================
--- lld/test/wasm/tls-no-shared.s
+++ lld/test/wasm/tls-no-shared.s
@@ -1,5 +1,5 @@
 # Test that linking without shared memory causes __tls_base to be
-# interlized
+# internalized
 
 # RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93554.316397.patch
Type: text/x-patch
Size: 3690 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210113/18819dad/attachment.bin>


More information about the llvm-commits mailing list