Repository navigation
Cranelift/aarch64: fix br_tables with very large target count. - #14826
Merged
Merged
Conversation
Previously, the `JTSequence` macro-instruction contained a conditional branch for the default (selector greater than table size) case. This default branch on aarch64 has a +/- 1MiB range. The `JTSequence` also contains the entire table of 32-bit offsets for each `br_table` target. As a result of these two facts, a branch may have an out-of-bounds target and silently wrap the offset, resulting in an incorrect branch target. This PR fixes the sequence to instead use the offset table for the default case too. The conditional branch is converted into a conditional-select that clamps the index to the last table entry (which we fill with the default target) if out-of-bounds.
alexcrichton
approved these changes
Oct 19, 2026
Merged
4 tasks done
This was referenced Oct 20, 2026
This was referenced Oct 24, 2026
This was referenced Oct 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, the JTSequence macro-instruction contained a conditional branch for the default (selector greater than table size) case. This default branch on aarch64 has a +/- 1MiB range. The JTSequence also contains the entire table of 32-bit offsets for each br_table target. As a result of these two facts, a branch may have an out-of-bounds target and silently wrap the offset, resulting in an incorrect branch target.
This PR fixes the sequence to instead use the offset table for the default case too. The conditional branch is converted into a conditional-select that clamps the index to the last table entry (which we fill with the default target) if out-of-bounds.
This PR was authored by @cfallin