From 1e4bf74dbe66e66758cd473388b1253f1770782c Mon Sep 17 00:00:00 2001 From: Vitaly Chipounov Date: Sun, 14 Apr 2024 12:35:27 +0200 Subject: [PATCH] makefile: use system capstone Signed-off-by: Vitaly Chipounov --- .github/workflows/build.yaml | 2 +- Dockerfile | 2 +- Makefile | 40 ++---------------------------------- libcpu/CMakeLists.txt | 4 +++- libs2e/CMakeLists.txt | 2 ++ libs2e/configure | 24 ---------------------- libs2e/src/CMakeLists.txt | 2 +- 7 files changed, 10 insertions(+), 66 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ebc049b76..1183edcf7 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -20,7 +20,7 @@ jobs: libglib2.0-dev python3-docutils libpng-dev \ gcc-multilib g++-multilib libgomp1 unzip software-properties-common \ libprotobuf-dev protobuf-compiler protobuf-c-compiler \ - libgmock-dev libgtest-dev rapidjson-dev libsoci-dev + libgmock-dev libgtest-dev rapidjson-dev libsoci-dev libcapstone-dev sudo apt-get install -f sudo apt-get install -y libgcc-s1:i386 libstdc++6:i386 diff --git a/Dockerfile b/Dockerfile index b4af54d35..5d19b2d99 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,7 +34,7 @@ RUN dpkg --add-architecture i386 && apt-get update && \ libbsd-dev libpixman-1-dev \ libglib2.0-dev libglib2.0-dev:i386 python3-docutils libpng-dev \ gcc-multilib g++-multilib libgomp1 unzip libzstd-dev \ - libgmock-dev libgtest-dev rapidjson-dev libsoci-dev + libgmock-dev libgtest-dev rapidjson-dev libsoci-dev libcapstone-dev # The unzip and libgomp1 dependencies are needed to unzip and run binary Z3 # distributions diff --git a/Makefile b/Makefile index 63bec8325..d81cc1bed 100644 --- a/Makefile +++ b/Makefile @@ -109,13 +109,6 @@ CLANG_LLVM_RELEASE_URL=https://github.com/S2E/s2e/releases/download/v2.0.0/$(CLA KLEE_DIRS=$(foreach suffix,-debug -release -coverage,$(addsuffix $(suffix),klee)) -# Capstone variables -CAPSTONE_VERSION=4.0.2 -CAPSTONE_SRC=$(CAPSTONE_VERSION).tar.gz -CAPSTONE_BUILD_DIR=capstone-$(CAPSTONE_VERSION)-build -CAPSTONE_SRC_DIR=capstone-$(CAPSTONE_VERSION) -CAPSTONE_URL=https://github.com/aquynh/capstone/archive/$(CAPSTONE_SRC) - # Z3 variables Z3_VERSION=4.7.1 Z3_SRC=z3-$(Z3_VERSION).tar.gz @@ -218,12 +211,6 @@ $(Z3_BUILD_DIR): tar -zxf $(Z3_SRC) mkdir -p $(S2E_BUILD)/$(Z3_BUILD_DIR) -# Download Capstone -$(CAPSTONE_BUILD_DIR): - $(call DOWNLOAD,$(CAPSTONE_URL),$(CAPSTONE_SRC_DIR).tar.gz) - tar -zxf $(CAPSTONE_SRC_DIR).tar.gz - mkdir -p $(S2E_BUILD)/$(CAPSTONE_BUILD_DIR) - $(LIBDWARF_BUILD_DIR): $(call DOWNLOAD,$(LIBDWARF_URL),$(S2E_BUILD)/$(LIBDWARF_BUILD_DIR).tar.gz) tar -Jxf $(S2E_BUILD)/$(LIBDWARF_BUILD_DIR).tar.gz @@ -294,27 +281,6 @@ stamps/z3: stamps/z3-binary touch $@ endif -############ -# Capstone # -############ - -CAPSTONE_CONFIGURE_FLAGS = -DCMAKE_INSTALL_PREFIX=$(S2E_PREFIX) \ - -DCMAKE_C_COMPILER=$(CLANG_CC) \ - -DCMAKE_CXX_COMPILER=$(CLANG_CXX) \ - -DCMAKE_C_FLAGS="-fno-omit-frame-pointer -fPIC" \ - -DCMAKE_CXX_FLAGS="-fno-omit-frame-pointer -fPIC" \ - -G "Unix Makefiles" - -stamps/capstone-configure: stamps/llvm-release-make $(CAPSTONE_BUILD_DIR) - cd $(CAPSTONE_BUILD_DIR) && \ - cmake $(CAPSTONE_CONFIGURE_FLAGS) $(S2E_BUILD)/$(CAPSTONE_SRC_DIR) - touch $@ - -stamps/capstone-make: stamps/capstone-configure - $(MAKE) -C $(CAPSTONE_BUILD_DIR) - $(MAKE) -C $(CAPSTONE_BUILD_DIR) install - touch $@ - ############ # libdwarf # ############ @@ -522,8 +488,6 @@ LIBS2E_CONFIGURE_FLAGS = --with-cc=$(CLANG_CC) --with-s2e-guest-incdir=$(S2E_SRC)/guest/common/include \ --with-z3-incdir=$(S2E_PREFIX)/include \ --with-z3-libdir=$(S2E_PREFIX)/lib \ - --with-capstone-incdir=$(S2E_PREFIX)/include \ - --with-capstone-libdir=$(S2E_PREFIX)/lib \ --with-libtcg-src=$(S2E_SRC)/libtcg \ --with-libcpu-src=$(S2E_SRC)/libcpu \ --with-libs2ecore-src=$(S2E_SRC)/libs2ecore \ @@ -550,7 +514,7 @@ LIBS2E_RELEASE_FLAGS = --with-llvm=$(LLVM_BUILD)/llvm-release stamps/libs2e-debug-configure: $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/libs2e) stamps/libs2e-debug-configure: stamps/lua-make stamps/libvmi-debug-install \ stamps/klee-debug-make stamps/libfsigc++-debug-make \ - stamps/libq-debug-make stamps/libcoroutine-debug-make stamps/capstone-make \ + stamps/libq-debug-make stamps/libcoroutine-debug-make \ stamps/klee-coverage-make stamps/libs2e-debug-configure: CONFIGURE_COMMAND = $(S2E_SRC)/libs2e/configure \ $(LIBS2E_CONFIGURE_FLAGS) \ @@ -559,7 +523,7 @@ stamps/libs2e-debug-configure: CONFIGURE_COMMAND = $(S2E_SRC)/libs2e/configure stamps/libs2e-release-configure: $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/libs2e) stamps/libs2e-release-configure: stamps/lua-make stamps/libvmi-release-install \ stamps/klee-release-make stamps/libfsigc++-release-make \ - stamps/libq-release-make stamps/libcoroutine-release-make stamps/capstone-make + stamps/libq-release-make stamps/libcoroutine-release-make stamps/libs2e-release-configure: CONFIGURE_COMMAND = $(S2E_SRC)/libs2e/configure \ $(LIBS2E_CONFIGURE_FLAGS) \ diff --git a/libcpu/CMakeLists.txt b/libcpu/CMakeLists.txt index 4b67eb79e..2bd37bb4b 100644 --- a/libcpu/CMakeLists.txt +++ b/libcpu/CMakeLists.txt @@ -23,6 +23,8 @@ configure_file(LIBCPUConfig.cmake.in ${CMAKE_CONFIG_FILE} @ONLY) find_package(PkgConfig REQUIRED) pkg_check_modules(GLIB_PKG glib-2.0) +pkg_check_modules(CAPSTONE REQUIRED capstone) + find_package(LIBQ REQUIRED) message(STATUS "Found libq ${LIBQ_PACKAGE_VERSION}") @@ -107,7 +109,7 @@ endforeach() include_directories(${GLIB_PKG_INCLUDE_DIRS} ${LIBQ_INCLUDE_DIR} - ${CAPSTONE_INCLUDE_DIR} + ${CAPSTONE_INCLUDE_DIRS} ${LIBTCG_INCLUDE_DIR} ${HOST_INCLUDE_DIR} ${TARGET_INCLUDE_DIR} diff --git a/libs2e/CMakeLists.txt b/libs2e/CMakeLists.txt index 42caa167e..854f9c5fc 100644 --- a/libs2e/CMakeLists.txt +++ b/libs2e/CMakeLists.txt @@ -44,6 +44,8 @@ find_package(PkgConfig REQUIRED) pkg_check_modules(GLIB_PKG glib-2.0) include_directories(${GLIB_PKG_INCLUDE_DIRS}) +pkg_check_modules (CAPSTONE REQUIRED capstone) + include(FindProtobuf) find_package(Protobuf REQUIRED) diff --git a/libs2e/configure b/libs2e/configure index 779b42374..ada6be307 100755 --- a/libs2e/configure +++ b/libs2e/configure @@ -42,8 +42,6 @@ echo " --with-libs2ecore-src=PATH Path to libs2ecore source" echo " --with-libs2eplugins-src=PATH Path to libs2eplugins source" echo " --with-z3-incdir=PATH Z3 include directory" echo " --with-z3-libdir=PATH Z3 library directory" -echo " --with-capstone-incdir=PATH Capstone include directory" -echo " --with-capstone-libdir=PATH Capstone lib directory" echo " --enable-debug Compile library with debug information" echo " --with-s2e-guest-incdir=PATH Path to S2E guest headers" } @@ -98,14 +96,6 @@ for opt do Z3_LIBDIR="$optarg" ;; - --with-capstone-incdir=*) - CAPSTONE_INCDIR="$optarg" - ;; - - --with-capstone-libdir=*) - CAPSTONE_LIBDIR="$optarg" - ;; - --with-fsigc++*) FSIGCXX_DIR="$optarg" ;; @@ -176,18 +166,6 @@ if [ ! -e "$Z3_LIBDIR/libz3.a" ]; then exit 1 fi -if [ ! -e "$CAPSTONE_INCDIR/capstone/xcore.h" ]; then - echo "Cannot find Capstone header files in $CAPSTONE_INCDIR" - print_usage - exit 1 -fi - -if [ ! -e "$CAPSTONE_LIBDIR/libcapstone.a" ]; then - echo "Cannot find Capstone library files in $CAPSTONE_LIBDIR" - print_usage - exit 1 -fi - rm -f config.log echo "# libs2e configured with:" >> config.log printf " '%s'" "$0" "$@" >> config.log @@ -278,7 +256,6 @@ cmake -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" \ -DTARGET_INCLUDE_DIR="$(cd $(pwd)/../ && echo $(pwd))" \ -DS2EGUEST_INCLUDE_DIR=$S2EGUEST_INCDIR \ -DLIBQ_DIR=$LIBQ_DIR \ - -DCAPSTONE_INCLUDE_DIR=$CAPSTONE_INCDIR \ -DWITH_TARGET="$target" \ -DCONFIG_DATE="$(date)" \ -DCONFIG_LIBCPU_DATADIR="$BUILD_DIR/$target" \ @@ -361,7 +338,6 @@ cmake -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" \ -DLUA_DIR="$LIBLUA_LIB" \ -DFSIGCXX_DIR="$FSIGCXX_DIR" \ -DZ3_DIR="$Z3_LIBDIR" \ - -DCAPSTONE_LIB_DIR=$CAPSTONE_LIBDIR \ -DWITH_TARGET="$target" \ "$SRC_DIR" diff --git a/libs2e/src/CMakeLists.txt b/libs2e/src/CMakeLists.txt index a07ce2f45..5e0085127 100644 --- a/libs2e/src/CMakeLists.txt +++ b/libs2e/src/CMakeLists.txt @@ -64,7 +64,7 @@ if(WITH_TARGET MATCHES "s2e") boost_regex) endif() -set(LIBS ${LIBS} ${LIBCOROUTINE_LIBRARY_DIR}/libcoroutine.a ${FSIGCXX_LIBRARY_DIR}/libfsigc++.a ${LIBQ_LIBRARY_DIR}/libq.a ${CAPSTONE_LIB_DIR}/libcapstone.a pthread glib-2.0 bsd dl) +set(LIBS ${LIBS} ${LIBCOROUTINE_LIBRARY_DIR}/libcoroutine.a ${FSIGCXX_LIBRARY_DIR}/libfsigc++.a ${LIBQ_LIBRARY_DIR}/libq.a ${CAPSTONE_LIBRARIES} pthread glib-2.0 bsd dl) target_link_libraries(tests2e PUBLIC ${LIBCOROUTINE_LIBRARY_DIR}/libcoroutine.a pthread glib-2.0) target_link_libraries(s2e ${LIBS})