[llvm] r370577 - [llvm-objcopy] Simplify alignToAddr with llvm::alignTo
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 31 03:48:10 PDT 2019
Author: maskray
Date: Sat Aug 31 03:48:09 2019
New Revision: 370577
URL: http://llvm.org/viewvc/llvm-project?rev=370577&view=rev
Log:
[llvm-objcopy] Simplify alignToAddr with llvm::alignTo
Modified:
llvm/trunk/tools/llvm-objcopy/ELF/Object.cpp
Modified: llvm/trunk/tools/llvm-objcopy/ELF/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/ELF/Object.cpp?rev=370577&r1=370576&r2=370577&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/ELF/Object.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/ELF/Object.cpp Sat Aug 31 03:48:09 2019
@@ -1863,19 +1863,6 @@ void Object::sortSections() {
});
}
-static uint64_t alignToAddr(uint64_t Offset, uint64_t Addr, uint64_t Align) {
- // Calculate Diff such that (Offset + Diff) & -Align == Addr & -Align.
- if (Align == 0)
- Align = 1;
- auto Diff =
- static_cast<int64_t>(Addr % Align) - static_cast<int64_t>(Offset % Align);
- // We only want to add to Offset, however, so if Diff < 0 we can add Align and
- // (Offset + Diff) & -Align == Addr & -Align will still hold.
- if (Diff < 0)
- Diff += Align;
- return Offset + Diff;
-}
-
// Orders segments such that if x = y->ParentSegment then y comes before x.
static void orderSegments(std::vector<Segment *> &Segments) {
llvm::stable_sort(Segments, compareSegmentsByOffset);
@@ -1903,8 +1890,8 @@ static uint64_t layoutSegments(std::vect
Seg->Offset =
Parent->Offset + Seg->OriginalOffset - Parent->OriginalOffset;
} else {
- Offset = alignToAddr(Offset, Seg->VAddr, Seg->Align);
- Seg->Offset = Offset;
+ Seg->Offset =
+ alignTo(Offset, std::max<uint64_t>(Seg->Align, 1), Seg->VAddr);
}
Offset = std::max(Offset, Seg->Offset + Seg->FileSize);
}
More information about the llvm-commits
mailing list