Index: llvm/include/llvm/CodeGen/NonRelocatableStringpool.h =================================================================== --- llvm/include/llvm/CodeGen/NonRelocatableStringpool.h +++ llvm/include/llvm/CodeGen/NonRelocatableStringpool.h @@ -1,4 +1,4 @@ -//===- NonRelocatableStringpool.h - A simple stringpool --------*- C++ -*-===// +//===- llvm/CodeGen/NonRelocatableStringpool.h - A simple stringpool -----===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,26 +6,20 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_TOOLS_DSYMUTIL_NONRELOCATABLESTRINGPOOL_H -#define LLVM_TOOLS_DSYMUTIL_NONRELOCATABLESTRINGPOOL_H +#ifndef LLVM_CODEGEN_NONRELOCATABLESTRINGPOOL_H +#define LLVM_CODEGEN_NONRELOCATABLESTRINGPOOL_H -#include "SymbolMap.h" - -#include "llvm/ADT/StringMap.h" -#include "llvm/ADT/StringRef.h" #include "llvm/CodeGen/DwarfStringPoolEntry.h" #include "llvm/Support/Allocator.h" #include #include namespace llvm { -namespace dsymutil { /// A string table that doesn't need relocations. /// -/// We are doing a final link, no need for a string table that has relocation -/// entries for every reference to it. This class provides this ability by just -/// associating offsets with strings. +/// Use this class when a string table doesn't need relocations. +/// This class provides this ability by just associating offsets with strings. class NonRelocatableStringpool { public: /// Entries are stored into the StringMap and simply linked together through @@ -34,10 +28,11 @@ using MapTy = StringMap; NonRelocatableStringpool( - SymbolMapTranslator Translator = SymbolMapTranslator()) + std::function Translator = nullptr, + bool PutEmptyString = false) : Translator(Translator) { - // Legacy dsymutil puts an empty string at the start of the line table. - EmptyString = getEntry(""); + if (PutEmptyString) + EmptyString = getEntry(""); } DwarfStringPoolEntryRef getEntry(StringRef S); @@ -65,7 +60,7 @@ uint32_t CurrentEndOffset = 0; unsigned NumEntries = 0; DwarfStringPoolEntryRef EmptyString; - SymbolMapTranslator Translator; + std::function Translator; }; /// Helper for making strong types. @@ -75,15 +70,14 @@ explicit StrongType(Args... A) : T(std::forward(A)...) {} }; -/// It's very easy to introduce bugs by passing the wrong string pool in the -/// dwarf linker. By using strong types the interface enforces that the right +/// It's very easy to introduce bugs by passing the wrong string pool. +/// By using strong types the interface enforces that the right /// kind of pool is used. struct UniqueTag {}; struct OffsetsTag {}; using UniquingStringPool = StrongType; using OffsetsStringPool = StrongType; -} // end namespace dsymutil } // end namespace llvm -#endif // LLVM_TOOLS_DSYMUTIL_NONRELOCATABLESTRINGPOOL_H +#endif // LLVM_CODEGEN_NONRELOCATABLESTRINGPOOL_H Index: llvm/lib/CodeGen/CMakeLists.txt =================================================================== --- llvm/lib/CodeGen/CMakeLists.txt +++ llvm/lib/CodeGen/CMakeLists.txt @@ -102,6 +102,7 @@ MIRPrinter.cpp MIRPrintingPass.cpp MacroFusion.cpp + NonRelocatableStringpool.cpp OptimizePHIs.cpp ParallelCG.cpp PeepholeOptimizer.cpp Index: llvm/lib/CodeGen/NonRelocatableStringpool.cpp =================================================================== --- llvm/lib/CodeGen/NonRelocatableStringpool.cpp +++ llvm/lib/CodeGen/NonRelocatableStringpool.cpp @@ -1,4 +1,4 @@ -//===- NonRelocatableStringpool.cpp - A simple stringpool ----------------===// +//===-- llvm/CodeGen/NonRelocatableStringpool.cpp - A simple stringpool --===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,10 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "NonRelocatableStringpool.h" +#include "llvm/CodeGen/NonRelocatableStringpool.h" namespace llvm { -namespace dsymutil { DwarfStringPoolEntryRef NonRelocatableStringpool::getEntry(StringRef S) { if (S.empty() && !Strings.empty()) @@ -52,5 +51,4 @@ return Result; } -} // namespace dsymutil } // namespace llvm Index: llvm/tools/dsymutil/CMakeLists.txt =================================================================== --- llvm/tools/dsymutil/CMakeLists.txt +++ llvm/tools/dsymutil/CMakeLists.txt @@ -28,7 +28,6 @@ DwarfStreamer.cpp MachODebugMapParser.cpp MachOUtils.cpp - NonRelocatableStringpool.cpp SymbolMap.cpp DEPENDS Index: llvm/tools/dsymutil/DeclContext.h =================================================================== --- llvm/tools/dsymutil/DeclContext.h +++ llvm/tools/dsymutil/DeclContext.h @@ -10,11 +10,11 @@ #define LLVM_TOOLS_DSYMUTIL_DECLCONTEXT_H #include "CompileUnit.h" -#include "NonRelocatableStringpool.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/StringRef.h" +#include "llvm/CodeGen/NonRelocatableStringpool.h" #include "llvm/DebugInfo/DWARF/DWARFDie.h" #include "llvm/Support/Path.h" Index: llvm/tools/dsymutil/DwarfLinker.cpp =================================================================== --- llvm/tools/dsymutil/DwarfLinker.cpp +++ llvm/tools/dsymutil/DwarfLinker.cpp @@ -12,7 +12,6 @@ #include "DeclContext.h" #include "DwarfStreamer.h" #include "MachOUtils.h" -#include "NonRelocatableStringpool.h" #include "dsymutil.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/BitVector.h" @@ -36,6 +35,7 @@ #include "llvm/CodeGen/AccelTable.h" #include "llvm/CodeGen/AsmPrinter.h" #include "llvm/CodeGen/DIE.h" +#include "llvm/CodeGen/NonRelocatableStringpool.h" #include "llvm/Config/config.h" #include "llvm/DebugInfo/DIContext.h" #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h" @@ -2701,12 +2701,12 @@ // This Dwarf string pool which is only used for uniquing. This one should // never be used for offsets as its not thread-safe or predictable. - UniquingStringPool UniquingStringPool; + UniquingStringPool UniquingStringPool(nullptr, true); // This Dwarf string pool which is used for emission. It must be used // serially as the order of calling getStringOffset matters for // reproducibility. - OffsetsStringPool OffsetsStringPool(Options.Translator); + OffsetsStringPool OffsetsStringPool(Options.Translator, true); // ODR Contexts for the link. DeclContextTree ODRContexts; Index: llvm/tools/dsymutil/DwarfStreamer.h =================================================================== --- llvm/tools/dsymutil/DwarfStreamer.h +++ llvm/tools/dsymutil/DwarfStreamer.h @@ -12,9 +12,9 @@ #include "CompileUnit.h" #include "DebugMap.h" #include "LinkUtils.h" -#include "NonRelocatableStringpool.h" #include "llvm/CodeGen/AccelTable.h" #include "llvm/CodeGen/AsmPrinter.h" +#include "llvm/CodeGen/NonRelocatableStringpool.h" #include "llvm/DebugInfo/DWARF/DWARFDebugLine.h" #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h" #include "llvm/MC/MCAsmBackend.h" Index: llvm/tools/dsymutil/MachOUtils.cpp =================================================================== --- llvm/tools/dsymutil/MachOUtils.cpp +++ llvm/tools/dsymutil/MachOUtils.cpp @@ -10,7 +10,7 @@ #include "BinaryHolder.h" #include "DebugMap.h" #include "LinkUtils.h" -#include "NonRelocatableStringpool.h" +#include "llvm/CodeGen/NonRelocatableStringpool.h" #include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCMachObjectWriter.h" #include "llvm/MC/MCObjectStreamer.h" @@ -442,7 +442,12 @@ } SmallString<0> NewSymtab; - NonRelocatableStringpool NewStrings(Translator); + std::function TranslationLambda = + Translator ? [&](StringRef Input) { return Translator(Input); } + : static_cast>(nullptr); + // Legacy dsymutil puts an empty string at the start of the line table. + // thus we set NonRelocatableStringpool(,PutEmptyString=true) + NonRelocatableStringpool NewStrings(TranslationLambda, true); unsigned NListSize = Is64Bit ? sizeof(MachO::nlist_64) : sizeof(MachO::nlist); unsigned NumSyms = 0; uint64_t NewStringsSize = 0;