[PATCH] D108897: [lld/mac] Set branchRange a bit more carefully
Nico Weber via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 29 12:26:16 PDT 2021
thakis created this revision.
thakis added a reviewer: lld-macho.
Herald added a reviewer: gkm.
Herald added a project: lld-macho.
thakis requested review of this revision.
- Don't subtract thunkSize from branchRange. Most places care about the actual maximal branch range. Subtract thunkSize in the one place that wants to leave room for a thunk.
- Set it to 0x800_0000 instead of 0xFF_FFFF
- Subtract 4 for the positive branch direction since it's a two's complement 24bit number sign-extended mutiplied by 4, so its range is -0x800_0000..+0x7FF_FFFC
- Make boundary checks include the boundary values
This doesn't make a huge difference in practice. It's preparation
for a "real" fix for PR51578 -- but it also lets the repro in comment 0
in that bug place one more thunk before hitting the TODO.
https://reviews.llvm.org/D108897
Files:
lld/MachO/Arch/ARM64.cpp
lld/MachO/ConcatOutputSection.cpp
Index: lld/MachO/ConcatOutputSection.cpp
===================================================================
--- lld/MachO/ConcatOutputSection.cpp
+++ lld/MachO/ConcatOutputSection.cpp
@@ -225,8 +225,8 @@
assert(isec->isFinal);
uint64_t isecVA = isec->getVA();
// Assign addresses up-to the forward branch-range limit
- while (finalIdx < endIdx &&
- isecAddr + inputs[finalIdx]->getSize() < isecVA + branchRange)
+ while (finalIdx < endIdx && isecAddr + inputs[finalIdx]->getSize() <
+ isecVA + branchRange - thunkSize)
finalizeOne(inputs[finalIdx++]);
if (isec->callSiteCount == 0)
continue;
@@ -255,7 +255,7 @@
// Calculate branch reachability boundaries
uint64_t callVA = isecVA + r.offset;
uint64_t lowVA = branchRange < callVA ? callVA - branchRange : 0;
- uint64_t highVA = callVA + branchRange;
+ uint64_t highVA = callVA + branchRange - 4;
// Calculate our call referent address
auto *funcSym = r.referent.get<Symbol *>();
ThunkInfo &thunkInfo = thunkMap[funcSym];
@@ -267,7 +267,7 @@
}
uint64_t funcVA = funcSym->resolveBranchVA();
++thunkInfo.callSitesUsed;
- if (lowVA < funcVA && funcVA < highVA) {
+ if (lowVA <= funcVA && funcVA <= highVA) {
// The referent is reachable with a simple call instruction.
continue;
}
@@ -276,7 +276,7 @@
// If an existing thunk is reachable, use it ...
if (thunkInfo.sym) {
uint64_t thunkVA = thunkInfo.isec->getVA();
- if (lowVA < thunkVA && thunkVA < highVA) {
+ if (lowVA <= thunkVA && thunkVA <= highVA) {
r.referent = thunkInfo.sym;
continue;
}
Index: lld/MachO/Arch/ARM64.cpp
===================================================================
--- lld/MachO/Arch/ARM64.cpp
+++ lld/MachO/Arch/ARM64.cpp
@@ -134,7 +134,7 @@
stubSize = sizeof(stubCode);
thunkSize = sizeof(thunkCode);
- branchRange = maxIntN(28) - thunkSize;
+ branchRange = 128 * 1024 * 1024;
stubHelperHeaderSize = sizeof(stubHelperHeaderCode);
stubHelperEntrySize = sizeof(stubHelperEntryCode);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108897.369335.patch
Type: text/x-patch
Size: 2193 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210829/8494e802/attachment.bin>
More information about the llvm-commits
mailing list