Skip to content

Commit

Permalink
Add option to enable ASan + UBSan. Bump XED and Remill.
Browse files Browse the repository at this point in the history
  • Loading branch information
fvrmatteo committed Nov 4, 2024
1 parent de4bcdb commit 0b86d0f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ cmake_minimum_required(VERSION 3.22)
project(dependencies)

option(USE_SYSTEM_LLVM "Use system LLVM" OFF)
option(USE_SANITIZERS "Use ASan and UBSan" OFF)

if(USE_SYSTEM_LLVM)
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin" AND NOT CMAKE_PREFIX_PATH)
execute_process(
COMMAND brew --prefix llvm
COMMAND brew --prefix llvm
RESULT_VARIABLE BREW_LLVM
OUTPUT_VARIABLE BREW_LLVM_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
Expand All @@ -24,8 +25,12 @@ if(USE_SYSTEM_LLVM)
message(STATUS "LLVM ${LLVM_PACKAGE_VERSION}: ${LLVM_DIR}")
endif()

include(superbuild.cmake)
if(USE_SANITIZERS)
list(APPEND CMAKE_C_FLAGS "-fsanitize=address,undefined")
list(APPEND CMAKE_CXX_FLAGS "-fsanitize=address,undefined")
endif()

include(superbuild.cmake)
simple_git(https://github.com/nlohmann/json v3.11.3
"-DJSON_BuildTests:STRING=OFF"
)
Expand All @@ -41,6 +46,7 @@ simple_git(https://github.com/gflags/gflags v2.2.2
)
simple_git(https://github.com/google/glog v0.6.0
"-DGFLAGS_USE_TARGET_NAMESPACE:STRING=ON"
"-DBUILD_TESTING:STRING=OFF"
)
simple_git(https://github.com/google/googletest v1.15.2
"-Dgtest_force_shared_crt:STRING=ON"
Expand All @@ -64,6 +70,7 @@ simple_git(https://github.com/lief-project/LIEF 0.15.1
)
simple_git(https://github.com/capstone-engine/capstone 5.0.3
"-DCAPSTONE_BUILD_TESTS:STRING=OFF"
"-DCAPSTONE_BUILD_CSTOOL:STRING=OFF"
)
simple_git(https://github.com/Z3Prover/z3 z3-4.13.2
"-DZ3_BUILD_LIBZ3_SHARED:STRING=OFF"
Expand All @@ -80,7 +87,7 @@ include(bitwuzla.cmake)
if(NOT USE_SYSTEM_LLVM)
include(llvm.cmake)
endif()
simple_git(https://github.com/LLVMParty/remill llvm-19-v1
simple_git(https://github.com/LLVMParty/remill llvm-19-v2
"-DUSE_SYSTEM_DEPENDENCIES:STRING=ON"
"-DREMILL_ENABLE_TESTING:STRING=OFF"
)
Expand Down
22 changes: 15 additions & 7 deletions llvm.cmake
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
option(LLVM_ENABLE_ASSERTIONS "Enable assertions in LLVM" ON)

set(LLVM_ARGS
"-DLLVM_ENABLE_PROJECTS:STRING=lld;clang;clang-tools-extra"
"-DLLVM_ENABLE_ASSERTIONS:STRING=${LLVM_ENABLE_ASSERTIONS}"
"-DLLVM_ENABLE_DUMP:STRING=${LLVM_ENABLE_ASSERTIONS}"
"-DLLVM_ENABLE_RTTI:STRING=ON"
"-DLLVM_ENABLE_LIBEDIT:STRING=OFF"
"-DLLVM_PARALLEL_LINK_JOBS:STRING=1"
"-DLLVM_ENABLE_DIA_SDK:STRING=OFF"
)

if(USE_SANITIZERS)
list(APPEND LLVM_ARGS "-DLLVM_USE_SANITIZER:STRING=Address;Undefined")
endif()

ExternalProject_Add(llvm
URL
"https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.0/llvm-project-19.1.0.src.tar.xz"
URL_HASH
"SHA256=5042522b49945bc560ff9206f25fb87980a9b89b914193ca00d961511ff0673c"
CMAKE_CACHE_ARGS
${CMAKE_ARGS}
"-DLLVM_ENABLE_PROJECTS:STRING=lld;clang;clang-tools-extra"
"-DLLVM_ENABLE_ASSERTIONS:STRING=${LLVM_ENABLE_ASSERTIONS}"
"-DLLVM_ENABLE_DUMP:STRING=${LLVM_ENABLE_ASSERTIONS}"
"-DLLVM_ENABLE_RTTI:STRING=ON"
"-DLLVM_ENABLE_LIBEDIT:STRING=OFF"
"-DLLVM_PARALLEL_LINK_JOBS:STRING=1"
"-DLLVM_ENABLE_DIA_SDK:STRING=OFF"
${LLVM_ARGS}
CMAKE_GENERATOR
"Ninja"
SOURCE_SUBDIR
Expand Down
11 changes: 8 additions & 3 deletions xed.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
list(APPEND MFILE_ARGS "--extra-cxxflags=${ADDITIONAL_FLAGS}")
endif()

if(USE_SANITIZERS)
list(APPEND MFILE_ARGS "--extra-ccflags=-fsanitize=address,undefined")
list(APPEND MFILE_ARGS "--extra-cxxflags=-fsanitize=address,undefined")
endif()

if(BUILD_SHARED_LIBS)
list(APPEND MFILE_ARGS "--shared")
else()
Expand All @@ -36,7 +41,7 @@ ExternalProject_Add(mbuild
GIT_REPOSITORY
"https://github.com/intelxed/mbuild"
GIT_TAG
"v2022.07.28"
"v2024.09.08"
GIT_PROGRESS
ON
GIT_SHALLOW
Expand All @@ -53,9 +58,9 @@ ExternalProject_Add(mbuild

ExternalProject_Add(xed
GIT_REPOSITORY
"https://github.com/intelxed/xed"
"https://github.com/LLVMParty/xed"
GIT_TAG
"v2022.10.11"
"sanitizers-v1"
GIT_PROGRESS
ON
GIT_SHALLOW
Expand Down

0 comments on commit 0b86d0f

Please sign in to comment.