Skip to content

Commit

Permalink
makefile: use system capstone
Browse files Browse the repository at this point in the history
Signed-off-by: Vitaly Chipounov <[email protected]>
  • Loading branch information
vitalych committed Apr 14, 2024
1 parent a0edcd4 commit b67bfe4
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 2 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 #
############
Expand Down Expand Up @@ -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 \
Expand All @@ -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) \
Expand All @@ -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) \
Expand Down
4 changes: 3 additions & 1 deletion libcpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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}
Expand Down
2 changes: 2 additions & 0 deletions libs2e/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
24 changes: 0 additions & 24 deletions libs2e/configure
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -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"
;;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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" \
Expand Down Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion libs2e/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit b67bfe4

Please sign in to comment.