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

Fix clang 16.0.4 Compilation on Windows #678

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 55 additions & 43 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/options.cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

set(REMILL_ENABLE_TESTING OFF)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move to cmake/options.cmake.


if(REMILL_ENABLE_TESTING)
include(CTest)
endif()
Expand All @@ -40,22 +42,44 @@ find_package(Z3 CONFIG REQUIRED)

# LLVM
find_package(LLVM CONFIG REQUIRED)
llvm_map_components_to_libnames(llvm_libs
support core irreader
bitreader bitwriter
passes asmprinter
aarch64info aarch64desc aarch64codegen aarch64asmparser
armcodegen armasmparser
interpreter mcjit
nvptxdesc
x86info x86codegen x86asmparser
sparccodegen sparcasmparser
webassemblydesc)
# https://github.com/JonathanSalwan/Triton/issues/1082#issuecomment-1030826696
if(LLVM_LINK_LLVM_DYLIB)
set(llvm_libs LLVM)
else()
llvm_map_components_to_libnames(llvm_libs
support
core
irreader
bitreader
bitwriter
passes
asmprinter
aarch64info
aarch64desc
aarch64codegen
aarch64asmparser
armcodegen
armasmparser
HipStdPar
CodeGenTypes
interpreter
mcjit
FrontendOffloading
nvptxdesc
Copy link
Collaborator

Choose a reason for hiding this comment

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

@2over12 thoughts on removing nvptx and wasm from cxx-common?

x86info
x86codegen
x86asmparser
sparccodegen
sparcasmparser
webassemblydesc)
endif()
message(STATUS "LLVM Libraries: ${llvm_libs}")

message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})

string(REPLACE "." ";" LLVM_VERSION_LIST ${LLVM_PACKAGE_VERSION})
list(GET LLVM_VERSION_LIST 0 LLVM_MAJOR_VERSION)
list(GET LLVM_VERSION_LIST 1 LLVM_MINOR_VERSION)
Expand Down Expand Up @@ -85,6 +109,7 @@ find_package(XED CONFIG REQUIRED)
find_package(glog CONFIG REQUIRED)

# Google gflags
set(GFLAGS_USE_TARGET_NAMESPACE ON)
find_package(gflags CONFIG REQUIRED)

set(sleigh_ENABLE_TESTS OFF)
Expand All @@ -94,6 +119,17 @@ file(GLOB sleigh_patches "${CMAKE_CURRENT_SOURCE_DIR}/patches/sleigh/*.patch")

set(sleigh_ADDITIONAL_PATCHES "${sleigh_patches}" CACHE STRING "" FORCE)

if(WIN32)
# In one of the sleigh headers they use std::byte without the std namespace prefix.
# This then causes a windows compilation failure, because of a conflicting definition
# of 'byte' in one of the windows SDK headers. So as a fix we must append
# _HAS_STD_BYTE to the compile definitions.
add_compile_definitions(_HAS_STD_BYTE=0)
# In another sleigh source file, there is an implicit narrowing conversion.
# This flag allows implicit narrowing.
add_compile_options ( -Xclang -Wno-narrowing)
endif()

# GHIDRA SLEIGH
FetchContent_Declare(sleigh
GIT_REPOSITORY https://github.com/lifting-bits/sleigh.git
Expand Down Expand Up @@ -131,7 +167,9 @@ add_library(remill_settings INTERFACE)

target_include_directories(remill_settings INTERFACE
$<BUILD_INTERFACE:${REMILL_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)
$<INSTALL_INTERFACE:include>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there should be a $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>, given that GNUInstallDirs is included.

Copy link
Contributor

Choose a reason for hiding this comment

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

The $<INSTALL_INTERFACE> with the GNUInstallDirs is already implicitly adding when exporting the target, so you should be able to actually remove it from the target.

$<BUILD_INTERFACE:${LLVM_INCLUDE_DIR}>
)

if(WIN32)
# warnings and compiler settings
Expand Down Expand Up @@ -203,7 +241,7 @@ else()
endif()

target_compile_definitions(remill_settings INTERFACE
"REMILL_INSTALL_SEMANTICS_DIR=\"${REMILL_INSTALL_SEMANTICS_DIR}\""
"REMILL_INSTALL_SEMANTICS_DIR=\"semantics\""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you explain this?

"REMILL_BUILD_SEMANTICS_DIR_X86=\"${REMILL_BUILD_SEMANTICS_DIR_X86}\""
"REMILL_BUILD_SEMANTICS_DIR_AARCH32=\"${REMILL_BUILD_SEMANTICS_DIR_AARCH32}\""
"REMILL_BUILD_SEMANTICS_DIR_AARCH64=\"${REMILL_BUILD_SEMANTICS_DIR_AARCH64}\""
Expand Down Expand Up @@ -279,6 +317,10 @@ target_link_libraries(remill INTERFACE
${LINKER_END_GROUP}
)

if(WIN32)
target_link_libraries(remill INTERFACE Ws2_32.lib)
endif()

#
# Also install clang, libllvm and llvm-link
#
Expand Down Expand Up @@ -325,33 +367,3 @@ if(REMILL_ENABLE_INSTALL_TARGET)
install(EXPORT remillTargets
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/remill")
endif()

# tests
if(REMILL_ENABLE_TESTING)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you explain why this is deleted?

# Tests require enabling exports on binaries
# https://cmake.org/cmake/help/latest/variable/CMAKE_ENABLE_EXPORTS.html#variable:CMAKE_ENABLE_EXPORTS
set(CMAKE_ENABLE_EXPORTS ON)

find_package(Threads REQUIRED)
add_custom_target(test_dependencies)

if(REMILL_ENABLE_TESTING_SLEIGH_THUMB)
message(STATUS "thumb tests enabled")
add_subdirectory(tests/Thumb)
endif()

if(REMILL_ENABLE_TESTING_SLEIGH_PPC)
message(STATUS "ppc tests enabled")
add_subdirectory(tests/PPC)
endif()

if(REMILL_ENABLE_TESTING_X86)
message(STATUS "X86 tests enabled")
add_subdirectory(tests/X86)
endif()

if(REMILL_ENABLE_TESTING_AARCH64)
message(STATUS "aarch64 tests enabled")
add_subdirectory(tests/AArch64)
endif()
endif()
16 changes: 9 additions & 7 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,24 @@
"name": "x86_64",
"hidden": true,
"environment": {
"VCPKG_ARCH": "x64"
"VCPKG_ARCH": "x86_64"
},
"architecture": {
"value": "x64",
"value": "x86_64",
"strategy": "external"
}
},
{
"name": "vcpkg-common",
"hidden": true,
"binaryDir": "$env{INSTALL_DIR}/build/remill",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build",
"generator": "Visual Studio 17 2022",
"toolset":"LLVM_v143",
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "$env{VCPKG_TARGET_TRIPLET}",
"CMAKE_TOOLCHAIN_FILE": "$env{CMAKE_TOOLCHAIN_FILE}",
"CMAKE_INSTALL_PREFIX": "$env{INSTALL_DIR}/install"
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"CMAKE_PREFIX_PATH": "$env{CXX_COMMON_ROOT}/Deps/installed/x64-windows-static-md-rel/share",
"VCPKG_TARGET_TRIPLET": "x64-windows-static-md-rel",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/install"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Choose your LLVM version
ARG LLVM_VERSION=16
ARG LLVM_VERSION=17
ARG ARCH=amd64
ARG UBUNTU_VERSION=22.04
ARG DISTRO_BASE=ubuntu${UBUNTU_VERSION}
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ Remill focuses on accurately lifting instructions. It is meant to be used as a l

[![Build Status](https://img.shields.io/github/workflow/status/lifting-bits/remill/CI/master)](https://github.com/lifting-bits/remill/actions?query=workflow%3ACI)

## Additional Documentation
## Documentation

- [How to contribute](docs/CONTRIBUTING.md)
To understand how Remill works you can take a look at the following resources:

- [Step-by-step guide on how Remill lifts an instruction](docs/LIFE_OF_AN_INSTRUCTION.md)
- [How to implement the semantics of an instruction](docs/ADD_AN_INSTRUCTION.md)
- [How instructions are lifted](docs/LIFE_OF_AN_INSTRUCTION.md)
- [The design and architecture of Remill](docs/DESIGN.md)

If you would like to contribute you can check out: [How to contribute](docs/CONTRIBUTING.md)

## Getting Help

If you are experiencing undocumented problems with Remill then ask for help in the `#binary-lifting` channel of the [Empire Hacking Slack](https://slack.empirehacking.nyc/).
Expand Down
1 change: 1 addition & 0 deletions bin/differential_tester_x86/LiftAndCompare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <glog/logging.h>
#include <gtest/gtest.h>
#include <llvm/ADT/StringExtras.h>
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/ExecutionEngine/GenericValue.h>
#include <llvm/ExecutionEngine/Interpreter.h>
Expand Down
2 changes: 1 addition & 1 deletion bin/lift/Lift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ int main(int argc, char *argv[]) {
arg_types.push_back(llvm::PointerType::get(context, 0));
}

const auto state_type = llvm::PointerType::get(context, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch.

const auto state_type = arch->StateStructType();
const auto func_type =
llvm::FunctionType::get(mem_ptr_type, arg_types, false);
const auto func = llvm::Function::Create(
Expand Down
2 changes: 1 addition & 1 deletion cmake/BCCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set(DEFAULT_BC_COMPILER_FLAGS
-ffreestanding -fno-common -fno-builtin -fno-exceptions -fno-rtti
-fno-asynchronous-unwind-tables -Wno-unneeded-internal-declaration
-Wno-unused-function -Wgnu-inline-cpp-without-extern
-Wno-pass-failed=transform-warning
-Wno-pass-failed=transform-warning -fshort-wchar -Xclang -mlong-double-80
Copy link
Collaborator

Choose a reason for hiding this comment

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

TIL about -mlong-double-80.

${EXTRA_BC_SYSROOT}
)

Expand Down
8 changes: 4 additions & 4 deletions cmake/git_watcher.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ macro(RunGitCommand)
# Most methods have a fall-back default value that's used in case of non-zero
# exit codes. If you're feeling risky, disable this safety check and use
# those default values.
if(GIT_FAIL_IF_NONZERO_EXIT )
string(REPLACE ";" " " args_with_spaces "${ARGV}")
message(FATAL_ERROR "${stderr} (${GIT_EXECUTABLE} ${args_with_spaces})")
endif()
#if(GIT_FAIL_IF_NONZERO_EXIT )
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add an option to cmake/options.cmake that disables this or disabled version embedding, instead of wiping this out?

# string(REPLACE ";" " " args_with_spaces "${ARGV}")
# message(FATAL_ERROR "${stderr} (${GIT_EXECUTABLE} ${args_with_spaces})")
#endif()
endif()
endmacro()

Expand Down
2 changes: 1 addition & 1 deletion cmake/options.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

include(CMakeDependentOption)

set(can_enable_testing TRUE)
set(can_enable_testing FALSE)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why? If this should be conditional on windows then make this an option rather than a set, and include(CMakeDependentOption) so that you can make it dependent on windows.

set(can_enable_testing_x86 FALSE)
set(can_enable_testing_aarch64 FALSE)

Expand Down
2 changes: 1 addition & 1 deletion cmake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function(InstallExternalTarget target_name target_path install_type installed_fi

install(FILES "${output_file_path}"
TYPE ${install_type}
PERMISSIONS OWNER_READ OWNER_EXECUTE
PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why?

GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)
Expand Down
Loading