Index: lib/MC/ELFObjectWriter.cpp =================================================================== --- lib/MC/ELFObjectWriter.cpp +++ lib/MC/ELFObjectWriter.cpp @@ -1286,6 +1286,7 @@ // Compute symbol table information. computeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap, SectionOffsets); + Asm.dump(); for (MCSectionELF *RelSection : Relocations) { align(RelSection->getAlignment()); Index: lib/MC/MCAssembler.cpp =================================================================== --- lib/MC/MCAssembler.cpp +++ lib/MC/MCAssembler.cpp @@ -1019,3 +1019,27 @@ } getBackend().finishLayout(*this, Layout); } + +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) +LLVM_DUMP_METHOD void MCAssembler::dump() const{ + raw_ostream &OS = errs(); + + OS << "dump(); + } + OS << "],\n"; + OS << " Symbols:["; + + for (const_symbol_iterator it = symbol_begin(), ie = symbol_end(); it != ie; ++it) { + if (it != symbol_begin()) OS << ",\n "; + OS << "("; + it->dump(); + OS << ", Index:" << it->getIndex() << ", "; + OS << ")"; + } + OS << "]>\n"; +} +#endif Index: lib/MC/MCFragment.cpp =================================================================== --- lib/MC/MCFragment.cpp +++ lib/MC/MCFragment.cpp @@ -464,26 +464,4 @@ } OS << ">"; } - -LLVM_DUMP_METHOD void MCAssembler::dump() const{ - raw_ostream &OS = errs(); - - OS << "dump(); - } - OS << "],\n"; - OS << " Symbols:["; - - for (const_symbol_iterator it = symbol_begin(), ie = symbol_end(); it != ie; ++it) { - if (it != symbol_begin()) OS << ",\n "; - OS << "("; - it->dump(); - OS << ", Index:" << it->getIndex() << ", "; - OS << ")"; - } - OS << "]>\n"; -} #endif Index: lib/MC/WasmObjectWriter.cpp =================================================================== --- lib/MC/WasmObjectWriter.cpp +++ lib/MC/WasmObjectWriter.cpp @@ -199,8 +199,9 @@ #endif }; +static const uint32_t INVALID_INDEX = -1; + struct WasmCustomSection { - const uint32_t INVALID_INDEX = -1; StringRef Name; MCSectionWasm *Section; @@ -238,8 +239,6 @@ // 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 (shared) Symbol index space. - DenseMap SymbolIndices; // Maps function/global symbols to the function/global/section index space. DenseMap WasmIndices; // Maps data symbols to the Wasm segment and offset/size with the segment. @@ -284,7 +283,6 @@ CodeRelocations.clear(); DataRelocations.clear(); TypeIndices.clear(); - SymbolIndices.clear(); WasmIndices.clear(); TableIndices.clear(); DataLocations.clear(); @@ -666,10 +664,7 @@ return TypeIndices[RelEntry.Symbol]; } - if (!SymbolIndices.count(RelEntry.Symbol)) - report_fatal_error("symbol not found in symbol index space: " + - RelEntry.Symbol->getName()); - return SymbolIndices[RelEntry.Symbol]; + return RelEntry.Symbol->getIndex(); } // Apply the portions of the relocation records that we can handle ourselves @@ -1344,8 +1339,10 @@ // Finally, populate the symbol table itself, in its "natural" order. for (const MCSymbol &S : Asm.symbols()) { const auto &WS = static_cast(S); - if (!isInSymtab(WS)) + if (!isInSymtab(WS)) { + WS.setIndex(INVALID_INDEX); continue; + } DEBUG(dbgs() << "adding to symtab: " << WS << "\n"); uint32_t Flags = 0; @@ -1369,10 +1366,12 @@ assert(DataLocations.count(&WS) > 0); Info.DataRef = DataLocations.find(&WS)->second; } - SymbolIndices[&WS] = SymbolInfos.size(); + WS.setIndex(SymbolInfos.size()); SymbolInfos.emplace_back(Info); } + DEBUG(Asm.dump()); + { auto HandleReloc = [&](const WasmRelocationEntry &Rel) { // Functions referenced by a relocation need to put in the table. This is @@ -1444,11 +1443,9 @@ report_fatal_error("fixups in .init_array should be symbol references"); if (Sym->getKind() != MCSymbolRefExpr::VK_WebAssembly_FUNCTION) report_fatal_error("symbols in .init_array should be for functions"); - auto I = SymbolIndices.find(cast(&Sym->getSymbol())); - if (I == SymbolIndices.end()) - report_fatal_error("symbols in .init_array should be defined"); - uint32_t Index = I->second; - InitFuncs.push_back(std::make_pair(Priority, Index)); + if (Sym->getSymbol().getIndex() == INVALID_INDEX) + report_fatal_error("symbols in .init_array should exist in symbtab"); + InitFuncs.push_back(std::make_pair(Priority, Sym->getSymbol().getIndex())); } }