Skip to content

Commit 6fce53a

Browse files
authored
[BOLT][AArch64] Skip as many zeros as possible in padding validation (llvm#166467)
We are skipping four zero's at a time when validating code padding in case that the next zero would be part of an instruction or constant island, and for functions that have large amount of padding (like due to hugify), this could be very slow. We now change the validation to skip as many as possible but still need to be 4's exact multiple number of zero's. No valid instruction has encoding as 0x00000000 and even if we stumble into some constant island, the API `BinaryFunction::isInConstantIsland()` has been made to find the size between the asked address and the end of island (llvm#164037), so this should be safe.
1 parent 3be8250 commit 6fce53a

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

bolt/lib/Core/BinaryContext.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,14 +1010,12 @@ bool BinaryContext::hasValidCodePadding(const BinaryFunction &BF) {
10101010
return Offset - StartOffset;
10111011
};
10121012

1013-
// Skip a sequence of zero bytes. For AArch64 we only skip 4 bytes of zeros
1014-
// in case the following zeros belong to constant island or veneer.
1013+
// Skip a sequence of zero bytes. For AArch64 we only skip 4's exact
1014+
// multiple number of zeros in case the following zeros belong to veneer.
10151015
auto skipZeros = [&]() {
10161016
const uint64_t StartOffset = Offset;
10171017
uint64_t CurrentOffset = Offset;
1018-
for (; CurrentOffset < BF.getMaxSize() &&
1019-
(!isAArch64() || CurrentOffset < StartOffset + 4);
1020-
++CurrentOffset)
1018+
for (; CurrentOffset < BF.getMaxSize(); ++CurrentOffset)
10211019
if ((*FunctionData)[CurrentOffset] != 0)
10221020
break;
10231021

0 commit comments

Comments
 (0)