13
13
#include " bolt/Core/DebugData.h"
14
14
#include " llvm/ADT/StringRef.h"
15
15
#include " llvm/CodeGen/DIE.h"
16
+ #include " llvm/DWP/DWP.h"
16
17
#include " llvm/MC/MCAsmLayout.h"
18
+ #include " llvm/MC/MCContext.h"
19
+ #include " llvm/Support/ToolOutputFile.h"
17
20
#include < cstdint>
18
21
#include < memory>
19
22
#include < mutex>
@@ -45,6 +48,7 @@ class DWARFRewriter {
45
48
uint64_t Length;
46
49
uint64_t TUHash;
47
50
};
51
+ using UnitMetaVectorType = std::vector<UnitMeta>;
48
52
49
53
private:
50
54
BinaryContext &BC;
@@ -88,15 +92,6 @@ class DWARFRewriter {
88
92
89
93
std::mutex LocListDebugInfoPatchesMutex;
90
94
91
- // / Dwo id specific its .debug_info.dwo section content.
92
- std::unordered_map<uint64_t , std::string> DwoDebugInfoMap;
93
-
94
- // / Dwo id specific its .debug_abbrev.dwo section content.
95
- std::unordered_map<uint64_t , std::string> DwoDebugAbbrevMap;
96
-
97
- // / Dwo id specific its .debug_types.dwo section content.
98
- std::unordered_map<uint64_t , std::string> DwoDebugTypeMap;
99
-
100
95
// / Dwo id specific its RangesBase.
101
96
std::unordered_map<uint64_t , uint64_t > DwoRangesBase;
102
97
@@ -107,12 +102,6 @@ class DWARFRewriter {
107
102
using GDBIndexTUEntryType = std::vector<GDBIndexTUEntry>;
108
103
GDBIndexTUEntryType GDBIndexTUEntryVector;
109
104
110
- using UnitMetaVectorType = std::vector<UnitMeta>;
111
- using TUnitMetaDwoMapType = std::unordered_map<uint64_t , UnitMetaVectorType>;
112
- using CUnitMetaDwoMapType = std::unordered_map<uint64_t , UnitMeta>;
113
- CUnitMetaDwoMapType CUnitMetaDwoMap;
114
- TUnitMetaDwoMapType TUnitMetaDwoMap;
115
-
116
105
// / DWARFLegacy is all DWARF versions before DWARF 5.
117
106
enum class DWARFVersion { DWARFLegacy, DWARF5 };
118
107
@@ -149,12 +138,6 @@ class DWARFRewriter {
149
138
// / Rewrite .gdb_index section if present.
150
139
void updateGdbIndexSection (CUOffsetMap &CUMap, uint32_t NumCUs);
151
140
152
- // / Output .dwo files.
153
- void writeDWOFiles (std::unordered_map<uint64_t , std::string> &DWOIdToName);
154
-
155
- // / Output .dwp files.
156
- void writeDWP (std::unordered_map<uint64_t , std::string> &DWOIdToName);
157
-
158
141
// / DWARFDie contains a pointer to a DIE and hence gets invalidated once the
159
142
// / embedded DIE is destroyed. This wrapper class stores a DIE internally and
160
143
// / could be cast to a DWARFDie that is valid even after the initial DIE is
@@ -197,39 +180,8 @@ class DWARFRewriter {
197
180
// / Update stmt_list for CUs based on the new .debug_line \p Layout.
198
181
void updateLineTableOffsets (const MCAsmLayout &Layout);
199
182
200
- // / Given a \p DWOId, return its DebugLocWriter if it exists.
201
- DebugLocWriter *getDebugLocWriter (uint64_t DWOId) {
202
- auto Iter = LocListWritersByCU.find (DWOId);
203
- return Iter == LocListWritersByCU.end () ? nullptr
204
- : LocListWritersByCU[DWOId].get ();
205
- }
206
-
207
- StringRef getDwoDebugInfoStr (uint64_t DWOId) {
208
- return DwoDebugInfoMap[DWOId];
209
- }
210
-
211
- StringRef getDwoDebugAbbrevStr (uint64_t DWOId) {
212
- return DwoDebugAbbrevMap[DWOId];
213
- }
214
-
215
- StringRef getDwoDebugTypeStr (uint64_t DWOId) {
216
- return DwoDebugTypeMap[DWOId];
217
- }
218
-
219
183
uint64_t getDwoRangesBase (uint64_t DWOId) { return DwoRangesBase[DWOId]; }
220
184
221
- void setDwoDebugInfoStr (uint64_t DWOId, StringRef Str) {
222
- DwoDebugInfoMap[DWOId] = Str.str ();
223
- }
224
-
225
- void setDwoDebugAbbrevStr (uint64_t DWOId, StringRef Str) {
226
- DwoDebugAbbrevMap[DWOId] = Str.str ();
227
- }
228
-
229
- void setDwoDebugTypeStr (uint64_t DWOId, StringRef Str) {
230
- DwoDebugTypeMap[DWOId] = Str.str ();
231
- }
232
-
233
185
void setDwoRangesBase (uint64_t DWOId, uint64_t RangesBase) {
234
186
DwoRangesBase[DWOId] = RangesBase;
235
187
}
@@ -242,30 +194,37 @@ class DWARFRewriter {
242
194
return GDBIndexTUEntryVector;
243
195
}
244
196
245
- // / Stores meta data for each CU per DWO ID. It's used to create cu-index for
246
- // / DWARF5.
247
- void addCUnitMetaEntry (const uint64_t DWOId, const UnitMeta &Entry) {
248
- auto RetVal = CUnitMetaDwoMap.insert ({DWOId, Entry});
249
- if (!RetVal.second )
250
- errs () << " BOLT-WARNING: [internal-dwarf-error]: Trying to set CU meta "
251
- " data twice for DWOID: "
252
- << Twine::utohexstr (DWOId) << " .\n " ;
253
- }
197
+ using OverriddenSectionsMap = std::unordered_map<DWARFSectionKind, StringRef>;
198
+ // / Output .dwo files.
199
+ void writeDWOFiles (DWARFUnit &, const OverriddenSectionsMap &,
200
+ const std::string &, DebugLocWriter &);
201
+ using KnownSectionsEntry = std::pair<MCSection *, DWARFSectionKind>;
202
+ struct DWPState {
203
+ std::unique_ptr<ToolOutputFile> Out;
204
+ std::unique_ptr<BinaryContext> TmpBC;
205
+ std::unique_ptr<MCStreamer> Streamer;
206
+ std::unique_ptr<DWPStringPool> Strings;
207
+ const MCObjectFileInfo *MCOFI = nullptr ;
208
+ const DWARFUnitIndex *CUIndex = nullptr ;
209
+ std::deque<SmallString<32 >> UncompressedSections;
210
+ MapVector<uint64_t , UnitIndexEntry> IndexEntries;
211
+ MapVector<uint64_t , UnitIndexEntry> TypeIndexEntries;
212
+ StringMap<KnownSectionsEntry> KnownSections;
213
+ uint32_t ContributionOffsets[8 ] = {};
214
+ uint32_t IndexVersion = 2 ;
215
+ uint64_t DebugInfoSize = 0 ;
216
+ uint16_t Version = 0 ;
217
+ bool IsDWP = false ;
218
+ };
219
+ // / Init .dwp file
220
+ void initDWPState (DWPState &);
254
221
255
- // / Stores meta data for each TU per DWO ID. It's used to create cu-index for
256
- // / DWARF5.
257
- void addTUnitMetaEntry (const uint64_t DWOId, const UnitMeta &Entry) {
258
- TUnitMetaDwoMap[DWOId].emplace_back (Entry);
259
- }
222
+ // / Write out .dwp File
223
+ void finalizeDWP (DWPState &);
260
224
261
- // / Returns Meta data for TUs in offset increasing order.
262
- UnitMetaVectorType &getTUnitMetaEntries (const uint64_t DWOId) {
263
- return TUnitMetaDwoMap[DWOId];
264
- }
265
- // / Returns Meta data for TUs in offset increasing order.
266
- const UnitMeta &getCUnitMetaEntry (const uint64_t DWOId) {
267
- return CUnitMetaDwoMap[DWOId];
268
- }
225
+ // / add content of dwo to .dwp file.
226
+ void updateDWP (DWARFUnit &, const OverriddenSectionsMap &, const UnitMeta &,
227
+ UnitMetaVectorType &, DWPState &, DebugLocWriter &);
269
228
};
270
229
271
230
} // namespace bolt
0 commit comments