[PATCH] D61171: [ELF] Change std::max<uint64_t> to uint32_t for section alignment

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 25 20:25:53 PDT 2019


MaskRay created this revision.
MaskRay added a reviewer: ruiu.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

We use `uint32_t SectionBase::Alignment` and `uint32_t
PhdrEntry::p_align` despite alignments being 64 bits in ELF64.
Fix the std::max template arguments accordingly.

The currently 160-byte InputSection will become 168 bytes if we make SectionBase::Alignment uint64_t.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D61171

Files:
  ELF/InputSection.cpp


Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -75,7 +75,7 @@
 
   // The ELF spec states that a value of 0 means the section has
   // no alignment constraits.
-  uint32_t V = std::max<uint64_t>(Alignment, 1);
+  uint32_t V = std::max<uint32_t>(Alignment, 1);
   if (!isPowerOf2_64(V))
     fatal(toString(this) + ": sh_addralign is not a power of 2");
   this->Alignment = V;
@@ -253,7 +253,7 @@
     }
 
     UncompressedSize = Hdr->ch_size;
-    Alignment = std::max<uint64_t>(Hdr->ch_addralign, 1);
+    Alignment = std::max<uint32_t>(Hdr->ch_addralign, 1);
     RawData = RawData.slice(sizeof(*Hdr));
     return;
   }
@@ -271,7 +271,7 @@
   }
 
   UncompressedSize = Hdr->ch_size;
-  Alignment = std::max<uint64_t>(Hdr->ch_addralign, 1);
+  Alignment = std::max<uint32_t>(Hdr->ch_addralign, 1);
   RawData = RawData.slice(sizeof(*Hdr));
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61171.196790.patch
Type: text/x-patch
Size: 951 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190426/41fae240/attachment.bin>


More information about the llvm-commits mailing list