From 98bdbdaedd839e5f1eaba085132118daed3a19a0 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sat, 19 Nov 2016 18:44:09 +0000 Subject: [PATCH] Split getFdeEncoding. llvm-svn: 287452 --- lld/ELF/EhFrame.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lld/ELF/EhFrame.cpp b/lld/ELF/EhFrame.cpp index c1e7b2d..29d4cb4 100644 --- a/lld/ELF/EhFrame.cpp +++ b/lld/ELF/EhFrame.cpp @@ -18,6 +18,7 @@ #include "EhFrame.h" #include "Error.h" +#include "Strings.h" #include "llvm/Object/ELF.h" #include "llvm/Support/Dwarf.h" @@ -60,6 +61,16 @@ static uint8_t readByte(ArrayRef &D) { return B; } +// Read a null-terminated string. +static StringRef readString(ArrayRef &D) { + const uint8_t *End = std::find(D.begin(), D.end(), '\0'); + if (End == D.end()) + fatal("corrupted CIE"); + StringRef S = toStringRef(D.slice(0, End - D.begin())); + D = D.slice(S.size() + 1); + return S; +} + // Skip an integer encoded in the LEB128 format. // Actual number is not of interest because only the runtime needs it. // But we need to be at least able to skip it so that we can read @@ -107,20 +118,14 @@ template uint8_t getFdeEncoding(ArrayRef D) { fatal("CIE too small"); D = D.slice(8); - uint8_t Version = readByte(D); + int Version = readByte(D); if (Version != 1 && Version != 3) - fatal("FDE version 1 or 3 expected, but got " + Twine((unsigned)Version)); + fatal("FDE version 1 or 3 expected, but got " + Twine(Version)); - const unsigned char *AugEnd = std::find(D.begin(), D.end(), '\0'); - if (AugEnd == D.end()) - fatal("corrupted CIE"); - StringRef Aug(reinterpret_cast(D.begin()), AugEnd - D.begin()); - D = D.slice(Aug.size() + 1); + StringRef Aug = readString(D); - // Skip code alignment factor. + // Skip code and data alignment factors. skipLeb128(D); - - // Skip data alignment factor. skipLeb128(D); // Skip the return address register. In CIE version 1 this is a single -- 2.7.4