Index: ELF/OutputSections.cpp =================================================================== --- ELF/OutputSections.cpp +++ ELF/OutputSections.cpp @@ -903,12 +903,8 @@ template uint8_t EHOutputSection::getFdeEncoding(ArrayRef D) { - auto Check = [](bool C) { - if (!C) - fatal("corrupted or unsupported CIE information"); - }; - - Check(D.size() >= 8); + if (D.size() < 8) + fatal("CIE too small"); D = D.slice(8); uint8_t Version = readByte(D); @@ -916,9 +912,10 @@ fatal("FDE version 1 or 3 expected, but got " + Twine((unsigned)Version)); auto AugEnd = std::find(D.begin() + 1, D.end(), '\0'); - Check(AugEnd != D.end()); - ArrayRef AugString(D.begin(), AugEnd - D.begin()); - D = D.slice(AugString.size() + 1); + if (AugEnd == D.end()) + fatal("corrupted CIE"); + StringRef Aug((char *)D.begin(), AugEnd - D.begin()); + D = D.slice(Aug.size() + 1); // Code alignment factor should always be 1 for .eh_frame. if (readByte(D) != 1) @@ -933,34 +930,13 @@ else skipLeb128(D); - while (!AugString.empty()) { - switch (readByte(AugString)) { - case 'z': - skipLeb128(D); - break; - case 'R': - return readByte(D); - case 'P': { - uint8_t Enc = readByte(D); - if ((Enc & 0xf0) == dwarf::DW_EH_PE_aligned) - fatal("DW_EH_PE_aligned encoding for address of a personality routine " - "handler not supported"); - unsigned EncSize = getSizeForEncoding(Enc); - Check(D.size() >= EncSize); - D = D.slice(EncSize); - break; - } - case 'S': - case 'L': - // L: Language Specific Data Area (LSDA) encoding - // S: This CIE represents a stack frame for the invocation of a signal - // handler - break; - default: - fatal("unknown .eh_frame augmentation string value"); - } - } - return dwarf::DW_EH_PE_absptr; + // We assume that the augmentation string always starts with 'z' + // (which specifies the size of the CIE field) and 'R' (which + // specifies the FDE encoding.) + if (!Aug.startswith("zR")) + fatal("unknown .eh_frame augmentation string: " + Aug); + skipLeb128(D); + return readByte(D); } template