[llvm] 12028cb - [DwarfGenerator] Calculate relative offset according to Dwarf Version (#84847)

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 20 09:18:35 PDT 2024


Author: Will Hawkins
Date: 2024-03-20T09:18:31-07:00
New Revision: 12028cb1dab9ba1b4ac826c3d70ca19c3b379255

URL: https://github.com/llvm/llvm-project/commit/12028cb1dab9ba1b4ac826c3d70ca19c3b379255
DIFF: https://github.com/llvm/llvm-project/commit/12028cb1dab9ba1b4ac826c3d70ca19c3b379255.diff

LOG: [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 <hawkinsw at obs.cr>

Added: 
    

Modified: 
    llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp

Removed: 
    


################################################################################
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