NationalSecurityAgency / ghidra

Ghidra is a software reverse engineering (SRE) framework
https://www.nsa.gov/ghidra
Apache License 2.0
52.21k stars 5.91k forks source link

LLVM/Clang for Windows support #2942

Closed astrelsky closed 1 year ago

astrelsky commented 3 years ago

Is your feature request related to a problem? Please describe. It is currently not possible to build Ghidra on windows without a visual studio ide installed. Having only the Visual Studio 2019 Build Tools and LLVM doesn't work.

Describe the solution you'd like If a C++ compiler is available or should be used.

Describe alternatives you've considered Install a garbage visual studio ide that just takes up space and is never used.

Danil6969 commented 3 years ago

You could use MSYS2 as a unix shell and terminal with mingw and install gcc or clang with gdb (if you need the latter) using pacman command. Then you just use the g++.exe or clang++.exe file downloaded by pacman. Also define macros for windows as here and here and disable compilation of PDB or port it somehow to be used with GCC or Clang (I don't see any sense in using this as PDB files are absent most times). Also the VS IDE has nothing to do with MS Build Tools if you want to go pure Windows-style. The only caveat is that you also have to install Windows SDK and ATL. But note that MSVC generates unoptimal code compared to Clang or even GCC so the generated decompiler executable will be slower.

astrelsky commented 3 years ago

You could use MSYS2 as a unix shell and terminal with mingw and install gcc or clang with gdb (if you need the latter) using pacman command. Then you just use the g++.exe or clang++.exe file downloaded by pacman. Also define macros for windows as here and here.

No, can just install llvm for windows. This is a build problem as there is no way to tell it to use clang. clang++ is already in the PATH. The build scripts just see there is no visual studio ide and fails even though I have the build tools.

Danil6969 commented 3 years ago

You may use this "selector". Also replace the path to a valid one and cut out vc(VisualCpp) {...}. And put if (false) instead of if (org.gradle.internal.os.OperatingSystem.current().isWindows()) here.

Danil6969 commented 3 years ago

As of "IDE" I have installed only the MS Build tools and the folder is also named as it contains full IDE, not just MSVC compiler while this is false and it takes much less space on HDD because of compiler only presence. Don't pay attention very much to this strange path naming scheme. Maybe it's just a historic issue because Microsoft decided to put it in the same folder where most people have installed IDE which uses this compiler by default. I have the only folder named "BuildTools" in "C:\Program Files (x86)\Microsoft Visual Studio\2019" and it was running pretty well before I fully switched to Clang (from my experience of decompiler tinkering).

astrelsky commented 3 years ago

You may use this "selector". Also replace the path to a valid one and cut out vc(VisualCpp) {...}. And put if (false) instead of if (org.gradle.internal.os.OperatingSystem.current().isWindows()) here.

I'll give this a shot on Monday. As long as it uses the Visual Studio Build Tools with clang and not make it should work.

astrelsky commented 3 years ago

@Danil6969 that did work I just had to disable the checks in a few other places. I'm going to leave this open though as it would be nice to have it supported.

ryanmkurtz commented 3 years ago

I'm interested in getting Ghidra to build on Windows with no admin required (so no Visual Studio). Did you achieve this?

astrelsky commented 3 years ago

I'm interested in getting Ghidra to build on Windows with no admin required (so no Visual Studio). Did you achieve this?

Yes. However, clang requires having the Visual Studio build tools so you still need admin.

ryanmkurtz commented 3 years ago

I'll give this setup a try. Not needing admin would be ideal, but not having to register your visual studio after 30 days would be a win too.

astrelsky commented 3 years ago

I'll give this setup a try. Not needing admin would be ideal, but not having to register your visual studio after 30 days would be a win too.

That's why I ended up going this route. It was easier to spend the time to figure this out then to jump through hoops to get a Pro license at work.

You don't need admin to create an offline install. So if you have a situation where you need to move it to an offline workstation where you do have admin rights but don't have admin rights where you can run the installer to download the layout you can still make it work. In order to do so you have to make the layout from a terminal of your choice.

I don't remember if mingw-w64 or msys2 require admin to install or not. That would be another route you can take as long as the right folders are added to your path and/or gradle is run from the provided terminal.

astrelsky commented 3 years ago

Gradle has built in plugins for c/c++ projects. Has using them been tried? It makes more sense to me to let gradle handle it then to try to implement the logic from scratch.

https://github.com/gradle/native-samples

astrelsky commented 3 years ago

@ryanmkurtz I just tried a default created c++ project using the gradle init script on a system without a visual studio ide (only the build tools). Gradle managed to build it and use the build tools without a problem. It may be more efficient to use the gradle cpp-application plugin instead of custom stuff.

ryanmkurtz commented 3 years ago

Gradle has built in plugins for c/c++ projects. Has using them been tried? It makes more sense to me to let gradle handle it then to try to implement the logic from scratch.

What do you mean implement the logic from scratch? Do you mean the stuff we have in there that discovers visual studio?

astrelsky commented 3 years ago

Gradle has built in plugins for c/c++ projects. Has using them been tried? It makes more sense to me to let gradle handle it then to try to implement the logic from scratch.

What do you mean implement the logic from scratch? Do you mean the stuff we have in there that discovers visual studio?

I did mean that. Is that not custom?

Either way it appears that gradle successfully found both the build tools and clang without any special modifications.

Edit: Also a crazy thought, I wonder if gradle could give the system endianess that could be used to pre-define a macro by command line for types.h.

ryanmkurtz commented 3 years ago

The Gradle changes I made to support building on ARM are still making their way through the pipe. Once the dust settles on that, I'll revisit LLM on Windows.

ryanmkurtz commented 1 year ago

Now that Ghidra supports VS Build Tools, is this request still important? We don't have LLVM/Clang support, but you no longer have to install the VS IDE.