From 26b697c4fe89c6357aa8488200b969fed59a0dc8 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Fri, 22 Feb 2019 21:41:42 +0000 Subject: [PATCH] [WebAssembly] MC: Handle aliases of aliases Differential Revision: https://reviews.llvm.org/D58417 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354694 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/WasmObjectWriter.cpp | 13 +++++++------ test/MC/WebAssembly/function-alias.ll | 9 +++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/MC/WasmObjectWriter.cpp b/lib/MC/WasmObjectWriter.cpp index d8dfc57c416..9ca239e3b47 100644 --- a/lib/MC/WasmObjectWriter.cpp +++ b/lib/MC/WasmObjectWriter.cpp @@ -558,12 +558,13 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm, } 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 @@ -1422,12 +1423,12 @@ uint64_t WasmObjectWriter::writeObject(MCAssembler &Asm, 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/test/MC/WebAssembly/function-alias.ll b/test/MC/WebAssembly/function-alias.ll index 0a3c53989bc..9fc91b6a8e2 100644 --- a/test/MC/WebAssembly/function-alias.ll +++ b/test/MC/WebAssembly/function-alias.ll @@ -5,8 +5,10 @@ target triple = "wasm32-unknown-unknown-wasm" @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 @@ define i8* @func() { ; 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) -- 2.50.1