From 42378b22e0fc6e0f9ed0aaf6ee3f913e51de415d Mon Sep 17 00:00:00 2001 From: YongKang Zhu Date: Tue, 4 Nov 2025 13:16:10 -0800 Subject: [PATCH] [BOLT][AArch64] Skip as many as possible zero's in code padding validation We are skipping four zero's as 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 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 (#164037), so this should be safe. --- bolt/lib/Core/BinaryContext.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp index 7af32c8c56635..b478925a4d7b7 100644 --- a/bolt/lib/Core/BinaryContext.cpp +++ b/bolt/lib/Core/BinaryContext.cpp @@ -1010,14 +1010,12 @@ bool BinaryContext::hasValidCodePadding(const BinaryFunction &BF) { return Offset - StartOffset; }; - // Skip a sequence of zero bytes. For AArch64 we only skip 4 bytes of zeros - // in case the following zeros belong to constant island or veneer. + // Skip a sequence of zero bytes. For AArch64 we only skip 4's exact + // multiple number of zeros in case the following zeros belong to veneer. auto skipZeros = [&]() { const uint64_t StartOffset = Offset; uint64_t CurrentOffset = Offset; - for (; CurrentOffset < BF.getMaxSize() && - (!isAArch64() || CurrentOffset < StartOffset + 4); - ++CurrentOffset) + for (; CurrentOffset < BF.getMaxSize(); ++CurrentOffset) if ((*FunctionData)[CurrentOffset] != 0) break;