diff --git a/lld/wasm/Symbols.cpp b/lld/wasm/Symbols.cpp --- a/lld/wasm/Symbols.cpp +++ b/lld/wasm/Symbols.cpp @@ -190,11 +190,6 @@ void Symbol::setGOTIndex(uint32_t index) { LLVM_DEBUG(dbgs() << "setGOTIndex " << name << " -> " << index << "\n"); assert(gotIndex == INVALID_INDEX); - if (config->isPic) { - // Any symbol that is assigned a GOT entry must be exported otherwise the - // dynamic linker won't be able create the entry that contains it. - forceExport = true; - } gotIndex = index; } diff --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp --- a/lld/wasm/SyntheticSections.cpp +++ b/lld/wasm/SyntheticSections.cpp @@ -167,6 +167,12 @@ return; LLVM_DEBUG(dbgs() << "addGOTEntry: " << toString(*sym) << "\n"); sym->setGOTIndex(numImportedGlobals++); + if (config->isPic) { + // Any symbol that is assigned an normal GOT entry must be exported + // otherwise the dynamic linker won't be able create the entry that contains + // it. + sym->forceExport = true; + } gotSymbols.push_back(sym); }