Repository navigation
Conversation
scan_instructions converts a relocation whose target (symbol address + addend) lies within [function_start, function_end) into an internal branch destination. For ARM/Thumb PC-relative branch relocations, the addend includes the pipeline's PC bias (-4 for Thumb, -8 for ARM) rather than an offset into the target, so the computed address is 4 or 8 bytes before the real target. A call to a function starting immediately after the caller in the same section then lands inside the caller's trailing bytes and becomes a BranchDest, while the other side (with per-function sections) keeps it as a Reloc, causing a false mismatch. Add Arch::reloc_branch_pc_bias (default 0) returning the bias to add to reloc.addend to cancel out the pipeline offset (+4 for Thumb branch relocs, +8 for ARM branch relocs), and use checked_add in scan_instructions. Also add R_ARM_JUMP24 to reloc_name, data_reloc_size, and write_branch_target for consistency, and add unit tests covering both ARM (-8) and Thumb (-4) adjacent-function calls and intra-function branch relocations. Fixes encounter#436
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.
Fixes #436
Summary
Arch::reloc_branch_pc_bias(default0) returning the bias to add toreloc.addendto cancel out a PC-relative branch's pipeline PC offset (+4for Thumb branch relocations,+8for ARM branch relocations).checked_addinArch::scan_instructionsbefore checking whether a relocation target falls within[function_start, function_end), preventing calls to an adjacent function in the same.textsection from being misclassified as internal branch destinations.R_ARM_JUMP24toreloc_name,data_reloc_size, andwrite_branch_targetinArchArmfor consistency withrelocation_override.read_armsnapshots whereLinkStateItem::OnStateLeave'sbl LinkStateItem::GetEquipBombchu()was previously misclassified as a branch to a literal-pool word (0x1a8).-8) and Thumb (-4) adjacent-function calls and intra-function branch relocations.Verification
cargo test(all 53 tests pass)cargo clippy -p objdiff-core --all-targets --all-features -- -D warnings(0 warnings)