Commit 1a837569 authored by Igor Kudrin's avatar Igor Kudrin
Browse files

[DebugInfo] Refine the condition to detect CIEs.

The condition was not accurate enough and could interpret some FDEs in
.eh_frame or 64-bit DWARF .debug_frame sections as CIEs. Even though
such FDEs are unlikely in a normal situation, the wrong interpretation
could hide an issue in a buggy generator.

Differential Revision: https://reviews.llvm.org/D73886
parent cd1dc7f1
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -285,6 +285,18 @@ void CFIProgram::dump(raw_ostream &OS, const MCRegisterInfo *MRI, bool IsEH,
  }
}

// Returns the CIE identifier to be used by the requested format.
// CIE ids for .debug_frame sections are defined in Section 7.24 of DWARFv5.
// For CIE ID in .eh_frame sections see
// https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html
constexpr uint64_t getCIEId(bool IsDWARF64, bool IsEH) {
  if (IsEH)
    return 0;
  if (IsDWARF64)
    return DW64_CIE_ID;
  return DW_CIE_ID;
}

void CIE::dump(raw_ostream &OS, const MCRegisterInfo *MRI, bool IsEH) const {
  OS << format("%08x %08x %08x CIE", (uint32_t)Offset, (uint32_t)Length,
               IsEH ? 0 : DW_CIE_ID)
@@ -379,10 +391,7 @@ void DWARFDebugFrame::parse(DWARFDataExtractor Data) {
    // The Id field's size depends on the DWARF format
    bool IsDWARF64 = Format == DWARF64;
    Id = Data.getRelocatedValue((IsDWARF64 && !IsEH) ? 8 : 4, &Offset);
    bool IsCIE =
        ((IsDWARF64 && Id == DW64_CIE_ID) || Id == DW_CIE_ID || (IsEH && !Id));

    if (IsCIE) {
    if (Id == getCIEId(IsDWARF64, IsEH)) {
      uint8_t Version = Data.getU8(&Offset);
      const char *Augmentation = Data.getCStr(&Offset);
      StringRef AugmentationString(Augmentation ? Augmentation : "");
+16 −0
Original line number Diff line number Diff line
# RUN: llvm-mc -triple x86_64-unknown-linux %s -filetype=obj -o - | \
# RUN:   llvm-dwarfdump -debug-frame - | \
# RUN:   FileCheck %s

# CHECK: 00000000 {{.*}} FDE

        .section .debug_frame,"",@progbits
## This FDE was formerly wrongly interpreted as a CIE because its CIE pointer
## is similar to DWARF32 CIE id.
        .long 0xffffffff        # DWARF64 mark
        .quad .Lend - .LCIEptr  # Length
.LCIEptr:
        .quad 0xffffffff        # CIE pointer
        .quad 0x1111abcd        # Initial location
        .quad 0x00010000        # Address range
.Lend:
+15 −0
Original line number Diff line number Diff line
# RUN: llvm-mc -triple x86_64-unknown-linux %s -filetype=obj -o - | \
# RUN:   not --crash llvm-dwarfdump -debug-frame - 2>&1 | \
# RUN:   FileCheck %s

# CHECK: Parsing FDE data at 0 failed due to missing CIE

        .section .eh_frame,"a",@unwind
## This FDE was formerly wrongly interpreted as a CIE because its CIE pointer
## is similar to CIE id of a .debug_frame FDE.
        .long .Lend - .LCIEptr  # Length
.LCIEptr:
        .long 0xffffffff        # CIE pointer
        .quad 0x1111abcd        # Initial location
        .quad 0x00010000        # Address range
.Lend: