[DWARF] Add CIE header fields address_size and segment_size when generating dwarf-4
authorKeith Walker <kwalker@arm.com>
Tue, 12 May 2015 15:25:08 +0000 (15:25 +0000)
committerKeith Walker <kwalker@arm.com>
Tue, 12 May 2015 15:25:08 +0000 (15:25 +0000)
The DWARF-4 specification added 2 new fields in the CIE header called
address_size and segment_size.
Create these 2 new fields when generating dwarf-4 CIE entries, print out
the new fields when dumping the CIE and update tests

Differential Revision: http://reviews.llvm.org/D9558

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237145 91177308-0d34-0410-b5e6-96231b3b80d8

lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
lib/MC/MCDwarf.cpp
test/MC/ARM/dwarf-cfi-initial-state.s
test/MC/ELF/cfi-sections.s
test/MC/ELF/cfi-version.ll

index 784652927ec55c879e8c5022bf6143e5fa76fa4b..1aa31be71fee047795948e1697277d43a70cc891 100644 (file)
@@ -189,10 +189,13 @@ public:
   // CIEs (and FDEs) are simply container classes, so the only sensible way to
   // create them is by providing the full parsed contents in the constructor.
   CIE(uint64_t Offset, uint64_t Length, uint8_t Version,
-      SmallString<8> Augmentation, uint64_t CodeAlignmentFactor,
+      SmallString<8> Augmentation, uint8_t AddressSize,
+      uint8_t SegmentDescriptorSize, uint64_t CodeAlignmentFactor,
       int64_t DataAlignmentFactor, uint64_t ReturnAddressRegister)
       : FrameEntry(FK_CIE, Offset, Length), Version(Version),
         Augmentation(std::move(Augmentation)),
+        AddressSize(AddressSize),
+        SegmentDescriptorSize(SegmentDescriptorSize),
         CodeAlignmentFactor(CodeAlignmentFactor),
         DataAlignmentFactor(DataAlignmentFactor),
         ReturnAddressRegister(ReturnAddressRegister) {}
@@ -208,6 +211,12 @@ public:
        << "\n";
     OS << format("  Version:               %d\n", Version);
     OS << "  Augmentation:          \"" << Augmentation << "\"\n";
+    if (Version >= 4) {
+      OS << format("  Address size:          %u\n",
+                   (uint32_t)AddressSize);
+      OS << format("  Segment desc size:     %u\n",
+                   (uint32_t)SegmentDescriptorSize);
+    }
     OS << format("  Code alignment factor: %u\n",
                  (uint32_t)CodeAlignmentFactor);
     OS << format("  Data alignment factor: %d\n",
@@ -222,9 +231,11 @@ public:
   }
 
 private:
-  /// The following fields are defined in section 6.4.1 of the DWARF standard v3
+  /// The following fields are defined in section 6.4.1 of the DWARF standard v4
   uint8_t Version;
   SmallString<8> Augmentation;
+  uint8_t AddressSize;
+  uint8_t SegmentDescriptorSize;
   uint64_t CodeAlignmentFactor;
   int64_t DataAlignmentFactor;
   uint64_t ReturnAddressRegister;
@@ -461,18 +472,18 @@ void DWARFDebugFrame::parse(DataExtractor Data) {
     bool IsCIE = ((IsDWARF64 && Id == DW64_CIE_ID) || Id == DW_CIE_ID);
 
     if (IsCIE) {
-      // Note: this is specifically DWARFv3 CIE header structure. It was
-      // changed in DWARFv4. We currently don't support reading DWARFv4
-      // here because LLVM itself does not emit it (and LLDB doesn't
-      // support it either).
       uint8_t Version = Data.getU8(&Offset);
       const char *Augmentation = Data.getCStr(&Offset);
+      uint8_t AddressSize = Version < 4 ? Data.getAddressSize() : Data.getU8(&Offset);
+      Data.setAddressSize(AddressSize);
+      uint8_t SegmentDescriptorSize = Version < 4 ? 0 : Data.getU8(&Offset);
       uint64_t CodeAlignmentFactor = Data.getULEB128(&Offset);
       int64_t DataAlignmentFactor = Data.getSLEB128(&Offset);
       uint64_t ReturnAddressRegister = Data.getULEB128(&Offset);
 
       auto Cie = make_unique<CIE>(StartOffset, Length, Version,
-                                  StringRef(Augmentation), CodeAlignmentFactor,
+                                  StringRef(Augmentation), AddressSize,
+                                  SegmentDescriptorSize, CodeAlignmentFactor,
                                   DataAlignmentFactor, ReturnAddressRegister);
       CIEs[StartOffset] = Cie.get();
       Entries.emplace_back(std::move(Cie));
index a8cb384054e0c5def2da3f2e546d97dac8555325..890b03170b027fd8f33cb54fa27c0b750cc4f2e6 100644 (file)
@@ -1302,6 +1302,14 @@ const MCSymbol &FrameEmitterImpl::EmitCIE(MCObjectStreamer &streamer,
   }
   streamer.EmitIntValue(0, 1);
 
+  if (CIEVersion >= 4) {
+    // Address Size
+    streamer.EmitIntValue(context.getAsmInfo()->getPointerSize(), 1);
+
+    // Segment Descriptor Size
+    streamer.EmitIntValue(0, 1);
+  }
+
   // Code Alignment Factor
   streamer.EmitULEB128IntValue(context.getAsmInfo()->getMinInstAlignment());
 
index 0d1c08af7282efd52653466520f2aaca8bbd86e3..d3f7ce420f920e4b3c2dd6418c7631facb1bd615 100644 (file)
@@ -13,5 +13,8 @@ bx lr
 # When llvm-dwarfdump prints the full info for the DW_CFA_def_cfa
 # field, we can check that here too.
 # CHECK: DW_CFA_def_cfa:
+# The following 2 DW_CFA_nop instructions are "padding"
+# CHECK: DW_CFA_nop:
+# CHECK: DW_CFA_nop:
 # CHECK-NOT: DW_CFA
 # CHECK: FDE
index 04240a8936ce3ad70c978a4cf44458305fdb2bc0..830fe260ec2ce213535fd7fcd3fef1744a30489c 100644 (file)
@@ -1,5 +1,11 @@
-// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | llvm-readobj -s -sd | FileCheck -check-prefix=ELF_64 %s
-// RUN: llvm-mc -filetype=obj -triple i686-pc-linux-gnu %s -o - | llvm-readobj -s -sd | FileCheck -check-prefix=ELF_32 %s
+// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu -dwarf-version 2 %s -o - | llvm-readobj -s -sd | FileCheck -check-prefix=ELF_64 -check-prefix=ELF_64_DWARF_2 %s
+// RUN: llvm-mc -filetype=obj -triple i686-pc-linux-gnu -dwarf-version 2 %s -o - | llvm-readobj -s -sd | FileCheck -check-prefix=ELF_32 -check-prefix=ELF_32_DWARF_2 %s
+
+// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu -dwarf-version 3 %s -o - | llvm-readobj -s -sd | FileCheck -check-prefix=ELF_64 -check-prefix=ELF_64_DWARF_3 %s
+// RUN: llvm-mc -filetype=obj -triple i686-pc-linux-gnu -dwarf-version 3 %s -o - | llvm-readobj -s -sd | FileCheck -check-prefix=ELF_32 -check-prefix=ELF_32_DWARF_3 %s
+
+// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu -dwarf-version 4 %s -o - | llvm-readobj -s -sd | FileCheck -check-prefix=ELF_64 -check-prefix=ELF_64_DWARF_4 %s
+// RUN: llvm-mc -filetype=obj -triple i686-pc-linux-gnu -dwarf-version 4 %s -o - | llvm-readobj -s -sd | FileCheck -check-prefix=ELF_32 -check-prefix=ELF_32_DWARF_4 %s
 
 .cfi_sections .debug_frame
 
@@ -26,8 +32,12 @@ f2:
 // ELF_64-NEXT:     AddressAlignment: 8
 // ELF_64-NEXT:     EntrySize: 0
 // ELF_64-NEXT:     SectionData (
-// ELF_64-NEXT:       0000: 14000000 FFFFFFFF 04000178 100C0708
-// ELF_64-NEXT:       0010: 90010000 00000000 14000000 00000000
+// ELF_64_DWARF_2-NEXT:       0000: 14000000 FFFFFFFF 01000178 100C0708
+// ELF_64_DWARF_2-NEXT:       0010: 90010000 00000000 14000000 00000000
+// ELF_64_DWARF_3-NEXT:       0000: 14000000 FFFFFFFF 03000178 100C0708
+// ELF_64_DWARF_3-NEXT:       0010: 90010000 00000000 14000000 00000000
+// ELF_64_DWARF_4-NEXT:       0000: 14000000 FFFFFFFF 04000800 0178100C
+// ELF_64_DWARF_4-NEXT:       0010: 07089001 00000000 14000000 00000000
 // ELF_64-NEXT:       0020: 00000000 00000000 01000000 00000000
 // ELF_64-NEXT:       0030: 14000000 00000000 00000000 00000000
 // ELF_64-NEXT:       0040: 01000000 00000000
@@ -47,9 +57,14 @@ f2:
 // ELF_32-NEXT:     AddressAlignment: 4
 // ELF_32-NEXT:     EntrySize: 0
 // ELF_32-NEXT:     SectionData (
-// ELF_32-NEXT:       0000: 10000000 FFFFFFFF 0400017C 080C0404
-// ELF_32-NEXT:       0010: 88010000 0C000000 00000000 00000000
+// ELF_32_DWARF_2-NEXT:       0000: 10000000 FFFFFFFF 0100017C 080C0404
+// ELF_32_DWARF_2-NEXT:       0010: 88010000 0C000000 00000000 00000000
+// ELF_32_DWARF_3-NEXT:       0000: 10000000 FFFFFFFF 0300017C 080C0404
+// ELF_32_DWARF_3-NEXT:       0010: 88010000 0C000000 00000000 00000000
+// ELF_32_DWARF_4-NEXT:       0000: 10000000 FFFFFFFF 04000400 017C080C
+// ELF_32_DWARF_4-NEXT:       0010: 04048801 0C000000 00000000 00000000
 // ELF_32-NEXT:       0020: 01000000 0C000000 00000000 01000000
 // ELF_32-NEXT:       0030: 01000000
+
 // ELF_32-NEXT:     )
 // ELF_32-NEXT:   }
index 3abe4a4c29fc7eadc29f1700704d34396386488e..9ea7be4a42b5bb52da368bb6e67730969e744ecd 100644 (file)
@@ -39,11 +39,17 @@ attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "n
 ; DWARF2:      .debug_frame contents:
 ; DWARF2:        Version:               1
 ; DWARF2-NEXT:   Augmentation:
+; DWARF2-NOT:    Address size:
+; DWARF2-NOT:    Segment desc size:
 
 ; DWARF3:      .debug_frame contents:
 ; DWARF3:        Version:               3
 ; DWARF3-NEXT:   Augmentation:
+; DWARF3-NOT:    Address size:
+; DWARF3-NOT:    Segment desc size:
 
 ; DWARF4:      .debug_frame contents:
 ; DWARF4:        Version:               4
 ; DWARF4-NEXT:   Augmentation:
+; DWARF4:        Address size:
+; DWARF4:        Segment desc size: