Skip to content

Commit

Permalink
Remove old cxx common logic (#500)
Browse files Browse the repository at this point in the history
* Remove old cxx-common references

* Test on this branch first

* Revert "Test on this branch first"

This reverts commit 888b584.
  • Loading branch information
ekilmer authored Apr 3, 2021
1 parent 2b241b8 commit 2eaf52c
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 974 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/vcpkg_ci.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,21 @@ jobs:
asset_path: remill_macos-10.15_packages.zip
asset_name: remill_macos-10.15_packages.zip
asset_content_type: application/gzip


Docker_Linux:
runs-on: ubuntu-latest
strategy:
matrix:
llvm: ["11"]
ubuntu: ["18.04"]
steps:
- uses: actions/checkout@v2
- name: Build LLVM ${{ matrix.llvm }} on ${{ matrix.ubuntu }}
run: |
docker build . -t docker.pkg.github.com/lifting-bits/remill/remill-llvm${{ matrix.llvm }}-ubuntu${{ matrix.ubuntu }}-amd64:latest -f Dockerfile --build-arg UBUNTU_VERSION=${{ matrix.ubuntu }} --build-arg ARCH=amd64 --build-arg LLVM_VERSION=${{ matrix.llvm }}
- name: Test Docker image
run: |
docker run --rm docker.pkg.github.com/lifting-bits/remill/remill-llvm${{ matrix.llvm }}-ubuntu${{ matrix.ubuntu }}-amd64:latest --arch amd64 --ir_out /dev/stdout --bytes c704ba01000000
docker run --rm docker.pkg.github.com/lifting-bits/remill/remill-llvm${{ matrix.llvm }}-ubuntu${{ matrix.ubuntu }}-amd64:latest --arch aarch64 --ir_out /dev/stdout --address 0x400544 --bytes FD7BBFA90000009000601891FD030091B7FFFF97E0031F2AFD7BC1A8C0035FD6
docker run --rm docker.pkg.github.com/lifting-bits/remill/remill-llvm${{ matrix.llvm }}-ubuntu${{ matrix.ubuntu }}-amd64:latest --arch aarch32 -ir_out /dev/stderr --bytes 0cd04de208008de504108de500208de508309de504009de500109de5903122e0c20fa0e110109fe5001091e5002081e5040081e50cd08de21eff2fe14000000000000000
196 changes: 54 additions & 142 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,75 +12,38 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if (NOT DEFINED ENV{TRAILOFBITS_LIBRARIES})
message(STATUS "Using new vcpkg build system")
include(CMakeLists_vcpkg.txt)
return()
endif()
include(cmake/vcpkg_helper.cmake)

project(remill)
cmake_minimum_required(VERSION 3.14)

include(GNUInstallDirs)

include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/settings.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/BCCompiler.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils_vcpkg.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/ccache.cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
include(CTest)

if (LLVM_Z3_INSTALL_DIR)
find_package(Z3 4.7.1)
set(need_z3 TRUE)
elseif(DEFINED CXX_COMMON_REPOSITORY_ROOT)
set(LLVM_Z3_INSTALL_DIR "${CXX_COMMON_REPOSITORY_ROOT}/z3" CACHE PATH "Path to the z3 installation")
set(need_z3 TRUE)
else()
set(need_z3 FALSE)
endif()

if(need_z3)
find_package(Z3 4.7.1)
if (NOT Z3_FOUND)
message(WARNING "Z3 >= 4.7.1 has not been found in LLVM_Z3_INSTALL_DIR: ${LLVM_Z3_INSTALL_DIR}.")
endif()
endif()

configureCcache()
FindAndSelectClangCompiler()

enable_language(C CXX ASM)

set(REMILL_SOURCE_DIR "${PROJECT_SOURCE_DIR}")

if(DEFINED WIN32)
set(dynamic_lib_prefix "")
set(dynamic_lib_extension "dll")
set(static_lib_prefix "")
set(static_lib_extension "lib")
set(executable_extension ".exe")
set(install_folder "${CMAKE_INSTALL_PREFIX}/remill")
else()
set(dynamic_lib_prefix "lib")
set(dynamic_lib_extension "so")
set(static_lib_prefix "lib")
set(static_lib_extension "a")
set(executable_extension "")
set(install_folder "${CMAKE_INSTALL_PREFIX}")
endif()

set(REMILL_INSTALL_LIB_DIR "${install_folder}/lib" CACHE PATH "Directory in which remill libraries will be installed")
set(REMILL_INSTALL_BIN_DIR "${install_folder}/bin" CACHE PATH "Directory in which remill binaries will be installed")
set(REMILL_INSTALL_INCLUDE_DIR "${install_folder}/include" CACHE PATH "Directory in which remill headers will be installed")
set(REMILL_INSTALL_SHARE_DIR "${install_folder}/share" CACHE PATH "Directory in which remill cmake files will be installed")
set(REMILL_INSTALL_LIB_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Directory in which remill libraries will be installed")
set(REMILL_INSTALL_BIN_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH "Directory in which remill binaries will be installed")
set(REMILL_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/remill" CACHE PATH "Directory in which remill headers will be installed")
set(REMILL_INSTALL_SHARE_DIR "${CMAKE_INSTALL_DATADIR}" CACHE PATH "Directory in which remill cmake files will be installed")

#
# libraries
#

# LLVM
find_package(LLVM REQUIRED CONFIG HINTS ${FINDPACKAGE_LLVM_HINTS})
find_package(LLVM CONFIG REQUIRED)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

string(REPLACE "." ";" LLVM_VERSION_LIST ${LLVM_PACKAGE_VERSION})
list(GET LLVM_VERSION_LIST 0 LLVM_MAJOR_VERSION)
Expand All @@ -93,6 +56,7 @@ target_include_directories(thirdparty_llvm SYSTEM INTERFACE
target_compile_definitions(thirdparty_llvm INTERFACE
${LLVM_DEFINITIONS}
)
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/BCCompiler.cmake")

# Go find only the static libraries of LLVM, and link against those.
foreach(LLVM_LIB IN LISTS LLVM_AVAILABLE_LIBS)
Expand All @@ -105,40 +69,41 @@ endforeach()
# These are out-of-order in `LLVM_AVAILABLE_LIBS` and should always be last.
list(REMOVE_ITEM LLVM_LIBRARIES LLVMMC LLVMCore LLVMSupport)
list(APPEND LLVM_LIBRARIES LLVMMC LLVMCore LLVMSupport)

target_link_libraries(thirdparty_llvm INTERFACE
${LLVM_LIBRARIES}
)

# Microsoft Z3
add_library(thirdparty_z3 INTERFACE)
if(Z3_FOUND)
target_include_directories(thirdparty_z3 SYSTEM INTERFACE
${Z3_INCLUDE_DIR}
)
target_link_libraries(thirdparty_z3 INTERFACE
${Z3_LIBRARIES}
)
# Microsoft Z3 with LLVM. Not exactly used in remill, but LLVM doesn't link
# against it correctly
# NOTE: If changing this, also replicate in remillConfig file
if (LLVM_WITH_Z3)
find_package(Z3 CONFIG REQUIRED 4.7.1)
get_target_property(LLVMSupport_LIBS LLVMSupport INTERFACE_LINK_LIBRARIES)
list(REMOVE_ITEM LLVMSupport_LIBS Z3)
list(APPEND LLVMSupport_LIBS z3::libz3)
set_target_properties(LLVMSupport PROPERTIES
INTERFACE_LINK_LIBRARIES "${LLVMSupport_LIBS}")
endif()

message(STATUS "LLVM Libraries: ${LLVM_LIBRARIES}")

# Intel XED
find_package(XED REQUIRED)
find_package(XED CONFIG REQUIRED)
add_library(thirdparty_xed INTERFACE)
target_include_directories(thirdparty_xed SYSTEM INTERFACE
${XED_INCLUDE_DIRS}
)
target_link_libraries(thirdparty_xed INTERFACE
${XED_LIBRARIES}
XED::XED
)

# Google glog module
find_package(glog REQUIRED)
find_package(glog CONFIG REQUIRED)
add_library(thirdparty_glog INTERFACE)
target_link_libraries(thirdparty_glog INTERFACE
glog::glog
)

# Google gflags
find_package(gflags REQUIRED)
find_package(gflags CONFIG REQUIRED)
add_library(thirdparty_gflags INTERFACE)
target_link_libraries(thirdparty_gflags INTERFACE
gflags
Expand Down Expand Up @@ -173,32 +138,33 @@ option(REMILL_BUILD_SPARC32_RUNTIME "Build the Runtime for SPARC32. Turn this of
# target settings
#

set(REMILL_LLVM_VERSION "${LLVM_MAJOR_VERSION}.${LLVM_MINOR_VERSION}")
set(REMILL_LLVM_VERSION "${LLVM_MAJOR_VERSION}")
message("Remill llvm version: ${REMILL_LLVM_VERSION}")
math(EXPR REMILL_LLVM_VERSION_NUMBER "${LLVM_MAJOR_VERSION} * 100 + ${LLVM_MINOR_VERSION}")

if(DEFINED WIN32)
set(REMILL_INSTALL_SEMANTICS_DIR "${install_folder}/${REMILL_LLVM_VERSION}/semantics" CACHE PATH "Directory into which semantics are installed")
else()
set(REMILL_INSTALL_SEMANTICS_DIR "${REMILL_INSTALL_SHARE_DIR}/remill/${REMILL_LLVM_VERSION}/semantics" CACHE PATH "Directory into which semantics are installed")
endif()
set(REMILL_INSTALL_SEMANTICS_DIR "${CMAKE_INSTALL_PREFIX}/${REMILL_INSTALL_SHARE_DIR}/remill/${REMILL_LLVM_VERSION}/semantics" CACHE PATH "Directory into which semantics are installed")

set(REMILL_BUILD_SEMANTICS_DIR_X86 "${CMAKE_CURRENT_BINARY_DIR}/lib/Arch/X86/Runtime")
set(REMILL_BUILD_SEMANTICS_DIR_AARCH32 "${CMAKE_CURRENT_BINARY_DIR}/lib/Arch/AArch32/Runtime")
set(REMILL_BUILD_SEMANTICS_DIR_AARCH64 "${CMAKE_CURRENT_BINARY_DIR}/lib/Arch/AArch64/Runtime")
set(REMILL_BUILD_SEMANTICS_DIR_SPARC32 "${CMAKE_CURRENT_BINARY_DIR}/lib/Arch/SPARC32/Runtime")
set(REMILL_BUILD_SEMANTICS_DIR_SPARC64 "${CMAKE_CURRENT_BINARY_DIR}/lib/Arch/SPARC64/Runtime")

# add everything as public.
set(REMILL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(REMILL_LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib")

add_library(remill_settings INTERFACE)

target_include_directories(remill_settings INTERFACE "${REMILL_INCLUDE_DIR}")
target_include_directories(remill_settings INTERFACE
$<BUILD_INTERFACE:${REMILL_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)

if(WIN32)
# warnings and compiler settings
target_compile_options(remill_settings INTERFACE
/MD /nologo /W3 /EHsc /wd4141 /wd4146 /wd4180 /wd4244
"$<$<CONFIG:Debug>:/MDd>$<$<CONFIG:Release>:/MD>"
/nologo /W3 /EHsc /wd4141 /wd4146 /wd4180 /wd4244
/wd4258 /wd4267 /wd4291 /wd4345 /wd4351 /wd4355 /wd4456
/wd4457 /wd4458 /wd4459 /wd4503 /wd4624 /wd4722 /wd4800
/wd4100 /wd4127 /wd4512 /wd4505 /wd4610 /wd4510 /wd4702
Expand Down Expand Up @@ -264,23 +230,20 @@ else()
endif()

target_compile_definitions(remill_settings INTERFACE
"REMILL_INSTALL_SEMANTICS_DIR=\"${REMILL_INSTALL_SEMANTICS_DIR}/\""
"REMILL_INSTALL_SEMANTICS_DIR=\"${REMILL_INSTALL_SEMANTICS_DIR}\""
"REMILL_BUILD_SEMANTICS_DIR_X86=\"${REMILL_BUILD_SEMANTICS_DIR_X86}\""
"REMILL_BUILD_SEMANTICS_DIR_AARCH32=\"${REMILL_BUILD_SEMANTICS_DIR_AARCH32}\""
"REMILL_BUILD_SEMANTICS_DIR_AARCH64=\"${REMILL_BUILD_SEMANTICS_DIR_AARCH64}\""
"REMILL_BUILD_SEMANTICS_DIR_SPARC32=\"${REMILL_BUILD_SEMANTICS_DIR_SPARC32}\""
"REMILL_BUILD_SEMANTICS_DIR_SPARC64=\"${REMILL_BUILD_SEMANTICS_DIR_SPARC64}\""
)

set(THIRDPARTY_LIBRARY_LIST thirdparty_z3
thirdparty_llvm
thirdparty_xed
thirdparty_glog
thirdparty_gflags)

set(THIRDPARTY_LIBRARY_LIST thirdparty_llvm thirdparty_xed thirdparty_glog thirdparty_gflags)
target_link_libraries(remill_settings INTERFACE
${THIRDPARTY_LIBRARY_LIST}
)
install(TARGETS remill_settings ${THIRDPARTY_LIBRARY_LIST}
EXPORT remillTargets)

add_subdirectory(lib/Arch)
add_subdirectory(lib/BC)
Expand All @@ -297,69 +260,18 @@ target_link_libraries(remill INTERFACE
remill_version
${LINKER_END_GROUP}
)
install(TARGETS remill EXPORT remillTargets)

#
# Also install clang, libllvm and llvm-link
#

set(INSTALLED_CLANG_NAME "remill-clang-${REMILL_LLVM_VERSION}${executable_extension}")
set(INSTALLED_LLVMLINK_NAME "remill-llvm-link-${REMILL_LLVM_VERSION}${executable_extension}")

if("${CXX_COMMON_REPOSITORY_ROOT}" STREQUAL "" OR NOT EXISTS "${CXX_COMMON_REPOSITORY_ROOT}/llvm")
set(INSTALLED_LIBLLVM_NAME "${dynamic_lib_prefix}LLVM-${REMILL_LLVM_VERSION}.${dynamic_lib_extension}")

# system binaries are not built statically, so we need to fix the rpath
find_program("clang_location" "clang-${REMILL_LLVM_VERSION}${executable_extension}")
if("${clang_location}" STREQUAL "clang_location-NOTFOUND")
message(FATAL_ERROR "InstallExternalTarget: Failed to locate the clang executable")
endif()

message("InstallExternalTarget: Found clang executable: ${clang_location}")

find_program("llvmlink_location" "llvm-link${executable_extension}")
if("${llvmlink_location}" STREQUAL "llvmlink_location-NOTFOUND")
message(FATAL_ERROR "InstallExternalTarget: Failed to locate the llvm-link executable")
endif()

message("InstallExternalTarget: Found llvm-link executable: ${llvmlink_location}")

find_library("libllvm_location" "${dynamic_lib_prefix}LLVM-${REMILL_LLVM_VERSION}.${dynamic_lib_extension}")
if("${libllvm_location}" STREQUAL "libllvm_location-NOTFOUND")
message(FATAL_ERROR "InstallExternalTarget: Failed to locate the libLLVM dynamic library")
endif()

message("InstallExternalTarget: Found libLLVM location: ${libllvm_location}")
set(INSTALLED_CLANG_NAME "remill-clang-${REMILL_LLVM_VERSION}${CMAKE_EXECUTABLE_SUFFIX}")
set(INSTALLED_LLVMLINK_NAME "remill-llvm-link-${REMILL_LLVM_VERSION}${CMAKE_EXECUTABLE_SUFFIX}")

InstallExternalTarget("ext_clang" "${clang_location}" "${REMILL_INSTALL_BIN_DIR}"
"${INSTALLED_CLANG_NAME}" "${REMILL_INSTALL_LIB_DIR}")
InstallExternalTarget("ext_clang" "${CLANG_PATH}" "BIN" "${INSTALLED_CLANG_NAME}")

InstallExternalTarget("ext_llvmlink" "${llvmlink_location}" "${REMILL_INSTALL_BIN_DIR}"
"${INSTALLED_LLVMLINK_NAME}" "${REMILL_INSTALL_LIB_DIR}")

else()
# The executable in our binary repository are statically built, meaning that we don't need
# to change the rpath
InstallExternalTarget("ext_clang" "${CXX_COMMON_REPOSITORY_ROOT}/llvm/bin/clang${executable_extension}"
"${REMILL_INSTALL_BIN_DIR}" "${INSTALLED_CLANG_NAME}")

InstallExternalTarget("ext_llvmlink" "${CXX_COMMON_REPOSITORY_ROOT}/llvm/bin/llvm-link${executable_extension}"
"${REMILL_INSTALL_BIN_DIR}" "${INSTALLED_LLVMLINK_NAME}")
endif()

set(REMILL_BC_LIBRARY_LOCATION "${REMILL_INSTALL_LIB_DIR}/${static_lib_prefix}remill_bc.${static_lib_extension}")
set(REMILL_ARCH_LIBRARY_LOCATION "${REMILL_INSTALL_LIB_DIR}/${static_lib_prefix}remill_arch.${static_lib_extension}")
set(REMILL_ARCH_X86_LIBRARY_LOCATION "${REMILL_INSTALL_LIB_DIR}/${static_lib_prefix}remill_arch_x86.${static_lib_extension}")
set(REMILL_ARCH_AARCH32_LIBRARY_LOCATION "${REMILL_INSTALL_LIB_DIR}/${static_lib_prefix}remill_arch_aarch32.${static_lib_extension}")
set(REMILL_ARCH_AARCH64_LIBRARY_LOCATION "${REMILL_INSTALL_LIB_DIR}/${static_lib_prefix}remill_arch_aarch64.${static_lib_extension}")
set(REMILL_ARCH_SPARC32_LIBRARY_LOCATION "${REMILL_INSTALL_LIB_DIR}/${static_lib_prefix}remill_arch_sparc32.${static_lib_extension}")
set(REMILL_ARCH_SPARC64_LIBRARY_LOCATION "${REMILL_INSTALL_LIB_DIR}/${static_lib_prefix}remill_arch_sparc64.${static_lib_extension}")
set(REMILL_OS_LIBRARY_LOCATION "${REMILL_INSTALL_LIB_DIR}/${static_lib_prefix}remill_os.${static_lib_extension}")
set(REMILL_VERSION_LIBRARY_LOCATION "${REMILL_INSTALL_LIB_DIR}/${static_lib_prefix}remill_version.${static_lib_extension}")


set(REMILL_INCLUDE_LOCATION "${REMILL_INSTALL_INCLUDE_DIR}")
get_target_property(REMILL_COMPILE_OPTIONS remill_settings INTERFACE_COMPILE_OPTIONS)
get_target_property(REMILL_COMPILE_DEFINITIONS remill_settings INTERFACE_COMPILE_DEFINITIONS)
InstallExternalTarget("ext_llvmlink" "${LLVMLINK_PATH}" "BIN" "${INSTALLED_LLVMLINK_NAME}")

GetTargetTree(THIRDPARTY_LIBRARIES ${THIRDPARTY_LIBRARY_LIST})
GetPublicIncludeFolders(THIRDPARTY_INCLUDE_DIRECTORIES ${THIRDPARTY_LIBRARIES})
Expand All @@ -381,22 +293,17 @@ list(REMOVE_DUPLICATES THIRDPARTY_LIBRARY_FILES)

# First do the basic substitutions.
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/remillConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/remillConfig.cmake.pregen"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/remillConfig_vcpkg.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/remillConfig.cmake"
@ONLY
)

# Then expand the generator expressions added to `THIRDPARTY_LIBRARY_FILES`.
file(GENERATE
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/remillConfig.cmake"
INPUT "${CMAKE_CURRENT_BINARY_DIR}/remillConfig.cmake.pregen"
)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/remillConfig.cmake"
"${CMAKE_CURRENT_LIST_DIR}/cmake/vcpkg_helper.cmake"
DESTINATION "${REMILL_INSTALL_LIB_DIR}/cmake/remill"
)

install(DIRECTORY "${REMILL_INCLUDE_DIR}/remill"
install(DIRECTORY "${REMILL_INCLUDE_DIR}/remill/"
DESTINATION "${REMILL_INSTALL_INCLUDE_DIR}"
)

Expand All @@ -409,8 +316,13 @@ add_custom_target(semantics)
# tools
add_subdirectory(bin)

install(EXPORT remillTargets
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/remill")

# tests
message("compiler ID ${CMAKE_C_COMPILER_ID}")
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
find_package(Threads REQUIRED)
add_custom_target(test_dependencies)

if(NOT "${PLATFORM_NAME}" STREQUAL "windows")
Expand Down
Loading

0 comments on commit 2eaf52c

Please sign in to comment.