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

Allow asm printing for CALL(RIPRelativeOffset(3)) #105

Merged
merged 4 commits into from
Mar 3, 2020

Conversation

certik
Copy link
Contributor

@certik certik commented Mar 2, 2020

Without this PR, you get an error:

Traceback (most recent call last):
  File "gen.py", line 40, in <module>
    print_fn(fn)
  File "gen.py", line 26, in print_fn
    line = "\t%s%s# %s" % (i.encode().hex(" "), tabs, i.format("gas"))
  File "/home/certik/miniconda3/envs/asm/lib/python3.8/site-packages/peachpy/x86_64/instructions.py", line 79, in format
    return text + self.gas_name + " " + ", ".join(format_operand(op, assembly_format) for op in reversed(self.operands))
  File "/home/certik/miniconda3/envs/asm/lib/python3.8/site-packages/peachpy/x86_64/instructions.py", line 79, in <genexpr>
    return text + self.gas_name + " " + ", ".join(format_operand(op, assembly_format) for op in reversed(self.operands))
  File "/home/certik/miniconda3/envs/asm/lib/python3.8/site-packages/peachpy/x86_64/operand.py", line 81, in format_operand
    return operand.format(assembly_format)
AttributeError: 'RIPRelativeOffset' object has no attribute 'format'

with this PR, the Python code:

    CALL(RIPRelativeOffset(3))

prints the following assembly:

call +3

and the following machine code:

e8 03 00 00 00

Copy link
Owner

@Maratyszcza Maratyszcza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the patch. However, proper assembly listing should be:

  • offset(%rip) when assembly_format == "gas"
  • offset(IP) when assembly_format == "go"
  • rip+offset otherwise

certik added 2 commits March 3, 2020 10:02
Previously it printed:

    CALL <peachpy.x86_64.operand.RIPRelativeOffset object at 0x7f6e1e126430>

Now it prints:

    CALL rip+28
@certik
Copy link
Contributor Author

certik commented Mar 3, 2020

Thanks @Maratyszcza. I implemented the correct assembly.

Copy link
Owner

@Maratyszcza Maratyszcza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor changes

peachpy/x86_64/operand.py Show resolved Hide resolved
peachpy/x86_64/operand.py Outdated Show resolved Hide resolved
@Maratyszcza Maratyszcza merged commit f189ad2 into Maratyszcza:master Mar 3, 2020
@Maratyszcza
Copy link
Owner

Thank you!

@certik certik deleted the offset branch March 3, 2020 20:09
@certik
Copy link
Contributor Author

certik commented Mar 3, 2020

Thanks for merging!

Maratyszcza pushed a commit that referenced this pull request May 26, 2022
Previously it printed:

    CALL <peachpy.x86_64.operand.RIPRelativeOffset object at 0x7f6e1e126430>

Now it prints:

    CALL rip+28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants