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

Use system packages #95

Merged
merged 4 commits into from
Apr 20, 2024
Merged
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
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
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
17 changes: 2 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ FROM ubuntu:22.04

# Install build dependencies
RUN dpkg --add-architecture i386 && apt-get update && \
apt-get -y install ca-certificates build-essential curl wget texinfo flex bison \
apt-get -y install ca-certificates build-essential cmake curl wget texinfo flex bison \
python-is-python3 python3-dev python3-venv python3-distro mingw-w64 lsb-release \
autoconf libtool libprotobuf-dev protobuf-compiler protobuf-c-compiler \
libdwarf-dev libelf-dev libelf-dev:i386 \
Expand All @@ -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
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 All @@ -47,12 +47,6 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get install -y gcc-9 g++-9
# Install S2E git
RUN apt-get -y install git

# CMake 3.13.4 or higher is required to build LLVM-13 from source.
# Ubuntu 18.04 comes with cmake 3.10.2
# Install the latest cmake (as of this writing)
RUN wget -O cmake.sh https://github.com/Kitware/CMake/releases/download/v3.23.1/cmake-3.23.1-Linux-x86_64.sh && \
sh ./cmake.sh --prefix=/usr/local --skip-license

# Build LLVM first (to avoid rebuilding it for every change)
RUN mkdir s2e
RUN mkdir s2e-build
Expand All @@ -65,19 +59,12 @@ RUN cd s2e-build && \
# Be explicit about not building Z3 from source, even though its default
ENV USE_Z3_BINARY=yes

# Build S2E dependencies
RUN cd s2e-build && \
make -f ../s2e/Makefile S2E_PREFIX=/opt/s2e stamps/soci-make

RUN cd s2e-build && \
make -f ../s2e/Makefile S2E_PREFIX=/opt/s2e stamps/z3

RUN cd s2e-build && \
make -f ../s2e/Makefile S2E_PREFIX=/opt/s2e stamps/libdwarf-make

RUN cd s2e-build && \
make -f ../s2e/Makefile S2E_PREFIX=/opt/s2e stamps/rapidjson-make

# Make the S2E codebase available in the container
COPY . s2e/

Expand Down
114 changes: 6 additions & 108 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 All @@ -131,27 +124,13 @@ LUA_VERSION=5.3.4
LUA_SRC=lua-$(LUA_VERSION).tar.gz
LUA_DIR=lua-$(LUA_VERSION)

# SOCI variables
SOCI_SRC_DIR=soci-src
SOCI_BUILD_DIR=soci
SOCI_GIT_REV=438e354
SOCI_GIT_URL=https://github.com/SOCI/soci.git

# libdwarf
# We don't use the one that ships with the distro because we need
# the latest features (PE file support mostly).
LIBDWARF_URL=https://www.prevanders.net/libdwarf-0.9.1.tar.xz
LIBDWARF_SRC_DIR=libdwarf-0.9.1
LIBDWARF_BUILD_DIR=libdwarf

# rapidjson
# We don't use the one that ships with the distro because we need
# the latest features.
RAPIDJSON_GIT_URL=https://github.com/Tencent/rapidjson.git
RAPIDJSON_GIT_REV=fd3dc29a5c2852df569e1ea81dbde2c412ac5051
RAPIDJSON_SRC_DIR=rapidjson
RAPIDJSON_BUILD_DIR=rapidjson-build


###########
# Targets #
Expand Down Expand Up @@ -232,28 +211,11 @@ $(Z3_BUILD_DIR):
tar -zxf $(Z3_SRC)
mkdir -p $(S2E_BUILD)/$(Z3_BUILD_DIR)

# Download SOCI
$(SOCI_BUILD_DIR):
git clone $(SOCI_GIT_URL) $(SOCI_SRC_DIR)
cd $(SOCI_SRC_DIR) && git checkout $(SOCI_GIT_REV)
mkdir -p $(S2E_BUILD)/$(SOCI_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
mkdir -p $(S2E_BUILD)/$(LIBDWARF_BUILD_DIR)

$(RAPIDJSON_BUILD_DIR):
git clone $(RAPIDJSON_GIT_URL) $(RAPIDJSON_SRC_DIR)
cd $(RAPIDJSON_SRC_DIR) && git checkout $(RAPIDJSON_GIT_REV)
mkdir -p $(S2E_BUILD)/$(RAPIDJSON_BUILD_DIR)

########
# LLVM #
########
Expand All @@ -271,26 +233,6 @@ CLANG_CC=$(S2E_BUILD)/llvm-release/bin/clang
CLANG_CXX=$(S2E_BUILD)/llvm-release/bin/clang++
CLANG_LIB=$(S2E_BUILD)/llvm-release/lib

########
# SOCI #
########

SOCI_CONFIGURE_FLAGS = -DCMAKE_INSTALL_PREFIX=$(S2E_PREFIX) \
-DCMAKE_C_COMPILER=$(CLANG_CC) \
-DCMAKE_CXX_COMPILER=$(CLANG_CXX) \
-DSOCI_TESTS=Off \
-DCMAKE_C_FLAGS="-fPIC" \
-G "Unix Makefiles"

stamps/soci-configure: stamps/llvm-release-make $(SOCI_BUILD_DIR)
stamps/soci-configure: CONFIGURE_COMMAND = cmake $(SOCI_CONFIGURE_FLAGS) \
$(S2E_BUILD)/$(SOCI_SRC_DIR)

stamps/soci-make: stamps/soci-configure
$(MAKE) -C $(SOCI_BUILD_DIR)
$(MAKE) -C $(SOCI_BUILD_DIR) install
touch $@

######
# Z3 #
######
Expand Down Expand Up @@ -339,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 All @@ -374,27 +295,6 @@ stamps/libdwarf-make: stamps/libdwarf-configure
$(MAKE) -C $(LIBDWARF_BUILD_DIR) install
touch $@

#############
# rapidjson #
#############

RAPIDJSON_CONFIGURE_FLAGS = -DCMAKE_INSTALL_PREFIX=$(S2E_PREFIX) \
-DCMAKE_C_FLAGS="$(CFLAGS_ARCH) -fno-omit-frame-pointer -fPIC" \
-DCMAKE_C_COMPILER=$(CLANG_CC) \
-DCMAKE_CXX_COMPILER=$(CLANG_CXX) \
-DRAPIDJSON_BUILD_TESTS=OFF


stamps/rapidjson-configure: stamps/llvm-release-make $(RAPIDJSON_BUILD_DIR)
cd $(RAPIDJSON_BUILD_DIR) && \
cmake $(RAPIDJSON_CONFIGURE_FLAGS) $(S2E_BUILD)/$(RAPIDJSON_SRC_DIR)
touch $@

stamps/rapidjson-make: stamps/rapidjson-configure
$(MAKE) -C $(RAPIDJSON_BUILD_DIR) install
touch $@


#######
# Lua #
#######
Expand Down Expand Up @@ -461,14 +361,14 @@ LIBVMI_COMMON_FLAGS = -DCMAKE_INSTALL_PREFIX=$(S2E_PREFIX) \
-DCMAKE_C_FLAGS="$(CFLAGS_ARCH) -fPIC" \
-G "Unix Makefiles"

stamps/libvmi-debug-configure: stamps/llvm-debug-make stamps/libdwarf-make stamps/rapidjson-make $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/libvmi)
stamps/libvmi-debug-configure: stamps/llvm-debug-make stamps/libdwarf-make $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/libvmi)
stamps/libvmi-debug-configure: CONFIGURE_COMMAND = cmake $(LIBVMI_COMMON_FLAGS) \
-DLLVM_DIR=$(LLVM_BUILD)/llvm-debug/lib/cmake/llvm \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS="$(CXXFLAGS_DEBUG) -fPIC" \
$(S2E_SRC)/libvmi

stamps/libvmi-release-configure: stamps/llvm-release-make stamps/libdwarf-make stamps/rapidjson-make $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/libvmi)
stamps/libvmi-release-configure: stamps/llvm-release-make stamps/libdwarf-make $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/libvmi)
stamps/libvmi-release-configure: CONFIGURE_COMMAND = cmake $(LIBVMI_COMMON_FLAGS) \
-DLLVM_DIR=$(LLVM_BUILD)/llvm-release/lib/cmake/llvm \
-DCMAKE_BUILD_TYPE=$(RELEASE_BUILD_TYPE) \
Expand Down Expand Up @@ -588,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 @@ -615,17 +513,17 @@ 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/soci-make stamps/libfsigc++-debug-make \
stamps/libq-debug-make stamps/libcoroutine-debug-make stamps/capstone-make \
stamps/klee-debug-make stamps/libfsigc++-debug-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) \
$(LIBS2E_DEBUG_FLAGS)

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/soci-make stamps/libfsigc++-release-make \
stamps/libq-release-make stamps/libcoroutine-release-make stamps/capstone-make
stamps/klee-release-make stamps/libfsigc++-release-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
Loading