summaryrefslogtreecommitdiffstats
path: root/lld/wasm/Writer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/wasm/Writer.cpp')
-rw-r--r--lld/wasm/Writer.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index 47e76748f79..8ed4d6b94cd 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -1142,6 +1142,10 @@ void Writer::calculateTypes() {
registerType(E->Signature);
}
+static bool requiresGOTAccess(const Symbol* Sym) {
+ return Config->Pic && !Sym->isHidden() && !Sym->isLocal();
+}
+
void Writer::processRelocations(InputChunk *Chunk) {
if (!Chunk->Live)
return;
@@ -1153,8 +1157,8 @@ void Writer::processRelocations(InputChunk *Chunk) {
case R_WASM_TABLE_INDEX_SLEB:
case R_WASM_TABLE_INDEX_REL_SLEB: {
FunctionSymbol *Sym = File->getFunctionSymbol(Reloc.Index);
- if (Sym->hasTableIndex() || !Sym->hasFunctionIndex())
- continue;
+ if (Sym->hasTableIndex() || !Sym->hasFunctionIndex() || requiresGOTAccess(Sym))
+ break;
Sym->setTableIndex(TableBase + IndirectFunctions.size());
IndirectFunctions.emplace_back(Sym);
break;
@@ -1206,7 +1210,7 @@ void Writer::processRelocations(InputChunk *Chunk) {
// will be converted into code by `generateRelocationCode`. This code
// requires the symbols to have GOT entires.
auto* Sym = File->getSymbols()[Reloc.Index];
- if (!Sym->isHidden() && !Sym->isLocal() && !Sym->isInGOT()) {
+ if (requiresGOTAccess(Sym) && !Sym->isInGOT()) {
Sym->setGOTIndex(NumImportedGlobals++);
GOTSymbols.push_back(Sym);
}
OpenPOWER on IntegriCloud