Index: include/llvm/Object/Wasm.h =================================================================== --- include/llvm/Object/Wasm.h +++ include/llvm/Object/Wasm.h @@ -42,31 +42,27 @@ }; 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; + // For a function or global symbol, the index into the the 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 then definitions. + uint32_t WasmIndex; - // For function, the type index + // For a function symbol, 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 +95,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 +147,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; @@ -206,6 +205,9 @@ private: bool isValidFunctionIndex(uint32_t Index) const; bool isDefinedFunctionIndex(uint32_t Index) const; + bool isValidGlobalIndex(uint32_t Index) const; + bool isDefinedGlobalIndex(uint32_t Index) const; + bool isValidFunctionSymbolIndex(uint32_t Index) const; wasm::WasmFunction& getDefinedFunction(uint32_t Index); const WasmSection &getWasmSection(DataRefImpl Ref) const; @@ -239,7 +241,7 @@ Error parseRelocSection(StringRef Name, const uint8_t *Ptr, const uint8_t *End); - void populateSymbolTable(); + Error populateSymbolTable(); wasm::WasmObjectHeader Header; std::vector Sections; @@ -264,6 +266,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 @@ -209,8 +209,10 @@ // Maps function symbols to the table element index space. Used // for TABLE_INDEX relocation types (i.e. address taken functions). DenseMap TableIndices; - // 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; DenseMap FunctionTypeIndices; @@ -243,6 +245,7 @@ DataRelocations.clear(); TypeIndices.clear(); SymbolIndices.clear(); + WasmIndices.clear(); TableIndices.clear(); FunctionTypeIndices.clear(); FunctionTypes.clear(); @@ -501,11 +504,16 @@ assert(Sym->isFunction()); return TableIndices[Sym]; } - case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB: case wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB: - case wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB: - // Provisional value is function/type/global index itself + // Provisional value is same as the index return getRelocationIndexValue(RelEntry); + case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB: + case wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB: + // Provisional value is function/global Wasm index + if (!WasmIndices.count(RelEntry.Symbol)) + report_fatal_error("symbol not found in wasm index space: " + + RelEntry.Symbol->getName()); + return WasmIndices[RelEntry.Symbol]; case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB: case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32: case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB: { @@ -515,7 +523,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; @@ -581,7 +589,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]; } @@ -978,9 +986,19 @@ SmallVector, 4> SymbolFlags; SmallVector, 2> InitFuncs; std::map> Comdats; + unsigned NumSymbols = 0; SmallVector DataSegments; uint32_t DataSize = 0; + auto AddSymbol = [&](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); + } + }; + // In the special .global_variables section, we've encoded global // variables used by the function. Translate them into the Globals // list. @@ -1075,8 +1093,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(); @@ -1084,22 +1101,20 @@ if (WS.isFunction()) { Import.Kind = wasm::WASM_EXTERNAL_FUNCTION; Import.Type = getFunctionType(WS); - SymbolIndices[&WS] = NumFunctionImports; - ++NumFunctionImports; + WasmIndices[&WS] = NumFunctionImports++; } else { Import.Kind = wasm::WASM_EXTERNAL_GLOBAL; Import.Type = int32_t(PtrType); Import.IsMutable = false; - SymbolIndices[&WS] = NumGlobalImports; - + WasmIndices[&WS] = NumGlobalImports++; // If this global is the stack pointer, make it mutable. if (WS.getName() == "__stack_pointer") Import.IsMutable = true; - - ++NumGlobalImports; } - Imports.push_back(Import); + + SymbolIndices[&WS] = NumSymbols++; + AddSymbol(WS); } } @@ -1148,16 +1163,12 @@ << " 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; + if (WS.isComdat() && !WS.isDefined()) + continue; - unsigned Index; + unsigned WasmIndex; if (WS.isFunction()) { if (WS.isDefined()) { @@ -1169,58 +1180,65 @@ report_fatal_error( "function symbols must have a size set with .size"); - // A definition. Take the next available index. - Index = NumFunctionImports + Functions.size(); - - // Prepare the function. + // A definition. Export the function body. + WasmIndex = NumFunctionImports + Functions.size(); WasmFunction Func; Func.Type = getFunctionType(WS); Func.Sym = &WS; - SymbolIndices[&WS] = Index; + WasmIndices[&WS] = WasmIndex; Functions.push_back(Func); + + auto &Section = static_cast(WS.getSection()); + if (const MCSymbolWasm *C = Section.getGroup()) { + Comdats[C->getName()].emplace_back( + WasmComdatEntry{wasm::WASM_COMDAT_FUNCTION, WasmIndex}); + } } else { // An import; the index was assigned above. - Index = SymbolIndices.find(&WS)->second; + WasmIndex = WasmIndices.find(&WS)->second; } - DEBUG(dbgs() << " -> function index: " << Index << "\n"); - } else { + DEBUG(dbgs() << " -> function index: " << WasmIndex << "\n"); + } else { if (WS.isTemporary() && !WS.getSize()) continue; - if (!WS.isDefined()) - continue; + if (WS.isDefined()) { + if (!WS.getSize()) + report_fatal_error("data symbols must have a size set with .size: " + + WS.getName()); - if (!WS.getSize()) - report_fatal_error("data symbols must have a size set with .size: " + - WS.getName()); + int64_t Size = 0; + if (!WS.getSize()->evaluateAsAbsolute(Size, Layout)) + report_fatal_error(".size expression must be evaluatable"); - int64_t Size = 0; - if (!WS.getSize()->evaluateAsAbsolute(Size, Layout)) - report_fatal_error(".size expression must be evaluatable"); + auto& DataSection = static_cast(WS.getSection()); + assert(DataSection.isWasmData()); - // For each global, prepare a corresponding wasm global holding its - // address. For externals these will also be named exports. - Index = NumGlobalImports + Globals.size(); - auto &DataSection = static_cast(WS.getSection()); - assert(DataSection.isWasmData()); - - WasmGlobal Global; - Global.Type = PtrType; - Global.IsMutable = false; - Global.HasImport = false; - Global.InitialValue = DataSection.getMemoryOffset() + Layout.getSymbolOffset(WS); - Global.ImportIndex = 0; - SymbolIndices[&WS] = Index; - DEBUG(dbgs() << " -> global index: " << Index << "\n"); - Globals.push_back(Global); + // For each global, prepare a corresponding wasm global holding its + // address. For externals these will also be named exports. + WasmIndex = NumGlobalImports + Globals.size(); + WasmGlobal Global; + Global.Type = PtrType; + Global.IsMutable = false; + Global.HasImport = false; + Global.InitialValue = + DataSection.getMemoryOffset() + Layout.getSymbolOffset(WS); + Global.ImportIndex = 0; + WasmIndices[&WS] = WasmIndex; + Globals.push_back(Global); + } else { + // An import; the index was assigned above. + WasmIndex = WasmIndices.find(&WS)->second; + } + DEBUG(dbgs() << " -> global index: " << WasmIndex << "\n"); } // 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 @@ -1228,15 +1246,8 @@ 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}); - } + SymbolIndices[&WS] = NumSymbols++; + AddSymbol(WS); } } @@ -1253,13 +1264,15 @@ 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; + WasmIndices[&WS] = WasmIndex; + DEBUG(dbgs() << " -> index:" << WasmIndex << "\n"); WasmExport Export; Export.FieldName = WS.getName(); - Export.Index = Index; + Export.Index = WasmIndex; if (WS.isFunction()) Export.Kind = wasm::WASM_EXTERNAL_FUNCTION; else @@ -1267,8 +1280,8 @@ DEBUG(dbgs() << " -> export " << Exports.size() << "\n"); Exports.push_back(Export); - if (!WS.isExternal()) - SymbolFlags.emplace_back(WS.getName(), wasm::WASM_SYMBOL_BINDING_LOCAL); + SymbolIndices[&WS] = NumSymbols++; + AddSymbol(WS); } { @@ -1281,12 +1294,12 @@ return; assert(Rel.Symbol->isFunction()); const MCSymbolWasm* WS = ResolveSymbol(*Rel.Symbol); - uint32_t SymbolIndex = SymbolIndices[WS]; + uint32_t WasmIndex = WasmIndices[WS]; uint32_t TableIndex = TableElems.size() + kInitialTableOffset; if (TableIndices.try_emplace(WS, TableIndex).second) { DEBUG(dbgs() << " -> adding " << WS->getName() << " 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,68 +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 && - isDefinedFunctionIndex(Export.Index)) { + WasmSymbol::SymbolType ExportType; + unsigned FunctionType = 0; + switch (Export.Kind) { + case wasm::WASM_EXTERNAL_GLOBAL: + assert(isValidGlobalIndex(Export.Index)); + if (!isDefinedGlobalIndex(Export.Index)) + 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 (!isDefinedFunctionIndex(Export.Index)) + return make_error("symbol cannot export an import", + object_error::parse_failed); + ExportType = WasmSymbol::SymbolType::FUNCTION_EXPORT; + FunctionType = FunctionTypes[Export.Index - NumImportedFunctions]; auto &Function = getDefinedFunction(Export.Index); 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, @@ -392,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); @@ -442,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); @@ -740,12 +753,11 @@ 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,13 +774,25 @@ } bool WasmObjectFile::isValidFunctionIndex(uint32_t Index) const { - return Index < FunctionTypes.size() + NumImportedFunctions; + return Index < NumImportedFunctions + FunctionTypes.size(); } bool WasmObjectFile::isDefinedFunctionIndex(uint32_t Index) const { return Index >= NumImportedFunctions && isValidFunctionIndex(Index); } +bool WasmObjectFile::isValidGlobalIndex(uint32_t Index) const { + return Index < NumImportedGlobals + Globals.size(); +} + +bool WasmObjectFile::isDefinedGlobalIndex(uint32_t Index) const { + return Index >= NumImportedGlobals && isValidGlobalIndex(Index); +} + +bool WasmObjectFile::isValidFunctionSymbolIndex(uint32_t Index) const { + return Index < Symbols.size() && Symbols[Index].isFunction(); +} + wasm::WasmFunction& WasmObjectFile::getDefinedFunction(uint32_t Index) { assert(isDefinedFunctionIndex(Index)); return Functions[Index - NumImportedFunctions]; @@ -940,9 +964,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 @@ -44,6 +44,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 @@ -97,25 +97,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 @@ -159,11 +159,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 @@ -28,13 +28,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 @@ -65,32 +65,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: @@ -100,83 +91,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: 1080808080000B +; 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 @@ -201,10 +192,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 @@ -215,6 +202,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 @@ -231,13 +222,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