diff --git a/lld/test/wasm/weak-undefined-pic.s b/lld/test/wasm/weak-undefined-pic.s --- a/lld/test/wasm/weak-undefined-pic.s +++ b/lld/test/wasm/weak-undefined-pic.s @@ -22,6 +22,7 @@ _start: .functype _start () -> () call get_foo_addr + call foo end_function .weak foo @@ -75,7 +76,10 @@ # RUN: obj2yaml %t3.wasm | FileCheck %s --check-prefix=IMPORT # IMPORT: - Type: IMPORT -# IMPORT: - Module: GOT.func +# IMPORT: Field: foo +# IMPORT-NEXT: Kind: FUNCTION +# IMPORT-NEXT: SigIndex: 0 +# IMPORT-NEXT: - Module: GOT.func # IMPORT-NEXT: Field: foo # IMPORT-NEXT: Kind: GLOBAL # IMPORT-NEXT: GlobalType: I32 diff --git a/lld/wasm/InputChunks.cpp b/lld/wasm/InputChunks.cpp --- a/lld/wasm/InputChunks.cpp +++ b/lld/wasm/InputChunks.cpp @@ -106,13 +106,12 @@ for (const WasmRelocation &rel : relocations) { uint8_t *loc = buf + rel.Offset - inputSectionOffset; - auto value = file->calcNewValue(rel, tombstone, this); LLVM_DEBUG(dbgs() << "apply reloc: type=" << relocTypeToString(rel.Type)); if (rel.Type != R_WASM_TYPE_INDEX_LEB) LLVM_DEBUG(dbgs() << " sym=" << file->getSymbols()[rel.Index]->getName()); LLVM_DEBUG(dbgs() << " addend=" << rel.Addend << " index=" << rel.Index - << " value=" << value << " offset=" << rel.Offset - << "\n"); + << " offset=" << rel.Offset << "\n"); + auto value = file->calcNewValue(rel, tombstone, this); switch (rel.Type) { case R_WASM_TYPE_INDEX_LEB: diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp --- a/lld/wasm/Writer.cpp +++ b/lld/wasm/Writer.cpp @@ -546,7 +546,7 @@ static bool shouldImport(Symbol *sym) { if (!sym->isUndefined()) return false; - if (sym->isWeak() && !config->relocatable) + if (sym->isWeak() && !config->relocatable && !config->isPic) return false; if (!sym->isLive()) return false;