From: Keith Walker Date: Tue, 12 May 2015 15:25:08 +0000 (+0000) Subject: [DWARF] Add CIE header fields address_size and segment_size when generating dwarf-4 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=09f089a39ecc90256225d922e6ee42b689af22a9 [DWARF] Add CIE header fields address_size and segment_size when generating dwarf-4 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 --- diff --git a/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp b/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp index 784652927ec..1aa31be71fe 100644 --- a/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp +++ b/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp @@ -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(StartOffset, Length, Version, - StringRef(Augmentation), CodeAlignmentFactor, + StringRef(Augmentation), AddressSize, + SegmentDescriptorSize, CodeAlignmentFactor, DataAlignmentFactor, ReturnAddressRegister); CIEs[StartOffset] = Cie.get(); Entries.emplace_back(std::move(Cie)); diff --git a/lib/MC/MCDwarf.cpp b/lib/MC/MCDwarf.cpp index a8cb384054e..890b03170b0 100644 --- a/lib/MC/MCDwarf.cpp +++ b/lib/MC/MCDwarf.cpp @@ -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()); diff --git a/test/MC/ARM/dwarf-cfi-initial-state.s b/test/MC/ARM/dwarf-cfi-initial-state.s index 0d1c08af728..d3f7ce420f9 100644 --- a/test/MC/ARM/dwarf-cfi-initial-state.s +++ b/test/MC/ARM/dwarf-cfi-initial-state.s @@ -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 diff --git a/test/MC/ELF/cfi-sections.s b/test/MC/ELF/cfi-sections.s index 04240a8936c..830fe260ec2 100644 --- a/test/MC/ELF/cfi-sections.s +++ b/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 @@ 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: } diff --git a/test/MC/ELF/cfi-version.ll b/test/MC/ELF/cfi-version.ll index 3abe4a4c29f..9ea7be4a42b 100644 --- a/test/MC/ELF/cfi-version.ll +++ b/test/MC/ELF/cfi-version.ll @@ -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: