-
Notifications
You must be signed in to change notification settings - Fork 11
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
x86_64-w64-mingw32-gcc support. PLEASE #9
Comments
Hi @swang206! I've wanted to add GAS assembly output for PE for some time but it keeps getting pushed down the list. As you suggest, it shouldn't be much work to get AT&T output. In fact, all you would really need to do so is register the printer for that syntax. void registerPrettyPrinters() {
// ...
registerPrinter({"pe", "raw"}, {"x86", "x64"}, {"att"}, {"gas"},
std::make_shared<AttPrettyPrinterFactory>(), false, false);
} Then use that syntax:
Unfortunately, that is where it starts to get more difficult. The output assembly has many issues and will not assemble. I will outline some of the immediate problems here, and maybe we can find solutions together.
How should we define this with GAS directives?
Symbols from
I believe this can be fixed with using the - movl _fmode,%eax
+ movl __imp___fmode,%eax That will require some additional work in the pretty printer for outputting the correct reference.
We approach PE and ELF binaries a little differently. By default, for ELF binaries, we elide This leads to problems if you intend to use
We can do a couple of things here, neither of which is clearly the "correct" solution.
The first will require some additional work on Perhaps I just don't have the commands right yet.
What do you think?
I expect that after we get initial support these assembly problems will be a non-significant amount of the effort. We definitely would like GAS assembly outputs for PE targets, but we still need so solve the challenges above before we can get there. Any help you can provide in addressing these issues, even if it just determining the correct directives and commands to reassemble the output assembly would be greatly appreciated. |
@swang206 Also,
Even if you cannot use the Microsoft compiler you might still be able reassemble MASM with other tools. Consider these examples.
Build and disassemble a PE32 binary:
Reassemble MASM with UASM.
UASM is an open source MASM-compatible assembler: http://www.terraspace.co.uk/uasm.html Link the object with MinGW:
... or ... Link the object with LLVM
|
You may find this project helpful while we are still working on GAS assembler output: https://github.com/mstorsjo/msvc-wine Setup a WINE-driven MSVC environment in a docker container:
Build and disassemble a PE32 binary:
Reassemble and link the MASM output in the docker container, with the Microsoft compiler:
Note that the container provides script wrappers around all of the MSVC tools:
So you could build the binary with
|
Kevin, Doing some tests, the
would get converted to:
This would fail to compile as
It also "seemed" to be correct just leaving them as The usage of For the entry point when compiling, I simply had to add a Would be interested in your thoughts on the jump table stuff and pointers on where to look at adjusting those. |
llvm-ml will compile MASM under msys2, if uasm is not working. the flags are odd and not documented it seems, but this will make your obj Then link with lld-link |
It seems unable to handle anything with relative addresses like this: |
I was able to get pprinter generating AT&T assembly syntax for Windows PE executables that can be compiled with clang/clang-cl. I need to do some additional testing and code cleanup, but will contribute back once done. It's available in our fork in the meantime if anyone is interested. https://github.com/R2IDefense/gtirb-pprinter |
Yay! I really want to add |
I really really need mingw-w64 support. i have a lot of programs that are using GCC that targets windows. Using Microsoft compiler isn't an option at all.
I really need that.
https://github.com/GrammaTech/gtirb-pprinter/blob/011f9202744bfb67f902deba34a614cc8edaf86d/src/gtirb_pprinter/AttPrettyPrinter.cpp
You can just add several things to AttPrettyPrinter to support PE. It would work perfectly without much effort. However, that solves a lot of my issues. Thank you. Please.
I love u.
The text was updated successfully, but these errors were encountered: