-
Notifications
You must be signed in to change notification settings - Fork 253
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
Create rewriter for x86 strcpy chain #1272
Conversation
Many x86 binaries contanains strcpy(<dst>, <src>) compiled as scasb/movsd/movsb sequence: ``` mov edi,<src> mov edx,<dst> or ecx,0FFh xor eax,eax repne scasb not ecx sub edi,ecx mov esi,edi mov eax,ecx mov edi,edx shr ecx,2h rep movsd mov ecx,eax and ecx,3h rep movsb ret ```
Allow DeadCodeEliminator to delete it.
var stms = block.Statements.ToArray(); | ||
for (int i = 0; i < stms.Length - 1; i++) | ||
{ | ||
if (TryRewriteStrcpy(subject, stms[i], stms[i + 1])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if there is another non-related statement between stms[i]
and stms[i+1]
? Would it be better to "chase" the definition-uses in the SsaState
to get more accurate results?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code excecutes after expression coalescing, so there is not statements between two memcpy
calls normally. And it is unsafe to reorder statements in common case.
50e142f
to
8d75284
Compare
Add support for any 2^n aligmnent intead of using magic number 4.
Looks good. Thanks for the contribution! |
Many x86 binaries contanains strcpy(
<dst>
,<src>
) compiled asscasb/movsd/movsb sequence: