Skip to content

Commit a1e9b5e

Browse files
committed
Merge from 'main' to 'sycl-web' (182 commits)
CONFLICT (content): Merge conflict in clang/lib/Driver/Types.cpp
2 parents f2376d4 + 5c6a146 commit a1e9b5e

File tree

1,351 files changed

+33244
-17242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,351 files changed

+33244
-17242
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ class BinaryContext {
204204
using DWOIdToCUMapType = std::unordered_map<uint64_t, DWARFUnit *>;
205205
DWOIdToCUMapType DWOCUs;
206206

207+
bool ContainsDwarf5{false};
208+
bool ContainsDwarfLegacy{false};
209+
207210
/// Preprocess DWO debug information.
208211
void preprocessDWODebugInfo();
209212

@@ -234,7 +237,13 @@ class BinaryContext {
234237
/// Get Number of DWOCUs in a map.
235238
uint32_t getNumDWOCUs() { return DWOCUs.size(); }
236239

237-
const std::map<unsigned, DwarfLineTable> &getDwarfLineTables() const {
240+
/// Returns true if DWARF5 is used.
241+
bool isDWARF5Used() const { return ContainsDwarf5; }
242+
243+
/// Returns true if DWARF4 or lower is used.
244+
bool isDWARFLegacyUsed() const { return ContainsDwarfLegacy; }
245+
246+
std::map<unsigned, DwarfLineTable> &getDwarfLineTables() {
238247
return DwarfLineTablesCUMap;
239248
}
240249

@@ -245,7 +254,8 @@ class BinaryContext {
245254
Expected<unsigned> getDwarfFile(StringRef Directory, StringRef FileName,
246255
unsigned FileNumber,
247256
Optional<MD5::MD5Result> Checksum,
248-
Optional<StringRef> Source, unsigned CUID);
257+
Optional<StringRef> Source, unsigned CUID,
258+
unsigned DWARFVersion);
249259

250260
/// [start memory address] -> [segment info] mapping.
251261
std::map<uint64_t, SegmentInfo> SegmentMapInfo;

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,9 @@ class BinaryFunction {
12791279
case ELF::R_AARCH64_MOVW_UABS_G2:
12801280
case ELF::R_AARCH64_MOVW_UABS_G2_NC:
12811281
case ELF::R_AARCH64_MOVW_UABS_G3:
1282+
case ELF::R_AARCH64_PREL16:
1283+
case ELF::R_AARCH64_PREL32:
1284+
case ELF::R_AARCH64_PREL64:
12821285
Rels[Offset] = Relocation{Offset, Symbol, RelType, Addend, Value};
12831286
return;
12841287
case ELF::R_AARCH64_CALL26:

bolt/include/bolt/Core/DebugData.h

Lines changed: 152 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ namespace llvm {
3434

3535
namespace bolt {
3636

37+
// DWARF5 Header in order of encoding.
38+
// Types represent encodnig sizes.
39+
using UnitLengthType = uint32_t;
40+
using VersionType = uint16_t;
41+
using AddressSizeType = uint8_t;
42+
using SegmentSelectorType = uint8_t;
43+
using OffsetEntryCountType = uint32_t;
44+
/// Get DWARF5 Header size.
45+
/// Rangelists and Loclists have the same header.
46+
constexpr uint32_t getDWARF5RngListLocListHeaderSize() {
47+
return sizeof(UnitLengthType) + sizeof(VersionType) +
48+
sizeof(AddressSizeType) + sizeof(SegmentSelectorType) +
49+
sizeof(OffsetEntryCountType);
50+
}
51+
3752
class BinaryContext;
3853

3954
/// Address range representation. Takes less space than DWARFAddressRange.
@@ -114,18 +129,23 @@ struct CUInfo {
114129
};
115130
using CUOffsetMap = std::map<uint32_t, CUInfo>;
116131

132+
enum class RangesWriterKind { DebugRangesWriter, DebugRangeListsWriter };
117133
/// Serializes the .debug_ranges DWARF section.
118134
class DebugRangesSectionWriter {
119135
public:
120136
DebugRangesSectionWriter();
121137

138+
DebugRangesSectionWriter(RangesWriterKind K) : Kind(K){};
139+
140+
virtual ~DebugRangesSectionWriter(){};
141+
122142
/// Add ranges with caching.
123-
uint64_t
143+
virtual uint64_t
124144
addRanges(DebugAddressRangesVector &&Ranges,
125145
std::map<DebugAddressRangesVector, uint64_t> &CachedRanges);
126146

127147
/// Add ranges and return offset into section.
128-
uint64_t addRanges(const DebugAddressRangesVector &Ranges);
148+
virtual uint64_t addRanges(const DebugAddressRangesVector &Ranges);
129149

130150
/// Returns an offset of an empty address ranges list that is always written
131151
/// to .debug_ranges
@@ -134,11 +154,18 @@ class DebugRangesSectionWriter {
134154
/// Returns the SectionOffset.
135155
uint64_t getSectionOffset();
136156

137-
std::unique_ptr<DebugBufferVector> finalize() {
157+
/// Returns a buffer containing Ranges.
158+
virtual std::unique_ptr<DebugBufferVector> finalize() {
138159
return std::move(RangesBuffer);
139160
}
140161

141-
private:
162+
RangesWriterKind getKind() const { return Kind; }
163+
164+
static bool classof(const DebugRangesSectionWriter *Writer) {
165+
return Writer->getKind() == RangesWriterKind::DebugRangesWriter;
166+
}
167+
168+
protected:
142169
std::unique_ptr<DebugBufferVector> RangesBuffer;
143170

144171
std::unique_ptr<raw_svector_ostream> RangesStream;
@@ -151,6 +178,58 @@ class DebugRangesSectionWriter {
151178

152179
/// Offset of an empty address ranges list.
153180
static constexpr uint64_t EmptyRangesOffset{0};
181+
182+
private:
183+
RangesWriterKind Kind;
184+
};
185+
186+
class DebugAddrWriter;
187+
class DebugRangeListsSectionWriter : public DebugRangesSectionWriter {
188+
public:
189+
DebugRangeListsSectionWriter()
190+
: DebugRangesSectionWriter(RangesWriterKind::DebugRangeListsWriter) {
191+
RangesBuffer = std::make_unique<DebugBufferVector>();
192+
RangesStream = std::make_unique<raw_svector_ostream>(*RangesBuffer);
193+
};
194+
virtual ~DebugRangeListsSectionWriter(){};
195+
196+
static void setAddressWriter(DebugAddrWriter *AddrW) { AddrWriter = AddrW; }
197+
198+
/// Add ranges with caching.
199+
virtual uint64_t addRanges(
200+
DebugAddressRangesVector &&Ranges,
201+
std::map<DebugAddressRangesVector, uint64_t> &CachedRanges) override;
202+
203+
/// Add ranges and return offset into section.
204+
virtual uint64_t addRanges(const DebugAddressRangesVector &Ranges) override;
205+
206+
virtual std::unique_ptr<DebugBufferVector> finalize() override {
207+
return std::move(RangesBuffer);
208+
}
209+
210+
/// Needs to be invoked before each CU is processed.
211+
/// \p CUID is a unique ID of each CU.
212+
void initSection(uint64_t CUID);
213+
214+
/// Writes out range lists for a current CU being processed.
215+
void finalizeSection();
216+
217+
static bool classof(const DebugRangesSectionWriter *Writer) {
218+
return Writer->getKind() == RangesWriterKind::DebugRangeListsWriter;
219+
}
220+
221+
private:
222+
static DebugAddrWriter *AddrWriter;
223+
/// Unique ID of CU being processed.
224+
uint64_t CUID{0};
225+
/// Current relative offset of range list entry within this CUs rangelist
226+
/// body.
227+
uint32_t CurrentOffset{0};
228+
/// Contains relative offset of each range list entry.
229+
SmallVector<uint32_t, 1> RangeEntries;
230+
231+
std::unique_ptr<DebugBufferVector> CUBodyBuffer;
232+
std::unique_ptr<raw_svector_ostream> CUBodyStream;
154233
};
155234

156235
/// Serializes the .debug_aranges DWARF section.
@@ -193,23 +272,25 @@ class DebugAddrWriter {
193272
public:
194273
DebugAddrWriter() = delete;
195274
DebugAddrWriter(BinaryContext *BC_);
275+
virtual ~DebugAddrWriter(){};
196276
/// Given an address returns an index in .debug_addr.
197277
/// Adds Address to map.
198-
uint32_t getIndexFromAddress(uint64_t Address, uint64_t DWOId);
278+
uint32_t getIndexFromAddress(uint64_t Address, uint64_t CUID);
199279

200280
/// Adds {Address, Index} to DWO ID CU.
201-
void addIndexAddress(uint64_t Address, uint32_t Index, uint64_t DWOId);
281+
void addIndexAddress(uint64_t Address, uint32_t Index, uint64_t CUID);
202282

203283
/// Creates consolidated .debug_addr section, and builds DWOID to offset map.
204-
AddressSectionBuffer finalize();
284+
virtual AddressSectionBuffer finalize();
205285

206-
/// Given DWOID returns offset of this CU in to .debug_addr section.
207-
uint64_t getOffset(uint64_t DWOId);
286+
/// Given DWARFUnit \p Unit returns offset of this CU in to .debug_addr
287+
/// section.
288+
virtual uint64_t getOffset(DWARFUnit &Unit);
208289

209290
/// Returns False if .debug_addr section was created..
210291
bool isInitialized() const { return !AddressMaps.empty(); }
211292

212-
private:
293+
protected:
213294
class AddressForDWOCU {
214295
public:
215296
AddressToIndexMap::iterator find(uint64_t Adddress) {
@@ -266,6 +347,18 @@ class DebugAddrWriter {
266347
std::mutex WriterMutex;
267348
};
268349

350+
class DebugAddrWriterDwarf5 : public DebugAddrWriter {
351+
public:
352+
DebugAddrWriterDwarf5() = delete;
353+
DebugAddrWriterDwarf5(BinaryContext *BC) : DebugAddrWriter(BC) {}
354+
355+
/// Creates consolidated .debug_addr section, and builds DWOID to offset map.
356+
virtual AddressSectionBuffer finalize() override;
357+
/// Given DWARFUnit \p Unit returns offset of this CU in to .debug_addr
358+
/// section.
359+
virtual uint64_t getOffset(DWARFUnit &Unit) override;
360+
};
361+
269362
using DebugStrBufferVector = SmallVector<char, 16>;
270363
class DebugStrWriter {
271364
public:
@@ -305,7 +398,8 @@ class DebugLocWriter {
305398
virtual ~DebugLocWriter(){};
306399

307400
/// Writes out location lists and stores internal patches.
308-
virtual void addList(uint64_t AttrOffset, DebugLocationsVector &&LocList);
401+
virtual void addList(uint64_t AttrOffset, uint32_t LocListIndex,
402+
DebugLocationsVector &&LocList);
309403

310404
/// Writes out locations in to a local buffer, and adds Debug Info patches.
311405
virtual void finalize(uint64_t SectionOffset,
@@ -314,6 +408,9 @@ class DebugLocWriter {
314408
/// Return internal buffer.
315409
virtual std::unique_ptr<DebugBufferVector> getBuffer();
316410

411+
/// Returns DWARF version.
412+
uint8_t getDwarfVersion() const { return DwarfVersion; }
413+
317414
/// Offset of an empty location list.
318415
static constexpr uint32_t EmptyListOffset = 0;
319416

@@ -325,13 +422,13 @@ class DebugLocWriter {
325422

326423
protected:
327424
std::unique_ptr<DebugBufferVector> LocBuffer;
328-
329425
std::unique_ptr<raw_svector_ostream> LocStream;
330426
/// Current offset in the section (updated as new entries are written).
331427
/// Starts with 0 here since this only writes part of a full location lists
332428
/// section. In the final section, the first 16 bytes are reserved for an
333429
/// empty list.
334430
uint32_t SectionOffset{0};
431+
uint8_t DwarfVersion{4};
335432
LocWriterKind Kind{LocWriterKind::DebugLocWriter};
336433

337434
private:
@@ -354,9 +451,12 @@ class DebugLoclistWriter : public DebugLocWriter {
354451
public:
355452
~DebugLoclistWriter() {}
356453
DebugLoclistWriter() = delete;
357-
DebugLoclistWriter(BinaryContext *BC, uint64_t DWOId_)
358-
: DebugLocWriter(BC), DWOId(DWOId_) {
454+
DebugLoclistWriter(BinaryContext *BC, uint64_t CID,
455+
uint32_t LocListsBaseAttrOffset, uint8_t DV, bool SD)
456+
: DebugLocWriter(BC), CUID(CID),
457+
LocListsBaseAttrOffset(LocListsBaseAttrOffset), IsSplitDwarf(SD) {
359458
Kind = LocWriterKind::DebugLoclistWriter;
459+
DwarfVersion = DV;
360460
assert(DebugLoclistWriter::AddrWriter &&
361461
"Please use SetAddressWriter to initialize "
362462
"DebugAddrWriter before instantiation.");
@@ -365,23 +465,39 @@ class DebugLoclistWriter : public DebugLocWriter {
365465
static void setAddressWriter(DebugAddrWriter *AddrW) { AddrWriter = AddrW; }
366466

367467
/// Stores location lists internally to be written out during finalize phase.
368-
virtual void addList(uint64_t AttrOffset,
468+
virtual void addList(uint64_t AttrOffset, uint32_t LocListIndex,
369469
DebugLocationsVector &&LocList) override;
370470

371471
/// Writes out locations in to a local buffer and applies debug info patches.
372472
void finalize(uint64_t SectionOffset,
373473
SimpleBinaryPatcher &DebugInfoPatcher) override;
374474

375475
/// Returns DWO ID.
376-
uint64_t getDWOID() const { return DWOId; }
476+
uint64_t getCUID() const { return CUID; }
477+
478+
LocWriterKind getKind() const { return DebugLocWriter::getKind(); }
377479

378480
static bool classof(const DebugLocWriter *Writer) {
379481
return Writer->getKind() == LocWriterKind::DebugLoclistWriter;
380482
}
381483

484+
bool isSplitDwarf() const { return IsSplitDwarf; }
485+
486+
constexpr static uint32_t InvalidIndex = UINT32_MAX;
487+
constexpr static uint32_t InvalidLocListsBaseAttrOffset = UINT32_MAX;
488+
382489
private:
490+
/// Writes out locations in to a local buffer and applies debug info patches.
491+
void finalizeDWARFLegacy(uint64_t SectionOffset,
492+
SimpleBinaryPatcher &DebugInfoPatcher);
493+
494+
/// Writes out locations in to a local buffer and applies debug info patches.
495+
void finalizeDWARF5(uint64_t SectionOffset,
496+
SimpleBinaryPatcher &DebugInfoPatcher);
497+
383498
struct LocPatch {
384499
uint64_t AttrOffset{0};
500+
uint32_t Index;
385501
DebugLocationsVector LocList;
386502
};
387503
using LocPatchVec = SmallVector<LocPatch, 4>;
@@ -395,7 +511,9 @@ class DebugLoclistWriter : public DebugLocWriter {
395511
uint64_t Address{0};
396512
};
397513
static DebugAddrWriter *AddrWriter;
398-
uint64_t DWOId{0};
514+
uint64_t CUID{0};
515+
uint32_t LocListsBaseAttrOffset{InvalidLocListsBaseAttrOffset};
516+
bool IsSplitDwarf{false};
399517
};
400518

401519
enum class PatcherKind { SimpleBinaryPatcher, DebugInfoBinaryPatcher };
@@ -914,6 +1032,9 @@ class DwarfLineTable {
9141032
/// Raw data representing complete debug line section for the unit.
9151033
StringRef RawData;
9161034

1035+
/// DWARF Version
1036+
uint16_t DwarfVersion;
1037+
9171038
public:
9181039
/// Emit line info for all units in the binary context.
9191040
static void emit(BinaryContext &BC, MCStreamer &Streamer);
@@ -937,6 +1058,14 @@ class DwarfLineTable {
9371058

9381059
void setLabel(MCSymbol *Label) { Header.Label = Label; }
9391060

1061+
/// Sets the root file \p Directory, \p FileName, optional \p CheckSum, and
1062+
/// optional \p Source.
1063+
void setRootFile(StringRef Directory, StringRef FileName,
1064+
Optional<MD5::MD5Result> Checksum,
1065+
Optional<StringRef> Source) {
1066+
Header.setRootFile(Directory, FileName, Checksum, Source);
1067+
}
1068+
9401069
/// Access to MC line info.
9411070
MCLineSection &getMCLineSections() { return MCLineSections; }
9421071

@@ -956,6 +1085,12 @@ class DwarfLineTable {
9561085
void addRawContents(StringRef DebugLineContents) {
9571086
RawData = DebugLineContents;
9581087
}
1088+
1089+
/// Sets DWARF version for this line table.
1090+
void setDwarfVersion(uint16_t V) { DwarfVersion = V; }
1091+
1092+
// Returns DWARF Version for this line table.
1093+
uint16_t getDwarfVersion() const { return DwarfVersion; }
9591094
};
9601095

9611096
struct AttrInfo {

0 commit comments

Comments
 (0)