De-template EhReader. NFC.

llvm-svn: 316733
This commit is contained in:
Rui Ueyama 2017-10-27 03:14:09 +00:00
parent d6b7a390d8
commit 8629752c04
4 changed files with 17 additions and 28 deletions

View File

@ -17,6 +17,7 @@
//===----------------------------------------------------------------------===//
#include "EhFrame.h"
#include "Config.h"
#include "InputSection.h"
#include "Relocations.h"
#include "Strings.h"
@ -36,7 +37,7 @@ using namespace lld;
using namespace lld::elf;
namespace {
template <class ELFT> class EhReader {
class EhReader {
public:
EhReader(InputSectionBase *S, ArrayRef<uint8_t> D) : IS(S), D(D) {}
size_t readEhRecordSize();
@ -59,22 +60,20 @@ private:
};
}
template <class ELFT>
size_t elf::readEhRecordSize(InputSectionBase *S, size_t Off) {
return EhReader<ELFT>(S, S->Data.slice(Off)).readEhRecordSize();
return EhReader(S, S->Data.slice(Off)).readEhRecordSize();
}
// .eh_frame section is a sequence of records. Each record starts with
// a 4 byte length field. This function reads the length.
template <class ELFT> size_t EhReader<ELFT>::readEhRecordSize() {
const endianness E = ELFT::TargetEndianness;
size_t EhReader::readEhRecordSize() {
if (D.size() < 4)
failOn(D.data(), "CIE/FDE too small");
// First 4 bytes of CIE/FDE is the size of the record.
// If it is 0xFFFFFFFF, the next 8 bytes contain the size instead,
// but we do not support that format yet.
uint64_t V = read32<E>(D.data());
uint64_t V = read32(D.data(), Config->Endianness);
if (V == UINT32_MAX)
failOn(D.data(), "CIE/FDE too large");
uint64_t Size = V + 4;
@ -84,7 +83,7 @@ template <class ELFT> size_t EhReader<ELFT>::readEhRecordSize() {
}
// Read a byte and advance D by one byte.
template <class ELFT> uint8_t EhReader<ELFT>::readByte() {
uint8_t EhReader::readByte() {
if (D.empty())
failOn(D.data(), "unexpected end of CIE");
uint8_t B = D.front();
@ -92,14 +91,14 @@ template <class ELFT> uint8_t EhReader<ELFT>::readByte() {
return B;
}
template <class ELFT> void EhReader<ELFT>::skipBytes(size_t Count) {
void EhReader::skipBytes(size_t Count) {
if (D.size() < Count)
failOn(D.data(), "CIE is too small");
D = D.slice(Count);
}
// Read a null-terminated string.
template <class ELFT> StringRef EhReader<ELFT>::readString() {
StringRef EhReader::readString() {
const uint8_t *End = std::find(D.begin(), D.end(), '\0');
if (End == D.end())
failOn(D.data(), "corrupted CIE (failed to read string)");
@ -112,7 +111,7 @@ template <class ELFT> StringRef EhReader<ELFT>::readString() {
// 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
// the field that follows a LEB128 number.
template <class ELFT> void EhReader<ELFT>::skipLeb128() {
void EhReader::skipLeb128() {
const uint8_t *ErrPos = D.data();
while (!D.empty()) {
uint8_t Val = D.front();
@ -141,7 +140,7 @@ static size_t getAugPSize(unsigned Enc) {
return 0;
}
template <class ELFT> void EhReader<ELFT>::skipAugP() {
void EhReader::skipAugP() {
uint8_t Enc = readByte();
if ((Enc & 0xf0) == DW_EH_PE_aligned)
failOn(D.data() - 1, "DW_EH_PE_aligned encoding is not supported");
@ -153,11 +152,11 @@ template <class ELFT> void EhReader<ELFT>::skipAugP() {
D = D.slice(Size);
}
template <class ELFT> uint8_t elf::getFdeEncoding(EhSectionPiece *P) {
return EhReader<ELFT>(P->Sec, P->data()).getFdeEncoding();
uint8_t elf::getFdeEncoding(EhSectionPiece *P) {
return EhReader(P->Sec, P->data()).getFdeEncoding();
}
template <class ELFT> uint8_t EhReader<ELFT>::getFdeEncoding() {
uint8_t EhReader::getFdeEncoding() {
skipBytes(8);
int Version = readByte();
if (Version != 1 && Version != 3)
@ -199,13 +198,3 @@ template <class ELFT> uint8_t EhReader<ELFT>::getFdeEncoding() {
}
return DW_EH_PE_absptr;
}
template size_t elf::readEhRecordSize<ELF32LE>(InputSectionBase *S, size_t Off);
template size_t elf::readEhRecordSize<ELF32BE>(InputSectionBase *S, size_t Off);
template size_t elf::readEhRecordSize<ELF64LE>(InputSectionBase *S, size_t Off);
template size_t elf::readEhRecordSize<ELF64BE>(InputSectionBase *S, size_t Off);
template uint8_t elf::getFdeEncoding<ELF32LE>(EhSectionPiece *P);
template uint8_t elf::getFdeEncoding<ELF32BE>(EhSectionPiece *P);
template uint8_t elf::getFdeEncoding<ELF64LE>(EhSectionPiece *P);
template uint8_t elf::getFdeEncoding<ELF64BE>(EhSectionPiece *P);

View File

@ -17,8 +17,8 @@ namespace elf {
class InputSectionBase;
struct EhSectionPiece;
template <class ELFT> size_t readEhRecordSize(InputSectionBase *S, size_t Off);
template <class ELFT> uint8_t getFdeEncoding(EhSectionPiece *P);
size_t readEhRecordSize(InputSectionBase *S, size_t Off);
uint8_t getFdeEncoding(EhSectionPiece *P);
} // namespace elf
} // namespace lld

View File

@ -834,7 +834,7 @@ void EhInputSection::split(ArrayRef<RelTy> Rels) {
ArrayRef<uint8_t> Data = this->Data;
unsigned RelI = 0;
for (size_t Off = 0, End = Data.size(); Off != End;) {
size_t Size = readEhRecordSize<ELFT>(this, Off);
size_t Size = readEhRecordSize(this, Off);
this->Pieces.emplace_back(Off, this, Size, getReloc(Off, Size, Rels, RelI));
// The empty record is the end marker.
if (Size == 4)

View File

@ -551,7 +551,7 @@ std::vector<EhFrameSection::FdeData> EhFrameSection::getFdeData() const {
std::vector<FdeData> Ret;
for (CieRecord *Rec : CieRecords) {
uint8_t Enc = getFdeEncoding<ELFT>(Rec->Cie);
uint8_t Enc = getFdeEncoding(Rec->Cie);
for (EhSectionPiece *Fde : Rec->Fdes) {
uint32_t Pc = getFdePc(Buf, Fde->OutputOff, Enc);
uint32_t FdeVA = getParent()->Addr + Fde->OutputOff;