From: Sam Clegg Date: Thu, 21 Dec 2017 02:43:39 +0000 (+0000) Subject: [WebAssmebly] Fix references to weak aliases X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1cf31bbca5b9c50f0002976945e9e9e2dafbfae7;p=platform%2Fupstream%2Fllvm.git [WebAssmebly] Fix references to weak aliases Corresponding LLVM change: https://reviews.llvm.org/D41472 Differential Revision: https://reviews.llvm.org/D41473 llvm-svn: 321244 --- diff --git a/lld/test/wasm/weak-alias-overide.ll b/lld/test/wasm/weak-alias-overide.ll index 0a47bc6..1fe33b9 100644 --- a/lld/test/wasm/weak-alias-overide.ll +++ b/lld/test/wasm/weak-alias-overide.ll @@ -79,7 +79,7 @@ entry: ; CHECK-NEXT: - Offset: ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 1 -; CHECK-NEXT: Functions: [ 0 ] +; CHECK-NEXT: Functions: [ 2 ] ; CHECK-NEXT: - Type: CODE ; CHECK-NEXT: Functions: ; CHECK-NEXT: - Locals: @@ -89,7 +89,7 @@ entry: ; CHECK-NEXT: - Locals: ; CHECK-NEXT: Body: 41000B ; CHECK-NEXT: - Locals: -; CHECK-NEXT: Body: 1080808080000B +; CHECK-NEXT: Body: 1082808080000B ; CHECK-NEXT: - Locals: ; CHECK-NEXT: Body: 1080808080000B ; CHECK-NEXT: - Locals: @@ -97,7 +97,7 @@ entry: ; CHECK-NEXT: - Locals: ; CHECK-NEXT: - Type: I32 ; CHECK-NEXT: Count: 2 -; CHECK-NEXT: Body: 23808080800041106B220024808080800020004181808080003602081080808080002101200041106A24808080800020010B +; CHECK-NEXT: Body: 23808080800041106B220024808080800020004181808080003602081082808080002101200041106A24808080800020010B ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: linking ; CHECK-NEXT: DataSize: 0 diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp index e7463da..1a1a681 100644 --- a/lld/wasm/InputFiles.cpp +++ b/lld/wasm/InputFiles.cpp @@ -198,13 +198,22 @@ void ObjFile::initializeSymbols() { DEBUG(dbgs() << "Function: " << WasmSym.ElementIndex << " -> " << toString(*S) << "\n"); FunctionSymbols[WasmSym.ElementIndex] = S; + if (WasmSym.HasAltIndex) + FunctionSymbols[WasmSym.AltIndex] = S; } else { DEBUG(dbgs() << "Global: " << WasmSym.ElementIndex << " -> " << toString(*S) << "\n"); GlobalSymbols[WasmSym.ElementIndex] = S; + if (WasmSym.HasAltIndex) + GlobalSymbols[WasmSym.AltIndex] = S; } } + DEBUG(for (size_t I = 0; I < FunctionSymbols.size(); ++I) + assert(FunctionSymbols[I] != nullptr); + for (size_t I = 0; I < GlobalSymbols.size(); ++I) + assert(GlobalSymbols[I] != nullptr);); + // Populate `TableSymbols` with all symbols that are called indirectly uint32_t SegmentCount = WasmObj->elements().size(); if (SegmentCount) { diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp index 108a60a..751008d 100644 --- a/lld/wasm/SymbolTable.cpp +++ b/lld/wasm/SymbolTable.cpp @@ -83,15 +83,7 @@ static const WasmSignature *getFunctionSig(const ObjFile &Obj, const WasmSymbol &Sym) { DEBUG(dbgs() << "getFunctionSig: " << Sym.Name << "\n"); const WasmObjectFile *WasmObj = Obj.getWasmObj(); - uint32_t FunctionType; - if (Obj.isImportedFunction(Sym.ElementIndex)) { - const WasmImport &Import = WasmObj->imports()[Sym.ImportIndex]; - FunctionType = Import.SigIndex; - } else { - uint32_t FunctionIndex = Sym.ElementIndex - Obj.NumFunctionImports(); - FunctionType = WasmObj->functionTypes()[FunctionIndex]; - } - return &WasmObj->types()[FunctionType]; + return &WasmObj->types()[Sym.FunctionType]; } // Check the type of new symbol matches that of the symbol is replacing.