Add support for compiling with MSVC
Mostly a draft to see if there is interest. The changes are quite minimal, the only functional change I made was the mulhshr function because MSVC doesn't support uint128_t. I made a pretty extensive test harness for the MSVC implementation though: https://godbolt.org/z/h9q7hj5P1
If this is something you would merge I can do CI with GitHub Actions for Windows as well.
Thank you so much for this PR and for your interest in Maat!
Everything looks good to me. It would be really amazing if you could integrate windows in the Github Actions CI before we merge this. Also, is there anything specific worth mentioning in BUILDING.md or HACKING.md for Windows builds?
Not really, the only thing I did was use vcpkg to get GMP. I can add some instructions, but there’s nothing platform specific.
I’ll try also building with lief and z3 for completeness sake and then add GH actions.
Awesome! No need to update the documentation then. Looking forward to seeing progress on this. Don't hesitate to ask if you have more questions.
I ran into some issues compiling maat with z3 and lief, will get back to it once I figure out what's going on.
@mrexodia Not sure if you're planning to use vcpkg for Z3 and LIEF, but I have pending PR for LIEF on vcpkg here[1]. It's pending/blocked because LIEF requires mbedtls v3 but other vcpkg ports require mbedtls v2 and aren't the easiest to upgrade/support both major versions 😞 . The failing tests are related to the other vcpkg ports that don't support mbedtls v3.
Moreover, I think the move to use vcpkg for all of CI would make building dependencies easier when supporting multiple OSes. I plan to work on this when I find the time, but I also need to figure out how to ensure OS compatibility with the native Python wheels, i.e. adding -mmacosx-version-min=10.15 to vcpkg's triplet file (most likely) and cross-compiling for Mac M1.
[1] https://github.com/microsoft/vcpkg/pull/22957
Thanks! For vcpkg it should be possible to use manifest mode and then an overlay for mbedtls v3 and lief. I was trying to stay compatible with the current LIEF version used, but this version doesn't compile with MSVC so I will upgrade to the latest LIEF/Z3 and provide vcpkg overlays.
@mrexodia I finally found some time to work on vcpkg support for sleigh and have opened a draft PR for maat to use dependencies all from vcpkg here https://github.com/trailofbits/maat/pull/128.
I also tested the vcpkg integration on Windows and the dependencies all seem to build fine. I also merged this branch into a test branch with the vcpkg integration, but I'm getting some additional errors in Maat that I think have been introduced since you first opened this PR.
- There are some complaints about strict strings from the generated https://github.com/trailofbits/maat/blob/master/generate/src/include/maat/config.hpp.in file, which can be fixed with the following patch
diff --git a/generate/src/include/maat/config.hpp.in b/generate/src/include/maat/config.hpp.in
index 3de9b6e..6d0266c 100644
--- a/generate/src/include/maat/config.hpp.in
+++ b/generate/src/include/maat/config.hpp.in
@@ -1,8 +1,8 @@
#ifndef MAAT_CONFIG_H
#define MAAT_CONFIG_H
-static constexpr char* maat_install_prefix = "@CMAKE_INSTALL_PREFIX@";
-static constexpr char* maat_specfile_dir_prefix = "@maat_INSTALL_DATADIR@/@spec_out_prefix@";
+static constexpr auto maat_install_prefix = "@CMAKE_INSTALL_PREFIX@";
+static constexpr auto maat_specfile_dir_prefix = "@maat_INSTALL_DATADIR@/@spec_out_prefix@";
#include <filesystem>
#include <list>
- There are more strict string errors in the Python code (I set
-Dmaat_BUILD_PYTHON_BINDINGS=OFFto silence that for now...) - There are some LIEF errors that I haven't yet looked into but I assume are due to upgraded LIEF
C:\src\maat\src\loader\loader_lief_elf.cpp(70,13): error C3861: 'S_ISREG': identifier not found [C:\src\maat\build\dev-win64\maat_maat.vcxproj]
C:\src\maat\src\loader\loader_lief_elf.cpp(76,18): error C3861: 'S_ISDIR': identifier not found [C:\src\maat\build\dev-win64\maat_maat.vcxproj]
Feel free to mess around with the vcpkg integration. I've left some TODOs in https://github.com/trailofbits/maat/pull/128 of what I was planning, but I won't get to working on that again for 2 weeks or so.
Thanks for picking this up, I lost track of it. I have the PR marked as editable by collaborators so feel free to push any fixes you might have. Otherwise I’ll pick it up some time in the future.