[lld] dd4a9c4 - [lld-macho][nfc] Convert more alignTo() to alignToPowerOf2()

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 7 16:59:48 PST 2023


Author: Jez Ng
Date: 2023-03-07T16:59:38-08:00
New Revision: dd4a9c463b35e32e2e05e975fc04fa80200d39d5

URL: https://github.com/llvm/llvm-project/commit/dd4a9c463b35e32e2e05e975fc04fa80200d39d5
DIFF: https://github.com/llvm/llvm-project/commit/dd4a9c463b35e32e2e05e975fc04fa80200d39d5.diff

LOG: [lld-macho][nfc] Convert more alignTo() to alignToPowerOf2()

Reviewed By: #lld-macho, smeenai

Differential Revision: https://reviews.llvm.org/D145261

Added: 
    

Modified: 
    lld/MachO/ConcatOutputSection.cpp
    lld/MachO/SyntheticSections.cpp
    lld/MachO/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MachO/ConcatOutputSection.cpp b/lld/MachO/ConcatOutputSection.cpp
index d4f60b6dd718..b68e55b78b07 100644
--- a/lld/MachO/ConcatOutputSection.cpp
+++ b/lld/MachO/ConcatOutputSection.cpp
@@ -126,7 +126,7 @@ bool TextOutputSection::needsThunks() const {
     return false;
   uint64_t isecAddr = addr;
   for (ConcatInputSection *isec : inputs)
-    isecAddr = alignTo(isecAddr, isec->align) + isec->getSize();
+    isecAddr = alignToPowerOf2(isecAddr, isec->align) + isec->getSize();
   if (isecAddr - addr + in.stubs->getSize() <=
       std::min(target->backwardBranchRange, target->forwardBranchRange))
     return false;
@@ -172,7 +172,7 @@ uint64_t TextOutputSection::estimateStubsInRangeVA(size_t callIdx) const {
   uint64_t isecEnd = isecVA;
   for (size_t i = callIdx; i < inputs.size(); i++) {
     InputSection *isec = inputs[i];
-    isecEnd = alignTo(isecEnd, isec->align) + isec->getSize();
+    isecEnd = alignToPowerOf2(isecEnd, isec->align) + isec->getSize();
   }
   // Estimate the address after which call sites can safely call stubs
   // directly rather than through intermediary thunks.
@@ -194,8 +194,8 @@ uint64_t TextOutputSection::estimateStubsInRangeVA(size_t callIdx) const {
 }
 
 void ConcatOutputSection::finalizeOne(ConcatInputSection *isec) {
-  size = alignTo(size, isec->align);
-  fileSize = alignTo(fileSize, isec->align);
+  size = alignToPowerOf2(size, isec->align);
+  fileSize = alignToPowerOf2(fileSize, isec->align);
   isec->outSecOff = size;
   isec->isFinal = true;
   size += isec->getSize();
@@ -248,8 +248,9 @@ void TextOutputSection::finalize() {
     // grows. So leave room for a bunch of thunks.
     unsigned slop = 256 * thunkSize;
     while (finalIdx < endIdx) {
-      uint64_t expectedNewSize = alignTo(addr + size, inputs[finalIdx]->align) +
-                               inputs[finalIdx]->getSize();
+      uint64_t expectedNewSize =
+          alignToPowerOf2(addr + size, inputs[finalIdx]->align) +
+          inputs[finalIdx]->getSize();
       if (expectedNewSize >= isecVA + forwardBranchRange - slop)
         break;
       finalizeOne(inputs[finalIdx++]);

diff  --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
index ca681eb9c90a..95da58ca23c2 100644
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -95,7 +95,7 @@ uint64_t MachHeaderSection::getSize() const {
   // If we are emitting an encryptable binary, our load commands must have a
   // separate (non-encrypted) page to themselves.
   if (config->emitEncryptionInfo)
-    size = alignTo(size, target->getPageSize());
+    size = alignToPowerOf2(size, target->getPageSize());
   return size;
 }
 
@@ -1642,7 +1642,7 @@ void CStringSection::finalizeContents() {
       // handled.
       uint32_t pieceAlign = 1
                             << llvm::countr_zero(isec->align | piece.inSecOff);
-      offset = alignTo(offset, pieceAlign);
+      offset = alignToPowerOf2(offset, pieceAlign);
       piece.outSecOff = offset;
       isec->isFinal = true;
       StringRef string = isec->getStringRef(i);
@@ -1717,7 +1717,8 @@ void DeduplicatedCStringSection::finalizeContents() {
       assert(it != stringOffsetMap.end());
       StringOffset &offsetInfo = it->second;
       if (offsetInfo.outSecOff == UINT64_MAX) {
-        offsetInfo.outSecOff = alignTo(size, 1ULL << offsetInfo.trailingZeros);
+        offsetInfo.outSecOff =
+            alignToPowerOf2(size, 1ULL << offsetInfo.trailingZeros);
         size =
             offsetInfo.outSecOff + s.size() + 1; // account for null terminator
       }

diff  --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
index 28c01d39764a..b090ca2a72b7 100644
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -1077,9 +1077,10 @@ void Writer::finalizeAddresses() {
     seg->addr = addr;
     assignAddresses(seg);
     // codesign / libstuff checks for segment ordering by verifying that
-    // `fileOff + fileSize == next segment fileOff`. So we call alignTo() before
-    // (instead of after) computing fileSize to ensure that the segments are
-    // contiguous. We handle addr / vmSize similarly for the same reason.
+    // `fileOff + fileSize == next segment fileOff`. So we call
+    // alignToPowerOf2() before (instead of after) computing fileSize to ensure
+    // that the segments are contiguous. We handle addr / vmSize similarly for
+    // the same reason.
     fileOff = alignToPowerOf2(fileOff, pageSize);
     addr = alignToPowerOf2(addr, pageSize);
     seg->vmSize = addr - seg->addr;
@@ -1122,8 +1123,8 @@ void Writer::assignAddresses(OutputSegment *seg) {
   for (OutputSection *osec : seg->getSections()) {
     if (!osec->isNeeded())
       continue;
-    addr = alignTo(addr, osec->align);
-    fileOff = alignTo(fileOff, osec->align);
+    addr = alignToPowerOf2(addr, osec->align);
+    fileOff = alignToPowerOf2(fileOff, osec->align);
     osec->addr = addr;
     osec->fileOff = isZeroFill(osec->flags) ? 0 : fileOff;
     osec->finalize();


        


More information about the llvm-commits mailing list