Index: llvm/include/llvm/Object/IRSymtab.h =================================================================== --- llvm/include/llvm/Object/IRSymtab.h +++ llvm/include/llvm/Object/IRSymtab.h @@ -38,6 +38,7 @@ namespace llvm { struct BitcodeFileContents; +class StringTableBuilder; namespace irsymtab { @@ -136,9 +137,10 @@ } // end namespace storage -/// Fills in Symtab and Strtab with a valid symbol and string table for Mods. +/// Fills in Symtab and StrtabBuilder with a valid symbol and string table for +/// Mods. Error build(ArrayRef Mods, SmallVector &Symtab, - SmallVector &Strtab); + StringTableBuilder &StrtabBuilder, BumpPtrAllocator &Alloc); /// This represents a symbol that has been read from a storage::Symbol and /// possibly a storage::Uncommon. Index: llvm/lib/Object/IRSymtab.cpp =================================================================== --- llvm/lib/Object/IRSymtab.cpp +++ llvm/lib/Object/IRSymtab.cpp @@ -46,15 +46,13 @@ /// Stores the temporary state that is required to build an IR symbol table. struct Builder { SmallVector &Symtab; - SmallVector &Strtab; + StringTableBuilder &StrtabBuilder; - Builder(SmallVector &Symtab, SmallVector &Strtab) - : Symtab(Symtab), Strtab(Strtab) {} + Builder(SmallVector &Symtab, StringTableBuilder &StrtabBuilder, + BumpPtrAllocator &Alloc) + : Symtab(Symtab), StrtabBuilder(StrtabBuilder), Saver(Alloc) {} - StringTableBuilder StrtabBuilder{StringTableBuilder::RAW}; - - BumpPtrAllocator Alloc; - StringSaver Saver{Alloc}; + StringSaver Saver; DenseMap ComdatMap; Mangler Mang; @@ -240,7 +238,7 @@ return Err; COFFLinkerOptsOS.flush(); - setStr(Hdr.COFFLinkerOpts, COFFLinkerOpts); + setStr(Hdr.COFFLinkerOpts, Saver.save(COFFLinkerOpts)); // We are about to fill in the header's range fields, so reserve space for it // and copy it in afterwards. @@ -251,19 +249,15 @@ writeRange(Hdr.Uncommons, Uncommons); *reinterpret_cast(Symtab.data()) = Hdr; - - raw_svector_ostream OS(Strtab); - StrtabBuilder.finalizeInOrder(); - StrtabBuilder.write(OS); - return Error::success(); } } // end anonymous namespace Error irsymtab::build(ArrayRef Mods, SmallVector &Symtab, - SmallVector &Strtab) { - return Builder(Symtab, Strtab).build(Mods); + StringTableBuilder &StrtabBuilder, + BumpPtrAllocator &Alloc) { + return Builder(Symtab, StrtabBuilder, Alloc).build(Mods); } // Upgrade a vector of bitcode modules created by an old version of LLVM by @@ -285,9 +279,15 @@ OwnedMods.push_back(std::move(*MOrErr)); } - if (Error E = build(Mods, FC.Symtab, FC.Strtab)) + StringTableBuilder StrtabBuilder(StringTableBuilder::RAW); + BumpPtrAllocator Alloc; + if (Error E = build(Mods, FC.Symtab, StrtabBuilder, Alloc)) return std::move(E); + StrtabBuilder.finalizeInOrder(); + FC.Strtab.resize(StrtabBuilder.getSize()); + StrtabBuilder.write((uint8_t *)FC.Strtab.data()); + FC.TheReader = {{FC.Symtab.data(), FC.Symtab.size()}, {FC.Strtab.data(), FC.Strtab.size()}}; return std::move(FC);