[lld] r297305 - Use uint32_t for alignment in more places, NFC.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 8 11:35:30 PST 2017


Author: rafael
Date: Wed Mar  8 13:35:29 2017
New Revision: 297305

URL: http://llvm.org/viewvc/llvm-project?rev=297305&view=rev
Log:
Use uint32_t for alignment in more places, NFC.

Modified:
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/InputSection.h
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/OutputSections.h
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/ELF/SymbolTable.h
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/ELF/Symbols.h
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/ELF/SyntheticSections.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=297305&r1=297304&r2=297305&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed Mar  8 13:35:29 2017
@@ -53,7 +53,7 @@ static ArrayRef<uint8_t> getSectionConte
 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(Input
 
   // 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::
                        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::getLocatio
 
 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,

Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=297305&r1=297304&r2=297305&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Wed Mar  8 13:35:29 2017
@@ -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,

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=297305&r1=297304&r2=297305&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Wed Mar  8 13:35:29 2017
@@ -299,7 +299,7 @@ static SectionKey createKey(InputSection
 
   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);

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=297305&r1=297304&r2=297305&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Wed Mar  8 13:35:29 2017
@@ -114,7 +114,7 @@ struct Out {
 struct SectionKey {
   StringRef Name;
   uint64_t Flags;
-  uint64_t Alignment;
+  uint32_t Alignment;
 };
 }
 }

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=297305&r1=297304&r2=297305&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Wed Mar  8 13:35:29 2017
@@ -319,7 +319,7 @@ static int compareDefinedNonCommon(Symbo
 
 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;

Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=297305&r1=297304&r2=297305&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Wed Mar  8 13:35:29 2017
@@ -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);
 

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=297305&r1=297304&r2=297305&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Wed Mar  8 13:35:29 2017
@@ -289,7 +289,7 @@ Undefined::Undefined(StringRefZ Name, bo
   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 N
 // 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 i
 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;

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=297305&r1=297304&r2=297305&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Wed Mar  8 13:35:29 2017
@@ -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;

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=297305&r1=297304&r2=297305&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Wed Mar  8 13:35:29 2017
@@ -2136,7 +2136,7 @@ template <class ELFT> bool VersionNeedSe
 }
 
 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) {}
 

Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=297305&r1=297304&r2=297305&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Wed Mar  8 13:35:29 2017
@@ -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;

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=297305&r1=297304&r2=297305&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Mar  8 13:35:29 2017
@@ -176,7 +176,7 @@ template <class ELFT> static void combin
 
     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>:
     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);
 




More information about the llvm-commits mailing list