From c49bdd6d5d026b2c8f4cd63a8c4e5c3491e07d5b Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 14 Apr 2017 01:34:45 +0000 Subject: [PATCH] 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 --- lld/ELF/InputSection.cpp | 10 ++++----- lld/ELF/SyntheticSections.cpp | 38 +++++++++++++++++------------------ lld/ELF/SyntheticSections.h | 20 ++++++------------ 3 files changed, 28 insertions(+), 40 deletions(-) diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 1067a1e5da3a..97ba06a15790 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -551,7 +551,6 @@ getRelocTargetVA(uint32_t Type, int64_t A, typename ELFT::uint P, // function as a performance optimization. template void InputSection::relocateNonAlloc(uint8_t *Buf, ArrayRef 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 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( + SymVA = SignExtend64( getRelocTargetVA(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( getRelocTargetVA(Type, Rel.Addend, AddrLoc, *Rel.Sym, Expr)); diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 4c2b91647e13..7009d3d34f66 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -534,11 +534,11 @@ template void EhFrameSection::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 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 -typename ELFT::uint EhFrameSection::getFdePc(uint8_t *Buf, size_t FdeOff, - uint8_t Enc) { +uint64_t EhFrameSection::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 void EhFrameSection::writeTo(uint8_t *Buf) { for (CieRecord *Cie : Cies) { uint8_t Enc = getFdeEncoding(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::EhFrameHdr->addFde(Pc, FdeVA); } } @@ -635,25 +635,23 @@ template bool GotSection::addDynTlsEntry(SymbolBody &Sym) { template bool GotSection::addTlsIndex() { if (TlsIndexOff != uint32_t(-1)) return false; - TlsIndexOff = NumEntries * sizeof(uintX_t); + TlsIndexOff = NumEntries * Config->Wordsize; NumEntries += 2; return true; } template -typename GotSection::uintX_t -GotSection::getGlobalDynAddr(const SymbolBody &B) const { - return this->getVA() + B.GlobalDynIndex * sizeof(uintX_t); +uint64_t GotSection::getGlobalDynAddr(const SymbolBody &B) const { + return this->getVA() + B.GlobalDynIndex * Config->Wordsize; } template -typename GotSection::uintX_t -GotSection::getGlobalDynOffset(const SymbolBody &B) const { - return B.GlobalDynIndex * sizeof(uintX_t); +uint64_t GotSection::getGlobalDynOffset(const SymbolBody &B) const { + return B.GlobalDynIndex * Config->Wordsize; } template void GotSection::finalizeContents() { - Size = NumEntries * sizeof(uintX_t); + Size = NumEntries * Config->Wordsize; } template bool GotSection::empty() const { @@ -1004,7 +1002,7 @@ static unsigned getVerDefNum() { return Config->VersionDefinitions.size() + 1; } template DynamicSection::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 void DynamicSection::finalizeContents() { add({IsRela ? DT_RELA : DT_REL, In::RelaDyn}); add({IsRela ? DT_RELASZ : DT_RELSZ, In::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 RelocationSection::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 void RelocationSection::finalizeContents() { template SymbolTableSection::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 void EhFrameHeader::writeTo(uint8_t *Buf) { write32(Buf + 8, Fdes.size()); Buf += 12; - uintX_t VA = this->getVA(); + uint64_t VA = this->getVA(); for (FdeData &Fde : Fdes) { write32(Buf, Fde.Pc - VA); write32(Buf + 4, Fde.FdeVA - VA); diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index f87fdf891173..1098c58a3baf 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -63,7 +63,6 @@ struct CieRecord { // Section for .eh_frame. template 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 bool isFdeLive(EhSectionPiece &Piece, ArrayRef 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 Cies; @@ -106,8 +105,6 @@ private: }; template 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 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 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 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 EhFrameHeader final : public SyntheticSection { - typedef typename ELFT::uint uintX_t; - public: EhFrameHeader(); void writeTo(uint8_t *Buf) override;