Replace uintX_t with uint64_t.

We generally want to use uint64_t instead of uintX_t if the 64-bit
type works for both 32-bit and 64-bit because it is simpler than
the variable-size type.

llvm-svn: 300293
This commit is contained in:
Rui Ueyama 2017-04-14 01:34:45 +00:00
parent b4654299f3
commit c49bdd6d5d
3 changed files with 28 additions and 40 deletions

View File

@ -551,7 +551,6 @@ getRelocTargetVA(uint32_t Type, int64_t A, typename ELFT::uint P,
// function as a performance optimization.
template <class ELFT, class RelTy>
void InputSection::relocateNonAlloc(uint8_t *Buf, ArrayRef<RelTy> Rels) {
typedef typename ELFT::uint uintX_t;
for (const RelTy &Rel : Rels) {
uint32_t Type = Rel.getType(Config->IsMips64EL);
uint64_t Offset = getOffset(Rel.r_offset);
@ -569,10 +568,10 @@ void InputSection::relocateNonAlloc(uint8_t *Buf, ArrayRef<RelTy> Rels) {
return;
}
uintX_t AddrLoc = this->OutSec->Addr + Offset;
uint64_t AddrLoc = this->OutSec->Addr + Offset;
uint64_t SymVA = 0;
if (!Sym.isTls() || Out::TlsPhdr)
SymVA = SignExtend64<sizeof(uintX_t) * 8>(
SymVA = SignExtend64<sizeof(typename ELFT::uint) * 8>(
getRelocTargetVA<ELFT>(Type, Addend, AddrLoc, Sym, R_ABS));
Target->relocateOne(BufLoc, Type, SymVA);
}
@ -596,14 +595,13 @@ void InputSectionBase::relocate(uint8_t *Buf, uint8_t *BufEnd) {
return;
}
typedef typename ELFT::uint uintX_t;
const unsigned Bits = sizeof(uintX_t) * 8;
const unsigned Bits = sizeof(typename ELFT::uint) * 8;
for (const Relocation &Rel : Relocations) {
uint64_t Offset = getOffset(Rel.Offset);
uint8_t *BufLoc = Buf + Offset;
uint32_t Type = Rel.Type;
uintX_t AddrLoc = getOutputSection()->Addr + Offset;
uint64_t AddrLoc = getOutputSection()->Addr + Offset;
RelExpr Expr = Rel.Expr;
uint64_t TargetVA = SignExtend64<Bits>(
getRelocTargetVA<ELFT>(Type, Rel.Addend, AddrLoc, *Rel.Sym, Expr));

View File

@ -534,11 +534,11 @@ template <class ELFT> void EhFrameSection<ELFT>::finalizeContents() {
size_t Off = 0;
for (CieRecord *Cie : Cies) {
Cie->Piece->OutputOff = Off;
Off += alignTo(Cie->Piece->size(), sizeof(uintX_t));
Off += alignTo(Cie->Piece->size(), Config->Wordsize);
for (EhSectionPiece *Fde : Cie->FdePieces) {
Fde->OutputOff = Off;
Off += alignTo(Fde->size(), sizeof(uintX_t));
Off += alignTo(Fde->size(), Config->Wordsize);
}
}
this->Size = Off;
@ -564,8 +564,8 @@ template <class ELFT> static uint64_t readFdeAddr(uint8_t *Buf, int Size) {
// Returns the VA to which a given FDE (on a mmap'ed buffer) is applied to.
// We need it to create .eh_frame_hdr section.
template <class ELFT>
typename ELFT::uint EhFrameSection<ELFT>::getFdePc(uint8_t *Buf, size_t FdeOff,
uint8_t Enc) {
uint64_t EhFrameSection<ELFT>::getFdePc(uint8_t *Buf, size_t FdeOff,
uint8_t Enc) {
// The starting address to which this FDE applies is
// stored at FDE + 8 byte.
size_t Off = FdeOff + 8;
@ -603,8 +603,8 @@ template <class ELFT> void EhFrameSection<ELFT>::writeTo(uint8_t *Buf) {
for (CieRecord *Cie : Cies) {
uint8_t Enc = getFdeEncoding<ELFT>(Cie->Piece);
for (SectionPiece *Fde : Cie->FdePieces) {
uintX_t Pc = getFdePc(Buf, Fde->OutputOff, Enc);
uintX_t FdeVA = this->OutSec->Addr + Fde->OutputOff;
uint64_t Pc = getFdePc(Buf, Fde->OutputOff, Enc);
uint64_t FdeVA = this->OutSec->Addr + Fde->OutputOff;
In<ELFT>::EhFrameHdr->addFde(Pc, FdeVA);
}
}
@ -635,25 +635,23 @@ template <class ELFT> bool GotSection<ELFT>::addDynTlsEntry(SymbolBody &Sym) {
template <class ELFT> bool GotSection<ELFT>::addTlsIndex() {
if (TlsIndexOff != uint32_t(-1))
return false;
TlsIndexOff = NumEntries * sizeof(uintX_t);
TlsIndexOff = NumEntries * Config->Wordsize;
NumEntries += 2;
return true;
}
template <class ELFT>
typename GotSection<ELFT>::uintX_t
GotSection<ELFT>::getGlobalDynAddr(const SymbolBody &B) const {
return this->getVA() + B.GlobalDynIndex * sizeof(uintX_t);
uint64_t GotSection<ELFT>::getGlobalDynAddr(const SymbolBody &B) const {
return this->getVA() + B.GlobalDynIndex * Config->Wordsize;
}
template <class ELFT>
typename GotSection<ELFT>::uintX_t
GotSection<ELFT>::getGlobalDynOffset(const SymbolBody &B) const {
return B.GlobalDynIndex * sizeof(uintX_t);
uint64_t GotSection<ELFT>::getGlobalDynOffset(const SymbolBody &B) const {
return B.GlobalDynIndex * Config->Wordsize;
}
template <class ELFT> void GotSection<ELFT>::finalizeContents() {
Size = NumEntries * sizeof(uintX_t);
Size = NumEntries * Config->Wordsize;
}
template <class ELFT> bool GotSection<ELFT>::empty() const {
@ -1004,7 +1002,7 @@ static unsigned getVerDefNum() { return Config->VersionDefinitions.size() + 1; }
template <class ELFT>
DynamicSection<ELFT>::DynamicSection()
: SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_DYNAMIC, sizeof(uintX_t),
: SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_DYNAMIC, Config->Wordsize,
".dynamic") {
this->Entsize = ELFT::Is64Bits ? 16 : 8;
@ -1071,7 +1069,7 @@ template <class ELFT> void DynamicSection<ELFT>::finalizeContents() {
add({IsRela ? DT_RELA : DT_REL, In<ELFT>::RelaDyn});
add({IsRela ? DT_RELASZ : DT_RELSZ, In<ELFT>::RelaDyn->OutSec->Size});
add({IsRela ? DT_RELAENT : DT_RELENT,
uintX_t(IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel))});
uint64_t(IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel))});
// MIPS dynamic loader does not support RELCOUNT tag.
// The problem is in the tight relation between dynamic
@ -1197,7 +1195,7 @@ uint32_t DynamicReloc::getSymIndex() const {
template <class ELFT>
RelocationSection<ELFT>::RelocationSection(StringRef Name, bool Sort)
: SyntheticSection(SHF_ALLOC, Config->IsRela ? SHT_RELA : SHT_REL,
sizeof(uintX_t), Name),
Config->Wordsize, Name),
Sort(Sort) {
this->Entsize = Config->IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
}
@ -1261,9 +1259,9 @@ template <class ELFT> void RelocationSection<ELFT>::finalizeContents() {
template <class ELFT>
SymbolTableSection<ELFT>::SymbolTableSection(StringTableSection &StrTabSec)
: SyntheticSection(StrTabSec.isDynamic() ? (uintX_t)SHF_ALLOC : 0,
: SyntheticSection(StrTabSec.isDynamic() ? (uint64_t)SHF_ALLOC : 0,
StrTabSec.isDynamic() ? SHT_DYNSYM : SHT_SYMTAB,
sizeof(uintX_t),
Config->Wordsize,
StrTabSec.isDynamic() ? ".dynsym" : ".symtab"),
StrTabSec(StrTabSec) {
this->Entsize = sizeof(Elf_Sym);
@ -1910,7 +1908,7 @@ template <class ELFT> void EhFrameHeader<ELFT>::writeTo(uint8_t *Buf) {
write32<E>(Buf + 8, Fdes.size());
Buf += 12;
uintX_t VA = this->getVA();
uint64_t VA = this->getVA();
for (FdeData &Fde : Fdes) {
write32<E>(Buf, Fde.Pc - VA);
write32<E>(Buf + 4, Fde.FdeVA - VA);

View File

@ -63,7 +63,6 @@ struct CieRecord {
// Section for .eh_frame.
template <class ELFT> class EhFrameSection final : public SyntheticSection {
typedef typename ELFT::uint uintX_t;
typedef typename ELFT::Shdr Elf_Shdr;
typedef typename ELFT::Rel Elf_Rel;
typedef typename ELFT::Rela Elf_Rela;
@ -97,7 +96,7 @@ private:
template <class RelTy>
bool isFdeLive(EhSectionPiece &Piece, ArrayRef<RelTy> Rels);
uintX_t getFdePc(uint8_t *Buf, size_t Off, uint8_t Enc);
uint64_t getFdePc(uint8_t *Buf, size_t Off, uint8_t Enc);
std::vector<CieRecord *> Cies;
@ -106,8 +105,6 @@ private:
};
template <class ELFT> class GotSection final : public SyntheticSection {
typedef typename ELFT::uint uintX_t;
public:
GotSection();
void writeTo(uint8_t *Buf) override;
@ -118,10 +115,10 @@ public:
void addEntry(SymbolBody &Sym);
bool addDynTlsEntry(SymbolBody &Sym);
bool addTlsIndex();
uintX_t getGlobalDynAddr(const SymbolBody &B) const;
uintX_t getGlobalDynOffset(const SymbolBody &B) const;
uint64_t getGlobalDynAddr(const SymbolBody &B) const;
uint64_t getGlobalDynOffset(const SymbolBody &B) const;
uintX_t getTlsIndexVA() { return this->getVA() + TlsIndexOff; }
uint64_t getTlsIndexVA() { return this->getVA() + TlsIndexOff; }
uint32_t getTlsIndexOff() const { return TlsIndexOff; }
// Flag to force GOT to be in output if we have relocations
@ -131,7 +128,7 @@ public:
private:
size_t NumEntries = 0;
uint32_t TlsIndexOff = -1;
uintX_t Size = 0;
uint64_t Size = 0;
};
// .note.gnu.build-id section.
@ -341,7 +338,6 @@ template <class ELFT> class DynamicSection final : public SyntheticSection {
typedef typename ELFT::Rela Elf_Rela;
typedef typename ELFT::Shdr Elf_Shdr;
typedef typename ELFT::Sym Elf_Sym;
typedef typename ELFT::uint uintX_t;
// The .dynamic section contains information for the dynamic linker.
// The section consists of fixed size entries, which consist of
@ -377,13 +373,12 @@ public:
private:
void addEntries();
void add(Entry E) { Entries.push_back(E); }
uintX_t Size = 0;
uint64_t Size = 0;
};
template <class ELFT> class RelocationSection final : public SyntheticSection {
typedef typename ELFT::Rel Elf_Rel;
typedef typename ELFT::Rela Elf_Rela;
typedef typename ELFT::uint uintX_t;
public:
RelocationSection(StringRef Name, bool Sort);
@ -409,7 +404,6 @@ struct SymbolTableEntry {
template <class ELFT> class SymbolTableSection final : public SyntheticSection {
public:
typedef typename ELFT::Sym Elf_Sym;
typedef typename ELFT::uint uintX_t;
SymbolTableSection(StringTableSection &StrTabSec);
@ -545,8 +539,6 @@ private:
// http://www.airs.com/blog/archives/460 (".eh_frame")
// http://www.airs.com/blog/archives/462 (".eh_frame_hdr")
template <class ELFT> class EhFrameHeader final : public SyntheticSection {
typedef typename ELFT::uint uintX_t;
public:
EhFrameHeader();
void writeTo(uint8_t *Buf) override;