Skip to content

Conversation

@yozhu
Copy link
Contributor

@yozhu yozhu commented Nov 4, 2025

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 (#164037), so this should be safe.

…ation

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 (llvm#164037), so this should
be safe.
@llvmbot
Copy link
Member

llvmbot commented Nov 4, 2025

@llvm/pr-subscribers-bolt

Author: YongKang Zhu (yozhu)

Changes

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 (#164037), so this should be safe.


Full diff: https://github.com/llvm/llvm-project/pull/166467.diff

1 Files Affected:

  • (modified) bolt/lib/Core/BinaryContext.cpp (+3-5)
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;
 

Copy link
Contributor

@aaupov aaupov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please retitle as "[BOLT][AArch64] Skip as many zeros as possible in padding validation".
Approving but please let ARM folks weigh in.

@yozhu yozhu changed the title [BOLT][AArch64] Skip as many as possible zero's in padding validation [BOLT][AArch64] Skip as many zeros as possible in padding validation Nov 4, 2025
@yozhu yozhu merged commit 6fce53a into llvm:main Nov 6, 2025
12 checks passed
@yozhu yozhu deleted the fixhang branch November 8, 2025 02:58
vinay-deshmukh pushed a commit to vinay-deshmukh/llvm-project that referenced this pull request Nov 8, 2025
…lvm#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants