mirror-llvm-project/llvm/lib/ObjCopy
Daniel Rodríguez Troitiño a891d7b38b
[llvm-objcopy][MachO] Use alignToPowerOf2 instead of alignTo (#204033)
During the review of #203680 I noticed that Mach-O objcopy files seems
to use `alignTo` and import `Alignment.h` to align some offsets to page
boundaries and similar requirements. However, the `alignTo` in
`Alignment.h`, while being intended for powers of 2, requires using an
alignment of type `llvm::Align`, and needs explicit conversion from
`uint64_t` and similar. Single `Alignment.h` includes `MathExtras.h`,
the `alignTo` being invoked ends up being a generic `alignTo` that does
not require powers of 2, and perform divisions and multiplications.
While some of those might be optimized by the compiler into efficient
power of 2 operations, there's an explicit `alignToPowerOf2` version
that is optimized and asserts the alignment is a power of 2 (with
asserts enabled). Since all the alignments should be power of 2 for the
Mach-O binary format, change from `alignTo` to `alignToPowerOf2` to make
the fact more visible (and get the extra safety net of the assertions).

As expected, the test suite of objcopy doesn't show any regressions, but
I have not done a performance benchmark around this either.
2026-06-20 13:08:41 -07:00
..
COFF [llvm] Avoid premature Twine .str() materialization (#204828) 2026-06-19 19:21:53 +02:00
DXContainer [llvm-objcopy][DirectX][NFC] Reuse isProgramPart() in DXContainerObjcopy (#204032) 2026-06-17 19:41:41 +02:00
ELF [llvm] Replace unordered_set<T *> with SmallPtrSet<T *, 0> (#204051) 2026-06-16 04:39:02 +00:00
MachO [llvm-objcopy][MachO] Use alignToPowerOf2 instead of alignTo (#204033) 2026-06-20 13:08:41 -07:00
wasm [objcopy][Wasm] Make strip-all remove all non-engine-interpreted sections (#180246) 2026-02-06 12:39:45 -08:00
XCOFF [llvm] Use "= default" (NFC) (#166088) 2025-11-02 17:16:47 -08:00
Archive.cpp [llvm-objcopy] Add --verbose option to llvm-strip/llvm-objcopy (#196611) 2026-06-03 08:17:25 +00:00
Archive.h
CMakeLists.txt
CommonConfig.cpp
ConfigManager.cpp [ObjCopy] Reject compress-debug-sections for non-ELF (#191314) 2026-04-30 11:22:33 +01:00
ObjCopy.cpp [llvm-objcopy] Add --verbose option to llvm-strip/llvm-objcopy (#196611) 2026-06-03 08:17:25 +00:00