Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alessandro/refactor/llvmmultiversion cmake (#111)
* Change copyright notice in all the places. Trying to get cmake to download all the things * CMake refactor * Added the lib repository installer * Fixed a couple of paths in library repository scripts * Spelling and a missing .gitignore file. * The google test library was not correctly linked * Removed the pre-compiled XED library * Removed unused files; fixed the INSTALL directives. Added automatic protobuf generation. * Added a package generator script for ArchLinux * Merged in Alessandro's cmake magic * Cleanups, compatibility changes * CMake cleanup. o Removed the cmake folder as it is no longer used. o Removed the library_repository_installer directory and replaced it with a submodule to the newly introduced cxx_common repository. o Added the 'use_remill_semantics' branch of mcsema as a submodule under tools/cmake. o Updated the README instructions (added --recursive to the git clone command). Warning: the mcsema submodule is pointing to my fork of the repository! * CMake: avoid re-defining the C/CXX/ASM compiler. This will prevent CMake from looping forever when using submodules. * The tools/mcsema submodule now points to the official repository. * mcsema submodule update * Updated the mcsema git submodule to track the newest changes. * Various CMake fixes (see details). o External include headers were not correctly marked as SYSTEM. This caused them to output warnings and break the build. o The PROJECT_SOURCE CMake variable has been replaced with CMAKE_SOURCE_DIR. o Updated the mcsema submodule to point to the latest CMake fixes. * Getting closer to having the test case runner work again without using the CFG protobufs. * Trying to make things use ubuntu clang/llvm packages * Update to the mcsema submodule. * Minor changes for llvm version compatibility * Test cases should run now. Had to compile the lifted testcases to a .S file, as with the .bc file, they were being optimized away.. I think. The compilation to assembly seems unusually slow, though. * Minor change * Some stuff for llvm 4.0 support * Remove mcsema sub-module * Remove cxx-common submodule * First steps toward getting travis working again * Attempt at getting travis working again * Using https for cloning instead of ssh * Minor build script update * Added ISEL_ prefix to isels to make it easier for ForEachISel to find them. Commented out the defer_inlining intrinsics. * Changes related to mcsema2 * Simplify runtime targets generation. (#110) * CMake refactor: Added a new language 'BC' for the bitcode (see details). The language is used to generate the runtimes used by the architecture modules. The required executables (clang++ and llvm-link) are automatically detected in the same way as other compilers are. A new CMake function has been added and it can be used to easily generate runtime targets in a way similar to add_executable: add_runtime(<name> SOURCE <source list> ADDRESS_SIZE <n> DEFINITIONS <definition list>) Additionally, all files ending with the *.bcpp extensions will automatically invoke the bitcode compiler when listed in an active target. This should open support for parallel compilation! You just have to list all your .cpp files when calling add_runtime. * CMake: Fixes to the BC language handler. * CMake/BC: Use '.bo' for object files. X86 runtime: Add -g/-O flags.
- Loading branch information
Showing
359 changed files
with
4,634 additions
and
47,864 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,138 +1,203 @@ | ||
# Copyright 2017 Peter Goodman (peter@trailofbits.com), all rights reserved. | ||
# Copyright (c) 2017 Trail of Bits, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
project(remill) | ||
cmake_minimum_required (VERSION 3.2) | ||
|
||
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8) | ||
message(FATAL_ERROR "Remill and its tools are 64-bit only tools.") | ||
endif() | ||
# add the BC (bitcode) language definition | ||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/BCCompiler") | ||
|
||
include(CTest) | ||
|
||
set(REMILL_SOURCE_DIR "${PROJECT_SOURCE_DIR}") | ||
|
||
# | ||
# compiler selection | ||
# | ||
|
||
if (DEFINED ENV{TRAILOFBITS_LIBRARIES}) | ||
set(LIBRARY_REPOSITORY_ROOT $ENV{TRAILOFBITS_LIBRARIES}) | ||
include("${LIBRARY_REPOSITORY_ROOT}/cmake/repository.cmake") | ||
|
||
message(STATUS "Using the following library repository: ${LIBRARY_REPOSITORY_ROOT}") | ||
else () | ||
message(STATUS "Using system libraries") | ||
endif () | ||
|
||
# llvm | ||
if (DEFINED ENV{LLVM_INSTALL_PREFIX}) | ||
set(LLVM_INSTALL_PREFIX $ENV{LLVM_INSTALL_PREFIX}) | ||
endif () | ||
|
||
if (DEFINED LLVM_INSTALL_PREFIX) | ||
list(APPEND FINDPACKAGE_LLVM_HINTS "${LLVM_INSTALL_PREFIX}/lib/cmake/llvm/") | ||
list(APPEND FINDPACKAGE_LLVM_HINTS "${LLVM_INSTALL_PREFIX}/share/llvm/cmake/") | ||
|
||
message(STATUS "Using LLVM_INSTALL_PREFIX hints for find_package(LLVM): ${FINDPACKAGE_LLVM_HINTS}") | ||
endif () | ||
|
||
# it is important to avoid re-defining these variables if they have been already | ||
# set or you risk ending up in a configure loop! | ||
if (NOT DEFINED CMAKE_C_COMPILER) | ||
if (DEFINED LLVM_INSTALL_PREFIX) | ||
set(CMAKE_C_COMPILER "${LLVM_INSTALL_PREFIX}/bin/clang") | ||
else () | ||
set(CMAKE_C_COMPILER "clang") | ||
endif () | ||
endif () | ||
|
||
if (NOT DEFINED CMAKE_CXX_COMPILER) | ||
if (DEFINED LLVM_INSTALL_PREFIX) | ||
set(CMAKE_CXX_COMPILER "${LLVM_INSTALL_PREFIX}/bin/clang++") | ||
else () | ||
set(CMAKE_CXX_COMPILER "clang++") | ||
endif () | ||
endif () | ||
|
||
if (NOT DEFINED CMAKE_ASM_COMPILER) | ||
if (DEFINED LLVM_INSTALL_PREFIX) | ||
set(CMAKE_ASM_COMPILER "${LLVM_INSTALL_PREFIX}/bin/clang") | ||
else () | ||
set(CMAKE_ASM_COMPILER ${CMAKE_CXX_COMPILER}) | ||
endif () | ||
endif () | ||
|
||
if (NOT DEFINED CMAKE_LLVM_LINK) | ||
if (DEFINED LLVM_INSTALL_PREFIX) | ||
set(CMAKE_LLVM_LINK "${LLVM_INSTALL_PREFIX}/bin/llvm-link") | ||
else () | ||
set(CMAKE_LLVM_LINK "llvm-link") | ||
endif () | ||
endif () | ||
|
||
enable_language(C) | ||
enable_language(CXX) | ||
enable_language(ASM) | ||
|
||
include(CTest) | ||
# | ||
# compiler settings | ||
# | ||
|
||
# enable the gnu extensions | ||
set(CMAKE_CXX_EXTENSIONS ON) | ||
|
||
# visual studio already defaults to c++11 | ||
if (NOT WIN32) | ||
set(CMAKE_CXX_STANDARD 11) | ||
endif () | ||
|
||
# warnings and compiler settings | ||
set(PROJECT_CXXWARNINGS "-Wall -Wextra -Werror -pedantic -Wno-unused-parameter -Wno-c++98-compat -Wno-unreachable-code-return -Wno-nested-anon-types -Wno-extended-offsetof -Wno-gnu-anonymous-struct -Wno-gnu-designator -Wno-variadic-macros -Wno-gnu-zero-variadic-macro-arguments -Wno-gnu-statement-expression -Wno-return-type-c-linkage -Wno-c99-extensions -Wno-ignored-attributes -Wno-unused-local-typedef") | ||
set(PROJECT_CXXFLAGS "${PROJECT_CXXFLAGS} -Wno-unknown-warning-option ${PROJECT_CXXWARNINGS} -fPIC -fno-omit-frame-pointer -fvisibility-inlines-hidden -fno-exceptions -fno-asynchronous-unwind-tables -fno-rtti") | ||
|
||
# default build type | ||
if (NOT CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE "RelWithDebInfo") | ||
endif () | ||
|
||
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") | ||
# debug symbols | ||
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") | ||
set(PROJECT_CXXFLAGS "${PROJECT_CXXFLAGS} -gdwarf-2 -g3") | ||
endif () | ||
|
||
find_package(LLVM 3.9 REQUIRED) | ||
# optimization flags and definitions | ||
if (CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
set(PROJECT_CXXFLAGS "${PROJECT_CXXFLAGS} -O0") | ||
else () | ||
set(PROJECT_CXXFLAGS "${PROJECT_CXXFLAGS} -O3") | ||
list(APPEND PROJECT_DEFINITIONS "NDEBUG") | ||
endif () | ||
|
||
# | ||
# libraries | ||
# | ||
|
||
find_package(LLVM REQUIRED CONFIG HINTS ${FINDPACKAGE_LLVM_HINTS}) | ||
|
||
set(LLVM_LIBRARIES LLVMCore LLVMSupport LLVMAnalysis LLVMipo LLVMIRReader LLVMBitReader LLVMBitWriter LLVMTransformUtils LLVMScalarOpts LLVMLTO) | ||
list(APPEND PROJECT_LIBRARIES ${LLVM_LIBRARIES}) | ||
|
||
list(APPEND PROJECT_DEFINITIONS ${LLVM_DEFINITIONS}) | ||
list(APPEND PROJECT_INCLUDEDIRECTORIES ${LLVM_INCLUDE_DIRS}) | ||
|
||
# xed | ||
find_package(XED REQUIRED) | ||
find_package(GLOG REQUIRED) | ||
find_package(GFLAGS REQUIRED) | ||
find_package(Protobuf REQUIRED) | ||
|
||
include_directories("${PROJECT_SOURCE_DIR}") | ||
include_directories("${LLVM_INCLUDE_DIRS}") | ||
include_directories("${XED_INCLUDE_DIRS}") | ||
include_directories("${GLOG_INCLUDE_DIRS}") | ||
include_directories("${GFLAGS_INCLUDE_DIRS}") | ||
include_directories("${PROTOBUF_INCLUDE_DIRS}") | ||
include_directories("${CMAKE_CURRENT_LIST_DIR}") | ||
|
||
set(CMAKE_ASM_COMPILER ${CMAKE_CXX_COMPILER}) | ||
|
||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG") | ||
|
||
if(NOT DEFINED CMAKE_C_COMPILER) | ||
set(CMAKE_C_COMPILER "${LLVM_INSTALL_PREFIX}/bin/clang-3.9") | ||
endif() | ||
|
||
if(NOT DEFINED CMAKE_CXX_COMPILER) | ||
set(CMAKE_CXX_COMPILER ${CMAKE_C_COMPILER}) | ||
endif() | ||
|
||
if(NOT DEFINED CMAKE_ASM_COMPILER) | ||
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) | ||
endif() | ||
|
||
if(NOT DEFINED CMAKE_LLVM_LINK) | ||
set(CMAKE_LLVM_LINK "${LLVM_INSTALL_PREFIX}/bin/llvm-link") | ||
endif() | ||
|
||
if(UNIX AND NOT APPLE) | ||
set(LINUX TRUE) | ||
endif() | ||
|
||
add_definitions(${LLVM_DEFINITIONS}) | ||
|
||
add_compile_options( | ||
-Wall | ||
-Wextra | ||
-Werror | ||
-pedantic | ||
|
||
-g3 | ||
-O0 | ||
|
||
-Wno-unused-parameter | ||
-Wno-c++98-compat | ||
-Wno-unreachable-code-return | ||
-Wno-nested-anon-types | ||
-Wno-extended-offsetof | ||
-Wno-gnu-anonymous-struct | ||
-Wno-gnu-designator | ||
-Wno-variadic-macros | ||
-Wno-gnu-zero-variadic-macro-arguments | ||
-Wno-gnu-statement-expression | ||
-Wno-return-type-c-linkage | ||
-Wno-c99-extensions | ||
-Wno-ignored-attributes | ||
-Wno-unused-local-typedef | ||
|
||
-fno-omit-frame-pointer | ||
-fvisibility-inlines-hidden | ||
|
||
-fno-exceptions | ||
-fno-rtti | ||
-fno-asynchronous-unwind-tables | ||
|
||
-fno-rtti | ||
-std=gnu++11 | ||
-m64 | ||
|
||
-DINSTALL_SEMANTICS_DIR="${CMAKE_INSTALL_PREFIX}/share/remill/semantics/" | ||
-DBUILD_SEMANTICS_DIR="${CMAKE_CURRENT_BINARY_DIR}/remill/Arch/X86/Runtime/" | ||
-DGOOGLE_PROTOBUF_NO_RTTI | ||
) | ||
list(APPEND PROJECT_LIBRARIES ${XED_LIBRARIES}) | ||
list(APPEND PROJECT_INCLUDEDIRECTORIES ${XED_INCLUDE_DIRS}) | ||
|
||
add_library(remill STATIC | ||
# google log module | ||
find_package(glog REQUIRED) | ||
list(APPEND PROJECT_LIBRARIES glog::glog) | ||
|
||
# gflags | ||
find_package(gflags REQUIRED) | ||
list(APPEND PROJECT_LIBRARIES gflags) | ||
|
||
# | ||
# target settings | ||
# | ||
|
||
list(APPEND PROJECT_DEFINITIONS "INSTALL_SEMANTICS_DIR=\"${CMAKE_INSTALL_PREFIX}share/remill/semantics/\"") | ||
list(APPEND PROJECT_DEFINITIONS "BUILD_SEMANTICS_DIR=\"${CMAKE_CURRENT_BINARY_DIR}/remill/Arch/X86/Runtime/\"") | ||
|
||
add_library(${PROJECT_NAME} STATIC | ||
remill/Arch/X86/Arch.cpp | ||
remill/Arch/Arch.cpp | ||
remill/Arch/Instruction.cpp | ||
remill/Arch/Name.cpp | ||
remill/CFG/BlockHasher.cpp | ||
remill/CFG/CFG.cpp | ||
|
||
remill/BC/IntrinsicTable.cpp | ||
remill/BC/Lifter.cpp | ||
remill/BC/Optimizer.cpp | ||
remill/BC/Util.cpp | ||
|
||
remill/OS/FileSystem.cpp | ||
remill/OS/OS.cpp | ||
third_party/murmurhash/MurmurHash2.cpp) | ||
|
||
target_link_libraries(remill | ||
${GFLAGS_LIBRARIES} | ||
${GLOG_LIBRARIES} | ||
${XED_LIBRARIES} | ||
${PROTOBUF_LIBRARIES} | ||
LLVMCore | ||
LLVMSupport | ||
LLVMAnalysis | ||
LLVMipo | ||
LLVMIRReader | ||
LLVMBitReader | ||
LLVMBitWriter | ||
LLVMTransformUtils | ||
LLVMScalarOpts | ||
LLVMLTO | ||
) | ||
|
||
install( | ||
TARGETS remill | ||
ARCHIVE DESTINATION lib | ||
) | ||
# this is needed for the #include directives with absolutes paths to work correctly; it must | ||
# also be set to PUBLIC since remill-lift includes some files directly | ||
list(APPEND PROJECT_INCLUDEDIRECTORIES ${CMAKE_SOURCE_DIR}) | ||
|
||
# add everything as public; the remill_lift executable will inherit all settings from us | ||
target_link_libraries(${PROJECT_NAME} PUBLIC ${PROJECT_LIBRARIES}) | ||
target_include_directories(${PROJECT_NAME} PUBLIC SYSTEM ${PROJECT_INCLUDEDIRECTORIES}) | ||
target_compile_definitions(${PROJECT_NAME} PUBLIC ${PROJECT_DEFINITIONS}) | ||
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS ${PROJECT_CXXFLAGS}) | ||
|
||
# | ||
# install directives | ||
# | ||
|
||
install(DIRECTORY DESTINATION "share/remill") | ||
|
||
# | ||
# additional targets | ||
# | ||
|
||
add_custom_target(semantics) | ||
add_subdirectory(remill/Arch/X86/Runtime) | ||
|
||
add_subdirectory(tools) | ||
# mcsema needs to be manually cloned into this repo. | ||
if (EXISTS ${CMAKE_SOURCE_DIR}/tools/mcsema) | ||
add_subdirectory(tools/mcsema) | ||
endif () | ||
|
||
|
||
add_subdirectory(tests/X86) | ||
# only enable tests when compiling under x64 | ||
if (CMAKE_SIZEOF_VOID_P EQUAL 8) | ||
if(UNIX AND NOT APPLE) | ||
set(LINUX TRUE) | ||
add_subdirectory(tests/X86) | ||
endif () | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.