ELF: Make EHOutputSection::readEntryLength a non-member function.

This function did not use any fields of the class.

llvm-svn: 259946
This commit is contained in:
Rui Ueyama 2016-02-05 22:56:03 +00:00
parent 95708931cf
commit c0c92609c4
2 changed files with 26 additions and 28 deletions

View File

@ -963,6 +963,31 @@ uint8_t EHOutputSection<ELFT>::getFdeEncoding(ArrayRef<uint8_t> D) {
return dwarf::DW_EH_PE_absptr;
}
template <class ELFT>
static typename ELFFile<ELFT>::uintX_t readEntryLength(ArrayRef<uint8_t> D) {
const endianness E = ELFT::TargetEndianness;
if (D.size() < 4)
fatal("Truncated CIE/FDE length");
uint64_t Len = read32<E>(D.data());
if (Len < UINT32_MAX) {
if (Len > (UINT32_MAX - 4))
fatal("CIE/FIE size is too large");
if (Len + 4 > D.size())
fatal("CIE/FIE ends past the end of the section");
return Len + 4;
}
if (D.size() < 12)
fatal("Truncated CIE/FDE length");
Len = read64<E>(D.data() + 4);
if (Len > (UINT64_MAX - 12))
fatal("CIE/FIE size is too large");
if (Len + 12 > D.size())
fatal("CIE/FIE ends past the end of the section");
return Len + 12;
}
template <class ELFT>
template <bool IsRela>
void EHOutputSection<ELFT>::addSectionAux(
@ -985,7 +1010,7 @@ void EHOutputSection<ELFT>::addSectionAux(
unsigned Index = S->Offsets.size();
S->Offsets.push_back(std::make_pair(Offset, -1));
uintX_t Length = readEntryLength(D);
uintX_t Length = readEntryLength<ELFT>(D);
// If CIE/FDE data length is zero then Length is 4, this
// shall be considered a terminator and processing shall end.
if (Length == 4)
@ -1038,32 +1063,6 @@ void EHOutputSection<ELFT>::addSectionAux(
}
}
template <class ELFT>
typename EHOutputSection<ELFT>::uintX_t
EHOutputSection<ELFT>::readEntryLength(ArrayRef<uint8_t> D) {
const endianness E = ELFT::TargetEndianness;
if (D.size() < 4)
fatal("Truncated CIE/FDE length");
uint64_t Len = read32<E>(D.data());
if (Len < UINT32_MAX) {
if (Len > (UINT32_MAX - 4))
fatal("CIE/FIE size is too large");
if (Len + 4 > D.size())
fatal("CIE/FIE ends past the end of the section");
return Len + 4;
}
if (D.size() < 12)
fatal("Truncated CIE/FDE length");
Len = read64<E>(D.data() + 4);
if (Len > (UINT64_MAX - 12))
fatal("CIE/FIE size is too large");
if (Len + 12 > D.size())
fatal("CIE/FIE ends past the end of the section");
return Len + 12;
}
template <class ELFT>
void EHOutputSection<ELFT>::addSection(InputSectionBase<ELFT> *C) {
auto *S = cast<EHInputSection<ELFT>>(C);

View File

@ -337,7 +337,6 @@ public:
private:
uint8_t getFdeEncoding(ArrayRef<uint8_t> D);
uintX_t readEntryLength(ArrayRef<uint8_t> D);
std::vector<EHInputSection<ELFT> *> Sections;
std::vector<Cie<ELFT>> Cies;