forked from OSchip/llvm-project
[llvm-objcopy] Simplify alignToAddr with llvm::alignTo
llvm-svn: 370577
This commit is contained in:
parent
e62c509cd4
commit
b0610c74e7
|
@ -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.
|
// Orders segments such that if x = y->ParentSegment then y comes before x.
|
||||||
static void orderSegments(std::vector<Segment *> &Segments) {
|
static void orderSegments(std::vector<Segment *> &Segments) {
|
||||||
llvm::stable_sort(Segments, compareSegmentsByOffset);
|
llvm::stable_sort(Segments, compareSegmentsByOffset);
|
||||||
|
@ -1903,8 +1890,8 @@ static uint64_t layoutSegments(std::vector<Segment *> &Segments,
|
||||||
Seg->Offset =
|
Seg->Offset =
|
||||||
Parent->Offset + Seg->OriginalOffset - Parent->OriginalOffset;
|
Parent->Offset + Seg->OriginalOffset - Parent->OriginalOffset;
|
||||||
} else {
|
} else {
|
||||||
Offset = alignToAddr(Offset, Seg->VAddr, Seg->Align);
|
Seg->Offset =
|
||||||
Seg->Offset = Offset;
|
alignTo(Offset, std::max<uint64_t>(Seg->Align, 1), Seg->VAddr);
|
||||||
}
|
}
|
||||||
Offset = std::max(Offset, Seg->Offset + Seg->FileSize);
|
Offset = std::max(Offset, Seg->Offset + Seg->FileSize);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue