diff --git a/build-scripts/.clang-format b/build-scripts/.clang-format new file mode 100644 index 00000000..eba62db8 --- /dev/null +++ b/build-scripts/.clang-format @@ -0,0 +1,94 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlinesLeft: true +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +ForEachMacros: [ foreach, foreach2, Q_FOREACH, BOOST_FOREACH, QLIST_FOREACH, QTAILQ_FOREACH ] +IncludeCategories: + - Regex: '^(<|"s2e/)' + Priority: 1 + - Regex: '^(<|"(llvm|klee)/)' + Priority: 2 + - Regex: '.*' + Priority: 3 +IncludeIsMainRegex: '$' +IndentCaseLabels: true +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 4 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +ReflowComments: true +SortIncludes: true +SpaceAfterCStyleCast: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 8 +UseTab: Never +... diff --git a/build-scripts/.gitignore b/build-scripts/.gitignore new file mode 100644 index 00000000..83b35fed --- /dev/null +++ b/build-scripts/.gitignore @@ -0,0 +1,3 @@ +s2e +s2e-env +*.pyc diff --git a/build-scripts/Dockerfile b/build-scripts/Dockerfile new file mode 100644 index 00000000..09718236 --- /dev/null +++ b/build-scripts/Dockerfile @@ -0,0 +1,71 @@ +# Copyright (C) 2017-2019, Cyberhaven +# All rights reserved. +# +# Licensed under the Cyberhaven Research License Agreement. + +# Installs S2E and its associated libraries and tools to /opt/s2e + +FROM ubuntu:18.04 + +# Use local mirrors if possible +RUN sed -i '1ideb mirror://mirrors.ubuntu.com/mirrors.txt xenial main restricted' /etc/apt/sources.list && \ + sed -i '1ideb mirror://mirrors.ubuntu.com/mirrors.txt xenial-updates main restricted' /etc/apt/sources.list && \ + sed -i '1ideb mirror://mirrors.ubuntu.com/mirrors.txt xenial-security main restricted' /etc/apt/sources.list + +# Install build dependencies +RUN dpkg --add-architecture i386 && apt-get update && \ + apt-get -y install build-essential cmake wget texinfo flex bison \ + python-dev mingw-w64 lsb-release + +# Install S2E dependencies +RUN apt-get update && apt-get -y install libdwarf-dev libelf-dev libelf-dev:i386 \ + libboost-dev zlib1g-dev libjemalloc-dev nasm pkg-config \ + libmemcached-dev libpq-dev libc6-dev-i386 binutils-dev \ + libboost-system-dev libboost-serialization-dev libboost-regex-dev \ + libbsd-dev libpixman-1-dev \ + libglib2.0-dev libglib2.0-dev:i386 python-docutils libpng12-dev gcc-multilib g++-multilib + +# Install S2E git +RUN apt-get -y install git + +# Build LLVM first (to avoid rebuilding it for every change) +RUN mkdir s2e +RUN mkdir s2e-build +COPY build-scripts/Makefile s2e/ +COPY build-scripts/determine_clang_binary_suffix.py s2e/ +RUN cd s2e-build && \ + make -f ../s2e/Makefile S2E_PREFIX=/opt/s2e stamps/clang-binary + +RUN cd s2e-build && \ + make -f ../s2e/Makefile S2E_PREFIX=/opt/s2e stamps/llvm-release-make + +# 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-make + +RUN cd s2e-build && \ + make -f ../s2e/Makefile S2E_PREFIX=/opt/s2e stamps/protobuf-make + +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/ + +# Build and install everything else +RUN cd s2e-build && \ + make -f ../s2e/Makefile S2E_PREFIX=/opt/s2e install + +# Install s2e-env +RUN apt-get -y install python-pip && \ + cd s2e/s2e-env && \ + pip install --process-dependency-links . + +# Don't keep sources and build files +RUN rm -rf s2e-build s2e diff --git a/build-scripts/Dockerfile.dist b/build-scripts/Dockerfile.dist new file mode 100644 index 00000000..0833864a --- /dev/null +++ b/build-scripts/Dockerfile.dist @@ -0,0 +1,39 @@ +# Copyright (C) 2017-2019, Cyberhaven +# All rights reserved. +# +# Licensed under the Cyberhaven Research License Agreement. + +FROM ubuntu:18.04 +MAINTAINER Vitaly Chipounov + +RUN sed -i '1ideb mirror://mirrors.ubuntu.com/mirrors.txt xenial main restricted' /etc/apt/sources.list && \ + sed -i '1ideb mirror://mirrors.ubuntu.com/mirrors.txt xenial-updates main restricted' /etc/apt/sources.list && \ + sed -i '1ideb mirror://mirrors.ubuntu.com/mirrors.txt xenial-security main restricted' /etc/apt/sources.list + +# i386 packages are required by IDA Pro, they are included here for convenience. +# You must provide your own copy of IDA Pro. +RUN dpkg --add-architecture i386 && apt-get update + +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y \ + git netcat nano apport psmisc vim p7zip-full unzip \ + python python-dev python-pip python-virtualenv \ + wget libsvn1 libcurl3 gdb python2.7-dbg libssl-dev \ + libstdc++6:i386 libpython2.7:i386 lib32ncurses5 lib32ncurses5-dev \ + libncurses5-dev libx32ncurses5-dev libncurses5-dev:i386 \ + libxml2-dev libicu-dev libxslt1-dev libffi-dev \ + lsof psmisc libboost-system1.65.1 libboost-serialization1.65.1 libboost-regex1.65.1 \ + libmemcached11 libgettextpo0 libelf1 libelf1:i386 libjemalloc1 \ + libpcre3 libpcre3-dev libpcre3:i386 \ + liblua5.1-0 liblua5.2-0 libsigc++-2.0-dev jq libpng12-0 \ + python-yaml python-matplotlib python-lxml python-pip sudo && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + libc6-dev-i386 lib32stdc++-4.8-dev time \ + $(apt-cache depends qemu-system-x86 | grep Depends | \ + sed "s/.*ends:\ //" | grep -v '<' | tr '\n' ' ') + +# Copy pre-compiled S2E files +COPY s2e /opt/s2e + +# Install s2e-env +COPY s2e-env /s2e-env +RUN cd /s2e-env && pip install --process-dependency-links . diff --git a/build-scripts/Makefile b/build-scripts/Makefile new file mode 100644 index 00000000..60384660 --- /dev/null +++ b/build-scripts/Makefile @@ -0,0 +1,880 @@ +# Environment variables: +# +# PARALLEL=no +# Turn off build parallelization. +# +# BUILD_ARCH=corei7, etc... +# Overrides the default clang -march settings. +# Useful to build S2E in VirtualBox or in other VMs that do not support +# some advanced instruction sets. +# +# LLVM_BUILD=... +# Contains llvm-release, llvm-debug, and llvm source folders +# Can be used to avoid rebuilding clang/llvm for every branch of S2E +# + +# Check the build directory +ifeq ($(shell ls libs2e/src/libs2e.c 2>&1),libs2e/src/libs2e.c) + $(error You should not run make in the S2E source directory!) +endif + +############# +# Variables # +############# + +# S2E variables +BUILD_SCRIPTS_SRC?=$(dir $(realpath $(lastword $(MAKEFILE_LIST)))) +S2E_SRC?=$(realpath $(BUILD_SCRIPTS_SRC)/../) +S2E_PREFIX?=$(CURDIR)/opt +S2E_BUILD:=$(CURDIR) + +# Either choose Release or RelWithDebInfo +RELEASE_BUILD_TYPE=RelWithDebInfo + +# corei7 avoids instructions not supported by VirtualBox. Use "native" instead +# to optimize for your current CPU. +BUILD_ARCH?=x86-64 + +# Set the number of parallel build jobs +OS:=$(shell uname) +ifeq ($(PARALLEL), no) +JOBS:=1 +else ifeq ($(OS),Darwin) +JOBS:=$(patsubst hw.ncpu:%,%,$(shell sysctl hw.ncpu)) +else ifeq ($(OS),Linux) +JOBS:=$(shell grep -c ^processor /proc/cpuinfo) +endif + +MAKE:=make -j$(JOBS) + +FIND_SOURCE=$(shell find $(1) -name '*.cpp' -o -name '*.h' -o -name '*.c') +FIND_CONFIG_SOURCE=$(shell find $(1) -name 'configure' -o -name 'CMakeLists.txt' -o -name '*.in') + +CFLAGS_ARCH:=-march=$(BUILD_ARCH) -mno-sse4.1 +CXXFLAGS_ARCH:=-march=$(BUILD_ARCH) -mno-sse4.1 + +CXXFLAGS_DEBUG:=$(CXXFLAGS_ARCH) +CXXFLAGS_RELEASE:=$(CXXFLAGS_ARCH) + + +# TODO: figure out how to automatically get the latest version without +# having to update this URL. +GUEST_TOOLS_BINARIES_URL=https://github.com/S2E/guest-tools/releases/download/v2.0.0/ + +# LLVM variables +LLVM_BUILD?=$(S2E_BUILD) +ifeq ($(LLVM_BUILD),$(S2E_BUILD)) +LLVM_DIRS=llvm-release llvm-debug +endif + +LLVM_VERSION=3.9.1 +LLVM_SRC=llvm-$(LLVM_VERSION).src.tar.xz +LLVM_SRC_DIR=llvm-$(LLVM_VERSION).src +LLVM_SRC_URL = http://llvm.org/releases/$(LLVM_VERSION) + +# The Python script should only return a single word - the suffix of the Clang +# binary to download. If an error message is printed to stderr, the Makefile +# error will be triggered. +CLANG_BINARY_SUFFIX=$(shell python $(BUILD_SCRIPTS_SRC)/determine_clang_binary_suffix.py 2>&1) +ifneq ($(words $(CLANG_BINARY_SUFFIX)), 1) +$(error "Failed to determine Clang binary to download: $(CLANG_BINARY_SUFFIX)") +endif + +KLEE_QEMU_DIRS=$(foreach suffix,-debug -release,$(addsuffix $(suffix),klee qemu)) + +CLANG_BINARY_DIR=clang+llvm-$(LLVM_VERSION)-$(CLANG_BINARY_SUFFIX) +CLANG_BINARY=$(CLANG_BINARY_DIR).tar.xz + +CLANG_SRC=cfe-$(LLVM_VERSION).src.tar.xz +CLANG_SRC_DIR=cfe-$(LLVM_VERSION).src +CLANG_DEST_DIR=$(LLVM_SRC_DIR)/tools/clang + +COMPILER_RT_SRC=compiler-rt-$(LLVM_VERSION).src.tar.xz +COMPILER_RT_SRC_DIR=compiler-rt-$(LLVM_VERSION).src +COMPILER_RT_DEST_DIR=$(LLVM_SRC_DIR)/projects/compiler-rt + +# Capstone variables +CAPSTONE_VERSION=3.0.5 +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 +Z3_SRC_DIR=z3-z3-$(Z3_VERSION) +Z3_BUILD_DIR=z3 +Z3_URL=https://github.com/Z3Prover/z3 + +# Lua variables +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=f0c0d25a9160a237c9ef8eddf9f28651621192f3 +SOCI_GIT_URL=https://github.com/SOCI/soci.git + +# Google Test +GTEST_VERSION=1.8.0 +GTEST_SRC_DIR=$(S2E_BUILD)/googletest-release-$(GTEST_VERSION) +GTEST_URL=https://github.com/google/googletest/archive/release-$(GTEST_VERSION).tar.gz + +# 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-20190110.tar.gz +LIBDWARF_SRC_DIR=libdwarf-20190110 +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=e80257a924b701dcbf5f6e78a7ab47efff6073ac +RAPIDJSON_SRC_DIR=rapidjson +RAPIDJSON_BUILD_DIR=rapidjson-build + +# protobuf +# We build our own because the one on Ubuntu 16 crashes. +PROTOBUF_URL=https://github.com/protocolbuffers/protobuf/releases/download/v3.7.1/protobuf-cpp-3.7.1.tar.gz +PROTOBUF_SRC_DIR=protobuf-3.7.1 +PROTOBUF_BUILD_DIR=protobuf + + +########### +# Targets # +########### + +all: all-release guest-tools + +all-release: stamps/qemu-release-make stamps/libs2e-release-make stamps/tools-release-make stamps/decree-make +all-debug: stamps/qemu-debug-make stamps/libs2e-debug-make stamps/tools-debug-make stamps/decree-make + +guest-tools: stamps/guest-tools32-make stamps/guest-tools64-make +guest-tools-win: stamps/guest-tools32-win-make stamps/guest-tools64-win-make + +guest-tools-install: stamps/guest-tools32-install stamps/guest-tools64-install +guest-tools-win-install: stamps/guest-tools32-win-install stamps/guest-tools64-win-install + +install: all-release stamps/libs2e-release-install stamps/tools-release-install \ + stamps/libvmi-release-install stamps/decree-install guest-tools-install \ + guest-tools-win-install stamps/llvm-release-install +install-debug: all-debug stamps/libs2e-debug-install stamps/tools-debug-install \ + stamps/libvmi-debug-install stamps/decree-install guest-tools-install \ + guest-tools-win-install stamps/llvm-release-install + +# From https://stackoverflow.com/questions/4219255/how-do-you-get-the-list-of-targets-in-a-makefile +list: + @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | \ + awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | \ + sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs + +.PHONY: all all-debug all-release +.PHONY: clean distclean guestclean +.PHONY: list + +ALWAYS: + +$(KLEE_QEMU_DIRS) $(LLVM_DIRS) libq-debug libq-release \ +libfsigc++-debug libfsigc++-release libvmi-debug libvmi-release \ +libcoroutine-release libcoroutine-debug libs2e-debug libs2e-release \ +tools-debug tools-release \ +guest-tools32 guest-tools64 guest-tools32-win guest-tools64-win \ +decree stamps: + mkdir -p $@ + +stamps/%-configure: | % stamps + cd $* && $(CONFIGURE_COMMAND) + touch $@ + +stamps/%-make: + $(MAKE) -C $* $(BUILD_OPTS) + touch $@ + +############# +# Downloads # +############# + +ifeq ($(LLVM_BUILD),$(S2E_BUILD)) +# Download LLVM +$(LLVM_SRC) $(CLANG_SRC) $(COMPILER_RT_SRC) $(CLANG_BINARY): + wget $(LLVM_SRC_URL)/$@ + +.INTERMEDIATE: $(CLANG_SRC_DIR) $(COMPILER_RT_SRC_DIR) $(CLANG_BINARY_DIR) + +$(LLVM_SRC_DIR): $(LLVM_SRC) $(CLANG_SRC_DIR) $(COMPILER_RT_SRC_DIR) + tar -xmf $< + mv $(CLANG_SRC_DIR) $(CLANG_DEST_DIR) + mv $(COMPILER_RT_SRC_DIR) $(COMPILER_RT_DEST_DIR) + +$(CLANG_SRC_DIR): $(CLANG_SRC) + tar -xmf $< + +$(COMPILER_RT_SRC_DIR): $(COMPILER_RT_SRC) + tar -xmf $< + +else +# Use the specified LLVM build folder, don't build LLVM +endif + +# Download Lua +$(LUA_SRC): + wget http://www.lua.org/ftp/$(LUA_SRC) + +$(LUA_DIR): | $(LUA_SRC) + tar -zxf $(LUA_SRC) + cp $(S2E_SRC)/lua/luaconf.h $(LUA_DIR)/src + +# Download Z3 +$(Z3_BUILD_DIR): + wget $(Z3_URL)/archive/$(Z3_SRC) + 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 GTest +$(GTEST_SRC_DIR): + cd $(S2E_BUILD) && wget -O $(GTEST_SRC_DIR).tar.gz $(GTEST_URL) + cd $(S2E_BUILD) && tar xzvf $(GTEST_SRC_DIR).tar.gz + +# Download Capstone +$(CAPSTONE_BUILD_DIR): + wget -O $(CAPSTONE_SRC_DIR).tar.gz $(CAPSTONE_URL) + tar -zxf $(CAPSTONE_SRC_DIR).tar.gz + mkdir -p $(S2E_BUILD)/$(CAPSTONE_BUILD_DIR) + +$(LIBDWARF_BUILD_DIR): + wget -O $(S2E_BUILD)/$(LIBDWARF_BUILD_DIR).tar.gz $(LIBDWARF_URL) + tar -zxf $(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) + +$(PROTOBUF_BUILD_DIR): + wget -O $(S2E_BUILD)/$(PROTOBUF_SRC_DIR).tar.gz $(PROTOBUF_URL) + tar -zxf $(S2E_BUILD)/$(PROTOBUF_SRC_DIR).tar.gz + mkdir -p $(S2E_BUILD)/$(PROTOBUF_BUILD_DIR) + +ifeq ($(LLVM_BUILD),$(S2E_BUILD)) + + +######## +# LLVM # +######## + +stamps/clang-binary: $(CLANG_BINARY) | stamps + tar -xmf $< + mkdir -p $(S2E_PREFIX) + cp -r $(CLANG_BINARY_DIR)/* $(S2E_PREFIX) + rm -r $(CLANG_BINARY_DIR)/* + touch $@ + +CLANG_CC = $(S2E_PREFIX)/bin/clang +CLANG_CXX = $(S2E_PREFIX)/bin/clang++ +CLANG_LIB = $(S2E_PREFIX)/lib + +LLVM_CONFIGURE_FLAGS = -DLLVM_TARGETS_TO_BUILD="X86" \ + -DLLVM_TARGET_ARCH="X86_64" \ + -DLLVM_INCLUDE_EXAMPLES=Off \ + -DLLVM_INCLUDE_DOCS=Off \ + -DLLVM_INCLUDE_TESTS=Off \ + -DLLVM_ENABLE_RTTI=On \ + -DLLVM_ENABLE_EH=On \ + -DLLVM_BINUTILS_INCDIR=/usr/include \ + -DCOMPILER_RT_BUILD_SANITIZERS=Off \ + -DENABLE_ASSERTIONS=On \ + -DCMAKE_C_COMPILER=$(CLANG_CC) \ + -DCMAKE_CXX_COMPILER=$(CLANG_CXX) \ + -DCMAKE_C_FLAGS="$(CFLAGS_ARCH)" \ + -G "Unix Makefiles" + +stamps/llvm-debug-configure: stamps/clang-binary $(LLVM_SRC_DIR) +stamps/llvm-debug-configure: CONFIGURE_COMMAND = cmake $(LLVM_CONFIGURE_FLAGS) \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_FLAGS="$(CXXFLAGS_DEBUG)" \ + $(LLVM_BUILD)/$(LLVM_SRC_DIR) + +stamps/llvm-release-configure: stamps/clang-binary $(LLVM_SRC_DIR) +stamps/llvm-release-configure: CONFIGURE_COMMAND = cmake $(LLVM_CONFIGURE_FLAGS) \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_CXX_FLAGS="$(CXXFLAGS_RELEASE)" \ + $(LLVM_BUILD)/$(LLVM_SRC_DIR) + +stamps/llvm-debug-make: stamps/llvm-debug-configure + +stamps/llvm-release-make: stamps/llvm-release-configure + +stamps/llvm-release-install: stamps/llvm-release-make + cp $(S2E_BUILD)/llvm-release/lib/LLVMgold.so $(S2E_PREFIX)/lib + +else +stamps/llvm-release-make: + echo "Won't build" +stamps/llvm-debug-make: + echo "Won't build" +stamps/llvm-release-install: + echo "Won't build" +endif + +######## +# SOCI # +######## + +SOCI_CONFIGURE_FLAGS = -DCMAKE_INSTALL_PREFIX=$(S2E_PREFIX) \ + -DCMAKE_C_COMPILER=$(CLANG_CC) \ + -DCMAKE_CXX_COMPILER=$(CLANG_CXX) \ + -DCMAKE_C_FLAGS="-fPIC" \ + -G "Unix Makefiles" + +stamps/soci-configure: stamps/clang-binary $(SOCI_BUILD_DIR) +stamps/soci-configure: CONFIGURE_COMMAND = cmake $(SOCI_CONFIGURE_FLAGS) \ + $(S2E_BUILD)/$(SOCI_SRC_DIR)/src + +stamps/soci-make: stamps/soci-configure + $(MAKE) -C $(SOCI_BUILD_DIR) + $(MAKE) -C $(SOCI_BUILD_DIR) install + touch $@ + +###### +# Z3 # +###### + +Z3_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" \ + -DBUILD_LIBZ3_SHARED=Off \ + -DUSE_OPENMP=Off \ + -G "Unix Makefiles" + +stamps/z3-configure: stamps/clang-binary $(Z3_BUILD_DIR) + cd $(Z3_SRC_DIR) && \ + python contrib/cmake/bootstrap.py create + cd $(Z3_BUILD_DIR) && \ + cmake $(Z3_CONFIGURE_FLAGS) $(S2E_BUILD)/$(Z3_SRC_DIR) + touch $@ + +stamps/z3-make: stamps/z3-configure + $(MAKE) -C $(Z3_BUILD_DIR) + $(MAKE) -C $(Z3_BUILD_DIR) install + touch $@ + +############ +# 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/clang-binary $(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 # +############ + +stamps/libdwarf-configure: stamps/clang-binary $(LIBDWARF_BUILD_DIR) + cd $(LIBDWARF_BUILD_DIR) && \ + CC=$(CLANG_CC) CXX=$(CLANG_CXX) $(S2E_BUILD)/$(LIBDWARF_SRC_DIR)/configure --prefix=$(S2E_PREFIX) + touch $@ + +stamps/libdwarf-make: stamps/libdwarf-configure + $(MAKE) -C $(LIBDWARF_BUILD_DIR) + $(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) \ + + +stamps/rapidjson-configure: stamps/clang-binary $(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 $@ + +############ +# protobuf # +############ + +stamps/protobuf-configure: stamps/clang-binary $(PROTOBUF_BUILD_DIR) + cd $(PROTOBUF_BUILD_DIR) && \ + CC=$(CLANG_CC) CXX=$(CLANG_CXX) CXXFLAGS=-fPIC CFLAGS=-fPIC $(S2E_BUILD)/$(PROTOBUF_SRC_DIR)/configure --prefix=$(S2E_PREFIX) + touch $@ + +stamps/protobuf-make: stamps/protobuf-configure + $(MAKE) -C $(PROTOBUF_BUILD_DIR) install + touch $@ + + +####### +# Lua # +####### + +stamps/lua-make: $(LUA_DIR) + sed -i 's/-lreadline//g' $(LUA_DIR)/src/Makefile + $(MAKE) -C $^ linux CFLAGS="-DLUA_USE_LINUX -O2 -g -fPIC" + touch $@ + +######## +# KLEE # +######## + +KLEE_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) \ + -DUSE_CMAKE_FIND_PACKAGE_LLVM=On \ + -DENABLE_UNIT_TESTS=On \ + -DGTEST_SRC_DIR=$(S2E_BUILD)/googletest-release-1.8.0 \ + -DENABLE_DOCS=Off \ + -DENABLE_SOLVER_Z3=On \ + -DZ3_INCLUDE_DIRS=$(S2E_PREFIX)/include \ + -DZ3_LIBRARIES=$(S2E_PREFIX)/lib/libz3.a + +stamps/klee-debug-configure: stamps/llvm-debug-make stamps/z3-make $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/klee) | $(GTEST_SRC_DIR) +stamps/klee-debug-configure: CONFIGURE_COMMAND = cmake $(KLEE_CONFIGURE_FLAGS) \ + -DCMAKE_BUILD_TYPE=Debug \ + -DLLVM_DIR=$(LLVM_BUILD)/llvm-debug/lib/cmake/llvm \ + -DCMAKE_CXX_FLAGS="$(CXXFLAGS_DEBUG) -fno-omit-frame-pointer -fPIC" \ + $(S2E_SRC)/klee + +stamps/klee-release-configure: stamps/llvm-release-make stamps/z3-make $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/klee) | $(GTEST_SRC_DIR) +stamps/klee-release-configure: CONFIGURE_COMMAND = cmake $(KLEE_CONFIGURE_FLAGS) \ + -DCMAKE_BUILD_TYPE=$(RELEASE_BUILD_TYPE) \ + -DLLVM_DIR=$(LLVM_BUILD)/llvm-release/lib/cmake/llvm \ + -DCMAKE_CXX_FLAGS="$(CXXFLAGS_RELEASE) -fno-omit-frame-pointer -fPIC" \ + $(S2E_SRC)/klee + +stamps/klee-debug-make: stamps/klee-debug-configure $(call FIND_SOURCE,$(S2E_SRC)/klee) + +stamps/klee-release-make: stamps/klee-release-configure $(call FIND_SOURCE,$(S2E_SRC)/klee) + +########## +# LibVMI # +########## + +LIBVMI_COMMON_FLAGS = -DCMAKE_INSTALL_PREFIX=$(S2E_PREFIX) \ + -DCMAKE_MODULE_PATH=$(S2E_SRC)/cmake \ + -DCMAKE_C_COMPILER=$(CLANG_CC) \ + -DCMAKE_CXX_COMPILER=$(CLANG_CXX) \ + -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: 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: CONFIGURE_COMMAND = cmake $(LIBVMI_COMMON_FLAGS) \ + -DLLVM_DIR=$(LLVM_BUILD)/llvm-release/lib/cmake/llvm \ + -DCMAKE_BUILD_TYPE=$(RELEASE_BUILD_TYPE) \ + -DCMAKE_CXX_FLAGS="$(CXXFLAGS_RELEASE) -fPIC" \ + $(S2E_SRC)/libvmi + +stamps/libvmi-debug-make: stamps/libvmi-debug-configure $(call FIND_SOURCE,$(S2E_SRC)/libvmi) + +stamps/libvmi-release-make: stamps/libvmi-release-configure $(call FIND_SOURCE,$(S2E_SRC)/libvmi) + +stamps/libvmi-debug-install: stamps/libvmi-debug-make + $(MAKE) -C libvmi-debug install + touch $@ + +stamps/libvmi-release-install: stamps/libvmi-release-make + $(MAKE) -C libvmi-release install + touch $@ + +############## +# libfsigc++ # +############## + +#TODO: factor out common flags + +LIBFSIGCXX_COMMON_FLAGS = -DCMAKE_MODULE_PATH=$(S2E_SRC)/cmake \ + -DCMAKE_C_COMPILER=$(CLANG_CC) \ + -DCMAKE_CXX_COMPILER=$(CLANG_CXX) \ + -DCMAKE_C_FLAGS="$(CFLAGS_ARCH)" \ + -G "Unix Makefiles" + +stamps/libfsigc++-debug-configure: stamps/clang-binary $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/libfsigc++) + +stamps/libfsigc++-debug-configure: CONFIGURE_COMMAND = cmake $(LIBFSIGCXX_COMMON_FLAGS) \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_FLAGS="$(CXXFLAGS_DEBUG)" \ + $(S2E_SRC)/libfsigc++ + + +stamps/libfsigc++-release-configure: stamps/clang-binary $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/libfsigc++) + +stamps/libfsigc++-release-configure: CONFIGURE_COMMAND = cmake $(LIBFSIGCXX_COMMON_FLAGS) \ + -DCMAKE_BUILD_TYPE=$(RELEASE_BUILD_TYPE) \ + -DCMAKE_CXX_FLAGS="$(CXXFLAGS_RELEASE)" \ + $(S2E_SRC)/libfsigc++ + +stamps/libfsigc++-debug-make: stamps/libfsigc++-debug-configure $(call FIND_SOURCE,$(S2E_SRC)/libfsigc++) + +stamps/libfsigc++-release-make: stamps/libfsigc++-release-configure $(call FIND_SOURCE,$(S2E_SRC)/libfsigc++) + +######## +# libq # +######## + +LIBQ_COMMON_FLAGS = -DCMAKE_MODULE_PATH=$(S2E_SRC)/cmake \ + -DCMAKE_C_COMPILER=$(CLANG_CC) \ + -DCMAKE_CXX_COMPILER=$(CLANG_CXX) \ + -DCMAKE_C_FLAGS="$(CFLAGS_ARCH)" \ + -G "Unix Makefiles" + +stamps/libq-debug-configure: stamps/clang-binary $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/libq) + +stamps/libq-debug-configure: CONFIGURE_COMMAND = cmake $(LIBQ_COMMON_FLAGS) \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_FLAGS="$(CXXFLAGS_DEBUG)" \ + $(S2E_SRC)/libq + + +stamps/libq-release-configure: stamps/clang-binary $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/libq) + +stamps/libq-release-configure: CONFIGURE_COMMAND = cmake $(LIBQ_COMMON_FLAGS) \ + -DCMAKE_BUILD_TYPE=$(RELEASE_BUILD_TYPE) \ + -DCMAKE_CXX_FLAGS="$(CXXFLAGS_RELEASE)" \ + $(S2E_SRC)/libq + +stamps/libq-debug-make: stamps/libq-debug-configure $(call FIND_SOURCE,$(S2E_SRC)/libq) + +stamps/libq-release-make: stamps/libq-release-configure $(call FIND_SOURCE,$(S2E_SRC)/libq) + +################ +# libcoroutine # +################ + +LIBCOROUTINE_COMMON_FLAGS = -DCMAKE_MODULE_PATH=$(S2E_SRC)/cmake \ + -DCMAKE_C_COMPILER=$(CLANG_CC) \ + -DCMAKE_CXX_COMPILER=$(CLANG_CXX) \ + -DCMAKE_C_FLAGS="$(CFLAGS_ARCH)" \ + -G "Unix Makefiles" + +stamps/libcoroutine-debug-configure: stamps/clang-binary $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/libcoroutine) + +stamps/libcoroutine-debug-configure: CONFIGURE_COMMAND = cmake $(LIBCOROUTINE_COMMON_FLAGS) \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_FLAGS="$(CXXFLAGS_DEBUG)" \ + $(S2E_SRC)/libcoroutine + + +stamps/libcoroutine-release-configure: stamps/clang-binary $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/libcoroutine) + +stamps/libcoroutine-release-configure: CONFIGURE_COMMAND = cmake $(LIBCOROUTINE_COMMON_FLAGS) \ + -DCMAKE_BUILD_TYPE=$(RELEASE_BUILD_TYPE) \ + -DCMAKE_CXX_FLAGS="$(CXXFLAGS_RELEASE)" \ + $(S2E_SRC)/libcoroutine + +stamps/libcoroutine-debug-make: stamps/libcoroutine-debug-configure $(call FIND_SOURCE,$(S2E_SRC)/libcoroutine) + +stamps/libcoroutine-release-make: stamps/libcoroutine-release-configure $(call FIND_SOURCE,$(S2E_SRC)/libcoroutine) + +######## +# QEMU # +######## + +QEMU_TARGETS=i386-softmmu,x86_64-softmmu + +QEMU_CONFIGURE_FLAGS = --prefix=$(S2E_PREFIX) \ + --target-list=$(QEMU_TARGETS) \ + --disable-smartcard \ + --disable-virtfs \ + --disable-xen \ + --disable-bluez \ + --disable-vde \ + --disable-libiscsi \ + --disable-docs \ + --disable-spice \ + $(EXTRA_QEMU_FLAGS) + +QEMU_DEBUG_FLAGS = --enable-debug + +QEMU_RELEASE_FLAGS = + +stamps/qemu-debug-configure: export CFLAGS:=$(CFLAGS_ARCH) -fno-omit-frame-pointer +stamps/qemu-debug-configure: export CXXFLAGS:=$(CXXFLAGS_RELEASE) -fno-omit-frame-pointer +stamps/qemu-debug-configure: CONFIGURE_COMMAND = $(S2E_SRC)/qemu/configure \ + $(QEMU_CONFIGURE_FLAGS) \ + $(QEMU_DEBUG_FLAGS) + +stamps/qemu-release-configure: CONFIGURE_COMMAND = $(S2E_SRC)/qemu/configure \ + $(QEMU_CONFIGURE_FLAGS) \ + $(QEMU_RELEASE_FLAGS) + +stamps/qemu-debug-make: stamps/qemu-debug-configure + $(MAKE) -C qemu-debug $(BUILD_OPTS) install + touch $@ + +stamps/qemu-release-make: stamps/qemu-release-configure + $(MAKE) -C qemu-release $(BUILD_OPTS) install + touch $@ + + +########## +# libs2e # +########## + +LIBS2E_CONFIGURE_FLAGS = --with-cc=$(CLANG_CC) \ + --with-cxx=$(CLANG_CXX) \ + --with-cflags=$(CFLAGS_ARCH) \ + --with-liblua=$(S2E_BUILD)/$(LUA_DIR)/src \ + --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 \ + --with-libs2eplugins-src=$(S2E_SRC)/libs2eplugins \ + --prefix=$(S2E_PREFIX) \ + $(EXTRA_QEMU_FLAGS) + +LIBS2E_DEBUG_FLAGS = --with-llvm=$(LLVM_BUILD)/llvm-debug \ + --with-klee=$(S2E_BUILD)/klee-debug \ + --with-libvmi=$(S2E_BUILD)/libvmi-debug \ + --with-fsigc++=$(S2E_BUILD)/libfsigc++-debug \ + --with-libq=$(S2E_BUILD)/libq-debug \ + --with-libcoroutine=$(S2E_BUILD)/libcoroutine-debug \ + --with-cxxflags="$(CXXFLAGS_DEBUG)" \ + --enable-debug + +LIBS2E_RELEASE_FLAGS = --with-llvm=$(LLVM_BUILD)/llvm-release \ + --with-klee=$(S2E_BUILD)/klee-release \ + --with-libvmi=$(S2E_BUILD)/libvmi-release \ + --with-fsigc++=$(S2E_BUILD)/libfsigc++-release \ + --with-libq=$(S2E_BUILD)/libq-release \ + --with-libcoroutine=$(S2E_BUILD)/libcoroutine-release \ + --with-cxxflags="$(CXXFLAGS_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/protobuf-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/protobuf-make +stamps/libs2e-release-configure: CONFIGURE_COMMAND = $(S2E_SRC)/libs2e/configure \ + $(LIBS2E_CONFIGURE_FLAGS) \ + $(LIBS2E_RELEASE_FLAGS) + +stamps/libs2e-debug-make: stamps/libs2e-debug-configure \ + $(call FIND_SOURCE,$(S2E_SRC)/libs2e) \ + $(call FIND_SOURCE,$(S2E_SRC)/libcpu) \ + $(call FIND_SOURCE,$(S2E_SRC)/libtcg) \ + $(call FIND_SOURCE,$(S2E_SRC)/libs2ecore) \ + $(call FIND_SOURCE,$(S2E_SRC)/libs2eplugins) + +stamps/libs2e-release-make: stamps/libs2e-release-configure \ + $(call FIND_SOURCE,$(S2E_SRC)/libs2e) \ + $(call FIND_SOURCE,$(S2E_SRC)/libcpu) \ + $(call FIND_SOURCE,$(S2E_SRC)/libtcg) \ + $(call FIND_SOURCE,$(S2E_SRC)/libs2ecore) \ + $(call FIND_SOURCE,$(S2E_SRC)/libs2eplugins) + +stamps/libs2e-release-install: stamps/libs2e-release-make + mkdir -p $(S2E_PREFIX)/share/libs2e/ + + install $(S2E_BUILD)/libs2e-release/x86_64-softmmu/libs2e.so $(S2E_PREFIX)/share/libs2e/libs2e-x86_64.so + install $(S2E_BUILD)/libs2e-release/i386-softmmu/libs2e.so $(S2E_PREFIX)/share/libs2e/libs2e-i386.so + + install $(S2E_BUILD)/libs2e-release/x86_64-s2e-softmmu/op_helper.bc.x86_64 $(S2E_PREFIX)/share/libs2e/ + install $(S2E_BUILD)/libs2e-release/x86_64-s2e-softmmu/libs2e.so $(S2E_PREFIX)/share/libs2e/libs2e-x86_64-s2e.so + + install $(S2E_BUILD)/libs2e-release/i386-s2e-softmmu/op_helper.bc.i386 $(S2E_PREFIX)/share/libs2e/ + install $(S2E_BUILD)/libs2e-release/i386-s2e-softmmu/libs2e.so $(S2E_PREFIX)/share/libs2e/libs2e-i386-s2e.so + + install $(S2E_BUILD)/libs2e-release/x86_64-s2e_sp-softmmu/op_helper_sp.bc.x86_64 $(S2E_PREFIX)/share/libs2e/ + install $(S2E_BUILD)/libs2e-release/x86_64-s2e_sp-softmmu/libs2e.so $(S2E_PREFIX)/share/libs2e/libs2e-x86_64-s2e_sp.so + + install $(S2E_BUILD)/libs2e-release/i386-s2e_sp-softmmu/op_helper_sp.bc.i386 $(S2E_PREFIX)/share/libs2e/ + install $(S2E_BUILD)/libs2e-release/i386-s2e_sp-softmmu/libs2e.so $(S2E_PREFIX)/share/libs2e/libs2e-i386-s2e_sp.so + + install $(S2E_SRC)/libs2eplugins/src/s2e/Plugins/Support/KeyValueStore.py $(S2E_PREFIX)/bin/ + cd $(S2E_SRC) && if [ -d ".git" ]; then git rev-parse HEAD > $(S2E_PREFIX)/share/libs2e/git-sha1; fi + + touch $@ + +stamps/libs2e-debug-install: stamps/libs2e-debug-make + mkdir -p $(S2E_PREFIX)/share/libs2e/ + + install $(S2E_BUILD)/libs2e-debug/x86_64-softmmu/libs2e.so $(S2E_PREFIX)/share/libs2e/libs2e-x86_64.so + + install $(S2E_BUILD)/libs2e-debug/i386-softmmu/libs2e.so $(S2E_PREFIX)/share/libs2e/libs2e-i386.so + + install $(S2E_BUILD)/libs2e-debug/x86_64-s2e-softmmu/op_helper.bc.x86_64 $(S2E_PREFIX)/share/libs2e/ + install $(S2E_BUILD)/libs2e-debug/x86_64-s2e-softmmu/libs2e.so $(S2E_PREFIX)/share/libs2e/libs2e-x86_64-s2e.so + + install $(S2E_BUILD)/libs2e-debug/i386-s2e-softmmu/op_helper.bc.i386 $(S2E_PREFIX)/share/libs2e/ + install $(S2E_BUILD)/libs2e-debug/i386-s2e-softmmu/libs2e.so $(S2E_PREFIX)/share/libs2e/libs2e-i386-s2e.so + + install $(S2E_BUILD)/libs2e-debug/x86_64-s2e_sp-softmmu/op_helper_sp.bc.x86_64 $(S2E_PREFIX)/share/libs2e/ + install $(S2E_BUILD)/libs2e-debug/x86_64-s2e_sp-softmmu/libs2e.so $(S2E_PREFIX)/share/libs2e/libs2e-x86_64-s2e_sp.so + + install $(S2E_BUILD)/libs2e-debug/i386-s2e_sp-softmmu/op_helper_sp.bc.i386 $(S2E_PREFIX)/share/libs2e/ + install $(S2E_BUILD)/libs2e-debug/i386-s2e_sp-softmmu/libs2e.so $(S2E_PREFIX)/share/libs2e/libs2e-i386-s2e_sp.so + + install $(S2E_SRC)/libs2eplugins/src/s2e/Plugins/Support/KeyValueStore.py $(S2E_PREFIX)/bin/ + cd $(S2E_SRC) && if [ -d ".git" ]; then git rev-parse HEAD > $(S2E_PREFIX)/share/libs2e/git-sha1; fi + + touch $@ + +######### +# Tools # +######### + +TOOLS_CONFIGURE_FLAGS = -DCMAKE_INSTALL_PREFIX=$(S2E_PREFIX) \ + -DCMAKE_C_COMPILER=$(CLANG_CC) \ + -DCMAKE_CXX_COMPILER=$(CLANG_CXX) \ + -DCMAKE_C_FLAGS="$(CFLAGS_ARCH)" \ + -DCMAKE_PREFIX_PATH="$(S2E_PREFIX)" \ + -DLIBCPU_SRC_DIR=$(S2E_SRC)/libcpu \ + -DLIBTCG_SRC_DIR=$(S2E_SRC)/libtcg \ + -DS2EPLUGINS_SRC_DIR=$(S2E_SRC)/libs2eplugins/src \ + -G "Unix Makefiles" + +stamps/tools-debug-configure: stamps/llvm-debug-make stamps/libvmi-debug-make stamps/libfsigc++-debug-make stamps/libq-debug-make +stamps/tools-debug-configure: CONFIGURE_COMMAND = cmake $(TOOLS_CONFIGURE_FLAGS) \ + -DLLVM_DIR=$(LLVM_BUILD)/llvm-debug/lib/cmake/llvm \ + -DVMI_DIR=$(S2E_BUILD)/libvmi-debug \ + -DFSIGCXX_DIR=$(S2E_BUILD)/libfsigc++-debug \ + -DLIBQ_DIR=$(S2E_BUILD)/libq-debug \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_FLAGS="$(CXXFLAGS_DEBUG)" \ + $(S2E_SRC)/tools + +stamps/tools-release-configure: stamps/llvm-release-make stamps/libvmi-release-make stamps/libfsigc++-release-make stamps/libq-release-make +stamps/tools-release-configure: CONFIGURE_COMMAND = cmake $(TOOLS_CONFIGURE_FLAGS) \ + -DLLVM_DIR=$(LLVM_BUILD)/llvm-release/lib/cmake/llvm \ + -DVMI_DIR=$(S2E_BUILD)/libvmi-release \ + -DFSIGCXX_DIR=$(S2E_BUILD)/libfsigc++-release \ + -DLIBQ_DIR=$(S2E_BUILD)/libq-release \ + -DCMAKE_BUILD_TYPE=$(RELEASE_BUILD_TYPE) \ + -DCMAKE_CXX_FLAGS="$(CXXFLAGS_RELEASE)" \ + $(S2E_SRC)/tools + +stamps/tools-debug-make: stamps/tools-debug-configure + +stamps/tools-release-make: stamps/tools-release-configure + +stamps/tools-release-install: stamps/tools-release-make + $(MAKE) -C tools-release install + touch $@ + +stamps/tools-debug-install: stamps/tools-debug-make + $(MAKE) -C tools-debug install + touch $@ + +############### +# Guest tools # +############### + +stamps/guest-tools32-configure: CONFIGURE_COMMAND = cmake \ + -DCMAKE_C_COMPILER=$(CLANG_CC) \ + -DCMAKE_INSTALL_PREFIX=$(S2E_PREFIX)/bin/guest-tools32 \ + -DCMAKE_TOOLCHAIN_FILE=$(S2E_SRC)/guest/cmake/Toolchain-linux-i686.cmake \ + $(S2E_SRC)/guest + +stamps/guest-tools64-configure: CONFIGURE_COMMAND = cmake \ + -DCMAKE_C_COMPILER=$(CLANG_CC) \ + -DCMAKE_INSTALL_PREFIX=$(S2E_PREFIX)/bin/guest-tools64 \ + -DCMAKE_TOOLCHAIN_FILE=$(S2E_SRC)/guest/cmake/Toolchain-linux-x86_64.cmake \ + $(S2E_SRC)/guest + +stamps/guest-tools32-win-configure: CONFIGURE_COMMAND = cmake \ + -DCMAKE_INSTALL_PREFIX=$(S2E_PREFIX)/bin/guest-tools32 \ + -DCMAKE_TOOLCHAIN_FILE=$(S2E_SRC)/guest/cmake/Toolchain-windows-i686.cmake \ + $(S2E_SRC)/guest + +stamps/guest-tools64-win-configure: CONFIGURE_COMMAND = cmake \ + -DCMAKE_INSTALL_PREFIX=$(S2E_PREFIX)/bin/guest-tools64 \ + -DCMAKE_TOOLCHAIN_FILE=$(S2E_SRC)/guest/cmake/Toolchain-windows-x86_64.cmake \ + $(S2E_SRC)/guest + +stamps/guest-tools32-make: stamps/guest-tools32-configure + +stamps/guest-tools64-make: stamps/guest-tools64-configure + +stamps/guest-tools32-win-make: stamps/guest-tools32-win-configure + +stamps/guest-tools64-win-make: stamps/guest-tools64-win-configure + +# Install precompiled windows drivers +guest-tools32-windrv: + mkdir -p $(S2E_PREFIX)/bin/guest-tools32 + cd $(S2E_PREFIX)/bin/guest-tools32 && wget -O s2e.sys $(GUEST_TOOLS_BINARIES_URL)/s2e32.sys + cd $(S2E_PREFIX)/bin/guest-tools32 && wget -O s2e.inf $(GUEST_TOOLS_BINARIES_URL)/s2e.inf + cd $(S2E_PREFIX)/bin/guest-tools32 && wget -O drvctl.exe $(GUEST_TOOLS_BINARIES_URL)/drvctl32.exe + +guest-tools64-windrv: + mkdir -p $(S2E_PREFIX)/bin/guest-tools64 + cd $(S2E_PREFIX)/bin/guest-tools64 && wget -O s2e.sys $(GUEST_TOOLS_BINARIES_URL)/s2e.sys + cd $(S2E_PREFIX)/bin/guest-tools64 && wget -O s2e.inf $(GUEST_TOOLS_BINARIES_URL)/s2e.inf + cd $(S2E_PREFIX)/bin/guest-tools64 && wget -O drvctl.exe $(GUEST_TOOLS_BINARIES_URL)/drvctl.exe + +stamps/guest-tools%-win-install: stamps/guest-tools%-win-make guest-tools32-windrv guest-tools64-windrv + $(MAKE) -C guest-tools$*-win install + +stamps/guest-tools%-install: stamps/guest-tools%-make guest-tools32-windrv guest-tools64-windrv + $(MAKE) -C guest-tools$* install + +########## +# DECREE # +########## + +stamps/decree-configure: CONFIGURE_COMMAND = cmake \ + -DCMAKE_INSTALL_PREFIX=$(S2E_PREFIX) \ + $(S2E_SRC)/decree + +stamps/decree-make: stamps/decree-configure + +stamps/decree-install: stamps/decree-make + $(MAKE) -C decree install + touch $@ diff --git a/build-scripts/Makefile.docker b/build-scripts/Makefile.docker new file mode 100644 index 00000000..beb1b7a6 --- /dev/null +++ b/build-scripts/Makefile.docker @@ -0,0 +1,60 @@ +# Copyright (C) 2017, Cyberhaven +# All rights reserved. +# +# Licensed under the Cyberhaven Research License Agreement. + +# Creates a docker image containing a ready-to-run S2E demo. +all: demo +demo: stamps/decree-demo + +# Check the build directory +ifeq ($(shell ls libs2e/src/libs2e.c 2>&1),libs2e/src/libs2e.c) + $(error You should not run make in the S2E source directory!) +endif + +# S2E variables +BUILD_SCRIPTS_SRC?=$(dir $(realpath $(lastword $(MAKEFILE_LIST)))) +S2E_SRC?=$(realpath $(BUILD_SCRIPTS_SRC)/../) +S2E_BUILD:=$(CURDIR) + +DOCKER_PREFIX=cyberhaven + +########## +# Docker # +########## + +stamps: + mkdir -p $@ + +# Build S2E inside a docker container +stamps/docker-s2e-build: | stamps + echo Building S2E inside docker container... + cd $(S2E_SRC) && docker build -t $(DOCKER_PREFIX)/s2e-build -f Dockerfile . + touch $@ + +$(S2E_BUILD)/docker $(S2E_BUILD)/docker-demo: + mkdir -p "$@" + +# This rule creates a container that only has S2E binaries in it. +# Note: it is not possible to simply delete build files from the s2e-build +# container, because docker would still keep intermediate layers. +# That would make the cyberhaven/s2e container unnecessarily large. +stamps/docker-s2e: stamps/docker-s2e-build $(S2E_BUILD)/docker $(BUILD_SCRIPTS_SRC)/Dockerfile.dist + echo Preparing docker build folder... + cp $(BUILD_SCRIPTS_SRC)/Dockerfile.dist $(S2E_BUILD)/docker + rsync -av --delete --exclude=venv --exclude=.git $(S2E_SRC)/s2e-env $(S2E_BUILD)/docker/ + + echo Extracting /opt/s2e from build image + cd $(S2E_BUILD)/docker && $(BUILD_SCRIPTS_SRC)/extract-docker-dir.sh $(DOCKER_PREFIX)/s2e-build /opt/s2e . + + echo Building $(DOCKER_PREFIX)/s2e + cd $(S2E_BUILD)/docker && docker build --force-rm=true -t $(DOCKER_PREFIX)/s2e -f Dockerfile.dist . + + touch $@ + +stamps/decree-demo: $(S2E_BUILD)/docker-demo stamps/docker-s2e + echo Building demo... + cp -r $(BUILD_SCRIPTS_SRC)/demo/* $(S2E_BUILD)/docker-demo + cp $(S2E_SRC)/decree/samples/* $(S2E_BUILD)/docker-demo + cd $(S2E_BUILD)/docker-demo && docker build -t $(DOCKER_PREFIX)/s2e-demo -f Dockerfile.demo . + touch $@ diff --git a/build-scripts/README.md b/build-scripts/README.md new file mode 100644 index 00000000..ea228ec7 --- /dev/null +++ b/build-scripts/README.md @@ -0,0 +1,14 @@ +S2E Build Scripts +================= + +This repository contains scripts to build S2E and package it in docker images. + +You should use this repository in conjunction with ```repo```: + +``` +cd $S2EDIR +repo init -u git://github.com/s2e/manifest.git +repo sync +``` + +Please refer to the S2E documentation for build instructions. diff --git a/build-scripts/create_qt_project.py b/build-scripts/create_qt_project.py new file mode 100755 index 00000000..113e89df --- /dev/null +++ b/build-scripts/create_qt_project.py @@ -0,0 +1,75 @@ +#!/usr/bin/python + +# Copyright (c) 2017 Dependable Systems Laboratory, EPFL +# Copyright (c) 2017 Cyberhaven +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +from subprocess import Popen, PIPE +import sys +import os + +blacklist = ['.git', '.repo', 'qemu', 'docs', 'doxygen'] + +files = [] +for root, directories, filenames in os.walk('.'): + for filename in filenames: + files.append(os.path.join(root, filename)) + +files.sort() + +dirs = set([""]) +s2e_files = open('s2e.files', 'w') +s2e_includes = open('s2e.includes', 'w') +for fname in files: + for b in blacklist: + if b in fname: + break + else: + if not os.path.isdir(fname): + s2e_files.write(fname + '\n') + + fdir = fname + while fdir != "": + fdir = os.path.dirname(fdir) + if fdir not in dirs and os.path.isdir(fdir): + s2e_includes.write(fdir + '\n') + dirs.add(fdir) + +s2e_includes.write('\n'.join([ + '../build/llvm-3.9.1.src/include', + '../build/llvm-release/include', + '../build/lua-5.3.4/src', + '/usr/include/glib-2.0', + + # This is for protobuf headers, pick one build folder + '../build/libs2e-release/i386-s2e-softmmu/libs2eplugins/src/', +])) + +s2e_files.close() +s2e_includes.close() + +with open("s2e.creator", "w") as fp: + fp.write("[General]\n") + +with open("s2e.config", "w") as fp: + fp.write("#define CONFIG_SYMBEX\n") + fp.write("#define CONFIG_SYMBEX_MP\n") + fp.write("#define CONFIG_SOFTMMU\n") + diff --git a/build-scripts/demo/Dockerfile.demo b/build-scripts/demo/Dockerfile.demo new file mode 100644 index 00000000..5bf7e8fa --- /dev/null +++ b/build-scripts/demo/Dockerfile.demo @@ -0,0 +1,5 @@ +FROM cyberhaven/s2e + +RUN mkdir /demo +COPY run.sh /demo/ +COPY CADET_00001 /demo/ diff --git a/build-scripts/demo/run.sh b/build-scripts/demo/run.sh new file mode 100755 index 00000000..41053ed2 --- /dev/null +++ b/build-scripts/demo/run.sh @@ -0,0 +1,97 @@ +#!/bin/bash + +# Copyright (c) 2017, Cyberhaven +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# +# Usage: ./run.sh UID GID path_to_binary [binary args...] +# + +if [ $# -lt 3 ]; then + echo "Usage: $0 uid gid path_to_binary [binary args...]" + exit 1 +fi + +MUID="$1" +shift + +MGID="$1" +shift + +BINARY_PATH="$1" +shift + +if [ ! -f "$BINARY_PATH" ]; then + echo "$BINARY_PATH was not found. This path must exist inside the container." + echo "If the binary is on your host machine, make sure that you mounted the host folder properly (-v docker option)." + exit 1 +fi + +BINARY_PATH="$(readlink -f "$BINARY_PATH")" +BINARY="$(basename "$BINARY_PATH")" + +# Project name doesn't have the extension +PROJECT="$(echo $BINARY | cut -f 1 -d '.')" + +# Verify that the specified group and user ids don't exist locally. +# If so, delete them. This may happen if the host OS is not Debian-based, +# where user ids may conflict with those preinstalled in the docker image. +GROUP=$(getent group $MGID | cut -d ':' -f 1) +USER=$(getent passwd $MUID | cut -d ':' -f 1) + +if [ "x$USER" != "x" ]; then + userdel $USER +fi + +if [ "x$GROUP" != "x" ]; then + groupdel $GROUP +fi + +groupadd -g $MGID s2e +useradd -u $MUID -g s2e s2e + +# S2E shared libraries are installed in a non-standard location, +# make sure the system can find them. +echo /opt/s2e/lib > /etc/ld.so.conf.d/s2e.conf +ldconfig + +ROOT="$(pwd)/s2e-demo" + +# Run the rest of the script with the uid/gid provided, otherwise +# new files will be owned by root. +exec sudo -u s2e /bin/bash - << EOF + +if [ ! -d "$ROOT" ]; then + s2e init -b /opt/s2e "$ROOT" +fi + +cd "$ROOT" + +if [ ! -d "projects/$PROJECT" ]; then + echo "Creating new project in projects/$PROJECT" + + # Automatically download image if needed + s2e new_project -n "$PROJECT" -d "$BINARY_PATH" $* +fi + +echo Running $PROJECT +s2e run "$PROJECT" + +EOF diff --git a/build-scripts/determine_clang_binary_suffix.py b/build-scripts/determine_clang_binary_suffix.py new file mode 100755 index 00000000..1b78615a --- /dev/null +++ b/build-scripts/determine_clang_binary_suffix.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python + +# Copyright (C) 2018 Adrian Herrera +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +""" +Inspects the current operating system and determines which Clang binary to +download. If a valid version is found, the suffix of the file to download is +printed to stdout. Otherwise an error message is printed to stderr. + +Note: This script is only really meant to be used by the S2E Makefile. It has +no real use outside of this. +""" + +from __future__ import print_function + +import platform +import sys + + +# Supported operating systems for Clang binary downloads +SUPPORTED_OS = ('ubuntu', 'debian') + + +def eprint(*args, **kwargs): + """Print to stderr and exit.""" + print(*args, file=sys.stderr, **kwargs) + sys.exit(1) + + +def _get_debian_version(version_string): + """ + Determine the Clang binary to download from the version string returned by + ``platform.linux_distribution``. + """ + version = int(version_string) + + if version >= 8: + return 'x86_64-linux-gnu-debian8' + else: + return None + + +def _get_ubuntu_version(version_string): + """ + Determine the Clang binary to downoad from the version string returned by + ``platform.linux_distribution``. + """ + major_version, minor_version = map(int, version_string.split('.')) + + # Currently S2E only supports LLVM 3.9.1, and the only Clang binary + # packages that exist for this version are for Ubuntu 14.04 and 16.04 + if major_version == 14 and minor_version >= 4: + return 'x86_64-linux-gnu-ubuntu-14.04', + elif major_version == 15: + return 'x86_64-linux-gnu-ubuntu-14.04', + elif major_version == 16 and minor_version >= 4: + return 'x86_64-linux-gnu-ubuntu-16.04', + elif major_version > 16: + return 'x86_64-linux-gnu-ubuntu-16.04', + else: + return None + + +def main(): + """The main function.""" + distro, version, _ = platform.linux_distribution() + + clang_ver_to_download = None + if distro.lower() == 'debian': + clang_ver_to_download = _get_debian_version(version) + elif distro.lower() == 'ubuntu': + clang_ver_to_download = _get_ubuntu_version(version) + else: + eprint('Linux distro %s is not supported' % distro) + + if clang_ver_to_download: + print('%s' % clang_ver_to_download) + else: + eprint('%s %s is not supported' % (distro, version)) + + +if __name__ == '__main__': + main() diff --git a/build-scripts/extract-docker-dir.sh b/build-scripts/extract-docker-dir.sh new file mode 100755 index 00000000..cc7d7eba --- /dev/null +++ b/build-scripts/extract-docker-dir.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Copyright (C) 2017, Cyberhaven +# All rights reserved. +# +# Licensed under the Cyberhaven Research License Agreement. + +set -e + +if [ "$#" -ne 3 ]; then + echo "Usage: $0 " + exit 1 +fi + +docker_image=$1 +docker_dir=$2 +output_dir=$(mkdir -p $3 && cd $3 && pwd) + +docker_container=`docker run -d "$docker_image" sleep 1000` +docker cp "${docker_container}:$docker_dir" "$output_dir" || true +docker kill "$docker_container" >/dev/null || true +docker rm "$docker_container" >/dev/null diff --git a/build-scripts/lua/luaconf.h b/build-scripts/lua/luaconf.h new file mode 100644 index 00000000..afd9b387 --- /dev/null +++ b/build-scripts/lua/luaconf.h @@ -0,0 +1,783 @@ +/* +** $Id: luaconf.h,v 1.259 2016/12/22 13:08:50 roberto Exp $ +** Configuration file for Lua +** See Copyright Notice in lua.h +*/ + + +#ifndef luaconf_h +#define luaconf_h + +#include +#include + + +/* +** =================================================================== +** Search for "@@" to find all configurable definitions. +** =================================================================== +*/ + + +/* +** {==================================================================== +** System Configuration: macros to adapt (if needed) Lua to some +** particular platform, for instance compiling it with 32-bit numbers or +** restricting it to C89. +** ===================================================================== +*/ + +/* +@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. You +** can also define LUA_32BITS in the make file, but changing here you +** ensure that all software connected to Lua will be compiled with the +** same configuration. +*/ +/* #define LUA_32BITS */ + + +/* +@@ LUA_USE_C89 controls the use of non-ISO-C89 features. +** Define it if you want Lua to avoid the use of a few C99 features +** or Windows-specific features on Windows. +*/ +/* #define LUA_USE_C89 */ + + +/* +** By default, Lua on Windows use (some) specific Windows features +*/ +#if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE) +#define LUA_USE_WINDOWS /* enable goodies for regular Windows */ +#endif + + +#if defined(LUA_USE_WINDOWS) +#define LUA_DL_DLL /* enable support for DLL */ +#define LUA_USE_C89 /* broadly, Windows is C89 */ +#endif + + +#if defined(LUA_USE_LINUX) +#define LUA_USE_POSIX +#define LUA_USE_DLOPEN /* needs an extra library: -ldl */ +//#define LUA_USE_READLINE /* needs some extra libraries */ +#endif + + +#if defined(LUA_USE_MACOSX) +#define LUA_USE_POSIX +#define LUA_USE_DLOPEN /* MacOS does not need -ldl */ +//#define LUA_USE_READLINE /* needs an extra library: -lreadline */ +#endif + + +/* +@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for +** C89 ('long' and 'double'); Windows always has '__int64', so it does +** not need to use this case. +*/ +#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS) +#define LUA_C89_NUMBERS +#endif + + + +/* +@@ LUAI_BITSINT defines the (minimum) number of bits in an 'int'. +*/ +/* avoid undefined shifts */ +#if ((INT_MAX >> 15) >> 15) >= 1 +#define LUAI_BITSINT 32 +#else +/* 'int' always must have at least 16 bits */ +#define LUAI_BITSINT 16 +#endif + + +/* +@@ LUA_INT_TYPE defines the type for Lua integers. +@@ LUA_FLOAT_TYPE defines the type for Lua floats. +** Lua should work fine with any mix of these options (if supported +** by your C compiler). The usual configurations are 64-bit integers +** and 'double' (the default), 32-bit integers and 'float' (for +** restricted platforms), and 'long'/'double' (for C compilers not +** compliant with C99, which may not have support for 'long long'). +*/ + +/* predefined options for LUA_INT_TYPE */ +#define LUA_INT_INT 1 +#define LUA_INT_LONG 2 +#define LUA_INT_LONGLONG 3 + +/* predefined options for LUA_FLOAT_TYPE */ +#define LUA_FLOAT_FLOAT 1 +#define LUA_FLOAT_DOUBLE 2 +#define LUA_FLOAT_LONGDOUBLE 3 + +#if defined(LUA_32BITS) /* { */ +/* +** 32-bit integers and 'float' +*/ +#if LUAI_BITSINT >= 32 /* use 'int' if big enough */ +#define LUA_INT_TYPE LUA_INT_INT +#else /* otherwise use 'long' */ +#define LUA_INT_TYPE LUA_INT_LONG +#endif +#define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT + +#elif defined(LUA_C89_NUMBERS) /* }{ */ +/* +** largest types available for C89 ('long' and 'double') +*/ +#define LUA_INT_TYPE LUA_INT_LONG +#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE + +#endif /* } */ + + +/* +** default configuration for 64-bit Lua ('long long' and 'double') +*/ +#if !defined(LUA_INT_TYPE) +#define LUA_INT_TYPE LUA_INT_LONGLONG +#endif + +#if !defined(LUA_FLOAT_TYPE) +#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE +#endif + +/* }================================================================== */ + + + + +/* +** {================================================================== +** Configuration for Paths. +** =================================================================== +*/ + +/* +** LUA_PATH_SEP is the character that separates templates in a path. +** LUA_PATH_MARK is the string that marks the substitution points in a +** template. +** LUA_EXEC_DIR in a Windows path is replaced by the executable's +** directory. +*/ +#define LUA_PATH_SEP ";" +#define LUA_PATH_MARK "?" +#define LUA_EXEC_DIR "!" + + +/* +@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for +** Lua libraries. +@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for +** C libraries. +** CHANGE them if your machine has a non-conventional directory +** hierarchy or if you want to install your libraries in +** non-conventional directories. +*/ +#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR +#if defined(_WIN32) /* { */ +/* +** In Windows, any exclamation mark ('!') in the path is replaced by the +** path of the directory of the executable file of the current process. +*/ +#define LUA_LDIR "!\\lua\\" +#define LUA_CDIR "!\\" +#define LUA_SHRDIR "!\\..\\share\\lua\\" LUA_VDIR "\\" +#define LUA_PATH_DEFAULT \ + LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \ + LUA_SHRDIR"?.lua;" LUA_SHRDIR"?\\init.lua;" \ + ".\\?.lua;" ".\\?\\init.lua" +#define LUA_CPATH_DEFAULT \ + LUA_CDIR"?.dll;" \ + LUA_CDIR"..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \ + LUA_CDIR"loadall.dll;" ".\\?.dll" + +#else /* }{ */ + +#define LUA_ROOT "/usr/local/" +#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR "/" +#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR "/" +#define LUA_PATH_DEFAULT \ + LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \ + "./?.lua;" "./?/init.lua" +#define LUA_CPATH_DEFAULT \ + LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so" +#endif /* } */ + + +/* +@@ LUA_DIRSEP is the directory separator (for submodules). +** CHANGE it if your machine does not use "/" as the directory separator +** and is not Windows. (On Windows Lua automatically uses "\".) +*/ +#if defined(_WIN32) +#define LUA_DIRSEP "\\" +#else +#define LUA_DIRSEP "/" +#endif + +/* }================================================================== */ + + +/* +** {================================================================== +** Marks for exported symbols in the C code +** =================================================================== +*/ + +/* +@@ LUA_API is a mark for all core API functions. +@@ LUALIB_API is a mark for all auxiliary library functions. +@@ LUAMOD_API is a mark for all standard library opening functions. +** CHANGE them if you need to define those functions in some special way. +** For instance, if you want to create one Windows DLL with the core and +** the libraries, you may want to use the following definition (define +** LUA_BUILD_AS_DLL to get it). +*/ +#if defined(LUA_BUILD_AS_DLL) /* { */ + +#if defined(LUA_CORE) || defined(LUA_LIB) /* { */ +#define LUA_API __declspec(dllexport) +#else /* }{ */ +#define LUA_API __declspec(dllimport) +#endif /* } */ + +#else /* }{ */ + +#define LUA_API extern + +#endif /* } */ + + +/* more often than not the libs go together with the core */ +#define LUALIB_API LUA_API +#define LUAMOD_API LUALIB_API + + +/* +@@ LUAI_FUNC is a mark for all extern functions that are not to be +** exported to outside modules. +@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables +** that are not to be exported to outside modules (LUAI_DDEF for +** definitions and LUAI_DDEC for declarations). +** CHANGE them if you need to mark them in some special way. Elf/gcc +** (versions 3.2 and later) mark them as "hidden" to optimize access +** when Lua is compiled as a shared library. Not all elf targets support +** this attribute. Unfortunately, gcc does not offer a way to check +** whether the target offers that support, and those without support +** give a warning about it. To avoid these warnings, change to the +** default definition. +*/ +#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \ + defined(__ELF__) /* { */ +#define LUAI_FUNC __attribute__((visibility("hidden"))) extern +#else /* }{ */ +#define LUAI_FUNC extern +#endif /* } */ + +#define LUAI_DDEC LUAI_FUNC +#define LUAI_DDEF /* empty */ + +/* }================================================================== */ + + +/* +** {================================================================== +** Compatibility with previous versions +** =================================================================== +*/ + +/* +@@ LUA_COMPAT_5_2 controls other macros for compatibility with Lua 5.2. +@@ LUA_COMPAT_5_1 controls other macros for compatibility with Lua 5.1. +** You can define it to get all options, or change specific options +** to fit your specific needs. +*/ +#if defined(LUA_COMPAT_5_2) /* { */ + +/* +@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated +** functions in the mathematical library. +*/ +#define LUA_COMPAT_MATHLIB + +/* +@@ LUA_COMPAT_BITLIB controls the presence of library 'bit32'. +*/ +#define LUA_COMPAT_BITLIB + +/* +@@ LUA_COMPAT_IPAIRS controls the effectiveness of the __ipairs metamethod. +*/ +#define LUA_COMPAT_IPAIRS + +/* +@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for +** manipulating other integer types (lua_pushunsigned, lua_tounsigned, +** luaL_checkint, luaL_checklong, etc.) +*/ +#define LUA_COMPAT_APIINTCASTS + +#endif /* } */ + + +#if defined(LUA_COMPAT_5_1) /* { */ + +/* Incompatibilities from 5.2 -> 5.3 */ +#define LUA_COMPAT_MATHLIB +#define LUA_COMPAT_APIINTCASTS + +/* +@@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'. +** You can replace it with 'table.unpack'. +*/ +#define LUA_COMPAT_UNPACK + +/* +@@ LUA_COMPAT_LOADERS controls the presence of table 'package.loaders'. +** You can replace it with 'package.searchers'. +*/ +#define LUA_COMPAT_LOADERS + +/* +@@ macro 'lua_cpcall' emulates deprecated function lua_cpcall. +** You can call your C function directly (with light C functions). +*/ +#define lua_cpcall(L,f,u) \ + (lua_pushcfunction(L, (f)), \ + lua_pushlightuserdata(L,(u)), \ + lua_pcall(L,1,0,0)) + + +/* +@@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library. +** You can rewrite 'log10(x)' as 'log(x, 10)'. +*/ +#define LUA_COMPAT_LOG10 + +/* +@@ LUA_COMPAT_LOADSTRING defines the function 'loadstring' in the base +** library. You can rewrite 'loadstring(s)' as 'load(s)'. +*/ +#define LUA_COMPAT_LOADSTRING + +/* +@@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library. +*/ +#define LUA_COMPAT_MAXN + +/* +@@ The following macros supply trivial compatibility for some +** changes in the API. The macros themselves document how to +** change your code to avoid using them. +*/ +#define lua_strlen(L,i) lua_rawlen(L, (i)) + +#define lua_objlen(L,i) lua_rawlen(L, (i)) + +#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ) +#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT) + +/* +@@ LUA_COMPAT_MODULE controls compatibility with previous +** module functions 'module' (Lua) and 'luaL_register' (C). +*/ +#define LUA_COMPAT_MODULE + +#endif /* } */ + + +/* +@@ LUA_COMPAT_FLOATSTRING makes Lua format integral floats without a +@@ a float mark ('.0'). +** This macro is not on by default even in compatibility mode, +** because this is not really an incompatibility. +*/ +/* #define LUA_COMPAT_FLOATSTRING */ + +/* }================================================================== */ + + + +/* +** {================================================================== +** Configuration for Numbers. +** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_* +** satisfy your needs. +** =================================================================== +*/ + +/* +@@ LUA_NUMBER is the floating-point type used by Lua. +@@ LUAI_UACNUMBER is the result of a 'default argument promotion' +@@ over a floating number. +@@ l_mathlim(x) corrects limit name 'x' to the proper float type +** by prefixing it with one of FLT/DBL/LDBL. +@@ LUA_NUMBER_FRMLEN is the length modifier for writing floats. +@@ LUA_NUMBER_FMT is the format for writing floats. +@@ lua_number2str converts a float to a string. +@@ l_mathop allows the addition of an 'l' or 'f' to all math operations. +@@ l_floor takes the floor of a float. +@@ lua_str2number converts a decimal numeric string to a number. +*/ + + +/* The following definitions are good for most cases here */ + +#define l_floor(x) (l_mathop(floor)(x)) + +#define lua_number2str(s,sz,n) \ + l_sprintf((s), sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)(n)) + +/* +@@ lua_numbertointeger converts a float number to an integer, or +** returns 0 if float is not within the range of a lua_Integer. +** (The range comparisons are tricky because of rounding. The tests +** here assume a two-complement representation, where MININTEGER always +** has an exact representation as a float; MAXINTEGER may not have one, +** and therefore its conversion to float may have an ill-defined value.) +*/ +#define lua_numbertointeger(n,p) \ + ((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \ + (n) < -(LUA_NUMBER)(LUA_MININTEGER) && \ + (*(p) = (LUA_INTEGER)(n), 1)) + + +/* now the variable definitions */ + +#if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT /* { single float */ + +#define LUA_NUMBER float + +#define l_mathlim(n) (FLT_##n) + +#define LUAI_UACNUMBER double + +#define LUA_NUMBER_FRMLEN "" +#define LUA_NUMBER_FMT "%.7g" + +#define l_mathop(op) op##f + +#define lua_str2number(s,p) strtof((s), (p)) + + +#elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE /* }{ long double */ + +#define LUA_NUMBER long double + +#define l_mathlim(n) (LDBL_##n) + +#define LUAI_UACNUMBER long double + +#define LUA_NUMBER_FRMLEN "L" +#define LUA_NUMBER_FMT "%.19Lg" + +#define l_mathop(op) op##l + +#define lua_str2number(s,p) strtold((s), (p)) + +#elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE /* }{ double */ + +#define LUA_NUMBER double + +#define l_mathlim(n) (DBL_##n) + +#define LUAI_UACNUMBER double + +#define LUA_NUMBER_FRMLEN "" +#define LUA_NUMBER_FMT "%.14g" + +#define l_mathop(op) op + +#define lua_str2number(s,p) strtod((s), (p)) + +#else /* }{ */ + +#error "numeric float type not defined" + +#endif /* } */ + + + +/* +@@ LUA_INTEGER is the integer type used by Lua. +** +@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER. +** +@@ LUAI_UACINT is the result of a 'default argument promotion' +@@ over a lUA_INTEGER. +@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers. +@@ LUA_INTEGER_FMT is the format for writing integers. +@@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER. +@@ LUA_MININTEGER is the minimum value for a LUA_INTEGER. +@@ lua_integer2str converts an integer to a string. +*/ + + +/* The following definitions are good for most cases here */ + +#define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d" + +#define LUAI_UACINT LUA_INTEGER + +#define lua_integer2str(s,sz,n) \ + l_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n)) + +/* +** use LUAI_UACINT here to avoid problems with promotions (which +** can turn a comparison between unsigneds into a signed comparison) +*/ +#define LUA_UNSIGNED unsigned LUAI_UACINT + + +/* now the variable definitions */ + +#if LUA_INT_TYPE == LUA_INT_INT /* { int */ + +#define LUA_INTEGER int +#define LUA_INTEGER_FRMLEN "" + +#define LUA_MAXINTEGER INT_MAX +#define LUA_MININTEGER INT_MIN + +#elif LUA_INT_TYPE == LUA_INT_LONG /* }{ long */ + +#define LUA_INTEGER long +#define LUA_INTEGER_FRMLEN "l" + +#define LUA_MAXINTEGER LONG_MAX +#define LUA_MININTEGER LONG_MIN + +#elif LUA_INT_TYPE == LUA_INT_LONGLONG /* }{ long long */ + +/* use presence of macro LLONG_MAX as proxy for C99 compliance */ +#if defined(LLONG_MAX) /* { */ +/* use ISO C99 stuff */ + +#define LUA_INTEGER long long +#define LUA_INTEGER_FRMLEN "ll" + +#define LUA_MAXINTEGER LLONG_MAX +#define LUA_MININTEGER LLONG_MIN + +#elif defined(LUA_USE_WINDOWS) /* }{ */ +/* in Windows, can use specific Windows types */ + +#define LUA_INTEGER __int64 +#define LUA_INTEGER_FRMLEN "I64" + +#define LUA_MAXINTEGER _I64_MAX +#define LUA_MININTEGER _I64_MIN + +#else /* }{ */ + +#error "Compiler does not support 'long long'. Use option '-DLUA_32BITS' \ + or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)" + +#endif /* } */ + +#else /* }{ */ + +#error "numeric integer type not defined" + +#endif /* } */ + +/* }================================================================== */ + + +/* +** {================================================================== +** Dependencies with C99 and other C details +** =================================================================== +*/ + +/* +@@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89. +** (All uses in Lua have only one format item.) +*/ +#if !defined(LUA_USE_C89) +#define l_sprintf(s,sz,f,i) snprintf(s,sz,f,i) +#else +#define l_sprintf(s,sz,f,i) ((void)(sz), sprintf(s,f,i)) +#endif + + +/* +@@ lua_strx2number converts an hexadecimal numeric string to a number. +** In C99, 'strtod' does that conversion. Otherwise, you can +** leave 'lua_strx2number' undefined and Lua will provide its own +** implementation. +*/ +#if !defined(LUA_USE_C89) +#define lua_strx2number(s,p) lua_str2number(s,p) +#endif + + +/* +@@ lua_number2strx converts a float to an hexadecimal numeric string. +** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that. +** Otherwise, you can leave 'lua_number2strx' undefined and Lua will +** provide its own implementation. +*/ +#if !defined(LUA_USE_C89) +#define lua_number2strx(L,b,sz,f,n) \ + ((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n))) +#endif + + +/* +** 'strtof' and 'opf' variants for math functions are not valid in +** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the +** availability of these variants. ('math.h' is already included in +** all files that use these macros.) +*/ +#if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF)) +#undef l_mathop /* variants not available */ +#undef lua_str2number +#define l_mathop(op) (lua_Number)op /* no variant */ +#define lua_str2number(s,p) ((lua_Number)strtod((s), (p))) +#endif + + +/* +@@ LUA_KCONTEXT is the type of the context ('ctx') for continuation +** functions. It must be a numerical type; Lua will use 'intptr_t' if +** available, otherwise it will use 'ptrdiff_t' (the nearest thing to +** 'intptr_t' in C89) +*/ +#define LUA_KCONTEXT ptrdiff_t + +#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \ + __STDC_VERSION__ >= 199901L +#include +#if defined(INTPTR_MAX) /* even in C99 this type is optional */ +#undef LUA_KCONTEXT +#define LUA_KCONTEXT intptr_t +#endif +#endif + + +/* +@@ lua_getlocaledecpoint gets the locale "radix character" (decimal point). +** Change that if you do not want to use C locales. (Code using this +** macro must include header 'locale.h'.) +*/ +#if !defined(lua_getlocaledecpoint) +#define lua_getlocaledecpoint() (localeconv()->decimal_point[0]) +#endif + +/* }================================================================== */ + + +/* +** {================================================================== +** Language Variations +** ===================================================================== +*/ + +/* +@@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some +** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from +** numbers to strings. Define LUA_NOCVTS2N to turn off automatic +** coercion from strings to numbers. +*/ +/* #define LUA_NOCVTN2S */ +/* #define LUA_NOCVTS2N */ + + +/* +@@ LUA_USE_APICHECK turns on several consistency checks on the C API. +** Define it as a help when debugging C code. +*/ +#if defined(LUA_USE_APICHECK) +#include +#define luai_apicheck(l,e) assert(e) +#endif + +/* }================================================================== */ + + +/* +** {================================================================== +** Macros that affect the API and must be stable (that is, must be the +** same when you compile Lua and when you compile code that links to +** Lua). You probably do not want/need to change them. +** ===================================================================== +*/ + +/* +@@ LUAI_MAXSTACK limits the size of the Lua stack. +** CHANGE it if you need a different limit. This limit is arbitrary; +** its only purpose is to stop Lua from consuming unlimited stack +** space (and to reserve some numbers for pseudo-indices). +*/ +#if LUAI_BITSINT >= 32 +#define LUAI_MAXSTACK 1000000 +#else +#define LUAI_MAXSTACK 15000 +#endif + + +/* +@@ LUA_EXTRASPACE defines the size of a raw memory area associated with +** a Lua state with very fast access. +** CHANGE it if you need a different size. +*/ +#define LUA_EXTRASPACE (sizeof(void *)) + + +/* +@@ LUA_IDSIZE gives the maximum size for the description of the source +@@ of a function in debug information. +** CHANGE it if you want a different size. +*/ +#define LUA_IDSIZE 60 + + +/* +@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. +** CHANGE it if it uses too much C-stack space. (For long double, +** 'string.format("%.99f", -1e4932)' needs 5034 bytes, so a +** smaller buffer would force a memory allocation for each call to +** 'string.format'.) +*/ +#if LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE +#define LUAL_BUFFERSIZE 8192 +#else +#define LUAL_BUFFERSIZE ((int)(0x80 * sizeof(void*) * sizeof(lua_Integer))) +#endif + +/* }================================================================== */ + + +/* +@@ LUA_QL describes how error messages quote program elements. +** Lua does not use these macros anymore; they are here for +** compatibility only. +*/ +#define LUA_QL(x) "'" x "'" +#define LUA_QS LUA_QL("%s") + + + + +/* =================================================================== */ + +/* +** Local configuration. You can use this space to add your redefinitions +** without modifying the main part of the file. +*/ + + + + + +#endif + diff --git a/build-scripts/pylint_rc b/build-scripts/pylint_rc new file mode 100644 index 00000000..2aec6467 --- /dev/null +++ b/build-scripts/pylint_rc @@ -0,0 +1,280 @@ +[MASTER] + +# Specify a configuration file. +#rcfile= + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Profiled execution. +profile=no + +# Add files or directories to the blacklist. They should be base names, not +# paths. +ignore=CVS,TraceEntries_pb2.py + +# Pickle collected data for later comparisons. +persistent=yes + +# List of plugins (as comma separated values of python modules names) to load, +# usually to register additional checkers. +load-plugins=pylint.extensions.comparetozero,pylint.extensions.emptystring + + +[MESSAGES CONTROL] + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time. See also the "--disable" option for examples. +#enable= + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once).You can also use "--disable=all" to +# disable everything first and then reenable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use"--disable=all --enable=classes +# --disable=W" +disable=invalid-name,broad-except,too-few-public-methods,missing-docstring,global-statement + + +[REPORTS] + +# Set the output format. Available formats are text, parseable, colorized, msvs +# (visual studio) and html. You can also give a reporter class, eg +# mypackage.mymodule.MyReporterClass. +output-format=text + +# Put messages in a separate file for each module / package specified on the +# command line instead of printing them on stdout. Reports (if any) will be +# written in a file name "pylint_global.[txt|html]". +files-output=no + +# Tells whether to display a full report or only the messages +reports=yes + +# Python expression which should return a note less than 10 (10 is the highest +# note). You have access to the variables errors warning, statement which +# respectively contain the number of errors / warnings messages and the total +# number of statements analyzed. This is used by the global evaluation report +# (RP0004). +evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) + +# Add a comment according to your evaluation note. This is used by the global +# evaluation report (RP0004). +comment=no + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details +#msg-template= + + +[FORMAT] + +# Maximum number of characters on a single line. +max-line-length=120 + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$ + +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=no + +# List of optional constructs for which whitespace checking is disabled +no-space-check=trailing-comma,dict-separator + +# Maximum number of lines in a module +max-module-lines=1000 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME,XXX + + +[TYPECHECK] + +# Tells whether missing members accessed in mixin class should be ignored. A +# mixin class is detected if its name ends with "mixin" (case insensitive). +ignore-mixin-members=yes + +# List of classes names for which member attributes should not be checked +# (useful for classes with attributes dynamically set). +ignored-classes=SQLObject + +# When zope mode is activated, add a predefined set of Zope acquired attributes +# to generated-members. +zope=no + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E0201 when accessed. Python regular +# expressions are accepted. +generated-members=REQUEST,acl_users,aq_parent + + +[SIMILARITIES] + +# Minimum lines number of a similarity. +min-similarity-lines=10 + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + +# Ignore imports when computing similarities. +ignore-imports=no + + +[VARIABLES] + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# A regular expression matching the beginning of the name of dummy variables +# (i.e. not used). +dummy-variables-rgx=_$|dummy + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid to define new builtins when possible. +additional-builtins= + + +[BASIC] + +# Required attributes for module, separated by a comma +required-attributes= + +# List of builtins function names that should not be used, separated by a comma +bad-functions=map,filter,apply,input + +# Regular expression which should only match correct module names +module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ + +# Regular expression which should only match correct module level names +const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ + +# Regular expression which should only match correct class names +class-rgx=[A-Z_][a-zA-Z0-9]+$ + +# Regular expression which should only match correct function names +function-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct method names +method-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct instance attribute names +attr-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct argument names +argument-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct variable names +variable-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct attribute names in class +# bodies +class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ + +# Regular expression which should only match correct list comprehension / +# generator expression variable names +inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ + +# Good variable names which should always be accepted, separated by a comma +good-names=i,j,k,ex,Run,_ + +# Bad variable names which should always be refused, separated by a comma +bad-names=foo,bar,baz,toto,tutu,tata + +# Regular expression which should only match function or class names that do +# not require a docstring. +no-docstring-rgx=__.*__ + +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=-1 + + +[IMPORTS] + +# Deprecated modules which should not be used, separated by a comma +deprecated-modules=regsub,TERMIOS,Bastion,rexec + +# Create a graph of every (i.e. internal and external) dependencies in the +# given file (report RP0402 must not be disabled) +import-graph= + +# Create a graph of external dependencies in the given file (report RP0402 must +# not be disabled) +ext-import-graph= + +# Create a graph of internal dependencies in the given file (report RP0402 must +# not be disabled) +int-import-graph= + + +[CLASSES] + +# List of interface methods to ignore, separated by a comma. This is used for +# instance to not check methods defines in Zope's Interface base class. +ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__,__new__,setUp + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=mcs + + +[DESIGN] + +# Maximum number of arguments for function / method +max-args=5 + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore +ignored-argument-names=_.* + +# Maximum number of locals for function / method body +max-locals=15 + +# Maximum number of return / yield for function / method body +max-returns=6 + +# Maximum number of branch for function / method body +max-branches=12 + +# Maximum number of statements in function / method body +max-statements=50 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of attributes for a class (see R0902). +max-attributes=7 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=2 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + + +[EXCEPTIONS] + +# Exceptions that will emit a warning when being caught. Defaults to +# "Exception" +overgeneral-exceptions=Exception diff --git a/build-scripts/run-clang-format.sh b/build-scripts/run-clang-format.sh new file mode 100755 index 00000000..b3734fee --- /dev/null +++ b/build-scripts/run-clang-format.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# Copyright (c) 2017 Dependable Systems Laboratory, EPFL +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# +# Automatically run clang-format on the S2E source code +# +# You must specify the path to the clang-format binary in the CLANG_FORMAT +# variable. This script must be run from the root directory of the S2E code +# repository +# + +set -e + +if [ -z "${CLANG_FORMAT}" ]; then + echo "Usage: CLANG_FORMAT=/path/to/clang-format ${0}" + echo "" + echo " CLANG_FORMAT - Path to the clang-format binary" + exit 1 +fi + +FILE_EXTS=".c .h .cpp .hpp .cc .hh .cxx" + +for EXT in ${FILE_EXTS}; do + echo "Applying clang-format to ${EXT} files..." + find -type f -name "*${EXT}" \ + -not -path "./guest/windows/*" \ + -not -path "./lua/*" \ + -not -path "./qemu/*" \ + -not -path "./build-scripts/*" \ + -exec ${CLANG_FORMAT} -i -style=file {} + +done diff --git a/build-scripts/run_pylint.py b/build-scripts/run_pylint.py new file mode 100755 index 00000000..699892c4 --- /dev/null +++ b/build-scripts/run_pylint.py @@ -0,0 +1,159 @@ +#!/usr/bin/env python + +# Copyright (c) 2017 Dependable Systems Lab, EPFL +# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html + +""" +Runs Pylint with some additional checkers. +""" + +from __future__ import print_function + +import os +import sys +import tokenize + +import astroid +from pylint.checkers import BaseChecker, BaseTokenChecker +from pylint.interfaces import IAstroidChecker, ITokenChecker +from pylint.lint import PyLinter +import six + + +################ +# Additional checkers +################ + +SINGLE_QUOTES = ('\'', '"') +TRIPLE_QUOTES = ('\'\'\'', '"""') + +DEFAULT_SINGLE_QUOTE = '\'' +DEFAULT_TRIPLE_QUOTE = '"""' + + +class LiteralQuoteChecker(BaseTokenChecker): + """ + Check that string literals use a consistent quote character, be it a single + quote or a double quote. + """ + + __implements__ = ITokenChecker + + name = 'string_literal_quotes' + msgs = {'C8001': ('Use quote character `%s` for string literals, not ' + '`%s`', + 'incorrect-string-literal-quote', + 'Used when the string literal quote character does not ' + 'match the one specified in the ' + '`expected-string-literal-quote` option.'), + 'C8002': ('Use `%s` triple-quotes, not `%s`', + 'incorrect-triple-quotes', + 'Used when the triple-quotes character does not match ' + 'the one specified in the `expected-triple-quote` ' + 'option.'), + } + options = (('expected-string-literal-quote', + {'type': 'choice', 'metavar': '<\' or ">', + 'default': DEFAULT_SINGLE_QUOTE, 'choices': SINGLE_QUOTES, + 'help': 'The default string literal quote character. Must be ' + 'either \' or "'}), + ('expected-string-triple-quote', + {'type': 'choice', 'metavar': '<\'\'\' or """>', + 'default': DEFAULT_TRIPLE_QUOTE, 'choices': TRIPLE_QUOTES, + 'help': 'The default string triple quote. Must be either ' + '\'\'\' or """'}), + ) + + def process_tokens(self, tokens): + for tok_type, token, (start_row, _), _, _ in tokens: + if tok_type == tokenize.STRING: + self._process_string_token(token, start_row) + + def _process_string_token(self, token, start_row): + expected_quote_char = self.config.expected_string_literal_quote + expected_triple_quotes = self.config.expected_string_triple_quote + + # Adapted from pylint/checkers/strings.py + for i, c in enumerate(token): + if c in SINGLE_QUOTES: + break + + # pylint: disable=undefined-loop-variable + # We ignore prefix markers like u, b, r + after_prefix = token[i:] + + # Check triple-quote strings + if len(after_prefix) >= 3 and after_prefix[:3] in TRIPLE_QUOTES: + if after_prefix[:3] != expected_triple_quotes: + self.add_message('incorrect-triple-quotes', line=start_row, + args=(expected_triple_quotes, + after_prefix[:3])) + # Check single quote strings + elif after_prefix[0] != expected_quote_char: + self.add_message('incorrect-string-literal-quote', line=start_row, + args=(expected_quote_char, after_prefix[0])) + + +class StringConcatChecker(BaseChecker): + """ + Look for string concatenation operations. + + We use a very naive approach and only look for string concatenations that + contain at least one string literal. + """ + + __implements__ = IAstroidChecker + + name = 'string_concatenation' + msgs = {'C8003': ('Prefer string substitution to string concatenation', + 'string-concat', + 'Used when a string concatenation operation is found.'), + } + + def visit_binop(self, node): + if node.op != '+': + return + + left = node.left + if (isinstance(left, astroid.Const) and + isinstance(left.value, six.string_types)): + self.add_message('string-concat', node=node) + + +def register(linter): + linter.register_checker(LiteralQuoteChecker(linter)) + linter.register_checker(StringConcatChecker(linter)) + + +################ +# Run pylint +################ + +FILE_DIR = os.path.dirname(__file__) +THIS_MODULE = os.path.splitext(os.path.basename(__file__))[0] +PYLINT_RC_PATH = os.path.join(os.path.realpath(FILE_DIR), 'pylint_rc') + + +def main(args): + if len(args) != 2: + print('Usage: %s /path/to/python/code' % args[0]) + sys.exit(1) + + # Need to add tis script's directory to the Python path so that this module + # can be made available to Pylint + sys.path.append(FILE_DIR) + + linter = PyLinter() + + linter.load_default_plugins() + linter.load_plugin_modules([THIS_MODULE]) + + linter.read_config_file(PYLINT_RC_PATH) + linter.load_config_file() + + linter.check(args[1]) + linter.generate_reports() + + +if __name__ == '__main__': + main(sys.argv) diff --git a/build-scripts/windows/Setup-DevHost.ps1 b/build-scripts/windows/Setup-DevHost.ps1 new file mode 100644 index 00000000..8488c184 --- /dev/null +++ b/build-scripts/windows/Setup-DevHost.ps1 @@ -0,0 +1,50 @@ +# Run this script in an admin powershell as follows: +# Set-ExecutionPolicy -Force -Scope Process Bypass; .\Setup-DevHost.ps1 + +# Install Chocolatey +iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) + +# Install some basic tools +choco install -y wget +choco install -y git +choco install -y rsync + +# Install VS2017 +choco install -y visualstudio2017community +choco install -y visualstudio2017-workload-nativedesktop --package-parameters "--includeOptional" + +# Download and install WDK 1803 +cd $env:USERPROFILE +wget.exe -O wdk_setup.exe https://go.microsoft.com/fwlink/?linkid=873060 +& .\wdk_setup.exe /features + /l wdk.log /norestart /quiet | Out-Null + +# The WDK installer does not install the VS extension in unattended mode. Do it manually. +& "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\vsixinstaller.exe" /q "C:\Program Files (x86)\Windows Kits\10\Vsix\WDK.vsix" | Out-Null + +# Install the OpenSSH Client and Server +dism /Online /Add-Capability /CapabilityName:OpenSSH.Client~~~~0.0.1.0 +dism /Online /Add-Capability /CapabilityName:OpenSSH.Server~~~~0.0.1.0 + +# Set up SSH +sc.exe config sshd start= auto +sc.exe config ssh-agent start= auto + +# Set up passwordless SSH +$SSHDir = "c:\Users\$env:USERNAME\.ssh" +$AuthorizedKeys = "$SSHDir\authorized_keys" + +mkdir $SSHDir +New-Item -Path $AuthorizedKeys -ItemType File + +# Repair-AuthorizedKeyPermission is supposed to fix passwordless login according to various +# tutorials, but in practice it breaks it. +# Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Confirm:$False +# Install-Module -Confirm:$False -Force OpenSSHUtils +# $ConfirmPreference = 'None'; Repair-AuthorizedKeyPermission $AuthorizedKeys -Confirm:$false + +sc.exe start sshd +sc.exe start ssh-agent + +# This will be used to convert PDBs into JSON files suitable for s2e-env +cd $env:USERPROFILE +wget.exe --no-check-certificate https://github.com/S2E/guest-tools/releases/download/v2.0.0/pdbparser.exe diff --git a/build-scripts/windows/remote-msbuild.sh b/build-scripts/windows/remote-msbuild.sh new file mode 100755 index 00000000..4f03085c --- /dev/null +++ b/build-scripts/windows/remote-msbuild.sh @@ -0,0 +1,82 @@ +#!/bin/bash +# Copyright (c) 2018 Cyberhaven +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# This script performs a remote build of a local Visual Studio Project. +# Use this script if you develop on a Linux box. The remote server must +# have Visual Studio Community 2017 installed. If you have any other version, +# please modify this script accordingly + +# Override these variables +REMOTE_HOST="${REMOTE_HOST:-192.168.187.140}" +REMOTE_USER="${REMOTE_USER:-s2e}" +REMOTE_FOLDER="${REMOTE_FOLDER:-build}" + +# These variables define the build configuration. They are solution-specific +# but you can usually choose between Debug/Release and x64/Win32. +VS_CONFIG="${VS_CONFIG:-Debug}" +VS_PLATFORM="${VS_PLATFORM:-x64}" + +VS_BUILD_OPTS="/property:Configuration=$VS_CONFIG /property:Platform=$VS_PLATFORM" +VS_ENV="C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\Common7\\Tools\\VsDevCmd.bat" +PDBPARSER="C:\\users\\$REMOTE_USER\\pdbparser.exe" +REMOTE_BUILD_PATH="c:\\users\\$REMOTE_USER\\$REMOTE_FOLDER" + +set -xe + +if [ $# -ne 1 ]; then + echo "Usage: $0 path/to/solution/dir" + exit 1 +fi + +SOLUTION_DIR="$1" +if [ ! -d "$SOLUTION_DIR" ]; then + echo "$SOLUTION_DIR does not exist" + exit 1 +fi + +# Generate build script in the solution dir. +# This script builds the solution then extracts line information +# from PDB files suitable for use by s2e-env. +cat <"$SOLUTION_DIR/build.bat" +call "$VS_ENV" +cd $REMOTE_BUILD_PATH +msbuild $VS_BUILD_OPTS + +setlocal enabledelayedexpansion + +FOR /R . %%A IN (*.sys *.exe *.dll) DO ( + echo Generating line information for %%A... + set BIN=%%A + set PDB=!BIN:.exe=.pdb! + set PDB=!BIN:.sys=.pdb! + $PDBPARSER -l %%A !PDB! > %%A.lines +) +EOF + +# rsync solution directory to remote location +# skip symlinks as windows doesn't understand them +rsync -rvz --no-links --delete "$SOLUTION_DIR"/* "${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_FOLDER}" + +# run msbuild remotely +ssh "${REMOTE_USER}@${REMOTE_HOST}" "cmd /c $REMOTE_BUILD_PATH\\build.bat" + +# rsync back the build artifacts +rsync -rvz "${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_FOLDER}"/* "$SOLUTION_DIR" diff --git a/build-scripts/windows/ssh-copy-id-win.sh b/build-scripts/windows/ssh-copy-id-win.sh new file mode 100755 index 00000000..3a489773 --- /dev/null +++ b/build-scripts/windows/ssh-copy-id-win.sh @@ -0,0 +1,51 @@ +#!/bin/bash +# Copyright (c) 2018 Cyberhaven +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# This script adds the authorized key of the current user to the remote Windows +# machine. The machine should have an SSH server running. + +if [ $# -ne 1 ]; then + echo "Usage: $0 user@host" + exit 1 +fi + +PUBKEY=~/.ssh/id_rsa.pub + +if [ ! -f "$PUBKEY" ]; then + echo "$PUBKEY does not exist" + exit 1 +fi + +HOST="$1" + +if ! echo $HOST | grep -q '@'; then + echo "Use user@host format instead of $HOST" + exit +fi + +USER="$(echo $HOST | cut -d '@' -f 1)" + +PKVAR="$(cat $PUBKEY)" + +REMOTE_FILE="c:\\users\\$USER\\.ssh\\authorized_keys" +echo "Adding contents of $PUBKEY to $REMOTE_FILE..." + +ssh "$HOST" "echo $PKVAR >> $REMOTE_FILE"