From 0b86d0fca79fd3d6d6761466c34252b9ee4ad9d4 Mon Sep 17 00:00:00 2001 From: Matteo Date: Tue, 5 Nov 2024 00:30:03 +0100 Subject: [PATCH] Add option to enable ASan + UBSan. Bump XED and Remill. --- CMakeLists.txt | 13 ++++++++++--- llvm.cmake | 22 +++++++++++++++------- xed.cmake | 11 ++++++++--- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 81184ce..e4cda17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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" ) @@ -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" @@ -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" @@ -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" ) diff --git a/llvm.cmake b/llvm.cmake index 6788f7c..8b4b795 100644 --- a/llvm.cmake +++ b/llvm.cmake @@ -1,5 +1,19 @@ 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" @@ -7,13 +21,7 @@ ExternalProject_Add(llvm "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 diff --git a/xed.cmake b/xed.cmake index 390c707..c5efa49 100644 --- a/xed.cmake +++ b/xed.cmake @@ -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() @@ -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 @@ -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