diff --git a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp index 8660c903c617d..535ea7e950c5d 100644 --- a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp @@ -7,9 +7,9 @@ //===----------------------------------------------------------------------===// #include "MachOLayoutBuilder.h" -#include "llvm/Support/Alignment.h" #include "llvm/Support/Errc.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/MathExtras.h" using namespace llvm; using namespace llvm::objcopy::macho; @@ -179,11 +179,11 @@ uint64_t MachOLayoutBuilder::layoutSegments() { if (IsObjectFile) { Offset += SegFileSize; } else { - Offset = alignTo(Offset + SegFileSize, PageSize); - SegFileSize = alignTo(SegFileSize, PageSize); + Offset = alignToPowerOf2(Offset + SegFileSize, PageSize); + SegFileSize = alignToPowerOf2(SegFileSize, PageSize); // Use the original vmsize if the segment is __PAGEZERO. - VMSize = - Segname == "__PAGEZERO" ? SegmentVmSize : alignTo(VMSize, PageSize); + VMSize = Segname == "__PAGEZERO" ? SegmentVmSize + : alignToPowerOf2(VMSize, PageSize); } switch (MLC.load_command_data.cmd) { @@ -289,19 +289,19 @@ Error MachOLayoutBuilder::layoutTail(uint64_t Offset) { uint64_t StartOfCodeSignature = Offset; uint32_t CodeSignatureSize = 0; if (O.CodeSignatureCommandIndex) { - StartOfCodeSignature = alignTo(StartOfCodeSignature, 16); + StartOfCodeSignature = alignToPowerOf2(StartOfCodeSignature, 16); // Note: These calculations are to be kept in sync with the same // calculations performed in LLD's CodeSignatureSection. - const uint32_t AllHeadersSize = - alignTo(CodeSignature.FixedHeadersSize + OutputFileName.size() + 1, - CodeSignature.Align); + const uint32_t AllHeadersSize = alignToPowerOf2( + CodeSignature.FixedHeadersSize + OutputFileName.size() + 1, + CodeSignature.Align); const uint32_t BlockCount = (StartOfCodeSignature + CodeSignature.BlockSize - 1) / CodeSignature.BlockSize; const uint32_t Size = - alignTo(AllHeadersSize + BlockCount * CodeSignature.HashSize, - CodeSignature.Align); + alignToPowerOf2(AllHeadersSize + BlockCount * CodeSignature.HashSize, + CodeSignature.Align); CodeSignature.StartOffset = StartOfCodeSignature; CodeSignature.AllHeadersSize = AllHeadersSize; @@ -321,13 +321,15 @@ Error MachOLayoutBuilder::layoutTail(uint64_t Offset) { case MachO::LC_SEGMENT: MLC->segment_command_data.cmdsize = sizeof(MachO::segment_command); MLC->segment_command_data.fileoff = StartOfLinkEdit; - MLC->segment_command_data.vmsize = alignTo(LinkEditSize, PageSize); + MLC->segment_command_data.vmsize = + alignToPowerOf2(LinkEditSize, PageSize); MLC->segment_command_data.filesize = LinkEditSize; break; case MachO::LC_SEGMENT_64: MLC->segment_command_64_data.cmdsize = sizeof(MachO::segment_command_64); MLC->segment_command_64_data.fileoff = StartOfLinkEdit; - MLC->segment_command_64_data.vmsize = alignTo(LinkEditSize, PageSize); + MLC->segment_command_64_data.vmsize = + alignToPowerOf2(LinkEditSize, PageSize); MLC->segment_command_64_data.filesize = LinkEditSize; break; } diff --git a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.h b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.h index 8d8716df22bba..22ae92249c437 100644 --- a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.h +++ b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.h @@ -33,8 +33,8 @@ struct CodeSignatureInfo { // For each block, a SHA256 hash (256 bits, 32 bytes) is written to // the CodeSignature section. static constexpr size_t HashSize = 256 / 8; - static constexpr size_t BlobHeadersSize = llvm::alignTo<8>( - sizeof(llvm::MachO::CS_SuperBlob) + sizeof(llvm::MachO::CS_BlobIndex)); + static constexpr size_t BlobHeadersSize = llvm::alignToPowerOf2( + sizeof(llvm::MachO::CS_SuperBlob) + sizeof(llvm::MachO::CS_BlobIndex), 8); // The size of the entire header depends upon the filename the binary is being // written to, but the rest of the header is fixed in size. static constexpr uint32_t FixedHeadersSize = diff --git a/llvm/lib/ObjCopy/MachO/MachOObjcopy.cpp b/llvm/lib/ObjCopy/MachO/MachOObjcopy.cpp index e9a371ffa926f..7f862595449b5 100644 --- a/llvm/lib/ObjCopy/MachO/MachOObjcopy.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOObjcopy.cpp @@ -157,7 +157,7 @@ static void updateLoadCommandPayloadString(LoadCommand &LC, StringRef S) { assert(isLoadCommandWithPayloadString(LC) && "unsupported load command encountered"); - uint32_t NewCmdsize = alignTo(sizeof(LCType) + S.size() + 1, 8); + uint32_t NewCmdsize = alignToPowerOf2(sizeof(LCType) + S.size() + 1, 8); LC.MachOLoadCommand.load_command_data.cmdsize = NewCmdsize; LC.Payload.assign(NewCmdsize - sizeof(LCType), 0); @@ -169,7 +169,8 @@ static LoadCommand buildRPathLoadCommand(StringRef Path) { MachO::rpath_command RPathLC; RPathLC.cmd = MachO::LC_RPATH; RPathLC.path = sizeof(MachO::rpath_command); - RPathLC.cmdsize = alignTo(sizeof(MachO::rpath_command) + Path.size() + 1, 8); + RPathLC.cmdsize = + alignToPowerOf2(sizeof(MachO::rpath_command) + Path.size() + 1, 8); LC.MachOLoadCommand.rpath_command_data = RPathLC; LC.Payload.assign(RPathLC.cmdsize - sizeof(MachO::rpath_command), 0); llvm::copy(Path, LC.Payload.begin()); @@ -351,7 +352,7 @@ static Error addSection(const NewSectionInfo &NewSection, Object &Obj) { // There's no segment named TargetSegName. Create a new load command and // Insert a new section into it. LoadCommand &NewSegment = - Obj.addSegment(TargetSegName, alignTo(Sec.Size, 16384)); + Obj.addSegment(TargetSegName, alignToPowerOf2(Sec.Size, 16384)); NewSegment.Sections.push_back(std::make_unique
(Sec)); NewSegment.Sections.back()->Addr = *NewSegment.getSegmentVMAddr(); return Error::success();