[llvm] r332030 - [DWARF] Fixing a bug in DWARF v5 string offsets tables where the length encoded the contribution

Wolfgang Pieb via llvm-commits llvm-commits at lists.llvm.org
Thu May 10 13:02:34 PDT 2018


Author: wolfgangp
Date: Thu May 10 13:02:34 2018
New Revision: 332030

URL: http://llvm.org/viewvc/llvm-project?rev=332030&view=rev
Log:
[DWARF] Fixing a bug in DWARF v5 string offsets tables where the length encoded the contribution
length excluding the table header. Instead it must encode the contribution length minus the length
field itself.

Reviewer: JDevliegehere

Differential Revision: https://reviews.llvm.org/D45922

Modified:
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp
    llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
    llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp
    llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-invalid-3.s
    llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-invalid-4.s
    llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-invalid-6.s
    llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-macho.s
    llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets.s
    llvm/trunk/test/DebugInfo/X86/string-offsets-multiple-cus.ll
    llvm/trunk/test/DebugInfo/X86/string-offsets-table.ll

Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h?rev=332030&r1=332029&r2=332030&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h Thu May 10 13:02:34 2018
@@ -169,6 +169,7 @@ struct BaseAddress {
 /// Represents a unit's contribution to the string offsets table.
 struct StrOffsetsContributionDescriptor {
   uint64_t Base = 0;
+  /// The contribution size not including the header.
   uint64_t Size = 0;
   /// Format and version.
   dwarf::FormParams FormParams = {0, 0, dwarf::DwarfFormat::DWARF32};

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp?rev=332030&r1=332029&r2=332030&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp Thu May 10 13:02:34 2018
@@ -36,9 +36,9 @@ void DwarfFile::emitStringOffsetsTableHe
   // FIXME: DWARF64
   // We are emitting the header for a contribution to the string offsets
   // table. The header consists of an entry with the contribution's
-  // size (not including the size of the header), the DWARF version and
+  // size (not including the size of the length field), the DWARF version and
   // 2 bytes of padding.
-  Asm->emitInt32(StrPool.size() * EntrySize);
+  Asm->emitInt32(StrPool.size() * EntrySize + 4);
   Asm->emitInt16(Asm->getDwarfVersion());
   Asm->emitInt16(0);
   // Define the symbol that marks the start of the contribution. It is

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=332030&r1=332029&r2=332030&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Thu May 10 13:02:34 2018
@@ -172,7 +172,11 @@ static void dumpDWARFv5StringOffsetsSect
       OS << (ContributionHeader - Offset) << "\n";
     }
     OS << format("0x%8.8x: ", (uint32_t)ContributionHeader);
-    OS << "Contribution size = " << Contribution->Size
+    // In DWARF v5 the contribution size in the descriptor does not equal
+    // the originally encoded length (it does not contain the length of the
+    // version field and the padding, a total of 4 bytes). Add them back in
+    // for reporting.
+    OS << "Contribution size = " << (Contribution->Size + (Version < 5 ? 0 : 4))
        << ", Format = " << (Format == DWARF32 ? "DWARF32" : "DWARF64")
        << ", Version = " << Version << "\n";
 

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp?rev=332030&r1=332029&r2=332030&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp Thu May 10 13:02:34 2018
@@ -517,7 +517,9 @@ parseDWARF64StringOffsetsTableHeader(DWA
   uint64_t Size = DA.getU64(&Offset);
   uint8_t Version = DA.getU16(&Offset);
   (void)DA.getU16(&Offset); // padding
-  return StrOffsetsContributionDescriptor(Offset, Size, Version, DWARF64);
+  // The encoded length includes the 2-byte version field and the 2-byte
+  // padding, so we need to subtract them out when we populate the descriptor.
+  return StrOffsetsContributionDescriptor(Offset, Size - 4, Version, DWARF64);
   //return Optional<StrOffsetsContributionDescriptor>(Descriptor);
 }
 
@@ -532,7 +534,10 @@ parseDWARF32StringOffsetsTableHeader(DWA
     return Optional<StrOffsetsContributionDescriptor>();
   uint8_t Version = DA.getU16(&Offset);
   (void)DA.getU16(&Offset); // padding
-  return StrOffsetsContributionDescriptor(Offset, ContributionSize, Version, DWARF32);
+  // The encoded length includes the 2-byte version field and the 2-byte
+  // padding, so we need to subtract them out when we populate the descriptor.
+  return StrOffsetsContributionDescriptor(Offset, ContributionSize - 4, Version,
+                                          DWARF32);
   //return Optional<StrOffsetsContributionDescriptor>(Descriptor);
 }
 

Modified: llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-invalid-3.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-invalid-3.s?rev=332030&r1=332029&r2=332030&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-invalid-3.s (original)
+++ llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-invalid-3.s Thu May 10 13:02:34 2018
@@ -71,7 +71,7 @@ CU1_5_end:
         .long str_CU1_dir
 .debug_str_offsets_segment0_end:
 # CU2's contribution
-        .long .debug_str_offsets_segment1_end-.debug_str_offsets_base1
+        .long .debug_str_offsets_segment1_end-.debug_str_offsets_base1+4
         .short 5    # DWARF version
         .short 0    # Padding
 .debug_str_offsets_base1:
@@ -80,7 +80,7 @@ CU1_5_end:
         .long str_CU2_dir
 .debug_str_offsets_segment1_end:
 # The TU's contribution
-        .long .debug_str_offsets_segment2_end-.debug_str_offsets_base2
+        .long .debug_str_offsets_segment2_end-.debug_str_offsets_base2+4
         .short 5    # DWARF version
         .short 0    # Padding
 .debug_str_offsets_base2:

Modified: llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-invalid-4.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-invalid-4.s?rev=332030&r1=332029&r2=332030&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-invalid-4.s (original)
+++ llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-invalid-4.s Thu May 10 13:02:34 2018
@@ -42,7 +42,7 @@ CU1_5_end:
 # CU1's contribution
 # The length is not a multiple of 4. Check that we don't read off the
 # end.
-        .long .debug_str_offsets_segment0_end-.debug_str_offsets_base0
+        .long .debug_str_offsets_segment0_end-.debug_str_offsets_base0+4
         .short 5    # DWARF version
         .short 0    # Padding
 .debug_str_offsets_base0:

Modified: llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-invalid-6.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-invalid-6.s?rev=332030&r1=332029&r2=332030&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-invalid-6.s (original)
+++ llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-invalid-6.s Thu May 10 13:02:34 2018
@@ -70,7 +70,7 @@ CU2_5_end:
 
         .section .debug_str_offsets,"", at progbits
 # CU1's contribution
-        .long .debug_str_offsets_segment1_end-.debug_str_offsets_base0
+        .long .debug_str_offsets_segment1_end-.debug_str_offsets_base0+4
         .short 5    # DWARF version
         .short 0    # Padding
 .debug_str_offsets_base0:
@@ -80,7 +80,7 @@ CU2_5_end:
 .debug_str_offsets_segment0_end:
 # CU2's contribution
 # Overlapping with CU1's contribution
-        .long .debug_str_offsets_segment1_end-.debug_str_offsets_base1
+        .long .debug_str_offsets_segment1_end-.debug_str_offsets_base1+4
         .short 5    # DWARF version
         .short 0    # Padding
 .debug_str_offsets_base1:

Modified: llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-macho.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-macho.s?rev=332030&r1=332029&r2=332030&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-macho.s (original)
+++ llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets-macho.s Thu May 10 13:02:34 2018
@@ -31,7 +31,7 @@ str_Variable3:
 
 	.section	__DWARF,__debug_str_offs,regular,debug
 Ldebug_str_offsets:
-        .long Ldebug_str_offsets_segment0_end-Ldebug_str_offsets_base0
+        .long Ldebug_str_offsets_segment0_end-Ldebug_str_offsets_base0+4
         .short 5    # DWARF version
         .short 0    # Padding
 Ldebug_str_offsets_base0:
@@ -47,7 +47,7 @@ Ldebug_str_offsets_segment0_end:
         .long 0
 # CU2's contribution (DWARF64 format)
         .long 0xffffffff
-        .quad Ldebug_str_offsets_segment1_end-Ldebug_str_offsets_base1
+        .quad Ldebug_str_offsets_segment1_end-Ldebug_str_offsets_base1+4
         .short 5    # DWARF version
         .short 0    # Padding
 Ldebug_str_offsets_base1:
@@ -56,7 +56,7 @@ Ldebug_str_offsets_base1:
         .quad str_CU2_dir
 Ldebug_str_offsets_segment1_end:
 # The TU's contribution
-        .long Ldebug_str_offsets_segment2_end-Ldebug_str_offsets_base2
+        .long Ldebug_str_offsets_segment2_end-Ldebug_str_offsets_base2+4
         .short 5    # DWARF version
         .short 0    # Padding
 Ldebug_str_offsets_base2:
@@ -250,7 +250,7 @@ TU_5_end:
 # 
 # The .debug_str_offsets section
 # COMMON:      .debug_str_offsets contents:
-# COMMON-NEXT: 0x00000000: Contribution size = 28, Format = DWARF32, Version = 5
+# COMMON-NEXT: 0x00000000: Contribution size = 32, Format = DWARF32, Version = 5
 # COMMON-NEXT: 0x00000008: 00000000 "Handmade DWARF producer"
 # COMMON-NEXT: 0x0000000c: 00000018 "Compile_Unit_1"
 # COMMON-NEXT: 0x00000010: 00000027 "/home/test/CU1"
@@ -259,10 +259,10 @@ TU_5_end:
 # COMMON-NEXT: 0x0000001c: 00000075 "MyVar2"
 # COMMON-NEXT: 0x00000020: 0000007c "MyVar3"
 # COMMON-NEXT: 0x00000024: Gap, length = 4
-# COMMON-NEXT: 0x00000028: Contribution size = 24, Format = DWARF64, Version = 5
+# COMMON-NEXT: 0x00000028: Contribution size = 28, Format = DWARF64, Version = 5
 # COMMON-NEXT: 0x00000038: 00000000 "Handmade DWARF producer"
 # COMMON-NEXT: 0x00000040: 00000036 "Compile_Unit_2"
 # COMMON-NEXT: 0x00000048: 00000045 "/home/test/CU2"
-# COMMON-NEXT: 0x00000050: Contribution size = 8, Format = DWARF32, Version = 5
+# COMMON-NEXT: 0x00000050: Contribution size = 12, Format = DWARF32, Version = 5
 # COMMON-NEXT: 0x00000058: 00000054 "Type_Unit"
 # COMMON-NEXT: 0x0000005c: 0000005e "MyStruct"

Modified: llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets.s?rev=332030&r1=332029&r2=332030&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets.s (original)
+++ llvm/trunk/test/DebugInfo/X86/dwarfdump-str-offsets.s Thu May 10 13:02:34 2018
@@ -32,7 +32,7 @@ str_Variable3:
 # Every unit contributes to the string_offsets table.
         .section .debug_str_offsets,"", at progbits
 # CU1's contribution
-        .long .debug_str_offsets_segment0_end-.debug_str_offsets_base0
+        .long .debug_str_offsets_segment0_end-.debug_str_offsets_base0+4
         .short 5    # DWARF version
         .short 0    # Padding
 .debug_str_offsets_base0:
@@ -48,7 +48,7 @@ str_Variable3:
         .long 0
 # CU2's contribution in DWARF64 format
         .long 0xffffffff
-        .quad .debug_str_offsets_segment1_end-.debug_str_offsets_base1
+        .quad .debug_str_offsets_segment1_end-.debug_str_offsets_base1+4
         .short 5    # DWARF version
         .short 0    # Padding
 .debug_str_offsets_base1:
@@ -57,7 +57,7 @@ str_Variable3:
         .quad str_CU2_dir
 .debug_str_offsets_segment1_end:
 # The TU's contribution
-        .long .debug_str_offsets_segment2_end-.debug_str_offsets_base2
+        .long .debug_str_offsets_segment2_end-.debug_str_offsets_base2+4
         .short 5    # DWARF version
         .short 0    # Padding
 .debug_str_offsets_base2:
@@ -79,7 +79,7 @@ dwo_str_TU_5_type:
 
         .section .debug_str_offsets.dwo,"", at progbits
 # One contribution only in a .dwo file
-        .long .debug_dwo_str_offsets_segment0_end-.debug_dwo_str_offsets_base0
+        .long .debug_dwo_str_offsets_segment0_end-.debug_dwo_str_offsets_base0+4
         .short 5    # DWARF version
         .short 0    # Padding
 .debug_dwo_str_offsets_base0:
@@ -358,7 +358,7 @@ TU_split_5_end:
 # 
 # The .debug_str_offsets section
 # COMMON:      .debug_str_offsets contents:
-# COMMON-NEXT: 0x00000000: Contribution size = 28, Format = DWARF32, Version = 5
+# COMMON-NEXT: 0x00000000: Contribution size = 32, Format = DWARF32, Version = 5
 # COMMON-NEXT: 0x00000008: 00000000 "Handmade DWARF producer"
 # COMMON-NEXT: 0x0000000c: 00000018 "Compile_Unit_1"
 # COMMON-NEXT: 0x00000010: 00000027 "/home/test/CU1"
@@ -367,16 +367,16 @@ TU_split_5_end:
 # COMMON-NEXT: 0x0000001c: 00000075 "MyVar2"
 # COMMON-NEXT: 0x00000020: 0000007c "MyVar3"
 # COMMON-NEXT: Gap, length = 4
-# COMMON-NEXT: 0x00000028: Contribution size = 24, Format = DWARF64, Version = 5
+# COMMON-NEXT: 0x00000028: Contribution size = 28, Format = DWARF64, Version = 5
 # COMMON-NEXT: 0x00000038: 00000000 "Handmade DWARF producer"
 # COMMON-NEXT: 0x00000040: 00000036 "Compile_Unit_2"
 # COMMON-NEXT: 0x00000048: 00000045 "/home/test/CU2"
-# COMMON-NEXT: 0x00000050: Contribution size = 8, Format = DWARF32, Version = 5
+# COMMON-NEXT: 0x00000050: Contribution size = 12, Format = DWARF32, Version = 5
 # COMMON-NEXT: 0x00000058: 00000054 "Type_Unit"
 # COMMON-NEXT: 0x0000005c: 0000005e "MyStruct"
 # 
 # SPLIT:       .debug_str_offsets.dwo contents:
-# SPLIT-NEXT:  0x00000000: Contribution size = 20, Format = DWARF32, Version = 5
+# SPLIT-NEXT:  0x00000000: Contribution size = 24, Format = DWARF32, Version = 5
 # SPLIT-NEXT:  0x00000008: 00000000 "Handmade split DWARF producer"
 # SPLIT-NEXT:  0x0000000c: 0000001e "V5_split_compile_unit"
 # SPLIT-NEXT:  0x00000010: 00000034 "/home/test/splitCU"

Modified: llvm/trunk/test/DebugInfo/X86/string-offsets-multiple-cus.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/string-offsets-multiple-cus.ll?rev=332030&r1=332029&r2=332030&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/string-offsets-multiple-cus.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/string-offsets-multiple-cus.ll Thu May 10 13:02:34 2018
@@ -94,7 +94,7 @@
 ; Check the .debug_str_offsets section header and make sure the referenced string
 ; has the correct offset.
 ; BOTH:           .debug_str_offsets contents:
-; BOTH-NEXT:      0x00000000: Contribution size = 80, Format = DWARF32, Version = 5
+; BOTH-NEXT:      0x00000000: Contribution size = 84, Format = DWARF32, Version = 5
 ; BOTH-NEXT:      0x[[CU1_STROFF]]:
 ; BOTH-NEXT:      {{.*:}}
 ; BOTH-NEXT:      {{.*:}}

Modified: llvm/trunk/test/DebugInfo/X86/string-offsets-table.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/string-offsets-table.ll?rev=332030&r1=332029&r2=332030&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/string-offsets-table.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/string-offsets-table.ll Thu May 10 13:02:34 2018
@@ -44,7 +44,7 @@
 ; Verify that the .debug_str_offsets section is there and that it starts
 ; with an 8-byte header, followed by offsets into the .debug_str section.
 ; MONOLITHIC:          .debug_str_offsets contents:
-; MONOLITHIC-NEXT:     Contribution size = 32, Format = DWARF32, Version = 5
+; MONOLITHIC-NEXT:     Contribution size = 36, Format = DWARF32, Version = 5
 ; MONOLITHIC-NEXT:     0x00000008: 00000000
 ; MONOLITHIC-NEXT:     0x0000000c: [[STRING2]]
 ; MONOLITHIC-NEXT:     0x00000010: [[STRING3]]
@@ -91,11 +91,11 @@
 ; Check the string offsets sections in both the main and the .dwo files and
 ; verify that the extracted string offsets are referenced correctly.
 ; SPLIT:      .debug_str_offsets contents:
-; SPLIT-NEXT: 0x00000000: Contribution size = 8, Format = DWARF32, Version = 5
+; SPLIT-NEXT: 0x00000000: Contribution size = 12, Format = DWARF32, Version = 5
 ; SPLIT-NEXT: 0x00000008: 00000000{{.*}}
 ; SPLIT-NEXT: 0x0000000c: [[STRING2SPLIT]]
 ; SPLIT:      .debug_str_offsets.dwo contents:
-; SPLIT-NEXT: 0x00000000: Contribution size = 32, Format = DWARF32, Version = 5
+; SPLIT-NEXT: 0x00000000: Contribution size = 36, Format = DWARF32, Version = 5
 ; SPLIT-NEXT: 0x00000008: 00000000{{.*}}
 ; SPLIT-NEXT: 0x0000000c: [[STRING2DWO]]{{.*}}
 ; SPLIT-NEXT: 0x00000010: [[STRING3DWO]]




More information about the llvm-commits mailing list