Improve runtime of ARM/AArch64 register name patching. - #3048
Draft
Rot127 wants to merge 4 commits into
Draft
Conversation
There was a problem hiding this comment.
Pull request overview
This PR optimizes ARM and AArch64 “Capstone register alias” patching by replacing repeated strstr/memmove loops with a single-pass in-place rewrite over the rendered assembly string, and adds a targeted YAML regression suite to validate aliasing behavior and avoid false positives in hex immediates.
Changes:
- Reworked ARM alias patching (
r9–r15→sb/sl/fp/ip/sp/lr/pc) into a single-pass copier. - Reworked AArch64 alias patching (
x29/x30→fp/lr) into a single-pass copier with a guard to avoid0x29/0x30literals. - Added a new YAML issue test suite covering alias replacements and false-positive cases.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/issues/arm_aarch64_reg_alias_patching.yaml | Adds regression test cases for ARM/AArch64 alias patching behavior. |
| arch/ARM/ARMMapping.c | Replaces multi-pass alias patching with a single-pass in-place rewrite for ARM. |
| arch/AArch64/AArch64Mapping.c | Replaces multi-pass alias patching with a single-pass in-place rewrite for AArch64, including hex-literal guard. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
Suppressed comments (1)
tests/issues/arm_aarch64_reg_alias_patching.yaml:246
- This test case name says "arm r13 at start of string", but in the expected asm "mov lr, sp" the alias for r13 (sp) appears at the end. Consider renaming to reflect what boundary you’re exercising.
name: "arm r13 at start of string"
| asm_text: "mov r0, pc" | ||
| - | ||
| input: | ||
| name: "arm r9 at end of string" |
Comment on lines
+106
to
+108
| // No r0-r9 register. | ||
| *dst++ = *src++; | ||
| src_len--; |
| @@ -881,32 +881,53 @@ bool AArch64_getInstruction(csh handle, const uint8_t *code, size_t code_len, | |||
| /// which are not set in LLVM. | |||
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.
Your checklist for this pull request
Detailed description
The old patching was atrocious. That makes it do the same thing in two passes over the string, not 10 or something.
Test plan
Added
Closing issues
...