From fcd208fdb3309a8d8637e7017415581f3eb62e18 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 8 Mar 2017 19:35:29 +0000 Subject: [PATCH] Use uint32_t for alignment in more places, NFC. llvm-svn: 297305 --- lld/ELF/InputSection.cpp | 17 ++++++++--------- lld/ELF/InputSection.h | 4 ++-- lld/ELF/OutputSections.cpp | 2 +- lld/ELF/OutputSections.h | 2 +- lld/ELF/SymbolTable.cpp | 2 +- lld/ELF/SymbolTable.h | 2 +- lld/ELF/Symbols.cpp | 16 ++++++++-------- lld/ELF/Symbols.h | 6 +++--- lld/ELF/SyntheticSections.cpp | 2 +- lld/ELF/SyntheticSections.h | 4 ++-- lld/ELF/Writer.cpp | 4 ++-- 11 files changed, 30 insertions(+), 31 deletions(-) diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 99d4db351f4e..a620d023e4c6 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -53,7 +53,7 @@ static ArrayRef getSectionContents(elf::ObjectFile *File, InputSectionBase::InputSectionBase(InputFile *File, uint64_t Flags, uint32_t Type, uint64_t Entsize, uint32_t Link, uint32_t Info, - uint64_t Alignment, ArrayRef Data, + uint32_t Alignment, ArrayRef Data, StringRef Name, Kind SectionKind) : File(File), Data(Data), Name(Name), SectionKind(SectionKind), Live(!Config->GcSections || !(Flags & SHF_ALLOC)), Assigned(false), @@ -64,15 +64,9 @@ InputSectionBase::InputSectionBase(InputFile *File, uint64_t Flags, // The ELF spec states that a value of 0 means the section has // no alignment constraits. - uint64_t V = std::max(Alignment, 1); + uint32_t V = std::max(Alignment, 1); if (!isPowerOf2_64(V)) fatal(toString(File) + ": section sh_addralign is not a power of 2"); - - // We reject object files having insanely large alignments even though - // they are allowed by the spec. I think 4GB is a reasonable limitation. - // We might want to relax this in the future. - if (V > UINT32_MAX) - fatal(toString(File) + ": section sh_addralign is too large"); this->Alignment = V; } @@ -84,6 +78,11 @@ InputSectionBase::InputSectionBase(elf::ObjectFile *File, Hdr->sh_entsize, Hdr->sh_link, Hdr->sh_info, Hdr->sh_addralign, getSectionContents(File, Hdr), Name, SectionKind) { + // We reject object files having insanely large alignments even though + // they are allowed by the spec. I think 4GB is a reasonable limitation. + // We might want to relax this in the future. + if (Hdr->sh_addralign > UINT32_MAX) + fatal(toString(File) + ": section sh_addralign is too large"); } size_t InputSectionBase::getSize() const { @@ -189,7 +188,7 @@ std::string InputSectionBase::getLocation(uint64_t Offset) { InputSectionBase InputSectionBase::Discarded; -InputSection::InputSection(uint64_t Flags, uint32_t Type, uint64_t Alignment, +InputSection::InputSection(uint64_t Flags, uint32_t Type, uint32_t Alignment, ArrayRef Data, StringRef Name, Kind K) : InputSectionBase(nullptr, Flags, Type, /*Entsize*/ 0, /*Link*/ 0, /*Info*/ 0, Alignment, Data, diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index b22e21469cd1..b243d9120824 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -79,7 +79,7 @@ public: InputSectionBase(InputFile *File, uint64_t Flags, uint32_t Type, uint64_t Entsize, uint32_t Link, uint32_t Info, - uint64_t Alignment, ArrayRef Data, StringRef Name, + uint32_t Alignment, ArrayRef Data, StringRef Name, Kind SectionKind); OutputSection *OutSec = nullptr; @@ -253,7 +253,7 @@ public: // .eh_frame. It also includes the synthetic sections themselves. class InputSection : public InputSectionBase { public: - InputSection(uint64_t Flags, uint32_t Type, uint64_t Alignment, + InputSection(uint64_t Flags, uint32_t Type, uint32_t Alignment, ArrayRef Data, StringRef Name, Kind K = Regular); template InputSection(ObjectFile *F, const typename ELFT::Shdr *Header, diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 2efb47b9fc86..544a6d087984 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -299,7 +299,7 @@ static SectionKey createKey(InputSectionBase *C, StringRef OutsecName) { typedef typename ELFT::uint uintX_t; - uintX_t Alignment = 0; + uint32_t Alignment = 0; uintX_t Flags = 0; if (Config->Relocatable && (C->Flags & SHF_MERGE)) { Alignment = std::max(C->Alignment, C->Entsize); diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index 660096fde015..63c8dce72ab0 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -114,7 +114,7 @@ struct Out { struct SectionKey { StringRef Name; uint64_t Flags; - uint64_t Alignment; + uint32_t Alignment; }; } } diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index 42ba18a39acc..9105253b8979 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -319,7 +319,7 @@ static int compareDefinedNonCommon(Symbol *S, bool WasInserted, uint8_t Binding, template Symbol *SymbolTable::addCommon(StringRef N, uint64_t Size, - uint64_t Alignment, uint8_t Binding, + uint32_t Alignment, uint8_t Binding, uint8_t StOther, uint8_t Type, InputFile *File) { Symbol *S; diff --git a/lld/ELF/SymbolTable.h b/lld/ELF/SymbolTable.h index aefa30d76d3a..f6a2b1151f6b 100644 --- a/lld/ELF/SymbolTable.h +++ b/lld/ELF/SymbolTable.h @@ -71,7 +71,7 @@ public: Symbol *addBitcode(StringRef Name, uint8_t Binding, uint8_t StOther, uint8_t Type, bool CanOmitFromDynSym, BitcodeFile *File); - Symbol *addCommon(StringRef N, uint64_t Size, uint64_t Alignment, + Symbol *addCommon(StringRef N, uint64_t Size, uint32_t Alignment, uint8_t Binding, uint8_t StOther, uint8_t Type, InputFile *File); diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index 9eb222362bbc..178c5e85b62b 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -289,7 +289,7 @@ Undefined::Undefined(StringRefZ Name, bool IsLocal, uint8_t StOther, this->File = File; } -DefinedCommon::DefinedCommon(StringRef Name, uint64_t Size, uint64_t Alignment, +DefinedCommon::DefinedCommon(StringRef Name, uint64_t Size, uint32_t Alignment, uint8_t StOther, uint8_t Type, InputFile *File) : Defined(SymbolBody::DefinedCommonKind, Name, /*IsLocal=*/false, StOther, Type), @@ -300,11 +300,11 @@ DefinedCommon::DefinedCommon(StringRef Name, uint64_t Size, uint64_t Alignment, // If a shared symbol is referred via a copy relocation, its alignment // becomes part of the ABI. This function returns a symbol alignment. // Because symbols don't have alignment attributes, we need to infer that. -template uint64_t SharedSymbol::getAlignment() const { +template uint32_t SharedSymbol::getAlignment() const { auto *File = cast>(this->File); - uint64_t SecAlign = File->getSection(getSym())->sh_addralign; + uint32_t SecAlign = File->getSection(getSym())->sh_addralign; uint64_t SymValue = getSym().st_value; - uint64_t SymAlign = uint64_t(1) << countTrailingZeros(SymValue); + uint32_t SymAlign = uint32_t(1) << countTrailingZeros(SymValue); return std::min(SecAlign, SymAlign); } @@ -433,7 +433,7 @@ template bool DefinedRegular::template isMipsPIC() const; template bool DefinedRegular::template isMipsPIC() const; template bool DefinedRegular::template isMipsPIC() const; -template uint64_t SharedSymbol::template getAlignment() const; -template uint64_t SharedSymbol::template getAlignment() const; -template uint64_t SharedSymbol::template getAlignment() const; -template uint64_t SharedSymbol::template getAlignment() const; +template uint32_t SharedSymbol::template getAlignment() const; +template uint32_t SharedSymbol::template getAlignment() const; +template uint32_t SharedSymbol::template getAlignment() const; +template uint32_t SharedSymbol::template getAlignment() const; diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h index 696a30cb3904..79bce2dd4560 100644 --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -156,7 +156,7 @@ public: class DefinedCommon : public Defined { public: - DefinedCommon(StringRef N, uint64_t Size, uint64_t Alignment, uint8_t StOther, + DefinedCommon(StringRef N, uint64_t Size, uint32_t Alignment, uint8_t StOther, uint8_t Type, InputFile *File); static bool classof(const SymbolBody *S) { @@ -168,7 +168,7 @@ public: uint64_t Offset; // The maximum alignment we have seen for this symbol. - uint64_t Alignment; + uint32_t Alignment; uint64_t Size; }; @@ -265,7 +265,7 @@ public: return getSym().st_size; } - template uint64_t getAlignment() const; + template uint32_t getAlignment() const; // This field is a pointer to the symbol's version definition. const void *Verdef; diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index d00bba1c2665..756499549808 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -2136,7 +2136,7 @@ template bool VersionNeedSection::empty() const { } MergeSyntheticSection::MergeSyntheticSection(StringRef Name, uint32_t Type, - uint64_t Flags, uint64_t Alignment) + uint64_t Flags, uint32_t Alignment) : SyntheticSection(Flags, Type, Alignment, Name), Builder(StringTableBuilder::RAW, Alignment) {} diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index b54e70478e4b..504516288893 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -32,7 +32,7 @@ namespace elf { class SyntheticSection : public InputSection { public: - SyntheticSection(uint64_t Flags, uint32_t Type, uint64_t Alignment, + SyntheticSection(uint64_t Flags, uint32_t Type, uint32_t Alignment, StringRef Name) : InputSection(Flags, Type, Alignment, {}, Name, InputSectionBase::Synthetic) { @@ -646,7 +646,7 @@ public: class MergeSyntheticSection final : public SyntheticSection { public: MergeSyntheticSection(StringRef Name, uint32_t Type, uint64_t Flags, - uint64_t Alignment); + uint32_t Alignment); void addSection(MergeInputSection *MS); void writeTo(uint8_t *Buf) override; void finalizeContents() override; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index ee225416a495..bcd6a0d434f6 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -176,7 +176,7 @@ template static void combineMergableSections() { StringRef OutsecName = getOutputSectionName(MS->Name); uintX_t Flags = getOutFlags(MS); - uintX_t Alignment = std::max(MS->Alignment, MS->Entsize); + uint32_t Alignment = std::max(MS->Alignment, MS->Entsize); auto I = llvm::find_if(MergeSections, [=](MergeSyntheticSection *Sec) { @@ -1477,7 +1477,7 @@ template void Writer::assignAddresses() { VA += getHeaderSize(); uintX_t ThreadBssOffset = 0; for (OutputSection *Sec : OutputSections) { - uintX_t Alignment = Sec->Alignment; + uint32_t Alignment = Sec->Alignment; if (Sec->PageAlign) Alignment = std::max(Alignment, Config->MaxPageSize);