[llvm] [DwarfGenerator] Calculate relative offset according to Dwarf Version (PR #84847)
Will Hawkins via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 11 15:50:01 PDT 2024
https://github.com/hawkinsw created https://github.com/llvm/llvm-project/pull/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).
>From ee9e776cdf9f7d94b60df2ffa832975a4fd18b00 Mon Sep 17 00:00:00 2001
From: Will Hawkins <hawkinsw at obs.cr>
Date: Mon, 11 Mar 2024 18:46:21 -0400
Subject: [PATCH] [DwarfGenerator] Calculate relative offset according to Dwarf
Version
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 <hawkinsw at obs.cr>
---
llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp b/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
index c5b9f5cfc0d4ac..ad5e51b7efb834 100644
--- a/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
@@ -568,12 +568,20 @@ StringRef dwarfgen::Generator::generate() {
for (auto &CU : CompileUnits) {
// Set the absolute .debug_info offset for this compile unit.
CU->setOffset(SecOffset);
- // The DIEs contain compile unit relative offsets.
- unsigned CUOffset = 11;
+ // The DIEs contain compile unit relative offsets and the offset depends
+ // on the Dwarf version.
+ unsigned CUOffset = 4 + // Length
+ 2 + // Version
+ 4 + // Abbreviation offset
+ 1; // Address size
+ if (Asm->getDwarfVersion() >= 5)
+ CUOffset += 1; // DW_UT_compile tag.
+
CUOffset = CU->getUnitDIE().computeSizeAndOffsets(CUOffset);
// Update our absolute .debug_info offset.
SecOffset += CUOffset;
- CU->setLength(CUOffset - 4);
+ unsigned CUOffsetUnitLength = 4;
+ CU->setLength(CUOffset - CUOffsetUnitLength);
}
Abbreviations.Emit(Asm.get(), TLOF->getDwarfAbbrevSection());
More information about the llvm-commits
mailing list