Skip to content

Commit 12028cb

Browse files
authored
[DwarfGenerator] Calculate relative offset according to Dwarf Version (#84847)
The relative offset for a CU in Dwarf v5 (and later) is different than the relative offset for a CU in Dwarf v4 (and before). Signed-off-by: Will Hawkins <[email protected]>
1 parent 4079370 commit 12028cb

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,12 +568,20 @@ StringRef dwarfgen::Generator::generate() {
568568
for (auto &CU : CompileUnits) {
569569
// Set the absolute .debug_info offset for this compile unit.
570570
CU->setOffset(SecOffset);
571-
// The DIEs contain compile unit relative offsets.
572-
unsigned CUOffset = 11;
571+
// The DIEs contain compile unit relative offsets and the offset depends
572+
// on the Dwarf version.
573+
unsigned CUOffset = 4 + // Length
574+
2 + // Version
575+
4 + // Abbreviation offset
576+
1; // Address size
577+
if (Asm->getDwarfVersion() >= 5)
578+
CUOffset += 1; // DW_UT_compile tag.
579+
573580
CUOffset = CU->getUnitDIE().computeSizeAndOffsets(CUOffset);
574581
// Update our absolute .debug_info offset.
575582
SecOffset += CUOffset;
576-
CU->setLength(CUOffset - 4);
583+
unsigned CUOffsetUnitLength = 4;
584+
CU->setLength(CUOffset - CUOffsetUnitLength);
577585
}
578586
Abbreviations.Emit(Asm.get(), TLOF->getDwarfAbbrevSection());
579587

0 commit comments

Comments
 (0)