Skip to content

Commit

Permalink
Merge pull request #92 from S2E/issue/libdwarf-0.9.1
Browse files Browse the repository at this point in the history
Upgraded libdwarf to 0.9.1
  • Loading branch information
vitalych authored Apr 13, 2024
2 parents e17812d + 41b0a19 commit 5814e5a
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 1,885 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ jobs:
libboost-system-dev libboost-serialization-dev libboost-regex-dev \
libbsd-dev libpixman-1-dev \
libglib2.0-dev python3-docutils libpng-dev \
gcc-multilib g++-multilib libgomp1 unzip software-properties-common
gcc-multilib g++-multilib libgomp1 unzip software-properties-common \
libprotobuf-dev protobuf-compiler protobuf-c-compiler
sudo apt-get install -f
sudo apt-get install -y libgcc-s1:i386 libstdc++6:i386
Expand Down
12 changes: 4 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ FROM ubuntu:22.04
RUN dpkg --add-architecture i386 && apt-get update && \
apt-get -y install ca-certificates build-essential curl wget texinfo flex bison \
python-is-python3 python3-dev python3-venv python3-distro mingw-w64 lsb-release \
autoconf libtool

# Install S2E dependencies
RUN apt-get update && apt-get -y install libdwarf-dev libelf-dev libelf-dev:i386 \
autoconf libtool libprotobuf-dev protobuf-compiler protobuf-c-compiler \
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 python3-docutils libpng-dev \
gcc-multilib g++-multilib libgomp1 unzip
gcc-multilib g++-multilib libgomp1 unzip libzstd-dev

# The unzip and libgomp1 dependencies are needed to unzip and run binary Z3
# distributions

Expand Down Expand Up @@ -72,9 +71,6 @@ RUN cd s2e-build && \
RUN cd s2e-build && \
make -f ../s2e/Makefile S2E_PREFIX=/opt/s2e stamps/z3

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

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

Expand Down
49 changes: 7 additions & 42 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ BUILD_ARCH?=native
CFLAGS_ARCH:=-march=$(BUILD_ARCH)
CXXFLAGS_ARCH:=-march=$(BUILD_ARCH)

CXXFLAGS_DEBUG:=$(CXXFLAGS_ARCH)
CXXFLAGS_DEBUG:=$(CXXFLAGS_ARCH) -fno-limit-debug-info
CXXFLAGS_RELEASE:=$(CXXFLAGS_ARCH)

SED:=sed
Expand Down Expand Up @@ -146,8 +146,8 @@ GTEST_URL=https://github.com/google/googletest/archive/release-$(GTEST_VERSION).
# 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_URL=https://www.prevanders.net/libdwarf-0.9.1.tar.xz
LIBDWARF_SRC_DIR=libdwarf-0.9.1
LIBDWARF_BUILD_DIR=libdwarf

# rapidjson
Expand All @@ -158,12 +158,6 @@ RAPIDJSON_GIT_REV=fd3dc29a5c2852df569e1ea81dbde2c412ac5051
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/archive/refs/tags/v3.21.12.tar.gz
PROTOBUF_SRC_DIR=protobuf-3.21.12
PROTOBUF_BUILD_DIR=protobuf


###########
# Targets #
Expand Down Expand Up @@ -265,22 +259,14 @@ $(CAPSTONE_BUILD_DIR):

$(LIBDWARF_BUILD_DIR):
$(call DOWNLOAD,$(LIBDWARF_URL),$(S2E_BUILD)/$(LIBDWARF_BUILD_DIR).tar.gz)
tar -zxf $(S2E_BUILD)/$(LIBDWARF_BUILD_DIR).tar.gz
tar -Jxf $(S2E_BUILD)/$(LIBDWARF_BUILD_DIR).tar.gz
mkdir -p $(S2E_BUILD)/$(LIBDWARF_BUILD_DIR)

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


$(PROTOBUF_SRC_DIR).tar.gz:
$(call DOWNLOAD,$(PROTOBUF_URL),$(S2E_BUILD)/$(PROTOBUF_SRC_DIR).tar.gz)

$(PROTOBUF_BUILD_DIR): $(PROTOBUF_SRC_DIR).tar.gz
tar -zxf $(S2E_BUILD)/$(PROTOBUF_SRC_DIR).tar.gz
mkdir -p $(S2E_BUILD)/$(PROTOBUF_BUILD_DIR)

########
# LLVM #
########
Expand Down Expand Up @@ -421,27 +407,6 @@ stamps/rapidjson-make: stamps/rapidjson-configure
$(MAKE) -C $(RAPIDJSON_BUILD_DIR) install
touch $@

############
# protobuf #
############

PROTOBUF_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) \
-Dprotobuf_BUILD_TESTS=OFF \
-DCMAKE_BUILD_TYPE=Release


stamps/protobuf-configure: stamps/llvm-release-make $(PROTOBUF_BUILD_DIR)
cd $(PROTOBUF_BUILD_DIR) && cd $(S2E_BUILD)/$(PROTOBUF_SRC_DIR) && ./autogen.sh && \
CC=$(CLANG_CC) CXX=$(CLANG_CXX) CXXFLAGS=-fPIC CFLAGS=-fPIC ./configure --prefix=$(S2E_PREFIX)
touch $@

stamps/protobuf-make: stamps/protobuf-configure
$(MAKE) -C $(S2E_BUILD)/$(PROTOBUF_SRC_DIR) install
touch $@


#######
# Lua #
Expand Down Expand Up @@ -681,16 +646,16 @@ 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/klee-coverage-make
stamps/klee-coverage-make
stamps/libs2e-debug-configure: CONFIGURE_COMMAND = $(S2E_SRC)/libs2e/configure \
$(LIBS2E_CONFIGURE_FLAGS) \
$(LIBS2E_DEBUG_FLAGS)

stamps/libs2e-release-configure: $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/libs2e)
stamps/libs2e-release-configure: stamps/lua-make stamps/libvmi-release-install \
stamps/klee-release-make stamps/soci-make stamps/libfsigc++-release-make \
stamps/libq-release-make stamps/libcoroutine-release-make stamps/capstone-make \
stamps/protobuf-make
stamps/libq-release-make stamps/libcoroutine-release-make stamps/capstone-make

stamps/libs2e-release-configure: CONFIGURE_COMMAND = $(S2E_SRC)/libs2e/configure \
$(LIBS2E_CONFIGURE_FLAGS) \
$(LIBS2E_RELEASE_FLAGS)
Expand Down
5 changes: 0 additions & 5 deletions libs2e/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,9 @@ find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB_PKG glib-2.0)
include_directories(${GLIB_PKG_INCLUDE_DIRS})

set(Protobuf_USE_STATIC_LIBS ON)
include(FindProtobuf)
find_package(Protobuf REQUIRED)

# Old CMake does not support static libraries, so we have to patch the library manually
string(REPLACE .so .a PROTOBUF_LIBRARIES "${PROTOBUF_LIBRARIES}")


##### LLVM #####
find_package(LLVM REQUIRED)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
Expand Down
2 changes: 0 additions & 2 deletions libs2eplugins/src/s2e/Plugins/Core/Vmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@

#include <llvm/ADT/DenseSet.h>
#include <llvm/Support/Path.h>
#include <vmi/ElfDwarf.h>
#include <vmi/ExecutableFile.h>
#include <vmi/PEFile.h>
#include <vmi/Vmi.h>

#include <vmi/FileProvider.h>
#include <vmi/RegisterProvider.h>
Expand Down
9 changes: 9 additions & 0 deletions libs2eplugins/src/s2e/Plugins/OSMonitors/ModuleDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ struct SectionDescriptor {
}
};

inline llvm::raw_ostream &operator<<(llvm::raw_ostream &out, const SectionDescriptor &md) {
out << "[SectionDescriptor"
<< " Name=" << md.name << " RTLB=" << hexval(md.runtimeLoadBase) << " NLB=" << hexval(md.nativeLoadBase)
<< " Size=" << hexval(md.size) << " R=" << hexval(md.readable) << " W=" << hexval(md.writable)
<< " X=" << hexval(md.executable) << "]";

return out;
}

using ModuleSections = std::vector<SectionDescriptor>;

///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ModuleMapManager : public ProcessRegionMapManager<ModuleDescriptorConstPtr
ModuleDescriptorConstPtr value) -> bool {
os << "pid=" << hexval(pid);
os << " [" << hexval(start) << ", " << hexval(end) << "] ";
os << value.get();
os << *value.get();
os << "\n";

return true;
Expand Down
26 changes: 16 additions & 10 deletions libvmi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,17 @@ message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")

add_definitions(${LLVM_DEFINITIONS})

find_package(RapidJSON REQUIRED)

set(ENV{PKG_CONFIG_PATH} ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig)
find_package(PkgConfig REQUIRED)
set(CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX})
pkg_check_modules(LIBDWARF REQUIRED IMPORTED_TARGET libdwarf)

find_path(LIBDWARF_INCLUDE_DIRS
NAMES libdwarf.h dwarf.h
HINTS ${CMAKE_INSTALL_PREFIX}/include)
message(STATUS "Found libdwarf include dir ${LIBDWARF_INCLUDE_DIRS}")

find_library(LIBDWARF_LIB
libdwarf.a
Expand All @@ -56,7 +64,8 @@ find_library(LIBDWARF_LIB
# configuration.
include_directories(${LLVM_INCLUDE_DIRS}
"include"
${LIBDWARF_INCLUDE_DIRS})
${LIBDWARF_INCLUDE_DIRS}
${RapidJSON_INCLUDE_DIRS})

link_directories(${LIBDWARF_LIB_DIRS})

Expand All @@ -76,24 +85,21 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -O2")
add_subdirectory(src)

add_executable(crashdump src/crashdump.cpp)
target_link_libraries(crashdump vmi ${LLVM_LIBS} z)

add_executable(vmidemo src/vmidemo.cpp)
target_link_libraries(vmidemo vmi ${LIBDWARF_LIB} elf ${LLVM_LIBS} z)
target_link_libraries(crashdump vmi ${LLVM_LIBS})

add_executable(injector src/injector.cpp)
target_link_libraries(injector vmi elf ${LLVM_LIBS} z)
target_link_libraries(injector vmi elf ${LLVM_LIBS})

add_executable(dump src/dump.cpp)
target_link_libraries(dump vmi elf ${LLVM_LIBS} z)
target_link_libraries(dump vmi elf ${LLVM_LIBS})

add_executable(reader src/reader.cpp)
target_link_libraries(reader vmi elf ${LLVM_LIBS} z)
target_link_libraries(reader vmi elf ${LLVM_LIBS})

add_executable(addrs2lines src/addrs2lines.cpp)
target_link_libraries(addrs2lines vmi ${LIBDWARF_LIB} elf ${LLVM_LIBS} z)
target_link_libraries(addrs2lines vmi ${LIBDWARF_LIB} elf ${LLVM_LIBS} zstd)

install(TARGETS crashdump vmidemo injector dump reader addrs2lines
install(TARGETS crashdump injector dump reader addrs2lines
RUNTIME DESTINATION bin)
install(DIRECTORY "include/vmi"
DESTINATION include)
Expand Down
96 changes: 0 additions & 96 deletions libvmi/include/vmi/ElfDwarf.h

This file was deleted.

Loading

0 comments on commit 5814e5a

Please sign in to comment.