[lld] 60ab8c8 - [lld][macho] Use reloc length correctly in hash computation (#165287)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 27 14:48:08 PDT 2025
Author: Ellis Hoag
Date: 2025-10-27T14:48:04-07:00
New Revision: 60ab8c89673a84a34e4245c5a590c45e22852f13
URL: https://github.com/llvm/llvm-project/commit/60ab8c89673a84a34e4245c5a590c45e22852f13
DIFF: https://github.com/llvm/llvm-project/commit/60ab8c89673a84a34e4245c5a590c45e22852f13.diff
LOG: [lld][macho] Use reloc length correctly in hash computation (#165287)
`Reloc::length` actually encodes the log2 of the length. Thanks @int3
for pointing this out in
https://github.com/llvm/llvm-project/issues/160894#issuecomment-3416250179.
This code computes hashes of relocations. With the correct length, the
hashes should more accurately represent the relocation. In my testing of
some large binaries, the compressed size change is negligable.
Added:
Modified:
lld/MachO/BPSectionOrderer.cpp
Removed:
################################################################################
diff --git a/lld/MachO/BPSectionOrderer.cpp b/lld/MachO/BPSectionOrderer.cpp
index 1f07ea9caf5df..d50abc22fc6c1 100644
--- a/lld/MachO/BPSectionOrderer.cpp
+++ b/lld/MachO/BPSectionOrderer.cpp
@@ -61,12 +61,13 @@ struct BPOrdererMachO : lld::BPOrderer<BPOrdererMachO> {
// Calculate relocation hashes
for (const auto &r : sec.relocs) {
- if (r.length == 0 || r.referent.isNull() || r.offset >= data.size())
+ uint32_t relocLength = 1 << r.length;
+ if (r.referent.isNull() || r.offset + relocLength > data.size())
continue;
uint64_t relocHash = getRelocHash(r, sectionToIdx);
uint32_t start = (r.offset < windowSize) ? 0 : r.offset - windowSize + 1;
- for (uint32_t i = start; i < r.offset + r.length; i++) {
+ for (uint32_t i = start; i < r.offset + relocLength; i++) {
auto window = data.drop_front(i).take_front(windowSize);
hashes.push_back(xxh3_64bits(window) ^ relocHash);
}
More information about the llvm-commits
mailing list