Use uint32_t for alignment in more places, NFC.

llvm-svn: 297305
This commit is contained in:
Rafael Espindola 2017-03-08 19:35:29 +00:00
parent 7596bd7a27
commit fcd208fdb3
11 changed files with 30 additions and 31 deletions

View File

@ -53,7 +53,7 @@ static ArrayRef<uint8_t> getSectionContents(elf::ObjectFile<ELFT> *File,
InputSectionBase::InputSectionBase(InputFile *File, uint64_t Flags,
uint32_t Type, uint64_t Entsize,
uint32_t Link, uint32_t Info,
uint64_t Alignment, ArrayRef<uint8_t> Data,
uint32_t Alignment, ArrayRef<uint8_t> 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<uint64_t>(Alignment, 1);
uint32_t V = std::max<uint64_t>(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<ELFT> *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<uint8_t> Data, StringRef Name, Kind K)
: InputSectionBase(nullptr, Flags, Type,
/*Entsize*/ 0, /*Link*/ 0, /*Info*/ 0, Alignment, Data,

View File

@ -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<uint8_t> Data, StringRef Name,
uint32_t Alignment, ArrayRef<uint8_t> 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<uint8_t> Data, StringRef Name, Kind K = Regular);
template <class ELFT>
InputSection(ObjectFile<ELFT> *F, const typename ELFT::Shdr *Header,

View File

@ -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<uintX_t>(C->Alignment, C->Entsize);

View File

@ -114,7 +114,7 @@ struct Out {
struct SectionKey {
StringRef Name;
uint64_t Flags;
uint64_t Alignment;
uint32_t Alignment;
};
}
}

View File

@ -319,7 +319,7 @@ static int compareDefinedNonCommon(Symbol *S, bool WasInserted, uint8_t Binding,
template <class ELFT>
Symbol *SymbolTable<ELFT>::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;

View File

@ -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);

View File

@ -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 <class ELFT> uint64_t SharedSymbol::getAlignment() const {
template <class ELFT> uint32_t SharedSymbol::getAlignment() const {
auto *File = cast<SharedFile<ELFT>>(this->File);
uint64_t SecAlign = File->getSection(getSym<ELFT>())->sh_addralign;
uint32_t SecAlign = File->getSection(getSym<ELFT>())->sh_addralign;
uint64_t SymValue = getSym<ELFT>().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<ELF32BE>() const;
template bool DefinedRegular::template isMipsPIC<ELF64LE>() const;
template bool DefinedRegular::template isMipsPIC<ELF64BE>() const;
template uint64_t SharedSymbol::template getAlignment<ELF32LE>() const;
template uint64_t SharedSymbol::template getAlignment<ELF32BE>() const;
template uint64_t SharedSymbol::template getAlignment<ELF64LE>() const;
template uint64_t SharedSymbol::template getAlignment<ELF64BE>() const;
template uint32_t SharedSymbol::template getAlignment<ELF32LE>() const;
template uint32_t SharedSymbol::template getAlignment<ELF32BE>() const;
template uint32_t SharedSymbol::template getAlignment<ELF64LE>() const;
template uint32_t SharedSymbol::template getAlignment<ELF64BE>() const;

View File

@ -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<ELFT>().st_size;
}
template <class ELFT> uint64_t getAlignment() const;
template <class ELFT> uint32_t getAlignment() const;
// This field is a pointer to the symbol's version definition.
const void *Verdef;

View File

@ -2136,7 +2136,7 @@ template <class ELFT> bool VersionNeedSection<ELFT>::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) {}

View File

@ -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;

View File

@ -176,7 +176,7 @@ template <class ELFT> static void combineMergableSections() {
StringRef OutsecName = getOutputSectionName(MS->Name);
uintX_t Flags = getOutFlags<ELFT>(MS);
uintX_t Alignment = std::max<uintX_t>(MS->Alignment, MS->Entsize);
uint32_t Alignment = std::max<uintX_t>(MS->Alignment, MS->Entsize);
auto I =
llvm::find_if(MergeSections, [=](MergeSyntheticSection *Sec) {
@ -1477,7 +1477,7 @@ template <class ELFT> void Writer<ELFT>::assignAddresses() {
VA += getHeaderSize<ELFT>();
uintX_t ThreadBssOffset = 0;
for (OutputSection *Sec : OutputSections) {
uintX_t Alignment = Sec->Alignment;
uint32_t Alignment = Sec->Alignment;
if (Sec->PageAlign)
Alignment = std::max<uintX_t>(Alignment, Config->MaxPageSize);