Skip to content

Commit 9e8c799

Browse files
committed
[Dsymutil][NFC] Move NonRelocatableStringpool into common CodeGen folder.
That refactoring moves NonRelocatableStringpool into common CodeGen folder. So that NonRelocatableStringpool could be used not only inside dsymutil. Differential Revision: https://reviews.llvm.org/D71068
1 parent c4d8c63 commit 9e8c799

File tree

8 files changed

+28
-31
lines changed

8 files changed

+28
-31
lines changed

llvm/tools/dsymutil/NonRelocatableStringpool.h renamed to llvm/include/llvm/CodeGen/NonRelocatableStringpool.h

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
1-
//===- NonRelocatableStringpool.h - A simple stringpool --------*- C++ -*-===//
1+
//===- llvm/CodeGen/NonRelocatableStringpool.h - A simple stringpool -----===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_TOOLS_DSYMUTIL_NONRELOCATABLESTRINGPOOL_H
10-
#define LLVM_TOOLS_DSYMUTIL_NONRELOCATABLESTRINGPOOL_H
9+
#ifndef LLVM_CODEGEN_NONRELOCATABLESTRINGPOOL_H
10+
#define LLVM_CODEGEN_NONRELOCATABLESTRINGPOOL_H
1111

12-
#include "SymbolMap.h"
13-
14-
#include "llvm/ADT/StringMap.h"
15-
#include "llvm/ADT/StringRef.h"
1612
#include "llvm/CodeGen/DwarfStringPoolEntry.h"
1713
#include "llvm/Support/Allocator.h"
1814
#include <cstdint>
1915
#include <vector>
2016

2117
namespace llvm {
22-
namespace dsymutil {
2318

2419
/// A string table that doesn't need relocations.
2520
///
26-
/// We are doing a final link, no need for a string table that has relocation
27-
/// entries for every reference to it. This class provides this ability by just
28-
/// associating offsets with strings.
21+
/// Use this class when a string table doesn't need relocations.
22+
/// This class provides this ability by just associating offsets with strings.
2923
class NonRelocatableStringpool {
3024
public:
3125
/// Entries are stored into the StringMap and simply linked together through
@@ -34,10 +28,11 @@ class NonRelocatableStringpool {
3428
using MapTy = StringMap<DwarfStringPoolEntry, BumpPtrAllocator>;
3529

3630
NonRelocatableStringpool(
37-
SymbolMapTranslator Translator = SymbolMapTranslator())
31+
std::function<StringRef(StringRef Input)> Translator = nullptr,
32+
bool PutEmptyString = false)
3833
: Translator(Translator) {
39-
// Legacy dsymutil puts an empty string at the start of the line table.
40-
EmptyString = getEntry("");
34+
if (PutEmptyString)
35+
EmptyString = getEntry("");
4136
}
4237

4338
DwarfStringPoolEntryRef getEntry(StringRef S);
@@ -65,7 +60,7 @@ class NonRelocatableStringpool {
6560
uint32_t CurrentEndOffset = 0;
6661
unsigned NumEntries = 0;
6762
DwarfStringPoolEntryRef EmptyString;
68-
SymbolMapTranslator Translator;
63+
std::function<StringRef(StringRef Input)> Translator;
6964
};
7065

7166
/// Helper for making strong types.
@@ -75,15 +70,14 @@ template <typename T, typename S> class StrongType : public T {
7570
explicit StrongType(Args... A) : T(std::forward<Args>(A)...) {}
7671
};
7772

78-
/// It's very easy to introduce bugs by passing the wrong string pool in the
79-
/// dwarf linker. By using strong types the interface enforces that the right
73+
/// It's very easy to introduce bugs by passing the wrong string pool.
74+
/// By using strong types the interface enforces that the right
8075
/// kind of pool is used.
8176
struct UniqueTag {};
8277
struct OffsetsTag {};
8378
using UniquingStringPool = StrongType<NonRelocatableStringpool, UniqueTag>;
8479
using OffsetsStringPool = StrongType<NonRelocatableStringpool, OffsetsTag>;
8580

86-
} // end namespace dsymutil
8781
} // end namespace llvm
8882

89-
#endif // LLVM_TOOLS_DSYMUTIL_NONRELOCATABLESTRINGPOOL_H
83+
#endif // LLVM_CODEGEN_NONRELOCATABLESTRINGPOOL_H

llvm/lib/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ add_llvm_component_library(LLVMCodeGen
102102
MIRPrinter.cpp
103103
MIRPrintingPass.cpp
104104
MacroFusion.cpp
105+
NonRelocatableStringpool.cpp
105106
OptimizePHIs.cpp
106107
ParallelCG.cpp
107108
PeepholeOptimizer.cpp

llvm/tools/dsymutil/NonRelocatableStringpool.cpp renamed to llvm/lib/CodeGen/NonRelocatableStringpool.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
//===- NonRelocatableStringpool.cpp - A simple stringpool ----------------===//
1+
//===-- llvm/CodeGen/NonRelocatableStringpool.cpp - A simple stringpool --===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "NonRelocatableStringpool.h"
9+
#include "llvm/CodeGen/NonRelocatableStringpool.h"
1010

1111
namespace llvm {
12-
namespace dsymutil {
1312

1413
DwarfStringPoolEntryRef NonRelocatableStringpool::getEntry(StringRef S) {
1514
if (S.empty() && !Strings.empty())
@@ -52,5 +51,4 @@ NonRelocatableStringpool::getEntriesForEmission() const {
5251
return Result;
5352
}
5453

55-
} // namespace dsymutil
5654
} // namespace llvm

llvm/tools/dsymutil/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ add_llvm_tool(dsymutil
2828
DwarfStreamer.cpp
2929
MachODebugMapParser.cpp
3030
MachOUtils.cpp
31-
NonRelocatableStringpool.cpp
3231
SymbolMap.cpp
3332

3433
DEPENDS

llvm/tools/dsymutil/DeclContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
#define LLVM_TOOLS_DSYMUTIL_DECLCONTEXT_H
1111

1212
#include "CompileUnit.h"
13-
#include "NonRelocatableStringpool.h"
1413
#include "llvm/ADT/DenseMap.h"
1514
#include "llvm/ADT/DenseMapInfo.h"
1615
#include "llvm/ADT/DenseSet.h"
1716
#include "llvm/ADT/StringRef.h"
17+
#include "llvm/CodeGen/NonRelocatableStringpool.h"
1818
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
1919
#include "llvm/Support/Path.h"
2020

llvm/tools/dsymutil/DwarfLinker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "DeclContext.h"
1313
#include "DwarfStreamer.h"
1414
#include "MachOUtils.h"
15-
#include "NonRelocatableStringpool.h"
1615
#include "dsymutil.h"
1716
#include "llvm/ADT/ArrayRef.h"
1817
#include "llvm/ADT/BitVector.h"
@@ -36,6 +35,7 @@
3635
#include "llvm/CodeGen/AccelTable.h"
3736
#include "llvm/CodeGen/AsmPrinter.h"
3837
#include "llvm/CodeGen/DIE.h"
38+
#include "llvm/CodeGen/NonRelocatableStringpool.h"
3939
#include "llvm/Config/config.h"
4040
#include "llvm/DebugInfo/DIContext.h"
4141
#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
@@ -2701,12 +2701,12 @@ bool DwarfLinker::link(const DebugMap &Map) {
27012701

27022702
// This Dwarf string pool which is only used for uniquing. This one should
27032703
// never be used for offsets as its not thread-safe or predictable.
2704-
UniquingStringPool UniquingStringPool;
2704+
UniquingStringPool UniquingStringPool(nullptr, true);
27052705

27062706
// This Dwarf string pool which is used for emission. It must be used
27072707
// serially as the order of calling getStringOffset matters for
27082708
// reproducibility.
2709-
OffsetsStringPool OffsetsStringPool(Options.Translator);
2709+
OffsetsStringPool OffsetsStringPool(Options.Translator, true);
27102710

27112711
// ODR Contexts for the link.
27122712
DeclContextTree ODRContexts;

llvm/tools/dsymutil/DwarfStreamer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#include "CompileUnit.h"
1313
#include "DebugMap.h"
1414
#include "LinkUtils.h"
15-
#include "NonRelocatableStringpool.h"
1615
#include "llvm/CodeGen/AccelTable.h"
1716
#include "llvm/CodeGen/AsmPrinter.h"
17+
#include "llvm/CodeGen/NonRelocatableStringpool.h"
1818
#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
1919
#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
2020
#include "llvm/MC/MCAsmBackend.h"

llvm/tools/dsymutil/MachOUtils.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "BinaryHolder.h"
1111
#include "DebugMap.h"
1212
#include "LinkUtils.h"
13-
#include "NonRelocatableStringpool.h"
13+
#include "llvm/CodeGen/NonRelocatableStringpool.h"
1414
#include "llvm/MC/MCAsmLayout.h"
1515
#include "llvm/MC/MCMachObjectWriter.h"
1616
#include "llvm/MC/MCObjectStreamer.h"
@@ -442,7 +442,12 @@ bool generateDsymCompanion(const DebugMap &DM, SymbolMapTranslator &Translator,
442442
}
443443

444444
SmallString<0> NewSymtab;
445-
NonRelocatableStringpool NewStrings(Translator);
445+
std::function<StringRef(StringRef)> TranslationLambda =
446+
Translator ? [&](StringRef Input) { return Translator(Input); }
447+
: static_cast<std::function<StringRef(StringRef)>>(nullptr);
448+
// Legacy dsymutil puts an empty string at the start of the line table.
449+
// thus we set NonRelocatableStringpool(,PutEmptyString=true)
450+
NonRelocatableStringpool NewStrings(TranslationLambda, true);
446451
unsigned NListSize = Is64Bit ? sizeof(MachO::nlist_64) : sizeof(MachO::nlist);
447452
unsigned NumSyms = 0;
448453
uint64_t NewStringsSize = 0;

0 commit comments

Comments
 (0)