Skip to content
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

Zasm wrong jump calculation #115

Closed
OptionalAssistant opened this issue Mar 26, 2024 · 3 comments · Fixed by #116
Closed

Zasm wrong jump calculation #115

OptionalAssistant opened this issue Mar 26, 2024 · 3 comments · Fixed by #116
Labels
bug Something isn't working

Comments

@OptionalAssistant
Copy link
Contributor

Hello,recently I have faced a problem with incorrect jump encoding.Do not think about the sense of the god it is just an example.
` Program program(MachineMode::I386);

x86::Assembler assembler(program);

auto label = assembler.createLabel();

ASSERT_EQ(assembler.jmp(label), Error::None);
for (int i = 0; i < 100; i++)
ASSERT_EQ(assembler.nop(), Error::None);
ASSERT_EQ(assembler.bind(label), Error::None);
ASSERT_EQ(assembler.int3(), Error::None);
ASSERT_EQ(assembler.align(Align::Type::Code, 10), Error::None);

Serializer serializer;
ASSERT_EQ(serializer.serialize(program, 0x0000000000401000), Error::None);`

My jmp should went to int3 instruction but it goes 3 bytes futher.I looked at the source code of zasm and noticed possible incorrect logic(I think).When jmp is encoding first time its size is 5.But on extrapass its value 2(cause now we already have bounded label and it changes from far jmp to short).So now ctx.drift is 3 and we should run pass one more time.But because of aligning at the end of the code drift becomes 0(3 - 3).And now zasm does not run the third pass (despite aligning happens not in range of our jmp)and he thinks that offset of int 3 is still 105 instead of 103.Am I doing something wrong or it is a bug?

P.S.Code is just an example dont take it as smth meaningful.

@OptionalAssistant
Copy link
Contributor Author

Dont pay attention to ASSERT_EQ I just copied some code from google test,rewrite and forgot to delete these macros

@ZehMatt
Copy link
Collaborator

ZehMatt commented Mar 26, 2024

Thanks for the report, I'll look into it once I get a bit of time.

@ZehMatt ZehMatt added the bug Something isn't working label Mar 26, 2024
ZehMatt added a commit that referenced this issue Mar 26, 2024
ZehMatt added a commit that referenced this issue Mar 26, 2024
Fix #115: Don't rely on address drift to determine extra pass
@ZehMatt
Copy link
Collaborator

ZehMatt commented Mar 26, 2024

Should be fixed, thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants