-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AARCH32] Incorrect Implementation of Carry Flag Behavior #7459
Comments
There are several variants of those instructions. Can you find a problematic instance, right-click on each instruction and select |
the decompiler's interpretation of this seems to be inverted, compared to the docs. The decompiler thinks this is an if(false), when it's actually essentially an if(true), to my understanding? |
the r0 register is the input parameter here, it is what is being compared |
mov r6,#0x0 |
Can you include the bytes too, please? |
00 60 a0 e3 |
(assuming you meant 01 00 50 e1 for the bytes of the third instruction). I think this might be related to how the code for the
Alternatively, in the Listing, you can edit the fields (click on the icon in the toolbar that looks like a brick wall over a down arrow) and enable the "Pcode" field. The gist is that the carry flag is set based on r1 <= r0 for the subtraction r0 - r1. Assuming again that you've turned off "Eliminate unreachable code" in the decompiler options, any "true" or "false" you see is based an inequality whose inputs are flipped from their order in the subtraction. So the decompiled code might be a bit confusing but should accurately reflect the assembly. Let us know if it doesn't. |
Here r1 is set to 0 though, so shouldn't r0 >=r1 always be true? how come it's making an if(false) instead? |
Oh wait, hmm. Seems like it.. would in fact never trigger, as it'd always jump? |
Describe the bug
ARM has unintuitive behavior involving the carry flag, where it behaves differently with subtraction operators. This behavior is not replicated by the decompiler, at least for ARMv6, causing incorrect output.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Per https://developer.arm.com/documentation/dui0801/l/Condition-Codes/Carry-flag?lang=en , the behavior of the carry flag is inverted on subtraction, being set to 1 if the operation didn't underflow.
Environment (please complete the following information):
Additional context
I am not sure what other ARM versions this is applicable to, but I know that this behavior is incorrectly implemented for ARMv6.
This is a pretty major issue, seeing how the carry flag is used in a lot of operations, causing a lot of code to be incorrectly decompiled, often times resulting in code being mistakenly marked as "unreachable".
The text was updated successfully, but these errors were encountered: