[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 09:35:21 PDT 2021
sbc100 created this revision.
Herald added subscribers: wingo, ecnelises, sunfish, jgravelle-google, dschuff.
sbc100 requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.
In the shared memory case we can always assume that TLS addresses
are relative to __tls_base. In the non-shared memory case TLS
variables are absolute, just like normal data addresses.
This simplifies the code in calcNewValue so that TLS relocations
no longer need special handling.
Repository:
rG LLVM Github Monorepo
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,9 @@
uint64_t DefinedData::getVA() const {
LLVM_DEBUG(dbgs() << "getVA: " << getName() << "\n");
+ // TLS relocations are relative to the start of the TLS output segment
+ 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.383398.patch
Type: text/x-patch
Size: 2085 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211029/6d40b3af/attachment.bin>
More information about the llvm-commits
mailing list