Skip to content

Commit

Permalink
Merge pull request #2 from thierry-tct/adding_llvm11_support
Browse files Browse the repository at this point in the history
Adding llvm11 support
  • Loading branch information
thierry-tct authored Jul 23, 2022
2 parents 0e8c125 + 62da78a commit cd40253
Show file tree
Hide file tree
Showing 138 changed files with 5,629 additions and 959 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
url = https://github.com/anhero/JsonBox.git
[submodule "lib/third-parties/dg"]
path = lib/third-parties/dg
url = https://github.com/thierry-tct/dg.git
url = https://github.com/mchalupa/dg.git
[submodule "lib/third-parties/FastBDT"]
path = lib/third-parties/FastBDT
url = https://github.com/thierry-tct/FastBDT.git
Expand Down
115 changes: 81 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Adapted from DG CMakeLists.txt file (https://github.com/mchalupa/dg/blob/master/CMakeLists.txt)
#cmake_minimum_required(VERSION 3.4.3)
cmake_minimum_required(VERSION 3.0.0)
cmake_minimum_required(VERSION 3.1.0)
project(MART_GenMu)

#if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Expand All @@ -18,6 +19,7 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/include )
# we need C++11 standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED on)
set(CMAKE_CXX_EXTENSIONS OFF)

OPTION(MART_GENMU "Support for Mutant Generation" ON)

Expand All @@ -31,20 +33,18 @@ endif()
#Set this to ON for generation of mutants object file (note that this will increase the executable size: 4MB VS 400MB)
OPTION(MART_GENMU_OBJECTFILE "Support for object file generation" OFF)

if(NOT CMAKE_BUILD_TYPE)
message(STATUS "The build type is not set. Setting to default.")
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "" FORCE)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "RelWithDebInfo"
"MinSizeRel" "Release")

message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")

if (MART_GENMU)
# for llvm dg we need cfg and postdom edges
#if (NOT ENABLE_CFG)
# message(STATUS "Enabling CFG edges due to llvm dg")
#endif()

#set(ENABLE_CFG ON)

#### Find LLVM INSTALLED
#include(${CMAKE_SOURCE_DIR}/cmake/find_llvm.cmake)
find_package(LLVM REQUIRED CONFIG)

message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
Expand All @@ -65,24 +65,24 @@ if (MART_GENMU)
# if we were provided a path to custom sources
# use that path
if (LLVM_SRC_PATH)
include_directories(${LLVM_SRC_PATH}/include)
message(STATUS "Looking for headers in given: ${LLVM_SRC_PATH}/include")
include_directories(SYSTEM ${LLVM_SRC_PATH}/include)
message(STATUS "Looking for headers in given: ${LLVM_SRC_PATH}/include")
else()
include_directories(${LLVM_INCLUDE_DIRS})
message(STATUS "Looking for headers in: ${LLVM_INCLUDE_DIRS}")
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
message(STATUS "Looking for headers in: ${LLVM_INCLUDE_DIRS}")
endif()

# if we were provided a path to custom build directory
# use that
if (LLVM_BUILD_PATH)
link_directories(${LLVM_BUILD_PATH}/lib)
link_directories(${LLVM_BUILD_PATH}/lib)

# llvm-config.h
include_directories("${LLVM_BUILD_PATH}/include")
message(STATUS "Looking for libraries in given: ${LLVM_BUILD_PATH}/lib")
# llvm-config.h
include_directories(SYSTEM "${LLVM_BUILD_PATH}/include")
message(STATUS "Looking for libraries in given: ${LLVM_BUILD_PATH}/lib")
else()
link_directories(${LLVM_LIBRARY_DIRS})
message(STATUS "Looking for libraries in: ${LLVM_LIBRARY_DIRS}")
link_directories(${LLVM_LIBRARY_DIRS})
message(STATUS "Looking for libraries in: ${LLVM_LIBRARY_DIRS}")
endif(LLVM_BUILD_PATH)

add_definitions(-DLLVM_TOOLS_BINARY_DIR="${LLVM_TOOLS_BINARY_DIR}")
Expand All @@ -92,7 +92,7 @@ if (MART_GENMU)

add_definitions(${LLVM_DEFINITIONS})

####
#### Mart +
if(MART_GENMU_OBJECTFILE)
add_definitions(-DMART_GENMU_OBJECTFILE)
set(KS_COMPONENTS_BY_VERSION llvm_libs all)
Expand All @@ -103,32 +103,70 @@ if (MART_GENMU)
irreader bitwriter analysis asmparser linker)
message(STATUS "MART_GENMU_OBJECTFILE is OFF")
endif(MART_GENMU_OBJECTFILE)
##
########

if (NOT ${LLVM_PACKAGE_VERSION} VERSION_LESS "3.5")
llvm_map_components_to_libnames(${KS_COMPONENTS_BY_VERSION})
option(LLVM_LINK_DYLIB "Link with LLVM dynamically" ON)

if (LLVM_LINK_DYLIB)
message(STATUS "LLVM linking: dynamic")
if (${LLVM_PACKAGE_VERSION} VERSION_LESS "3.8")
set(llvm_libs LLVM-${LLVM_PACKAGE_VERSION})
else()
# only LLVM 3.8+ provide unversioned library
set(llvm_libs LLVM)
endif()
else()
llvm_map_components_to_libraries(${KS_COMPONENTS_BY_VERSION})
message(STATUS "LLVM linking: static")
if (NOT ${LLVM_PACKAGE_VERSION} VERSION_LESS "3.5")
llvm_map_components_to_libnames(${KS_COMPONENTS_BY_VERSION})
else()
llvm_map_components_to_libraries(${KS_COMPONENTS_BY_VERSION})
endif()
endif()

add_definitions(-DHAVE_LLVM)
endif(MART_GENMU)

#if (ENABLE_CFG)
# add_definitions(-DENABLE_CFG)
#endif()
# LLVM 10 and newer require at least c++14 standard
if (${LLVM_PACKAGE_VERSION} VERSION_GREATER "9.0")
set(CMAKE_CXX_STANDARD 14)
option(USE_CXX14 "Use C++14 standard" ON)
endif()
endif(MART_GENMU)

message(STATUS "Using compiler: ${CMAKE_CXX_COMPILER}")

# explicitly add -std=c++11 and -fno-rtti
# --------------------------------------------------
# Compiler flags
# --------------------------------------------------
# explicitly add -std=c++11 (-std=c++14) and -fno-rtti
# we have CMAKE_CXX_STANDARD, but for some reason it does not
# put the -std=c++11 or -std=gnu++11 to the flags
# on some systems. For the -fno-rtti: LLVM still got problems
# with turning RTTI off...
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -std=c++11 -Wall -Wextra")
# put the -std=c++11 (-std=c++14) or -std=gnu++11 (-std=gnu++14)
# to the flags on some systems.
# For the -fno-rtti: LLVM still got problems with turning RTTI off...
if (USE_CXX14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -Wall -Wextra")
if (NO_EXCEPTIONS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
message(STATUS "NO_EXCEPTION is enabled")
endif()

if (USE_CLANG_SANITIZERS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fsanitize=address")
set(CMAKE_REQUIRED_FLAGS "-fsanitize=undefined,address") # for linker
check_cxx_compiler_flag("-fsanitize=undefined,address" sanitizers_work)
set(CMAKE_REQUIRED_FLAGS "")

if (sanitizers_work)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined,address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-sanitize-recover=all")
add_definitions(-DUSING_SANITIZERS)
else()
message(WARNING "Used compiler does not support sanitizers or its support is incomplete.")
endif()
endif()

# Debug Release RelWithDebInfo MinSizeRel.
Expand All @@ -155,5 +193,14 @@ add_subdirectory(lib)
add_subdirectory(tools)
add_subdirectory(scripts)
add_subdirectory(test EXCLUDE_FROM_ALL)
add_subdirectory(docs EXCLUDE_FROM_ALL)

#message(STATUS "Run: `make CollectMutOpHeaders && make` to compile")

if(NOT MART_GENMU)
set(INSTALL_EXCLUDE_PATTERNS PATTERN "llvm" EXCLUDE)
endif()
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
${INSTALL_EXCLUDE_PATTERNS})

84 changes: 64 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,82 @@
# sudo docker build --no-cache -t thierrytct/mart:llvm-9.0.0 . --build-arg llvm_version=9.0.0 && sudo docker push thierrytct/mart:llvm-9.0.0
##############################################################################
#
# Some build examples:
# - LLVM 3.4.2
# $ sudo docker build --no-cache -t thierrytct/mart:llvm-3.4.2 . --build-arg llvm_version=3.4.2 --build-arg base_image=thierrytct/llvm:3.4.2 --build-arg using_custom_llvm_base_image=on
# $ sudo docker push thierrytct/mart:llvm-3.4.2
# - LLVM 11
# $ sudo docker build --no-cache -t thierrytct/mart:llvm-11 . --build-arg llvm_version=11 --build-arg mutant_selection_on=on
# $ sudo docker push thierrytct/mart:llvm-11
# - LLVM latest
# $ sudo docker build --no-cache -t thierrytct/mart:llvm-latest . --build-arg mutant_selection_on=on
# $ sudo docker push thierrytct/mart:llvm-latest
#
# When using the latest version on LLVM (with version specified), do
# $ sudo docker image tag thierrytct/mart:llvm-<latest-llvm-version> thierrytct/mart:latest
# $ sudo docker push thierrytct/mart:latest
#
##############################################################################

#ARG llvm_version=3.8.1
ARG llvm_version=3.4.2
#ARG llvm_version=9.0.0
ARG base_image=docker.io/ubuntu:focal

FROM thierrytct/llvm:$llvm_version
ARG llvm_version=3.4.2
#ARG llvm_version=9.0.0
FROM $base_image AS base

# set this to enable mutant selection (with features axtraction)
# Tells whether the specified base image is a custom llvm built image.
# In that case, llvm will not be installed anymore
ARG using_custom_llvm_base_image
# The llvm_version to use, in case not using custom llvm base image.
# if not specified in that case, the latest LLVM version is used
ARG llvm_version
# build type. one of: Debug, Release, RelWithDebInfo and MinSizeRel
# default is RelWithDebInfo
ARG built_type=Debug
# set this to enable mutant selection (with features extraction)
# This relies on dg, so careful with newer LLVM versions, need to
# update compatibility with dg
ARG mutant_selection_on

ARG mart_location=/home/MART

RUN mkdir -p $mart_location/build $mart_location/src
RUN mkdir -p ${mart_location}/build $mart_location/src

#git clone https://github.com/thierry-tct/mart.git /tmp/mart/src
COPY . $mart_location/src
COPY . ${mart_location}/src

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get -y update; exit 0
# Install LLVM if not using custom llvm base image
RUN if [ "${using_custom_llvm_base_image}" = "" ]; then \
apt-get -y install cmake g++\
&& apt-get install -y python3-pip python3-dev \
&& cd /usr/local/bin \
&& ln -s /usr/bin/python3 python \
&& cd - \
&& { test -f $(dirname $(which pip3))/pip || ln -s $(which pip3) $(dirname $(which pip3))/pip; } \
&& pip install wllvm \
|| exit 1; \
llvm_version_suffix=""; \
[ "${llvm_version}" != "" ] && llvm_version_suffix="-${llvm_version}"; \
apt-get -y install llvm${llvm_version_suffix} clang${llvm_version_suffix} llvm${llvm_version_suffix}-dev \
|| exit 1; \
[ "${llvm_version}" != "" ] && ${mart_location}/src/update-alternatives-llvm-clang.sh ${llvm_version} 100; \
fi

# fdupes needed for post compilation TCE. XXX 'make gitversion' is needed for dg
# libtinfo-dev is needed because of linking error with llvm-9 (problem -ltinfo)
# zlib1g-dev is needed because of linking error with llvm-9 ubuntu (problem -lz)
# libtinfo-dev is needed because of linking error for some versions (problem -ltinfo)
# zlib1g-dev is needed because of linking error for some version with ubuntu (problem -lz)
RUN apt-get -y install fdupes libtinfo-dev zlib1g-dev \
&& mkdir -p $mart_location/build && cd $mart_location/build \
&& if [ "$mutant_selection_on" = "" ]; then extra=""; else extra="-DMART_MUTANT_SELECTION=on"; fi \
&& cmake $extra -DLLVM_DIR=/usr/local/share/llvm/cmake/ $mart_location/src \
&& make CollectMutOpHeaders && { make gitversion || echo "No gitversion need"; } && make
ENV PATH="$mart_location/build/tools:${PATH}"
&& mkdir -p ${mart_location}/build && cd ${mart_location}/build \
&& if [ "${mutant_selection_on}" = "" ]; then extra=""; else extra="-DMART_MUTANT_SELECTION=on"; fi \
&& if [ "${using_custom_llvm_base_image}" != "" ]; then extra+=" -DLLVM_DIR=/usr/local/share/llvm/cmake/"; fi \
&& cmake ${extra} -DCMAKE_BUILD_TYPE=${built_type} ${mart_location}/src \
&& { make gitversion || echo "No gitversion need"; } && make

ENV PATH="${mart_location}/build/tools:${PATH}"
ENV MART_BINARY_DIR="${mart_location}/build/tools"

COPY ./example $mart_location/example
COPY ./example ${mart_location}/example

CMD ["$mart_location/bash", "$mart_location/example/run_example.sh"]
CMD ["bash", "-c", "${MART_BINARY_DIR}/../../example/run_example.sh"]


# && sed -i'' "s|/home/LLVM/llvm-$llvm_version/build_cmake/bin|$(dirname $(which clang))|g; s|/home/LLVM/llvm-$llvm_version/src/cmake/modules|/usr/local/share/llvm/cmake/|g" /usr/local/share/llvm/cmake/LLVMConfig.cmake \
Loading

0 comments on commit cd40253

Please sign in to comment.