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

Can xed be used to generate code for JIT engine #208

Open
dibyendumajumdar opened this issue Aug 16, 2019 · 8 comments
Open

Can xed be used to generate code for JIT engine #208

dibyendumajumdar opened this issue Aug 16, 2019 · 8 comments
Labels

Comments

@dibyendumajumdar
Copy link

Hi I assume that xed can be used as an assembler for a JIT engine? Is there an example of how to do this? Thank you

@markcharney
Copy link
Contributor

yes. XED was originally created to be the instruction encoder/decoder for Intel's Pin binary instrumentation system, which is a JIT at its core. XED is also used in Intel's ZSIM emulator. There are papers on both (links below), but they are closed source projects. You'd probably get more out of reading the papers than sifting through enormous code bases. Maybe some of the people who sometimes respond to issues posted here can point out other examples.

https://software.intel.com/en-us/articles/pin-a-binary-instrumentation-tool-papers
https://pdfs.semanticscholar.org/d853/013b71946850d0570d6c493a930dfd20d4cf.pdf

@dibyendumajumdar
Copy link
Author

Thank you. So there is no example in the repo showing how to compile and execute a simple function?

@markcharney
Copy link
Contributor

there are simple examples of how to use xed in the examples directory. But a JIT is significantly beyond a simple example.

@dibyendumajumdar
Copy link
Author

Perhaps my question wasn't clear - I am only looking for a sample that shows how to compile something like:

int f(int a) { return a; }

That is, what facilities if any XED provides to generate a compiled object. I couldn't find any example that does that.

@markcharney
Copy link
Contributor

I think you may have the wrong project. This project is for encoding and decoding x86 instructions. The decoder decodes 1...15 bytes and produces a data structure describing the instruction. The encoder takes a data structure describing an instruction and produces an array of 1...15 bytes.

This project does not parse C code.

@dibyendumajumdar
Copy link
Author

dibyendumajumdar commented Aug 16, 2019

Sorry let me try again. Of course I know what this project does. I only gave an example of a simple function. I want to be able to create an assembly function, and the C function is just to show an example of a simple function. I want to emit the assembly code and be able to invoke the function.

I have my own C front-end if that helps. I am looking for an assembler library in C.

I know I can encode instructions using XED. But can I generate equivalent of an object file in memory that can then be invoked.

@markcharney
Copy link
Contributor

Well XED is not an assembler either, sorry. With XED, one can generate (encoded) x86 instructions to a buffer, make the buffer executable and jump to it. How one makes a buffer executable is O/S dependent (mprotect() on linux) and you'd probably need a little assembly stub to do an indirect jump to the code you generated. You'd have to keep track of instruction sizes and patch branch displacements as well.

@dibyendumajumdar
Copy link
Author

Okay that's what I was trying to understand. I was hoping for an example of that in the samples, but I couldn't find any. Anyway I can figure out what to do.

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

No branches or pull requests

2 participants