diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -557,12 +557,13 @@ } static const MCSymbolWasm *resolveSymbol(const MCSymbolWasm &Symbol) { - if (Symbol.isVariable()) { - const MCExpr *Expr = Symbol.getVariableValue(); + const MCSymbolWasm* Ret = &Symbol; + while (Ret->isVariable()) { + const MCExpr *Expr = Ret->getVariableValue(); auto *Inner = cast(Expr); - return cast(&Inner->getSymbol()); + Ret = cast(&Inner->getSymbol()); } - return &Symbol; + return Ret; } // Compute a value to write into the code at the location covered @@ -1421,12 +1422,12 @@ LLVM_DEBUG(dbgs() << WS.getName() << ": weak alias of '" << *ResolvedSym << "'\n"); - if (WS.isFunction()) { + if (ResolvedSym->isFunction()) { assert(WasmIndices.count(ResolvedSym) > 0); uint32_t WasmIndex = WasmIndices.find(ResolvedSym)->second; WasmIndices[&WS] = WasmIndex; LLVM_DEBUG(dbgs() << " -> index:" << WasmIndex << "\n"); - } else if (WS.isData()) { + } else if (ResolvedSym->isData()) { assert(DataLocations.count(ResolvedSym) > 0); const wasm::WasmDataReference &Ref = DataLocations.find(ResolvedSym)->second; diff --git a/llvm/test/MC/WebAssembly/function-alias.ll b/llvm/test/MC/WebAssembly/function-alias.ll --- a/llvm/test/MC/WebAssembly/function-alias.ll +++ b/llvm/test/MC/WebAssembly/function-alias.ll @@ -5,8 +5,10 @@ @foo = alias i8, bitcast (i8* ()* @func to i8*) @bar = alias i8* (), i8* ()* @func +@bar2 = alias i8* (), i8* ()* @bar define i8* @func() { + call i8* @bar2(); ret i8* @foo; } @@ -19,6 +21,13 @@ ; CHECK-NEXT: ElementIndex: 0x0 ; CHECK-NEXT: } ; CHECK-NEXT: Symbol { +; CHECK-NEXT: Name: bar2 +; CHECK-NEXT: Type: FUNCTION (0x0) +; CHECK-NEXT: Flags [ (0x0) +; CHECK-NEXT: ] +; CHECK-NEXT: ElementIndex: 0x0 +; CHECK-NEXT: } +; CHECK-NEXT: Symbol { ; CHECK-NEXT: Name: foo ; CHECK-NEXT: Type: FUNCTION (0x0) ; CHECK-NEXT: Flags [ (0x0)