Index: test/wasm/init-fini.ll =================================================================== --- test/wasm/init-fini.ll +++ test/wasm/init-fini.ll @@ -108,43 +108,62 @@ ; RELOC: Name: linking ; RELOC-NEXT: DataSize: 0 ; RELOC-NEXT: SymbolInfo: -; RELOC-NEXT: - Name: func1 +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 0 ; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; RELOC-NEXT: - Name: func2 +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 1 ; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; RELOC-NEXT: - Name: func3 +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 2 ; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; RELOC-NEXT: - Name: func4 +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 3 ; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; RELOC-NEXT: - Name: _start +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 5 ; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; RELOC-NEXT: - Name: .Lcall_dtors.101 +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 6 ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] -; RELOC-NEXT: - Name: .Lregister_call_dtors.101 +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 7 ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] -; RELOC-NEXT: - Name: .Lbitcast +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 8 ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] -; RELOC-NEXT: - Name: .Lcall_dtors.1001 +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 9 ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] -; RELOC-NEXT: - Name: .Lregister_call_dtors.1001 +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 10 ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] -; RELOC-NEXT: - Name: myctor +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 11 ; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; RELOC-NEXT: - Name: mydtor +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 12 ; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; RELOC-NEXT: - Name: .Lcall_dtors.101.1 +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 13 ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] -; RELOC-NEXT: - Name: .Lregister_call_dtors.101.1 +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 14 ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] -; RELOC-NEXT: - Name: .Lcall_dtors.202 +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 15 ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] -; RELOC-NEXT: - Name: .Lregister_call_dtors.202 +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 16 ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] -; RELOC-NEXT: - Name: .Lcall_dtors.2002 +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 17 ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] -; RELOC-NEXT: - Name: .Lregister_call_dtors.2002 +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 18 ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] -; RELOC-NEXT: - Name: __dso_handle +; RELOC-NEXT: - Kind: GLOBAL +; RELOC-NEXT: Index: 0 ; RELOC-NEXT: Flags: [ BINDING_WEAK, VISIBILITY_HIDDEN ] ; RELOC-NEXT: InitFunctions: ; RELOC-NEXT: - Priority: 101 Index: test/wasm/locals-duplicate.test =================================================================== --- test/wasm/locals-duplicate.test +++ test/wasm/locals-duplicate.test @@ -472,21 +472,29 @@ ; RELOC-NEXT: Name: linking ; RELOC-NEXT: DataSize: 24 ; RELOC-NEXT: SymbolInfo: -; RELOC-NEXT: - Name: colliding_func1.1 +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 0 ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] -; RELOC-NEXT: - Name: colliding_func3 +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 2 ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] -; RELOC-NEXT: - Name: colliding_func2.1 +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 10 ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] -; RELOC-NEXT: - Name: colliding_func3.1 +; RELOC-NEXT: - Kind: FUNCTION +; RELOC-NEXT: Index: 11 ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] -; RELOC-NEXT: - Name: colliding_global1.1 +; RELOC-NEXT: - Kind: GLOBAL +; RELOC-NEXT: Index: 0 ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] -; RELOC-NEXT: - Name: colliding_global3 +; RELOC-NEXT: - Kind: GLOBAL +; RELOC-NEXT: Index: 2 ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] -; RELOC-NEXT: - Name: colliding_global2.1 +; RELOC-NEXT: - Kind: GLOBAL +; RELOC-NEXT: Index: 4 ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] -; RELOC-NEXT: - Name: colliding_global3.1 +; RELOC-NEXT: - Kind: GLOBAL +; RELOC-NEXT: Index: 5 ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] ; RELOC-NEXT: SegmentInfo: ; RELOC-NEXT: - Index: 0 Index: test/wasm/relocatable.ll =================================================================== --- test/wasm/relocatable.ll +++ test/wasm/relocatable.ll @@ -229,23 +229,32 @@ ; CHECK-NEXT: Name: linking ; CHECK-NEXT: DataSize: 31 ; CHECK-NEXT: SymbolInfo: -; CHECK-NEXT: - Name: bar_import +; CHECK-NEXT: - Kind: FUNCTION +; CHECK-NEXT: Index: 2 ; CHECK-NEXT: Flags: [ BINDING_WEAK ] -; CHECK-NEXT: - Name: hello +; CHECK-NEXT: - Kind: FUNCTION +; CHECK-NEXT: Index: 3 ; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; CHECK-NEXT: - Name: my_func +; CHECK-NEXT: - Kind: FUNCTION +; CHECK-NEXT: Index: 4 ; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; CHECK-NEXT: - Name: func_comdat +; CHECK-NEXT: - Kind: FUNCTION +; CHECK-NEXT: Index: 5 ; CHECK-NEXT: Flags: [ BINDING_WEAK ] -; CHECK-NEXT: - Name: data_comdat +; CHECK-NEXT: - Kind: GLOBAL +; CHECK-NEXT: Index: 2 ; CHECK-NEXT: Flags: [ BINDING_WEAK ] -; CHECK-NEXT: - Name: func_addr1 +; CHECK-NEXT: - Kind: GLOBAL +; CHECK-NEXT: Index: 3 ; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; CHECK-NEXT: - Name: func_addr2 +; CHECK-NEXT: - Kind: GLOBAL +; CHECK-NEXT: Index: 4 ; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; CHECK-NEXT: - Name: func_addr3 +; CHECK-NEXT: - Kind: GLOBAL +; CHECK-NEXT: Index: 5 ; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; CHECK-NEXT: - Name: data_addr1 +; CHECK-NEXT: - Kind: GLOBAL +; CHECK-NEXT: Index: 6 ; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ] ; CHECK-NEXT: SegmentInfo: ; CHECK-NEXT: - Index: 0 Index: wasm/Writer.cpp =================================================================== --- wasm/Writer.cpp +++ wasm/Writer.cpp @@ -392,28 +392,32 @@ if (!Config->Relocatable) return; - std::vector> SymbolInfo; - auto addSymInfo = [&](const Symbol *Sym, StringRef ExternalName) { + std::vector> SymbolInfo; + auto addSymInfo = [&](const Symbol *Sym) { uint32_t Flags = (Sym->isLocal() ? WASM_SYMBOL_BINDING_LOCAL : Sym->isWeak() ? WASM_SYMBOL_BINDING_WEAK : 0) | (Sym->isHidden() ? WASM_SYMBOL_VISIBILITY_HIDDEN : 0); - if (Flags) - SymbolInfo.emplace_back(ExternalName, Flags); + if (Flags) { + uint32_t Kind = Sym->isFunction() ? WASM_EXTERNAL_FUNCTION + : WASM_EXTERNAL_GLOBAL; + SymbolInfo.emplace_back(Kind, Sym->getOutputSymbolIndex(), Flags); + } }; // (Imports can't have internal linkage, their names don't need to be budged.) for (const Symbol *Sym : ImportedFunctions) - addSymInfo(Sym, Sym->getName()); + addSymInfo(Sym); for (const Symbol *Sym : ImportedGlobals) - addSymInfo(Sym, Sym->getName()); + addSymInfo(Sym); for (const WasmExportEntry &E : ExportedSymbols) - addSymInfo(E.Sym, E.FieldName); + addSymInfo(E.Sym); if (!SymbolInfo.empty()) { SubSection SubSection(WASM_SYMBOL_INFO); writeUleb128(SubSection.getStream(), SymbolInfo.size(), "num sym info"); - for (auto Pair: SymbolInfo) { - writeStr(SubSection.getStream(), Pair.first, "sym name"); - writeUleb128(SubSection.getStream(), Pair.second, "sym flags"); + for (auto Tuple: SymbolInfo) { + writeUleb128(SubSection.getStream(), std::get<0>(Tuple), "sym kind"); + writeUleb128(SubSection.getStream(), std::get<1>(Tuple), "sym index"); + writeUleb128(SubSection.getStream(), std::get<2>(Tuple), "sym flags"); } SubSection.finalizeContents(); SubSection.writeToStream(OS);