Skip to content

Commit 1cf11a4

Browse files
committed
[Dsymutil][Debuginfo][NFC] Reland: Refactor dsymutil to separate DWARF optimizing part. llvm#2.
Summary: This patch relands D71271. The problem with D71271 is that it has cyclic dependency: CodeGen->AsmPrinter->DebugInfoDWARF->CodeGen. To avoid cyclic dependency this patch puts implementation for DWARFOptimizer into separate library: lib/DWARFLinker. Thus the difference between this patch and D71271 is in that DWARFOptimizer renamed into DWARFLinker and it`s files are put into lib/DWARFLinker. Reviewers: JDevlieghere, friss, dblaikie, aprantl Reviewed By: JDevlieghere Subscribers: thegameg, merge_guards_bot, probinson, mgorny, hiraditya, llvm-commits Tags: #llvm, #debug-info Differential Revision: https://reviews.llvm.org/D71839
1 parent 96d2d96 commit 1cf11a4

18 files changed

+342
-215
lines changed

llvm/include/llvm/CodeGen/NonRelocatableStringpool.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- llvm/CodeGen/NonRelocatableStringpool.h - A simple stringpool -----===//
1+
//===- NonRelocatableStringpool.h -------------------------------*- C++ -*-===//
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//===- DWARFLinker.h --------------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_DWARFLINKER_DWARFLINKER_H
10+
#define LLVM_DWARFLINKER_DWARFLINKER_H
11+
12+
#include "llvm/CodeGen/NonRelocatableStringpool.h"
13+
#include "llvm/DWARFLinker/DWARFLinkerDeclContext.h"
14+
#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
15+
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
16+
#include <map>
17+
18+
namespace llvm {
19+
20+
enum class DwarfLinkerClient { Dsymutil, LLD, General };
21+
22+
/// Partial address range. Besides an offset, only the
23+
/// HighPC is stored. The structure is stored in a map where the LowPC is the
24+
/// key.
25+
struct ObjFileAddressRange {
26+
/// Function HighPC.
27+
uint64_t HighPC;
28+
/// Offset to apply to the linked address.
29+
/// should be 0 for not-linked object file.
30+
int64_t Offset;
31+
32+
ObjFileAddressRange(uint64_t EndPC, int64_t Offset)
33+
: HighPC(EndPC), Offset(Offset) {}
34+
35+
ObjFileAddressRange() : HighPC(0), Offset(0) {}
36+
};
37+
38+
/// Map LowPC to ObjFileAddressRange.
39+
using RangesTy = std::map<uint64_t, ObjFileAddressRange>;
40+
41+
/// AddressesMap represents information about valid addresses used
42+
/// by debug information. Valid addresses are those which points to
43+
/// live code sections. i.e. relocations for these addresses point
44+
/// into sections which would be/are placed into resulting binary.
45+
class AddressesMap {
46+
public:
47+
virtual ~AddressesMap();
48+
49+
/// Returns true if represented addresses are from linked file.
50+
/// Returns false if represented addresses are from not-linked
51+
/// object file.
52+
virtual bool areRelocationsResolved() const = 0;
53+
54+
/// Checks that there are valid relocations against a .debug_info
55+
/// section. Reset current relocation pointer if neccessary.
56+
virtual bool hasValidRelocs(bool ResetRelocsPtr = true) = 0;
57+
58+
/// Checks that there is a relocation against .debug_info
59+
/// table between \p StartOffset and \p NextOffset.
60+
///
61+
/// This function must be called with offsets in strictly ascending
62+
/// order because it never looks back at relocations it already 'went past'.
63+
/// \returns true and sets Info.InDebugMap if it is the case.
64+
virtual bool hasValidRelocationAt(uint64_t StartOffset, uint64_t EndOffset,
65+
CompileUnit::DIEInfo &Info) = 0;
66+
67+
/// Apply the valid relocations to the buffer \p Data, taking into
68+
/// account that Data is at \p BaseOffset in the debug_info section.
69+
///
70+
/// This function must be called with monotonic \p BaseOffset values.
71+
///
72+
/// \returns true whether any reloc has been applied.
73+
virtual bool applyValidRelocs(MutableArrayRef<char> Data, uint64_t BaseOffset,
74+
bool IsLittleEndian) = 0;
75+
76+
/// Returns all valid functions address ranges(i.e., those ranges
77+
/// which points to sections with code).
78+
virtual RangesTy &getValidAddressRanges() = 0;
79+
80+
/// Erases all data.
81+
virtual void clear() = 0;
82+
};
83+
84+
} // end namespace llvm
85+
86+
#endif // LLVM_DWARFLINKER_DWARFLINKER_H

llvm/tools/dsymutil/CompileUnit.h llvm/include/llvm/DWARFLinker/DWARFLinkerCompileUnit.h

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
//===- tools/dsymutil/CompileUnit.h - Dwarf debug info linker ---*- C++ -*-===//
1+
//===- DWARFLinkerCompileUnit.h ---------------------------------*- C++ -*-===//
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_COMPILEUNIT_H
10-
#define LLVM_TOOLS_DSYMUTIL_COMPILEUNIT_H
9+
#ifndef LLVM_DWARFLINKER_DWARFLINKERCOMPILEUNIT_H
10+
#define LLVM_DWARFLINKER_DWARFLINKERCOMPILEUNIT_H
1111

1212
#include "llvm/ADT/IntervalMap.h"
1313
#include "llvm/CodeGen/DIE.h"
1414
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
15+
#include "llvm/Support/DataExtractor.h"
1516

1617
namespace llvm {
17-
namespace dsymutil {
1818

1919
class DeclContext;
2020

@@ -46,7 +46,7 @@ struct PatchLocation {
4646
};
4747

4848
/// Stores all information relating to a compile unit, be it in its original
49-
/// instance in the object file to its brand new cloned and linked DIE tree.
49+
/// instance in the object file to its brand new cloned and generated DIE tree.
5050
class CompileUnit {
5151
public:
5252
/// Information gathered about a DIE in the object file.
@@ -325,7 +325,6 @@ class CompileUnit {
325325
std::string ClangModuleName;
326326
};
327327

328-
} // end namespace dsymutil
329328
} // end namespace llvm
330329

331-
#endif // LLVM_TOOLS_DSYMUTIL_COMPILEUNIT_H
330+
#endif // LLVM_DWARFLINKER_DWARFLINKERCOMPILEUNIT_H

llvm/tools/dsymutil/DeclContext.h llvm/include/llvm/DWARFLinker/DWARFLinkerDeclContext.h

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
//===- tools/dsymutil/DeclContext.h - Dwarf debug info linker ---*- C++ -*-===//
1+
//===- DWARFLinkerDeclContext.h ---------------------------------*- C++ -*-===//
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_DECLCONTEXT_H
10-
#define LLVM_TOOLS_DSYMUTIL_DECLCONTEXT_H
9+
#ifndef LLVM_DWARFLINKER_DWARFLINKERDECLCONTEXT_H
10+
#define LLVM_DWARFLINKER_DWARFLINKERDECLCONTEXT_H
1111

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

2121
namespace llvm {
22-
namespace dsymutil {
2322

2423
struct DeclMapInfo;
2524

@@ -165,7 +164,6 @@ struct DeclMapInfo : private DenseMapInfo<DeclContext *> {
165164
}
166165
};
167166

168-
} // end namespace dsymutil
169167
} // end namespace llvm
170168

171-
#endif // LLVM_TOOLS_DSYMUTIL_DECLCONTEXT_H
169+
#endif // LLVM_DWARFLINKER_DWARFLINKERDECLCONTEXT_H

llvm/lib/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_subdirectory(CodeGen)
88
add_subdirectory(BinaryFormat)
99
add_subdirectory(Bitcode)
1010
add_subdirectory(Bitstream)
11+
add_subdirectory(DWARFLinker)
1112
add_subdirectory(Frontend)
1213
add_subdirectory(Transforms)
1314
add_subdirectory(Linker)

llvm/lib/CodeGen/NonRelocatableStringpool.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- llvm/CodeGen/NonRelocatableStringpool.cpp - A simple stringpool --===//
1+
//===-- NonRelocatableStringpool.cpp --------------------------------------===//
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.

llvm/lib/DWARFLinker/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
add_llvm_component_library(LLVMDWARFLinker
2+
DWARFLinkerCompileUnit.cpp
3+
DWARFLinkerDeclContext.cpp
4+
DWARFLinker.cpp
5+
6+
)

llvm/lib/DWARFLinker/DWARFLinker.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//=== DWARFLinker.cpp -----------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "llvm/DWARFLinker/DWARFLinker.h"
10+
11+
namespace llvm {
12+
13+
AddressesMap::~AddressesMap() {}
14+
15+
} // namespace llvm

llvm/tools/dsymutil/CompileUnit.cpp llvm/lib/DWARFLinker/DWARFLinkerCompileUnit.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
//===- tools/dsymutil/CompileUnit.h - Dwarf compile unit ------------------===//
1+
//===- DWARFLinkerCompileUnit.cpp -----------------------------------------===//
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 "CompileUnit.h"
10-
#include "DeclContext.h"
9+
#include "llvm/DWARFLinker/DWARFLinkerCompileUnit.h"
10+
#include "llvm/DWARFLinker/DWARFLinkerDeclContext.h"
1111

1212
namespace llvm {
13-
namespace dsymutil {
1413

1514
/// Check if the DIE at \p Idx is in the scope of a function.
1615
static bool inFunctionScope(CompileUnit &U, unsigned Idx) {
@@ -142,5 +141,4 @@ void CompileUnit::addTypeAccelerator(const DIE *Die,
142141
Pubtypes.emplace_back(Name, Die, QualifiedNameHash, ObjcClassImplementation);
143142
}
144143

145-
} // namespace dsymutil
146144
} // namespace llvm

llvm/tools/dsymutil/DeclContext.cpp llvm/lib/DWARFLinker/DWARFLinkerDeclContext.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
//===- tools/dsymutil/DeclContext.cpp - Declaration context ---------------===//
1+
//===- DWARFLinkerDeclContext.cpp -----------------------------------------===//
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 "DeclContext.h"
9+
#include "llvm/DWARFLinker/DWARFLinkerDeclContext.h"
1010
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
1111
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
1212
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
1313

1414
namespace llvm {
15-
namespace dsymutil {
1615

1716
/// Set the last DIE/CU a context was seen in and, possibly invalidate the
1817
/// context if it is ambiguous.
@@ -206,5 +205,5 @@ PointerIntPair<DeclContext *, 1> DeclContextTree::getChildDeclContext(
206205

207206
return PointerIntPair<DeclContext *, 1>(*ContextIter);
208207
}
209-
} // namespace dsymutil
208+
210209
} // namespace llvm

llvm/lib/DWARFLinker/LLVMBuild.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
;===- ./lib/DWARFLinker/LLVMBuild.txt ---------------*- Conf -*--===;
2+
;
3+
; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
; See https://llvm.org/LICENSE.txt for license information.
5+
; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
;
7+
;===------------------------------------------------------------------------===;
8+
;
9+
; This is an LLVMBuild description file for the components in this subdirectory.
10+
;
11+
; For more information on the LLVMBuild system, please see:
12+
;
13+
; http://llvm.org/docs/LLVMBuild.html
14+
;
15+
;===------------------------------------------------------------------------===;
16+
17+
[component_0]
18+
type = Library
19+
name = DWARFLinker
20+
parent = Libraries
21+
required_libraries = DebugInfoDWARF AsmPrinter CodeGen MC Object Support

llvm/lib/LLVMBuild.txt

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ subdirectories =
2323
CodeGen
2424
DebugInfo
2525
Demangle
26+
DWARFLinker
2627
ExecutionEngine
2728
Frontend
2829
FuzzMutate

llvm/tools/dsymutil/CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set(LLVM_LINK_COMPONENTS
99
AllTargetsInfos
1010
AsmPrinter
1111
DebugInfoDWARF
12+
DWARFLinker
1213
MC
1314
Object
1415
CodeGen
@@ -22,10 +23,8 @@ add_llvm_tool(dsymutil
2223
dsymutil.cpp
2324
BinaryHolder.cpp
2425
CFBundle.cpp
25-
CompileUnit.cpp
2626
DebugMap.cpp
27-
DeclContext.cpp
28-
DwarfLinker.cpp
27+
DwarfLinkerForBinary.cpp
2928
DwarfStreamer.cpp
3029
MachODebugMapParser.cpp
3130
MachOUtils.cpp

0 commit comments

Comments
 (0)