[lld] r316733 - De-template EhReader. NFC.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 26 20:14:09 PDT 2017


Author: ruiu
Date: Thu Oct 26 20:14:09 2017
New Revision: 316733

URL: http://llvm.org/viewvc/llvm-project?rev=316733&view=rev
Log:
De-template EhReader. NFC.

Modified:
    lld/trunk/ELF/EhFrame.cpp
    lld/trunk/ELF/EhFrame.h
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/SyntheticSections.cpp

Modified: lld/trunk/ELF/EhFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/EhFrame.cpp?rev=316733&r1=316732&r2=316733&view=diff
==============================================================================
--- lld/trunk/ELF/EhFrame.cpp (original)
+++ lld/trunk/ELF/EhFrame.cpp Thu Oct 26 20:14:09 2017
@@ -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<EL
 }
 
 // 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<E
   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
 // 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
   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<E
   }
   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);

Modified: lld/trunk/ELF/EhFrame.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/EhFrame.h?rev=316733&r1=316732&r2=316733&view=diff
==============================================================================
--- lld/trunk/ELF/EhFrame.h (original)
+++ lld/trunk/ELF/EhFrame.h Thu Oct 26 20:14:09 2017
@@ -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
 

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=316733&r1=316732&r2=316733&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Thu Oct 26 20:14:09 2017
@@ -834,7 +834,7 @@ void EhInputSection::split(ArrayRef<RelT
   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)

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=316733&r1=316732&r2=316733&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Thu Oct 26 20:14:09 2017
@@ -551,7 +551,7 @@ std::vector<EhFrameSection::FdeData> EhF
   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;




More information about the llvm-commits mailing list