Index: include/llvm/BinaryFormat/Wasm.h =================================================================== --- include/llvm/BinaryFormat/Wasm.h +++ include/llvm/BinaryFormat/Wasm.h @@ -90,7 +90,7 @@ }; struct WasmFunction { - uint32_t Index; + uint32_t Index; // Wasm Function index space std::vector Locals; ArrayRef Body; uint32_t CodeSectionOffset; Index: include/llvm/Object/Wasm.h =================================================================== --- include/llvm/Object/Wasm.h +++ include/llvm/Object/Wasm.h @@ -42,31 +42,38 @@ }; WasmSymbol(StringRef Name, SymbolType Type, uint32_t Section, - uint32_t ElementIndex, uint32_t FunctionType = 0) - : Name(Name), Type(Type), Section(Section), ElementIndex(ElementIndex), - FunctionType(FunctionType) {} + uint32_t SymbolIndex, uint32_t WasmIndex, + uint32_t FunctionType = 0) + : Name(Name), Type(Type), Section(Section), SymbolIndex(SymbolIndex), + WasmIndex(WasmIndex), FunctionType(FunctionType) {} StringRef Name; SymbolType Type; uint32_t Section; uint32_t Flags = 0; - // Index into either the function or global index space. - uint32_t ElementIndex; + // Index into either the Symbol index space, which consists of all Symbols + // together, in order of declaration. + uint32_t SymbolIndex; + // Index into the the function or global Wasm index space. This is the + // index space used by the Wasm format for referring to a function or + // global, and consists of the imports followed by the function/global + // definitions. + // To be crystal clear, the following Wasm file has three linker symbols, + // and two Wasm callable items: + // (import "env" "externalFn" ...) + // (export "exportedFn" (func $exportedFnBody)) + // (export "exportedFnAlias" (func $exportedFnBody)) + // (func $exportedFnBody ...) + // Symbol index space = + // [ 0: import externalFn, 1: export exportedFn, 2: export exportedFnAlias ] + // Wasm function index space = + // [ 0: import externalFn, 1: definition exportedFnBody ] + uint32_t WasmIndex; // For function, the type index uint32_t FunctionType; - // Symbols can be both exported and imported (in the case of the weakly - // defined symbol). In this the import index is stored as AltIndex. - uint32_t AltIndex = 0; - bool HasAltIndex = false; - - void setAltIndex(uint32_t Index) { - HasAltIndex = true; - AltIndex = Index; - } - bool isFunction() const { return Type == WasmSymbol::SymbolType::FUNCTION_IMPORT || Type == WasmSymbol::SymbolType::FUNCTION_EXPORT; @@ -99,7 +106,8 @@ void print(raw_ostream &Out) const { Out << "Name=" << Name << ", Type=" << static_cast(Type) - << ", Flags=" << Flags << " ElemIndex=" << ElementIndex; + << ", Flags=" << Flags << " SymbolIndex=" << SymbolIndex + << ", WasmIndex=" << WasmIndex; } #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) @@ -150,6 +158,8 @@ ArrayRef comdats() const { return Comdats; } ArrayRef debugNames() const { return DebugNames; } uint32_t startFunction() const { return StartFunction; } + uint32_t getNumImportedGlobals() const { return NumImportedGlobals; } + uint32_t getNumImportedFunctions() const { return NumImportedFunctions; } void moveSymbolNext(DataRefImpl &Symb) const override; @@ -205,6 +215,8 @@ private: bool isValidFunctionIndex(uint32_t Index) const; + bool isValidFunctionSymbolIndex(uint32_t Index) const; + bool isValidGlobalIndex(uint32_t Index) const; const WasmSection &getWasmSection(DataRefImpl Ref) const; const wasm::WasmRelocation &getWasmRelocation(DataRefImpl Ref) const; @@ -236,7 +248,7 @@ Error parseRelocSection(StringRef Name, const uint8_t *Ptr, const uint8_t *End); - void populateSymbolTable(); + Error populateSymbolTable(); wasm::WasmObjectHeader Header; std::vector Sections; @@ -261,6 +273,8 @@ uint32_t ImportSection = 0; uint32_t ExportSection = 0; + // TODO: will get rid of this map in next commit, once we get replace the + // WASM_SYMBOL_INFO section with WASM_SYMBOL_TABLE StringMap SymbolMap; }; Index: lib/MC/WasmObjectWriter.cpp =================================================================== --- lib/MC/WasmObjectWriter.cpp +++ lib/MC/WasmObjectWriter.cpp @@ -215,8 +215,10 @@ // Index values to use for fixing up call_indirect type indices. // Maps function symbols to the index of the type of the function DenseMap TypeIndices; - // Maps function/global symbols to the function/global index space. + // Maps function/global symbols to the (shared) Symbol index space. DenseMap SymbolIndices; + // Maps function/global symbols to the function/global Wasm index space. + DenseMap WasmIndices; // Maps function symbol indices to the table element index space. Used // for TABLE_INDEX relocation types (i.e. address taken functions). SmallVector TableIndices; @@ -508,9 +510,9 @@ // Provisional value is table address of the resolved symbol itself const MCSymbolWasm *Sym = ResolveSymbol(*RelEntry.Symbol); assert(Sym->isFunction()); - assert(SymbolIndices.count(Sym)); - uint32_t SymbolIndex = SymbolIndices[Sym]; - int32_t TableIndex = TableIndices[SymbolIndex]; + assert(WasmIndices.count(Sym)); + uint32_t WasmIndex = WasmIndices[Sym]; + int32_t TableIndex = TableIndices[WasmIndex]; assert(TableIndex >= 0); return TableIndex; } @@ -528,7 +530,7 @@ if (!Sym->isDefined()) return 0; - uint32_t GlobalIndex = SymbolIndices[Sym]; + uint32_t GlobalIndex = WasmIndices[Sym]; const WasmGlobal& Global = Globals[GlobalIndex - NumGlobalImports]; uint64_t Address = Global.InitialValue + RelEntry.Addend; @@ -594,7 +596,7 @@ } if (!SymbolIndices.count(RelEntry.Symbol)) - report_fatal_error("symbol not found in function/global index space: " + + report_fatal_error("symbol not found in symbol index space: " + RelEntry.Symbol->getName()); return SymbolIndices[RelEntry.Symbol]; } @@ -977,6 +979,16 @@ return Pair.first->second; } +static void addFlags(SmallVector, 4> &SymbolFlags, + const MCSymbolWasm &WS) { + uint32_t Flags = (WS.isWeak() ? wasm::WASM_SYMBOL_BINDING_WEAK : 0) | + (WS.isHidden() ? wasm::WASM_SYMBOL_VISIBILITY_HIDDEN : 0) | + (!WS.isExternal() && WS.isDefined() ? wasm::WASM_SYMBOL_BINDING_LOCAL : 0); + if (Flags != 0) { + SymbolFlags.emplace_back(WS.getName(), Flags); + } +} + void WasmObjectWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) { DEBUG(dbgs() << "WasmObjectWriter::writeObject\n"); @@ -991,6 +1003,7 @@ SmallVector, 4> SymbolFlags; SmallVector, 2> InitFuncs; std::map> Comdats; + unsigned NumSymbols = 0; SmallVector DataSegments; uint32_t DataSize = 0; @@ -1088,8 +1101,7 @@ continue; // If the symbol is not defined in this translation unit, import it. - if ((!WS.isDefined() && !WS.isComdat()) || - WS.isVariable()) { + if (!WS.isDefined() && !WS.isComdat()) { WasmImport Import; Import.ModuleName = WS.getModuleName(); Import.FieldName = WS.getName(); @@ -1097,19 +1109,20 @@ if (WS.isFunction()) { Import.Kind = wasm::WASM_EXTERNAL_FUNCTION; Import.Type = getFunctionType(WS); - SymbolIndices[&WS] = NumFunctionImports; - ++NumFunctionImports; + WasmIndices[&WS] = NumFunctionImports++; + SymbolIndices[&WS] = NumSymbols++; } else { Import.Kind = wasm::WASM_EXTERNAL_GLOBAL; Import.Type = int32_t(PtrType); Import.IsMutable = false; - SymbolIndices[&WS] = NumGlobalImports; + WasmIndices[&WS] = NumGlobalImports++; + SymbolIndices[&WS] = NumSymbols++; // If this global is the stack pointer, make it mutable. if (WS.getName() == "__stack_pointer") Import.IsMutable = true; - ++NumGlobalImports; + addFlags(SymbolFlags, WS); } Imports.push_back(Import); @@ -1153,23 +1166,18 @@ const auto &WS = static_cast(S); DEBUG(dbgs() << "MCSymbol: '" << S << "'" - << " isDefined=" << S.isDefined() << " isExternal=" - << S.isExternal() << " isTemporary=" << S.isTemporary() + << " isDefined=" << S.isDefined() + << " isExternal=" << S.isExternal() + << " isTemporary=" << S.isTemporary() << " isFunction=" << WS.isFunction() << " isWeak=" << WS.isWeak() << " isHidden=" << WS.isHidden() << " isVariable=" << WS.isVariable() << "\n"); - if (WS.isWeak() || WS.isHidden()) { - uint32_t Flags = (WS.isWeak() ? wasm::WASM_SYMBOL_BINDING_WEAK : 0) | - (WS.isHidden() ? wasm::WASM_SYMBOL_VISIBILITY_HIDDEN : 0); - SymbolFlags.emplace_back(WS.getName(), Flags); - } - if (WS.isVariable()) continue; - unsigned Index; + unsigned WasmIndex, SymbolIndex; if (WS.isFunction()) { if (WS.isDefined()) { @@ -1182,21 +1190,24 @@ "function symbols must have a size set with .size"); // A definition. Take the next available index. - Index = NumFunctionImports + Functions.size(); + WasmIndex = NumFunctionImports + Functions.size(); + SymbolIndex = NumSymbols++; // Prepare the function. WasmFunction Func; Func.Type = getFunctionType(WS); Func.Sym = &WS; - SymbolIndices[&WS] = Index; + SymbolIndices[&WS] = SymbolIndex; + WasmIndices[&WS] = WasmIndex; Functions.push_back(Func); } else { // An import; the index was assigned above. - Index = SymbolIndices.find(&WS)->second; + WasmIndex = WasmIndices.find(&WS)->second; + SymbolIndex = SymbolIndices.find(&WS)->second; } - DEBUG(dbgs() << " -> function index: " << Index << "\n"); - } else { + DEBUG(dbgs() << " -> function index: " << WasmIndex << "\n"); + } else { if (WS.isTemporary() && !WS.getSize()) continue; @@ -1213,7 +1224,8 @@ // For each global, prepare a corresponding wasm global holding its // address. For externals these will also be named exports. - Index = NumGlobalImports + Globals.size(); + WasmIndex = NumGlobalImports + Globals.size(); + SymbolIndex = NumSymbols++; auto &DataSection = static_cast(WS.getSection()); assert(DataSection.isWasmData()); @@ -1223,16 +1235,19 @@ Global.HasImport = false; Global.InitialValue = DataSection.getMemoryOffset() + Layout.getSymbolOffset(WS); Global.ImportIndex = 0; - SymbolIndices[&WS] = Index; - DEBUG(dbgs() << " -> global index: " << Index << "\n"); + SymbolIndices[&WS] = SymbolIndex; + WasmIndices[&WS] = WasmIndex; + DEBUG(dbgs() << " -> global index: " << WasmIndex << "\n"); Globals.push_back(Global); } + addFlags(SymbolFlags, WS); + // If the symbol is visible outside this translation unit, export it. if (WS.isDefined()) { WasmExport Export; Export.FieldName = WS.getName(); - Export.Index = Index; + Export.Index = WasmIndex; if (WS.isFunction()) Export.Kind = wasm::WASM_EXTERNAL_FUNCTION; else @@ -1240,14 +1255,11 @@ DEBUG(dbgs() << " -> export " << Exports.size() << "\n"); Exports.push_back(Export); - if (!WS.isExternal()) - SymbolFlags.emplace_back(WS.getName(), wasm::WASM_SYMBOL_BINDING_LOCAL); - if (WS.isFunction()) { auto &Section = static_cast(WS.getSection()); if (const MCSymbolWasm *C = Section.getGroup()) Comdats[C->getName()].emplace_back( - WasmComdatEntry{wasm::WASM_COMDAT_FUNCTION, Index}); + WasmComdatEntry{wasm::WASM_COMDAT_FUNCTION, WasmIndex}); } } } @@ -1265,22 +1277,24 @@ const auto &WS = static_cast(S); const MCSymbolWasm *ResolvedSym = ResolveSymbol(WS); DEBUG(dbgs() << WS.getName() << ": weak alias of '" << *ResolvedSym << "'\n"); - assert(SymbolIndices.count(ResolvedSym) > 0); - uint32_t Index = SymbolIndices.find(ResolvedSym)->second; - DEBUG(dbgs() << " -> index:" << Index << "\n"); + assert(WasmIndices.count(ResolvedSym) > 0); + uint32_t WasmIndex = WasmIndices.find(ResolvedSym)->second; + DEBUG(dbgs() << " -> index:" << WasmIndex << "\n"); + + SymbolIndices[&WS] = NumSymbols++; + WasmIndices[&WS] = WasmIndex; + + addFlags(SymbolFlags, WS); WasmExport Export; Export.FieldName = WS.getName(); - Export.Index = Index; + Export.Index = WasmIndex; if (WS.isFunction()) Export.Kind = wasm::WASM_EXTERNAL_FUNCTION; else Export.Kind = wasm::WASM_EXTERNAL_GLOBAL; DEBUG(dbgs() << " -> export " << Exports.size() << "\n"); Exports.push_back(Export); - - if (!WS.isExternal()) - SymbolFlags.emplace_back(WS.getName(), wasm::WASM_SYMBOL_BINDING_LOCAL); } { @@ -1294,11 +1308,11 @@ return; assert(Rel.Symbol->isFunction()); const MCSymbolWasm* WS = ResolveSymbol(*Rel.Symbol); - uint32_t SymbolIndex = SymbolIndices[WS]; - if (TableIndices[SymbolIndex] == -1) { - TableIndices[SymbolIndex] = TableElems.size() + kInitialTableOffset; + uint32_t WasmIndex = WasmIndices[WS]; + if (TableIndices[WasmIndex] == -1) { + TableIndices[WasmIndex] = TableElems.size() + kInitialTableOffset; DEBUG(dbgs() << " -> adding to table: " << TableElems.size() << "\n"); - TableElems.push_back(SymbolIndex); + TableElems.push_back(WasmIndex); } }; Index: lib/Object/WasmObjectFile.cpp =================================================================== --- lib/Object/WasmObjectFile.cpp +++ lib/Object/WasmObjectFile.cpp @@ -317,67 +317,80 @@ return Error::success(); } -void WasmObjectFile::populateSymbolTable() { +Error WasmObjectFile::populateSymbolTable() { + Symbols.reserve(NumImportedFunctions + NumImportedGlobals + Exports.size()); + // Add imports to symbol table - size_t GlobalIndex = 0; - size_t FunctionIndex = 0; for (const wasm::WasmImport& Import : Imports) { + WasmSymbol::SymbolType ImportType; + unsigned FunctionType = 0; switch (Import.Kind) { case wasm::WASM_EXTERNAL_GLOBAL: assert(Import.Global.Type == wasm::WASM_TYPE_I32); - SymbolMap.try_emplace(Import.Field, Symbols.size()); - Symbols.emplace_back(Import.Field, WasmSymbol::SymbolType::GLOBAL_IMPORT, - ImportSection, GlobalIndex++); - DEBUG(dbgs() << "Adding import: " << Symbols.back() - << " sym index:" << Symbols.size() << "\n"); + ImportType = WasmSymbol::SymbolType::GLOBAL_IMPORT; break; case wasm::WASM_EXTERNAL_FUNCTION: - SymbolMap.try_emplace(Import.Field, Symbols.size()); - Symbols.emplace_back(Import.Field, - WasmSymbol::SymbolType::FUNCTION_IMPORT, - ImportSection, FunctionIndex++, Import.SigIndex); - DEBUG(dbgs() << "Adding import: " << Symbols.back() - << " sym index:" << Symbols.size() << "\n"); + ImportType = WasmSymbol::SymbolType::FUNCTION_IMPORT; + FunctionType = Import.SigIndex; break; default: - break; + continue; } + unsigned SymbolIndex = Symbols.size(); + if (!SymbolMap.try_emplace(Import.Field, SymbolIndex).second) + return make_error( + "Duplicate symbol name " + Import.Field, + object_error::parse_failed); + unsigned WasmIndex = SymbolIndex; + Symbols.emplace_back(Import.Field, ImportType, ImportSection, SymbolIndex, + WasmIndex, FunctionType); + DEBUG(dbgs() << "Adding import: " << Symbols.back() + << " sym index:" << SymbolIndex << "\n"); } // Add exports to symbol table for (const wasm::WasmExport& Export : Exports) { - if (Export.Kind == wasm::WASM_EXTERNAL_FUNCTION || - Export.Kind == wasm::WASM_EXTERNAL_GLOBAL) { - WasmSymbol::SymbolType ExportType = - Export.Kind == wasm::WASM_EXTERNAL_FUNCTION - ? WasmSymbol::SymbolType::FUNCTION_EXPORT - : WasmSymbol::SymbolType::GLOBAL_EXPORT; - auto Pair = SymbolMap.try_emplace(Export.Name, Symbols.size()); - if (Pair.second) { - Symbols.emplace_back(Export.Name, ExportType, - ExportSection, Export.Index); - DEBUG(dbgs() << "Adding export: " << Symbols.back() - << " sym index:" << Symbols.size() << "\n"); - } else { - uint32_t SymIndex = Pair.first->second; - const WasmSymbol &OldSym = Symbols[SymIndex]; - WasmSymbol NewSym(Export.Name, ExportType, ExportSection, Export.Index); - NewSym.setAltIndex(OldSym.ElementIndex); - Symbols[SymIndex] = NewSym; - - DEBUG(dbgs() << "Replacing existing symbol: " << NewSym - << " sym index:" << SymIndex << "\n"); - } - } - if (Export.Kind == wasm::WASM_EXTERNAL_FUNCTION) { + WasmSymbol::SymbolType ExportType; + unsigned FunctionType = 0; + switch (Export.Kind) { + case wasm::WASM_EXTERNAL_GLOBAL: + assert(isValidGlobalIndex(Export.Index)); + if (Export.Index < NumImportedGlobals) + return make_error("symbol cannot export an import", + object_error::parse_failed); + ExportType = WasmSymbol::SymbolType::GLOBAL_EXPORT; + break; + case wasm::WASM_EXTERNAL_FUNCTION: { + assert(isValidFunctionIndex(Export.Index)); + if (Export.Index < NumImportedFunctions) + return make_error("symbol cannot export an import", + object_error::parse_failed); + ExportType = WasmSymbol::SymbolType::FUNCTION_EXPORT; + FunctionType = FunctionTypes[Export.Index - NumImportedFunctions]; auto &Function = Functions[Export.Index - NumImportedFunctions]; if (Function.Name.empty()) { // Use the export's name to set a name for the Function, but only if one // hasn't already been set. Function.Name = Export.Name; } + break; } + default: + continue; + } + unsigned SymbolIndex = Symbols.size(); + if (!SymbolMap.try_emplace(Export.Name, SymbolIndex).second) + return make_error( + "Duplicate symbol name " + Export.Name, + object_error::parse_failed); + unsigned WasmIndex = Export.Index; + Symbols.emplace_back(Export.Name, ExportType, ExportSection, SymbolIndex, + WasmIndex, FunctionType); + DEBUG(dbgs() << "Adding export: " << Symbols.back() + << " sym index:" << SymbolIndex << "\n"); } + + return Error::success(); } Error WasmObjectFile::parseLinkingSection(const uint8_t *Ptr, @@ -391,7 +404,8 @@ // Only populate the symbol table with imports and exports if the object // has a linking section (i.e. its a relocatable object file). Otherwise // the global might not represent symbols at all. - populateSymbolTable(); + if (Error Err = populateSymbolTable()) + return Err; while (Ptr < End) { uint8_t Type = readVarint7(Ptr); @@ -441,7 +455,7 @@ wasm::WasmInitFunc Init; Init.Priority = readVaruint32(Ptr); Init.FunctionIndex = readVaruint32(Ptr); - if (!isValidFunctionIndex(Init.FunctionIndex)) + if (!isValidFunctionSymbolIndex(Init.FunctionIndex)) return make_error("Invalid function index: " + Twine(Init.FunctionIndex), object_error::parse_failed); @@ -736,16 +750,15 @@ Ex.Index = readVaruint32(Ptr); switch (Ex.Kind) { case wasm::WASM_EXTERNAL_FUNCTION: - if (Ex.Index >= FunctionTypes.size() + NumImportedFunctions) + if (!isValidFunctionIndex(Ex.Index)) return make_error("Invalid function export", object_error::parse_failed); break; - case wasm::WASM_EXTERNAL_GLOBAL: { - if (Ex.Index >= Globals.size() + NumImportedGlobals) + case wasm::WASM_EXTERNAL_GLOBAL: + if (!isValidGlobalIndex(Ex.Index)) return make_error("Invalid global export", object_error::parse_failed); break; - } case wasm::WASM_EXTERNAL_MEMORY: case wasm::WASM_EXTERNAL_TABLE: break; @@ -762,7 +775,15 @@ } bool WasmObjectFile::isValidFunctionIndex(uint32_t Index) const { - return Index < FunctionTypes.size() + NumImportedFunctions; + return Index < NumImportedFunctions + FunctionTypes.size(); +} + +bool WasmObjectFile::isValidFunctionSymbolIndex(uint32_t Index) const { + return Index < Symbols.size() && Symbols[Index].isFunction(); +} + +bool WasmObjectFile::isValidGlobalIndex(uint32_t Index) const { + return Index < NumImportedGlobals + Globals.size(); } Error WasmObjectFile::parseStartSection(const uint8_t *Ptr, const uint8_t *End) { @@ -931,9 +952,9 @@ case WasmSymbol::SymbolType::FUNCTION_IMPORT: case WasmSymbol::SymbolType::GLOBAL_IMPORT: case WasmSymbol::SymbolType::FUNCTION_EXPORT: - return Sym.ElementIndex; + return Sym.WasmIndex; case WasmSymbol::SymbolType::GLOBAL_EXPORT: { - uint32_t GlobalIndex = Sym.ElementIndex - NumImportedGlobals; + uint32_t GlobalIndex = Sym.WasmIndex - NumImportedGlobals; assert(GlobalIndex < Globals.size()); const wasm::WasmGlobal &Global = Globals[GlobalIndex]; // WasmSymbols correspond only to I32_CONST globals Index: test/MC/WebAssembly/func-address.ll =================================================================== --- test/MC/WebAssembly/func-address.ll +++ test/MC/WebAssembly/func-address.ll @@ -42,6 +42,6 @@ ; CHECK: Relocation { ; CHECK: Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB (1) ; CHECK: Offset: 0x1E -; CHECK: Index: 0x2 +; CHECK: Index: 0x3 ; CHECK: } ; CHECK: } Index: test/MC/WebAssembly/global-ctor-dtor.ll =================================================================== --- test/MC/WebAssembly/global-ctor-dtor.ll +++ test/MC/WebAssembly/global-ctor-dtor.ll @@ -95,25 +95,25 @@ ; CHECK-NEXT: Index: 0 ; CHECK-NEXT: Offset: 0x00000004 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB -; CHECK-NEXT: Index: 5 +; CHECK-NEXT: Index: 6 ; CHECK-NEXT: Offset: 0x0000000F ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 1 ; CHECK-NEXT: Offset: 0x00000017 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB -; CHECK-NEXT: Index: 1 +; CHECK-NEXT: Index: 2 ; CHECK-NEXT: Offset: 0x0000001D ; CHECK-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB -; CHECK-NEXT: Index: 2 +; CHECK-NEXT: Index: 3 ; CHECK-NEXT: Offset: 0x0000002C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB -; CHECK-NEXT: Index: 7 +; CHECK-NEXT: Index: 8 ; CHECK-NEXT: Offset: 0x00000037 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 1 ; CHECK-NEXT: Offset: 0x0000003F ; CHECK-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB -; CHECK-NEXT: Index: 1 +; CHECK-NEXT: Index: 2 ; CHECK-NEXT: Offset: 0x00000045 ; CHECK-NEXT: Functions: ; CHECK-NEXT: - Index: 5 @@ -121,13 +121,13 @@ ; CHECK-NEXT: Body: 1080808080000B ; CHECK-NEXT: - Index: 6 ; CHECK-NEXT: Locals: -; CHECK-NEXT: Body: 024041818080800041004180808080001081808080000D000F0B00000B +; CHECK-NEXT: Body: 024041818080800041004180808080001082808080000D000F0B00000B ; CHECK-NEXT: - Index: 7 ; CHECK-NEXT: Locals: -; CHECK-NEXT: Body: 1082808080000B +; CHECK-NEXT: Body: 1083808080000B ; CHECK-NEXT: - Index: 8 ; CHECK-NEXT: Locals: -; CHECK-NEXT: Body: 024041828080800041004180808080001081808080000D000F0B00000B +; CHECK-NEXT: Body: 024041828080800041004180808080001082808080000D000F0B00000B ; CHECK-NEXT: - Type: DATA ; CHECK-NEXT: Segments: ; CHECK-NEXT: - SectionOffset: 6 @@ -157,11 +157,11 @@ ; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: InitFunctions: ; CHECK-NEXT: - Priority: 42 -; CHECK-NEXT: FunctionIndex: 3 -; CHECK-NEXT: - Priority: 42 -; CHECK-NEXT: FunctionIndex: 6 -; CHECK-NEXT: - Priority: 65535 ; CHECK-NEXT: FunctionIndex: 4 +; CHECK-NEXT: - Priority: 42 +; CHECK-NEXT: FunctionIndex: 7 ; CHECK-NEXT: - Priority: 65535 -; CHECK-NEXT: FunctionIndex: 8 +; CHECK-NEXT: FunctionIndex: 5 +; CHECK-NEXT: - Priority: 65535 +; CHECK-NEXT: FunctionIndex: 9 ; CHECK-NEXT: ... Index: test/MC/WebAssembly/reloc-code.ll =================================================================== --- test/MC/WebAssembly/reloc-code.ll +++ test/MC/WebAssembly/reloc-code.ll @@ -26,13 +26,13 @@ ; CHECK-NEXT: Relocation { ; CHECK-NEXT: Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB (3) ; CHECK-NEXT: Offset: 0x9 -; CHECK-NEXT: Index: 0x0 +; CHECK-NEXT: Index: 0x3 ; CHECK-NEXT: Addend: 0 ; CHECK-NEXT: } ; CHECK-NEXT: Relocation { ; CHECK-NEXT: Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB (3) ; CHECK-NEXT: Offset: 0x14 -; CHECK-NEXT: Index: 0x1 +; CHECK-NEXT: Index: 0x4 ; CHECK-NEXT: Addend: 0 ; CHECK-NEXT: } ; CHECK-NEXT: Relocation { Index: test/MC/WebAssembly/weak-alias.ll =================================================================== --- test/MC/WebAssembly/weak-alias.ll +++ test/MC/WebAssembly/weak-alias.ll @@ -63,32 +63,23 @@ ; CHECK-NEXT: ElemType: ANYFUNC ; CHECK-NEXT: Limits: ; CHECK-NEXT: Initial: 0x00000001 -; CHECK-NEXT: - Module: env -; CHECK-NEXT: Field: foo_alias -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: SigIndex: 0 -; CHECK-NEXT: - Module: env -; CHECK-NEXT: Field: bar_alias -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: GlobalType: I32 -; CHECK-NEXT: GlobalMutable: false ; CHECK-NEXT: - Type: FUNCTION ; CHECK-NEXT: FunctionTypes: [ 0, 0, 0, 0, 0 ] ; CHECK-NEXT: - Type: GLOBAL ; CHECK-NEXT: Globals: -; CHECK-NEXT: - Index: 1 +; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Type: I32 ; CHECK-NEXT: Mutable: false ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 8 -; CHECK-NEXT: - Index: 2 +; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Type: I32 ; CHECK-NEXT: Mutable: false ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 16 -; CHECK-NEXT: - Index: 3 +; CHECK-NEXT: - Index: 2 ; CHECK-NEXT: Type: I32 ; CHECK-NEXT: Mutable: false ; CHECK-NEXT: InitExpr: @@ -98,83 +89,83 @@ ; CHECK-NEXT: Exports: ; CHECK-NEXT: - Name: foo ; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 1 +; CHECK-NEXT: Index: 0 ; CHECK-NEXT: - Name: call_direct ; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 2 +; CHECK-NEXT: Index: 1 ; CHECK-NEXT: - Name: call_alias ; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 3 +; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Name: call_direct_ptr ; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 4 +; CHECK-NEXT: Index: 3 ; CHECK-NEXT: - Name: direct_address ; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 1 +; CHECK-NEXT: Index: 0 ; CHECK-NEXT: - Name: call_alias_ptr ; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 5 +; CHECK-NEXT: Index: 4 ; CHECK-NEXT: - Name: alias_address ; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 2 +; CHECK-NEXT: Index: 1 ; CHECK-NEXT: - Name: bar ; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 3 +; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Name: foo_alias ; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 1 +; CHECK-NEXT: Index: 0 ; CHECK-NEXT: - Name: bar_alias ; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 3 +; CHECK-NEXT: Index: 2 ; CHECK-NEXT: - Type: ELEM ; CHECK-NEXT: Segments: ; CHECK-NEXT: - Offset: ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 1 -; CHECK-NEXT: Functions: [ 1 ] +; CHECK-NEXT: Functions: [ 0 ] ; CHECK-NEXT: - Type: CODE ; CHECK-NEXT: Relocations: ; CHECK-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB -; CHECK-NEXT: Index: 1 +; CHECK-NEXT: Index: 0 ; CHECK-NEXT: Offset: 0x00000009 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 8 ; CHECK-NEXT: Offset: 0x00000012 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 1 +; CHECK-NEXT: Index: 4 ; CHECK-NEXT: Offset: 0x0000001E ; CHECK-NEXT: - Type: R_WEBASSEMBLY_TYPE_INDEX_LEB ; CHECK-NEXT: Index: 0 ; CHECK-NEXT: Offset: 0x00000024 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 2 +; CHECK-NEXT: Index: 6 ; CHECK-NEXT: Offset: 0x00000031 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_TYPE_INDEX_LEB ; CHECK-NEXT: Index: 0 ; CHECK-NEXT: Offset: 0x00000037 ; CHECK-NEXT: Functions: -; CHECK-NEXT: - Index: 1 +; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Locals: ; CHECK-NEXT: Body: 41000B -; CHECK-NEXT: - Index: 2 -; CHECK-NEXT: Locals: -; CHECK-NEXT: Body: 1081808080000B -; CHECK-NEXT: - Index: 3 +; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Locals: ; CHECK-NEXT: Body: 1080808080000B -; CHECK-NEXT: - Index: 4 +; CHECK-NEXT: - Index: 2 +; CHECK-NEXT: Locals: +; CHECK-NEXT: Body: 1088808080000B +; CHECK-NEXT: - Index: 3 ; CHECK-NEXT: Locals: ; CHECK-NEXT: Body: 410028028880808000118080808000000B -; CHECK-NEXT: - Index: 5 +; CHECK-NEXT: - Index: 4 ; CHECK-NEXT: Locals: ; CHECK-NEXT: Body: 410028029080808000118080808000000B ; CHECK-NEXT: - Type: DATA ; CHECK-NEXT: Relocations: ; CHECK-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_I32 -; CHECK-NEXT: Index: 1 +; CHECK-NEXT: Index: 0 ; CHECK-NEXT: Offset: 0x0000000F ; CHECK-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_I32 -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 8 ; CHECK-NEXT: Offset: 0x00000018 ; CHECK-NEXT: Segments: ; CHECK-NEXT: - SectionOffset: 6 @@ -199,10 +190,6 @@ ; CHECK-NEXT: Name: linking ; CHECK-NEXT: DataSize: 20 ; CHECK-NEXT: SymbolInfo: -; CHECK-NEXT: - Name: foo_alias -; CHECK-NEXT: Flags: [ BINDING_WEAK, VISIBILITY_HIDDEN ] -; CHECK-NEXT: - Name: bar_alias -; CHECK-NEXT: Flags: [ BINDING_WEAK, VISIBILITY_HIDDEN ] ; CHECK-NEXT: - Name: foo ; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ] ; CHECK-NEXT: - Name: call_direct @@ -213,6 +200,10 @@ ; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ] ; CHECK-NEXT: - Name: call_alias_ptr ; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ] +; CHECK-NEXT: - Name: foo_alias +; CHECK-NEXT: Flags: [ BINDING_WEAK, VISIBILITY_HIDDEN ] +; CHECK-NEXT: - Name: bar_alias +; CHECK-NEXT: Flags: [ BINDING_WEAK, VISIBILITY_HIDDEN ] ; CHECK-NEXT: SegmentInfo: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name: .data.bar @@ -229,13 +220,13 @@ ; CHECK-NEXT: ... ; CHECK-SYMS: SYMBOL TABLE: -; CHECK-SYMS-NEXT: 00000001 gw F EXPORT .hidden foo_alias -; CHECK-SYMS-NEXT: 00000000 gw EXPORT .hidden bar_alias -; CHECK-SYMS-NEXT: 00000001 g F EXPORT .hidden foo -; CHECK-SYMS-NEXT: 00000002 g F EXPORT .hidden call_direct -; CHECK-SYMS-NEXT: 00000003 g F EXPORT .hidden call_alias -; CHECK-SYMS-NEXT: 00000004 g F EXPORT .hidden call_direct_ptr -; CHECK-SYMS-NEXT: 00000008 g EXPORT direct_address -; CHECK-SYMS-NEXT: 00000005 g F EXPORT .hidden call_alias_ptr -; CHECK-SYMS-NEXT: 00000010 g EXPORT alias_address -; CHECK-SYMS-NEXT: 00000000 g EXPORT bar +; CHECK-SYMS-NEXT: 00000000 g F EXPORT .hidden foo +; CHECK-SYMS-NEXT: 00000001 g F EXPORT .hidden call_direct +; CHECK-SYMS-NEXT: 00000002 g F EXPORT .hidden call_alias +; CHECK-SYMS-NEXT: 00000003 g F EXPORT .hidden call_direct_ptr +; CHECK-SYMS-NEXT: 00000008 g EXPORT direct_address +; CHECK-SYMS-NEXT: 00000004 g F EXPORT .hidden call_alias_ptr +; CHECK-SYMS-NEXT: 00000010 g EXPORT alias_address +; CHECK-SYMS-NEXT: 00000000 g EXPORT bar +; CHECK-SYMS-NEXT: 00000000 gw F EXPORT .hidden foo_alias +; CHECK-SYMS-NEXT: 00000000 gw EXPORT .hidden bar_alias