Skip to content

Commit ff291b5

Browse files
committedJan 27, 2016
[DebugInfo] Support zero-length CIE in the _eh_frame parser
MCJIT emits zero-length CIE at the end of the _eh_frame section. This change ensures that parser inside DebugInfo will not crash and correctly record such cases. We are now recording DW_EH_PE_omit as a default value for FDE and LSDA encodings. Also Offset != EndAugmentationOffset assertion check will only happen if augmentation string had 'z' letter in it. Differential Revision: http://reviews.llvm.org/D16588 llvm-svn: 258931
1 parent 7124c11 commit ff291b5

File tree

3 files changed

+37
-30
lines changed

3 files changed

+37
-30
lines changed
 

‎llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp

+27-30
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ class CIE : public FrameEntry {
201201
SmallString<8> Augmentation, uint8_t AddressSize,
202202
uint8_t SegmentDescriptorSize, uint64_t CodeAlignmentFactor,
203203
int64_t DataAlignmentFactor, uint64_t ReturnAddressRegister,
204-
SmallString<8> AugmentationData, Optional<uint32_t> FDEPointerEncoding,
205-
Optional<uint32_t> LSDAPointerEncoding)
204+
SmallString<8> AugmentationData, uint32_t FDEPointerEncoding,
205+
uint32_t LSDAPointerEncoding)
206206
: FrameEntry(FK_CIE, Offset, Length), Version(Version),
207207
Augmentation(std::move(Augmentation)),
208208
AddressSize(AddressSize),
@@ -219,10 +219,10 @@ class CIE : public FrameEntry {
219219
StringRef getAugmentationString() const { return Augmentation; }
220220
uint64_t getCodeAlignmentFactor() const { return CodeAlignmentFactor; }
221221
int64_t getDataAlignmentFactor() const { return DataAlignmentFactor; }
222-
Optional<uint32_t> getFDEPointerEncoding() const {
222+
uint32_t getFDEPointerEncoding() const {
223223
return FDEPointerEncoding;
224224
}
225-
Optional<uint32_t> getLSDAPointerEncoding() const {
225+
uint32_t getLSDAPointerEncoding() const {
226226
return LSDAPointerEncoding;
227227
}
228228

@@ -265,8 +265,8 @@ class CIE : public FrameEntry {
265265

266266
// The following are used when the CIE represents an EH frame entry.
267267
SmallString<8> AugmentationData;
268-
Optional<uint32_t> FDEPointerEncoding;
269-
Optional<uint32_t> LSDAPointerEncoding;
268+
uint32_t FDEPointerEncoding;
269+
uint32_t LSDAPointerEncoding;
270270
};
271271

272272

@@ -556,25 +556,23 @@ void DWARFDebugFrame::parse(DataExtractor Data) {
556556
uint64_t ReturnAddressRegister = Data.getULEB128(&Offset);
557557

558558
// Parse the augmentation data for EH CIEs
559-
StringRef AugmentationData;
560-
Optional<uint32_t> FDEPointerEncoding;
561-
Optional<uint32_t> LSDAPointerEncoding;
559+
StringRef AugmentationData("");
560+
uint32_t FDEPointerEncoding = DW_EH_PE_omit;
561+
uint32_t LSDAPointerEncoding = DW_EH_PE_omit;
562562
if (IsEH) {
563563
Optional<uint32_t> PersonalityEncoding;
564564
Optional<uint64_t> Personality;
565565

566-
uint64_t AugmentationLength = 0;
567-
uint32_t StartAugmentationOffset = 0;
568-
uint32_t EndAugmentationOffset = 0;
566+
Optional<uint64_t> AugmentationLength;
567+
uint32_t StartAugmentationOffset;
568+
uint32_t EndAugmentationOffset;
569569

570570
// Walk the augmentation string to get all the augmentation data.
571571
for (unsigned i = 0, e = AugmentationString.size(); i != e; ++i) {
572572
switch (AugmentationString[i]) {
573573
default:
574574
ReportError("Unknown augmentation character in entry at %lx");
575575
case 'L':
576-
if (LSDAPointerEncoding)
577-
ReportError("Duplicate LSDA encoding in entry at %lx");
578576
LSDAPointerEncoding = Data.getU8(&Offset);
579577
break;
580578
case 'P': {
@@ -585,8 +583,6 @@ void DWARFDebugFrame::parse(DataExtractor Data) {
585583
break;
586584
}
587585
case 'R':
588-
if (FDEPointerEncoding)
589-
ReportError("Duplicate FDE encoding in entry at %lx");
590586
FDEPointerEncoding = Data.getU8(&Offset);
591587
break;
592588
case 'z':
@@ -596,20 +592,22 @@ void DWARFDebugFrame::parse(DataExtractor Data) {
596592
// the string contains a 'z'.
597593
AugmentationLength = Data.getULEB128(&Offset);
598594
StartAugmentationOffset = Offset;
599-
EndAugmentationOffset =
600-
Offset + static_cast<uint32_t>(AugmentationLength);
595+
EndAugmentationOffset = Offset +
596+
static_cast<uint32_t>(*AugmentationLength);
601597
}
602598
}
603599

604-
if (Offset != EndAugmentationOffset)
605-
ReportError("Parsing augmentation data at %lx failed");
600+
if (AugmentationLength.hasValue()) {
601+
if (Offset != EndAugmentationOffset)
602+
ReportError("Parsing augmentation data at %lx failed");
606603

607-
AugmentationData = Data.getData().slice(StartAugmentationOffset,
608-
EndAugmentationOffset);
604+
AugmentationData = Data.getData().slice(StartAugmentationOffset,
605+
EndAugmentationOffset);
606+
}
609607
}
610608

611609
auto Cie = make_unique<CIE>(StartOffset, Length, Version,
612-
StringRef(Augmentation), AddressSize,
610+
AugmentationString, AddressSize,
613611
SegmentDescriptorSize, CodeAlignmentFactor,
614612
DataAlignmentFactor, ReturnAddressRegister,
615613
AugmentationData, FDEPointerEncoding,
@@ -628,12 +626,11 @@ void DWARFDebugFrame::parse(DataExtractor Data) {
628626
if (!Cie)
629627
ReportError("Parsing FDE data at %lx failed due to missing CIE");
630628

631-
Optional<uint32_t> FDEPointerEncoding = Cie->getFDEPointerEncoding();
632-
if (!FDEPointerEncoding)
633-
ReportError("Parsing at %lx failed due to missing pointer encoding");
629+
InitialLocation = readPointer(Data, Offset,
630+
Cie->getFDEPointerEncoding());
631+
AddressRange = readPointer(Data, Offset,
632+
Cie->getFDEPointerEncoding());
634633

635-
InitialLocation = readPointer(Data, Offset, *FDEPointerEncoding);
636-
AddressRange = readPointer(Data, Offset, *FDEPointerEncoding);
637634
StringRef AugmentationString = Cie->getAugmentationString();
638635
if (!AugmentationString.empty()) {
639636
// Parse the augmentation length and data for this FDE.
@@ -644,8 +641,8 @@ void DWARFDebugFrame::parse(DataExtractor Data) {
644641

645642
// Decode the LSDA if the CIE augmentation string said we should.
646643
uint64_t LSDA = 0;
647-
if (Optional<uint32_t> Encoding = Cie->getLSDAPointerEncoding())
648-
LSDA = readPointer(Data, Offset, *Encoding);
644+
if (Cie->getLSDAPointerEncoding() != DW_EH_PE_omit)
645+
LSDA = readPointer(Data, Offset, Cie->getLSDAPointerEncoding());
649646

650647
if (Offset != EndAugmentationOffset)
651648
ReportError("Parsing augmentation data at %lx failed");
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# RUN: llvm-objdump -dwarf=frames %p/Inputs/eh_frame_zero_cie.o 2>/dev/null | FileCheck %s
2+
3+
# CHECK: .eh_frame contents:
4+
5+
# CHECK: 00000000 00000000 ffffffff CIE
6+
# CHECK: Version: 0
7+
# CHECK: Augmentation: ""
8+
# CHECK: Code alignment factor: 0
9+
# CHECK: Data alignment factor: 0
10+
# CHECK: Return address column: 0

0 commit comments

Comments
 (0)
Please sign in to comment.