[lld] r287452 - Split getFdeEncoding.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 19 10:44:09 PST 2016
Author: ruiu
Date: Sat Nov 19 12:44:09 2016
New Revision: 287452
URL: http://llvm.org/viewvc/llvm-project?rev=287452&view=rev
Log:
Split getFdeEncoding.
Modified:
lld/trunk/ELF/EhFrame.cpp
Modified: lld/trunk/ELF/EhFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/EhFrame.cpp?rev=287452&r1=287451&r2=287452&view=diff
==============================================================================
--- lld/trunk/ELF/EhFrame.cpp (original)
+++ lld/trunk/ELF/EhFrame.cpp Sat Nov 19 12:44:09 2016
@@ -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<uint8_t
return B;
}
+// Read a null-terminated string.
+static StringRef readString(ArrayRef<uint8_t> &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 <class ELFT> uint8_t getFdeEnco
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<const char *>(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
More information about the llvm-commits
mailing list