[PATCH] D112831: [lld][WebAssembly] Handle TLS variables in Symbol::getVA. NFC

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 29 10:05:07 PDT 2021


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

- comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112831

Files:
  lld/wasm/InputFiles.cpp
  lld/wasm/Symbols.cpp


Index: lld/wasm/Symbols.cpp
===================================================================
--- lld/wasm/Symbols.cpp
+++ lld/wasm/Symbols.cpp
@@ -305,6 +305,11 @@
 
 uint64_t DefinedData::getVA() const {
   LLVM_DEBUG(dbgs() << "getVA: " << getName() << "\n");
+  // In the shared memory case, TLS symbols are relative to the start of the TLS
+  // output segment (__tls_base).  When building without shared memory, TLS
+  // symbols absolute, just like non-TLS.
+  if (isTLS() && config->sharedMemory)
+    return getOutputSegmentOffset() + value;
   if (segment)
     return segment->getVA(value);
   return value;
Index: lld/wasm/InputFiles.cpp
===================================================================
--- lld/wasm/InputFiles.cpp
+++ lld/wasm/InputFiles.cpp
@@ -169,18 +169,12 @@
   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_MEMORY_ADDR_TLS_SLEB64:
   case R_WASM_MEMORY_ADDR_LOCREL_I32: {
     if (isa<UndefinedData>(sym) || sym->isUndefWeak())
       return 0;
     auto D = cast<DefinedData>(sym);
-    // Treat non-TLS relocation against symbols that live in the TLS segment
-    // like TLS relocations.  This behaviour exists to support older object
-    // files created before we introduced TLS relocations.
-    // TODO(sbc): Remove this legacy behaviour one day.  This will break
-    // backward compat with old object files built with `-fPIC`.
-    if (D->segment && D->segment->outputSeg->isTLS())
-      return D->getOutputSegmentOffset() + reloc.Addend;
-
     uint64_t value = D->getVA() + reloc.Addend;
     if (reloc.Type == R_WASM_MEMORY_ADDR_LOCREL_I32) {
       const auto *segment = cast<InputSegment>(chunk);
@@ -190,12 +184,6 @@
     }
     return value;
   }
-  case R_WASM_MEMORY_ADDR_TLS_SLEB:
-  case R_WASM_MEMORY_ADDR_TLS_SLEB64:
-    if (isa<UndefinedData>(sym) || sym->isUndefWeak())
-      return 0;
-    // TLS relocations are relative to the start of the TLS output segment
-    return cast<DefinedData>(sym)->getOutputSegmentOffset() + reloc.Addend;
   case R_WASM_TYPE_INDEX_LEB:
     return typeMap[reloc.Index];
   case R_WASM_FUNCTION_INDEX_LEB:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112831.383410.patch
Type: text/x-patch
Size: 2214 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211029/f0b35d62/attachment.bin>


More information about the llvm-commits mailing list