Fixes for reloc overflows#1427
Open
Shankar Easwaran (quic-seaswara) wants to merge 3 commits into
Open
Conversation
Check for relocation overflows for R_AARCH64_ADR_PREL_PG_HI21 Add test that verifies a link within range succeeds and a link that overflows the 21-bit field is caught with an overflow diagnostic. Fixes #1329 Signed-off-by: Shankar Easwaran <seaswara@qti.qualcomm.com>
The ADR instruction encodes (S + A) - P in a 21-bit signed immediate field. Add a signed 21-bit range check for R_AARCH64_ADR_PREL_LO21. The LDR (literal) instruction encodes (S + A) - P in a 19-bit signed field scaled by 4. Add a signed 21-bit range check on the raw byte offset for R_AARCH64_LD_PREL_LO19. Since the field is scaled by 4, X must also be a multiple of 4 per ABI requirements; add a new error_reloc_not_aligned error diagnostic and return BadReloc if not. Add lit tests that verify a link within range succeeds, a link that overflows the 21-bit field is caught with an overflow diagnostic, and an R_AARCH64_LD_PREL_LO19 relocation with a misaligned X is caught with an alignment error. Update the AArch64 relocation developer documentation to record the 4-byte alignment requirement for LD_PREL_LO19. Signed-off-by: Shankar Easwaran <seaswara@qti.qualcomm.com>
…ARCH64_JUMP26 BL/B encodes (S + A) - P in a 26-bit signed field scaled by 4 (+/-128MB). Unlike ADR/LDR, out-of-range branches are handled transparently via trampoline stub insertion rather than an overflow error. However, the PC-relative offset must still be 4-byte aligned; a misaligned target is always an input error. Add an alignment check (X & 0x3) in the call() relocator, matching the pattern already used by ld_prel_lo19. Expand the lit test to cover in-range, out-of-range (trampoline), and misaligned target cases. Signed-off-by: Shankar Easwaran <seaswara@qti.qualcomm.com>
Eli Friedman (efriedma-quic)
approved these changes
Jul 8, 2026
Eli Friedman (efriedma-quic)
left a comment
Contributor
There was a problem hiding this comment.
LGTM, assuming this is the same as the patch to main.
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.
No description provided.