Index: llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp +++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp @@ -189,10 +189,13 @@ // 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 @@ << "\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 @@ } 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 @@ 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(StartOffset, Length, Version, - StringRef(Augmentation), CodeAlignmentFactor, + StringRef(Augmentation), AddressSize, + SegmentDescriptorSize, CodeAlignmentFactor, DataAlignmentFactor, ReturnAddressRegister); CIEs[StartOffset] = Cie.get(); Entries.emplace_back(std::move(Cie)); Index: llvm/trunk/lib/MC/MCDwarf.cpp =================================================================== --- llvm/trunk/lib/MC/MCDwarf.cpp +++ llvm/trunk/lib/MC/MCDwarf.cpp @@ -1302,6 +1302,14 @@ } 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: llvm/trunk/test/MC/ARM/dwarf-cfi-initial-state.s =================================================================== --- llvm/trunk/test/MC/ARM/dwarf-cfi-initial-state.s +++ llvm/trunk/test/MC/ARM/dwarf-cfi-initial-state.s @@ -13,5 +13,8 @@ # 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: llvm/trunk/test/MC/ELF/cfi-sections.s =================================================================== --- llvm/trunk/test/MC/ELF/cfi-sections.s +++ llvm/trunk/test/MC/ELF/cfi-sections.s @@ -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 @@ // 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 @@ // 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: llvm/trunk/test/MC/ELF/cfi-version.ll =================================================================== --- llvm/trunk/test/MC/ELF/cfi-version.ll +++ llvm/trunk/test/MC/ELF/cfi-version.ll @@ -39,11 +39,17 @@ ; 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: