Skip to content

Commit fad0546

Browse files
committed
[lld][WebAssembly] Handle TLS variables in Symbol::getVA. NFC
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. Differential Revision: https://reviews.llvm.org/D112831
1 parent 33cc0cf commit fad0546

2 files changed

Lines changed: 7 additions & 14 deletions

File tree

‎lld/wasm/InputFiles.cpp‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,12 @@ uint64_t ObjFile::calcNewValue(const WasmRelocation &reloc, uint64_t tombstone,
169169
case R_WASM_MEMORY_ADDR_REL_SLEB64:
170170
case R_WASM_MEMORY_ADDR_I32:
171171
case R_WASM_MEMORY_ADDR_I64:
172+
case R_WASM_MEMORY_ADDR_TLS_SLEB:
173+
case R_WASM_MEMORY_ADDR_TLS_SLEB64:
172174
case R_WASM_MEMORY_ADDR_LOCREL_I32: {
173175
if (isa<UndefinedData>(sym) || sym->isUndefWeak())
174176
return 0;
175177
auto D = cast<DefinedData>(sym);
176-
// Treat non-TLS relocation against symbols that live in the TLS segment
177-
// like TLS relocations. This behaviour exists to support older object
178-
// files created before we introduced TLS relocations.
179-
// TODO(sbc): Remove this legacy behaviour one day. This will break
180-
// backward compat with old object files built with `-fPIC`.
181-
if (D->segment && D->segment->outputSeg->isTLS())
182-
return D->getOutputSegmentOffset() + reloc.Addend;
183-
184178
uint64_t value = D->getVA() + reloc.Addend;
185179
if (reloc.Type == R_WASM_MEMORY_ADDR_LOCREL_I32) {
186180
const auto *segment = cast<InputSegment>(chunk);
@@ -190,12 +184,6 @@ uint64_t ObjFile::calcNewValue(const WasmRelocation &reloc, uint64_t tombstone,
190184
}
191185
return value;
192186
}
193-
case R_WASM_MEMORY_ADDR_TLS_SLEB:
194-
case R_WASM_MEMORY_ADDR_TLS_SLEB64:
195-
if (isa<UndefinedData>(sym) || sym->isUndefWeak())
196-
return 0;
197-
// TLS relocations are relative to the start of the TLS output segment
198-
return cast<DefinedData>(sym)->getOutputSegmentOffset() + reloc.Addend;
199187
case R_WASM_TYPE_INDEX_LEB:
200188
return typeMap[reloc.Index];
201189
case R_WASM_FUNCTION_INDEX_LEB:

‎lld/wasm/Symbols.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ uint32_t DefinedFunction::getExportedFunctionIndex() const {
305305

306306
uint64_t DefinedData::getVA() const {
307307
LLVM_DEBUG(dbgs() << "getVA: " << getName() << "\n");
308+
// In the shared memory case, TLS symbols are relative to the start of the TLS
309+
// output segment (__tls_base). When building without shared memory, TLS
310+
// symbols absolute, just like non-TLS.
311+
if (isTLS() && config->sharedMemory)
312+
return getOutputSegmentOffset() + value;
308313
if (segment)
309314
return segment->getVA(value);
310315
return value;

0 commit comments

Comments
 (0)