From 981377412d027e7956702371d0072f77a6a4b9bc Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Sat, 18 Jun 2022 15:59:47 -0400 Subject: [PATCH 01/37] Major CMake refactor --- .github/workflows/main.yml | 28 +- CMakeLists.txt | 544 ++++++------------------- CMakePresets.json | 131 ++++++ cmake/dev-mode.cmake | 14 + cmake/docs.cmake | 15 + cmake/install-config.cmake.in | 28 ++ cmake/install-rules.cmake | 96 +++++ cmake/options.cmake | 66 ++- cmake/prelude.cmake | 10 + cmake/project-is-top-level.cmake | 6 + include/libsleigh.hh | 43 -- support/CMakeLists.txt | 53 ++- support/GhidraVersion.cpp.in | 2 +- support/SpecFilePaths.h.in | 4 +- support/Support.cpp | 4 +- support/Version.cpp.in | 2 +- support/{ => include/sleigh}/Support.h | 0 support/{ => include/sleigh}/Version.h | 0 support/include/sleigh/libsleigh.hh | 43 ++ tests/CMakeLists.txt | 37 ++ tests/find_package/CMakeLists.txt | 2 +- tools/sleigh-lift/CMakeLists.txt | 32 +- 22 files changed, 637 insertions(+), 523 deletions(-) create mode 100644 CMakePresets.json create mode 100644 cmake/dev-mode.cmake create mode 100644 cmake/docs.cmake create mode 100644 cmake/install-rules.cmake create mode 100644 cmake/prelude.cmake create mode 100644 cmake/project-is-top-level.cmake delete mode 100644 include/libsleigh.hh rename support/{ => include/sleigh}/Support.h (100%) rename support/{ => include/sleigh}/Version.h (100%) create mode 100644 support/include/sleigh/libsleigh.hh create mode 100644 tests/CMakeLists.txt diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 583ff6679..34beecbb6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -96,6 +96,9 @@ jobs: # This should be multiplied by the number of compilation jobs and be no # larger than 5G, which is the cache max size file(APPEND "$ENV{GITHUB_ENV}" "CCACHE_MAXSIZE=400M\n") + # Tell CMake to use ccache + file(APPEND "$ENV{GITHUB_ENV}" "CMAKE_CXX_COMPILER_LAUNCHER=ccache\n") + file(APPEND "$ENV{GITHUB_ENV}" "CMAKE_C_COMPILER_LAUNCHER=ccache\n") # Clear stats before every build execute_process(COMMAND ccache -z) @@ -103,17 +106,9 @@ jobs: run: cmake --version - name: Configure the project - run: cmake - -S . - -B build - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - -DCMAKE_C_COMPILER_LAUNCHER=ccache - -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + run: cmake "--preset=ci-$("${{ matrix.os }}".split("-")[0])" -Dsleigh_GHIDRA_RELEASE_TYPE=${{ matrix.release }} - -Dsleigh_ENABLE_TESTS=ON - -Dsleigh_ENABLE_EXAMPLES=ON - -Dsleigh_ENABLE_PACKAGING=ON - -Dsleigh_ENABLE_DOCUMENTATION=ON + -Dsleigh_BUILD_DOCUMENTATION=ON - name: Build the project run: cmake @@ -122,18 +117,29 @@ jobs: -j 2 -v + - name: Build the docs + if: runner.os != 'Windows' + run: cmake + --build build + --config ${{ matrix.build_type }} + --target docs + -v + - name: Run the example run: cmake --build build -j 2 --config ${{ matrix.build_type }} - --target sleighexample_runner + --target sleigh_example_runner - name: Run the install target run: cmake --install build --config ${{ matrix.build_type }} --prefix install + - name: Smoketest sleigh lift + run: ./install/bin/sleighLift disassemble x86-64.sla 4881ecc00f0000 + - name: Test install directory working-directory: tests/find_package run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index e7a2bfce6..9dd637838 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,33 +8,24 @@ cmake_minimum_required(VERSION 3.15) +include(cmake/prelude.cmake) + # Sets "library_root" variable for decompiler cpp root directory # Sets "ghidra_version" for numeric version number # Use "ghidrasource_SOURCE_DIR" variable for Ghidra repo root include(src/setup-ghidra-source.cmake) -project("sleigh" +project(sleigh VERSION "${ghidra_version}" + DESCRIPTION "Unofficial CMake build for Ghidra SLEIGH" + HOMEPAGE_URL "https://github.com/lifting-bits/sleigh" + LANGUAGES CXX ) -include("cmake/options.cmake") - -if(sleigh_ENABLE_TESTS) - include("CTest") -endif() - -if(sleigh_ENABLE_PACKAGING) - include("cmake/packaging.cmake") - - if(CMAKE_BUILD_TYPE STREQUAL "Debug") - message(WARNING "sleigh: Packaging a Debug version") - endif() -endif() +include(cmake/project-is-top-level.cmake) +include(cmake/options.cmake) set(public_include_header_list - "${PROJECT_SOURCE_DIR}/include/libsleigh.hh" - "${PROJECT_SOURCE_DIR}/support/Support.h" - "${PROJECT_SOURCE_DIR}/support/Version.h" "${library_root}/address.hh" "${library_root}/context.hh" "${library_root}/emulate.hh" @@ -188,82 +179,12 @@ set(sleigh_slacomp_source_list "${library_root}/slghscan.cc" ) -# -# sleigh settings -# - -add_library(sleigh_settings INTERFACE) -add_library(sleigh::sleigh_settings ALIAS sleigh_settings) - -target_compile_features(sleigh_settings INTERFACE - cxx_std_11 -) - -set(sleigh_SPEC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/sleigh/specfiles/") -set(sleigh_SPEC_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/specfiles/") - -set_target_properties(sleigh_settings PROPERTIES - INTERFACE_POSITION_INDEPENDENT_CODE ON -) - -if(sleigh_ENABLE_SANITIZERS) - message(STATUS "sleigh: Sanitizers have been enabled") - - if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") - message(WARNING "sleigh: Debug builds are preferred when sanitizers are enabled") - endif() - - set(flag_list - -fno-omit-frame-pointer -fsanitize=undefined,address - ) - - target_compile_options(sleigh_settings INTERFACE ${flag_list}) - target_link_options(sleigh_settings INTERFACE ${flag_list}) -endif() - -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set(debug_setting_list - OPACTION_DEBUG - MERGEMULTI_DEBUG - BLOCKCONSISTENT_DEBUG - DFSVERIFY_DEBUG - ) - - foreach(debug_setting ${debug_setting_list}) - if(NOT sleigh_${debug_setting}) - continue() - endif() - - message(STATUS "sleigh: Enabling debug setting: sleigh_${debug_setting}") - - target_compile_definitions(sleigh_settings INTERFACE - ${debug_setting} - ) - endforeach() -endif() - -set(internal_setting_list - CPUI_STATISTICS - CPUI_RULECOMPILE -) - -foreach(internal_setting ${internal_setting_list}) - if(NOT sleigh_${internal_setting}) - continue() - endif() - - message(STATUS "sleigh: Enabling internal setting: sleigh_${internal_setting}") - - target_compile_definitions(sleigh_settings INTERFACE - ${internal_setting} - ) -endforeach() # -# decomp_opt, decomp_dbg +# decomp # -add_executable(decomp_opt +add_executable(sleigh_decompiler ${sleigh_core_source_list} ${sleigh_deccore_source_list} ${sleigh_extra_source_list} @@ -271,132 +192,81 @@ add_executable(decomp_opt "${library_root}/consolemain.cc" ) -add_executable(sleigh::decomp_opt ALIAS decomp_opt) +add_executable(sleigh::decompiler ALIAS sleigh_decompiler) +target_compile_features(sleigh_decompiler PUBLIC cxx_std_11) +target_include_directories(sleigh_decompiler PRIVATE $) if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") - target_compile_definitions(decomp_opt PRIVATE + target_compile_definitions(sleigh_decompiler PRIVATE __TERMINAL__ ) endif() - -target_link_libraries(decomp_opt PRIVATE - sleigh::sleigh_settings +target_compile_definitions(sleigh_decompiler PRIVATE + $<$:CPUI_DEBUG> ) -target_include_directories(decomp_opt PRIVATE $) - -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - target_compile_definitions(decomp_opt PRIVATE - CPUI_DEBUG - ) - - set_target_properties(decomp_opt PROPERTIES - OUTPUT_NAME "decomp_dbg" - ) -endif() - -# -# ghidra_test_dbg -# - -if(sleigh_ENABLE_TESTS) - add_executable(ghidra_test_dbg - ${sleigh_core_source_list} - ${sleigh_deccore_source_list} - ${sleigh_source_list} - ${sleigh_extra_source_list} - - "${library_root}/test.cc" - - "${library_root}/../unittests/testcirclerange.cc" - "${library_root}/../unittests/testfloatemu.cc" - "${library_root}/../unittests/testtypes.cc" - ) - - target_link_libraries(ghidra_test_dbg PRIVATE - sleigh::sleigh_settings - ) - target_include_directories(ghidra_test_dbg PRIVATE $) - - if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") - target_compile_definitions(ghidra_test_dbg PRIVATE - __TERMINAL__ - ) - endif() - - add_test( - NAME ghidra_unittest_dbg - COMMAND ghidra_test_dbg -sleighpath "${CMAKE_CURRENT_BINARY_DIR}" unittests - ) +sleigh_add_optional_defines(sleigh_decompiler PRIVATE) - add_test( - NAME ghidra_datatest_dbg - COMMAND ghidra_test_dbg -sleighpath "${CMAKE_CURRENT_BINARY_DIR}" - -path "${ghidrasource_SOURCE_DIR}/Ghidra/Features/Decompiler/src/decompile/datatests" - datatests - ) -endif() +set_target_properties(sleigh_decompiler PROPERTIES + EXPORT_NAME decompiler + OUTPUT_NAME decomp + OUTPUT_NAME_DEBUG decomp_dbg +) # -# ghidra_opt, ghidra_dbg +# ghidra # -add_executable(ghidra_opt +add_executable(sleigh_ghidra ${sleigh_core_source_list} ${sleigh_deccore_source_list} ${sleigh_ghidra_source_list} -) -add_executable(sleigh::ghidra_opt ALIAS ghidra_opt) -target_link_libraries(ghidra_opt PRIVATE - sleigh::sleigh_settings + "$<$:${library_root}/callgraph.cc>" + "$<$:${library_root}/ifacedecomp.cc>" + "$<$:${library_root}/ifaceterm.cc>" + "$<$:${library_root}/interface.cc>" + "$<$:${library_root}/testfunction.cc>" ) -target_include_directories(ghidra_opt PRIVATE $) - -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - target_sources(ghidra_opt PRIVATE - "${library_root}/callgraph.cc" - "${library_root}/ifacedecomp.cc" - "${library_root}/ifaceterm.cc" - "${library_root}/interface.cc" - "${library_root}/testfunction.cc" - ) +add_executable(sleigh::ghidra ALIAS sleigh_ghidra) - target_compile_definitions(ghidra_opt PRIVATE - CPUI_DEBUG - ) +target_compile_features(sleigh_ghidra PUBLIC cxx_std_11) +target_include_directories(sleigh_ghidra PRIVATE $) +target_compile_definitions(sleigh_ghidra PRIVATE + $<$:CPUI_DEBUG> +) +sleigh_add_optional_defines(sleigh_ghidra PRIVATE) - set_target_properties(ghidra_opt PROPERTIES - OUTPUT_NAME "ghidra_dbg" - ) -endif() +set_target_properties(sleigh_ghidra PROPERTIES + EXPORT_NAME ghidra + OUTPUT_NAME ghidra + OUTPUT_NAME_DEBUG ghidra_dbg +) # -# sleigh_opt, sleigh_dbg +# sleigh # -add_executable(sleigh_opt +add_executable(sleigh_sleigh ${sleigh_core_source_list} ${sleigh_source_list} ${sleigh_slacomp_source_list} ) -add_executable(sleigh::sleigh_opt ALIAS sleigh_opt) - -target_link_libraries(sleigh_opt PRIVATE - sleigh::sleigh_settings +add_executable(sleigh::sleigh ALIAS sleigh_sleigh) + +target_compile_features(sleigh_sleigh PUBLIC cxx_std_11) +target_include_directories(sleigh_sleigh PRIVATE $) +sleigh_add_optional_defines(sleigh_sleigh PRIVATE) +set_target_properties(sleigh_sleigh PROPERTIES + EXPORT_NAME sleigh + OUTPUT_NAME sleigh + OUTPUT_NAME_DEBUG sleigh_dbg ) -target_include_directories(sleigh_opt PRIVATE $) - -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set_target_properties(sleigh_opt PROPERTIES - OUTPUT_NAME "sleigh_dbg" - ) -endif() # -# sla, sla_dbg +# sla # -add_library(sla +add_library(sleigh_sla ${sleigh_core_source_list} ${sleigh_source_list} @@ -406,82 +276,57 @@ add_library(sla "${library_root}/emulate.cc" "${library_root}/opbehavior.cc" ) -add_library(sleigh::sla ALIAS sla) +add_library(sleigh::sla ALIAS sleigh_sla) -target_link_libraries(sla PUBLIC - sleigh::sleigh_settings -) +target_compile_features(sleigh_sla PUBLIC cxx_std_11) # Private include search path '#include "..." -target_include_directories(sla PRIVATE $) +target_include_directories(sleigh_sla PRIVATE $) # Public include search path in build directory target_include_directories( - sla SYSTEM + sleigh_sla SYSTEM INTERFACE $ ) +target_compile_definitions(sleigh_sla PRIVATE "$<$:YYDEBUG>") +sleigh_add_optional_defines(sleigh_sla PUBLIC) -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - target_compile_definitions(sla PRIVATE - YYDEBUG - ) - - set_target_properties(sla PROPERTIES - OUTPUT_NAME "sla_dbg" - ) -endif() +set_target_properties(sleigh_sla PROPERTIES + EXPORT_NAME sla + OUTPUT_NAME sla + OUTPUT_NAME_DEBUG sla_dbg +) # -# decomp, decomp_dbg +# decomp # -add_library(decomp +add_library(sleigh_decomp ${sleigh_core_source_list} ${sleigh_deccore_source_list} ${sleigh_extra_source_list} ${sleigh_source_list} ) -add_library(sleigh::decomp ALIAS decomp) +add_library(sleigh::decomp ALIAS sleigh_decomp) -target_link_libraries(decomp PUBLIC - sleigh::sleigh_settings -) +target_compile_features(sleigh_decomp PUBLIC cxx_std_11) # Private include search path '#include "..." -target_include_directories(decomp PRIVATE $) +target_include_directories(sleigh_decomp PRIVATE $) # Public include search path in build directory target_include_directories( - decomp SYSTEM + sleigh_decomp SYSTEM INTERFACE $ ) +sleigh_add_optional_defines(sleigh_decomp PUBLIC) -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set_target_properties(decomp PROPERTIES - OUTPUT_NAME "decomp_dbg" - ) -endif() - -# -# Documentation -# - -if(sleigh_ENABLE_DOCUMENTATION) - message(STATUS "sleigh: Documentation has been enabled") - - find_package(Doxygen REQUIRED COMPONENTS dot) - - set(documentation_output "${CMAKE_CURRENT_BINARY_DIR}/doc") - # Always run this target because we have no source file tracking for incremental builds - add_custom_target(sleigh_documentation - COMMAND "${CMAKE_COMMAND}" -E remove_directory "${library_root}/../doc" "${documentation_output}" - COMMAND Doxygen::doxygen Doxyfile - COMMAND "${CMAKE_COMMAND}" -E copy_directory "${library_root}/../doc" "${documentation_output}" - COMMENT "sleigh: Generating the Doxygen documentation" - WORKING_DIRECTORY "${library_root}" - VERBATIM - ) -endif() +set_target_properties(sleigh_decomp PROPERTIES + EXPORT_NAME decomp + OUTPUT_NAME decomp + OUTPUT_NAME_DEBUG decomp_dbg +) # # Spec files # + # Sets 'spec_file_list' variable if(NOT "${sleigh_GHIDRA_RELEASE_TYPE}" STREQUAL "HEAD") include(spec-files-list/spec_files_stable.cmake) @@ -541,7 +386,7 @@ foreach(spec_file ${spec_file_list}) # Compile the sla file sleigh_compile( TARGET "${spec_target}" - COMPILER "$" + COMPILER "$" SLASPEC "${spec_file}" LOG_FILE "${spec_build_log}" OUT_FILE "${spec_out}" @@ -583,200 +428,73 @@ add_custom_target(sleigh_all_sla_specs ALL DEPENDS ) # -# Examples +# Included Example # -if(sleigh_ENABLE_EXAMPLES) - add_executable(sleighexample - "${library_root}/sleighexample.cc" - ) - - target_link_libraries(sleighexample PRIVATE - sleigh::sla - sleigh::decomp - ) - - add_custom_target(sleighexample_runner - "${CMAKE_COMMAND}" -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/specfiles" - COMMAND "${CMAKE_COMMAND}" -E create_symlink "${spec_files_root_dir}/x86/data/languages/x86.sla" "${CMAKE_CURRENT_BINARY_DIR}/specfiles/x86.sla" - COMMAND sleighexample disassemble - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" - ) - - add_dependencies( - sleighexample_runner - sleigh_spec_x86 - ) -endif() - -# Add support library before configuring install targets -add_subdirectory(support) - -# -# Install targets -# - -if(NOT CMAKE_SKIP_INSTALL_RULES) - include("GNUInstallDirs") - - install( - TARGETS - sleigh_settings - - sla - decomp - support - - decomp_opt - ghidra_opt - sleigh_opt - - EXPORT - sleighTargets - - INCLUDES DESTINATION - ${CMAKE_INSTALL_INCLUDEDIR} - ) - - install( - FILES - ${public_include_header_list} - - DESTINATION - ${CMAKE_INSTALL_INCLUDEDIR}/sleigh - ) - - # Install the compiled sla files found in 'Ghidra' top-level directory - install( - DIRECTORY - "${spec_files_build_dir}" - - DESTINATION - "${CMAKE_INSTALL_DATADIR}/sleigh" - ) - - set(CMAKE_INSTALL_DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/sleigh") - - if(sleigh_ENABLE_DOCUMENTATION) - # Build docs during install - install(CODE - "execute_process( - COMMAND \"${CMAKE_COMMAND}\" --build \"${CMAKE_BINARY_DIR}\" --target sleigh_documentation - COMMAND_ECHO STDOUT - )" - ) - install( - DIRECTORY - "${documentation_output}/html/" - - DESTINATION - "${CMAKE_INSTALL_DOCDIR}" - ) - endif(sleigh_ENABLE_DOCUMENTATION) - - if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set(output_folder_path "${CMAKE_CURRENT_BINARY_DIR}/symlinks") - - add_custom_command( - OUTPUT "${output_folder_path}" - COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/symlinks" - COMMENT "sleigh: Generating symlink folder" - VERBATIM +if(PROJECT_IS_TOP_LEVEL) + option(sleigh_BUILD_EXAMPLE "Build included sleigh example" "${sleigh_DEVELOPER_MODE}") + if(sleigh_BUILD_EXAMPLE) + add_executable(sleigh_example + "${library_root}/sleighexample.cc" ) - add_custom_target(sleigh_symlinks_folder_builder DEPENDS - "${output_folder_path}" + target_compile_features(sleigh_example PRIVATE cxx_std_11) + sleigh_add_optional_defines(sleigh_example PRIVATE) + target_link_libraries(sleigh_example PRIVATE + sleigh::sla + sleigh::decomp ) - add_custom_target(sleigh_symlinks_builder ALL) - - foreach(target_name "decomp" - "ghidra" - "sleigh") - - set(source_name "${target_name}_dbg") - set(destination_name "${target_name}_opt") - set(output_path "${output_folder_path}/${destination_name}") - - add_custom_command( - OUTPUT "${output_path}" - COMMAND "${CMAKE_COMMAND}" -E create_symlink "${source_name}" "${destination_name}" - WORKING_DIRECTORY "${output_folder_path}" - COMMENT "sleigh: Generating executable symlink: ${source_name} -> ${destination_name}" - VERBATIM - ) - - set(target_name "sleigh_${source_name}_symlink_builder") - add_custom_target("${target_name}" DEPENDS - "${output_path}" - ) - - add_dependencies("${target_name}" - sleigh_symlinks_folder_builder - ) - - add_dependencies(sleigh_symlinks_builder - "${target_name}" - ) - - install( - FILES - "${output_path}" - - DESTINATION - "${CMAKE_INSTALL_BINDIR}" - - PERMISSIONS - OWNER_READ OWNER_WRITE OWNER_EXECUTE - GROUP_READ GROUP_EXECUTE - WORLD_READ WORLD_EXECUTE + add_custom_target(sleigh_example_runner) + + set(example_actions disassemble pcode emulate) + foreach(action ${example_actions}) + add_custom_target(sleigh_example_${action} + "${CMAKE_COMMAND}" -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/specfiles" + COMMAND "${CMAKE_COMMAND}" -E create_symlink + "${spec_files_root_dir}/x86/data/languages/x86.sla" + "${CMAKE_CURRENT_BINARY_DIR}/specfiles/x86.sla" + COMMAND sleigh_example ${action} + COMMENT "Running example ${action}" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" ) + add_dependencies(sleigh_example_${action} sleigh_spec_x86) + add_dependencies(sleigh_example_runner sleigh_example_${action}) endforeach() endif() +endif() - set( - sleigh_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/sleigh" - CACHE PATH "CMake package config location relative to the install prefix" - ) - mark_as_advanced(sleigh_INSTALL_CMAKEDIR) - - install( - EXPORT sleighTargets - DESTINATION "${sleigh_INSTALL_CMAKEDIR}" - NAMESPACE sleigh:: - ) - - # Specfiles installation setup - set( - sleigh_INSTALL_DATADIR "${CMAKE_INSTALL_DATADIR}/sleigh" - CACHE PATH "sleigh data installation location relative to the install prefix" - ) - mark_as_advanced(sleigh_INSTALL_DATADIR) +# +# Install rules +# - set(sleigh_INSTALL_SPECDIR "${sleigh_INSTALL_DATADIR}/specfiles" - CACHE PATH "sleigh specfile root destination relative to the install prefix" - ) - mark_as_advanced(sleigh_INSTALL_SPECDIR) +if(NOT CMAKE_SKIP_INSTALL_RULES) + include(cmake/install-rules.cmake) +endif() - include(CMakePackageConfigHelpers) +# +# Extras provided by Trail of Bits +# - configure_package_config_file(cmake/install-config.cmake.in - ${PROJECT_BINARY_DIR}/install-config.cmake - INSTALL_DESTINATION "${sleigh_INSTALL_CMAKEDIR}" - NO_CHECK_REQUIRED_COMPONENTS_MACRO - PATH_VARS sleigh_INSTALL_SPECDIR - ) +if(sleigh_BUILD_EXTRATOOLS) + add_subdirectory(tools) +endif() - install( - FILES ${PROJECT_BINARY_DIR}/install-config.cmake - RENAME sleighConfig.cmake - DESTINATION "${sleigh_INSTALL_CMAKEDIR}" - ) +if(sleigh_BUILD_SUPPORT) + # Add support library before configuring install targets + add_subdirectory(support) +endif() - install( - FILES cmake/modules/sleighCompile.cmake - DESTINATION "${sleigh_INSTALL_CMAKEDIR}/modules" +# +# Developer mode +# +if(NOT sleigh_DEVELOPER_MODE) + return() +elseif(NOT PROJECT_IS_TOP_LEVEL) + message( + AUTHOR_WARNING + "Developer mode is intended for developers of sleigh" ) endif() -add_subdirectory(tools) +include(cmake/dev-mode.cmake) diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 000000000..d63525c3d --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,131 @@ +{ + "version": 2, + "cmakeMinimumRequired": { + "major": 3, + "minor": 15, + "patch": 0 + }, + "configurePresets": [ + { + "name": "cmake-pedantic", + "hidden": true, + "warnings": { + "dev": true, + "deprecated": true, + "uninitialized": true, + "unusedCli": true, + "systemVars": false + }, + "errors": { + "dev": true, + "deprecated": true + } + }, + { + "name": "dev-mode", + "hidden": true, + "inherits": "cmake-pedantic", + "cacheVariables": { + "sleigh_DEVELOPER_MODE": "ON", + "sleigh_BUILD_SUPPORT": "ON", + "sleigh_BUILD_EXTRATOOLS": "ON" + } + }, + { + "name": "ci-std", + "description": "This preset makes sure the project actually builds with at least the specified standard", + "hidden": true, + "cacheVariables": { + "CMAKE_CXX_EXTENSIONS": "OFF", + "CMAKE_CXX_STANDARD": "11", + "CMAKE_CXX_STANDARD_REQUIRED": "ON" + } + }, + { + "name": "ci-std-tools", + "description": "This preset makes sure the project actually builds with at least the specified standard for extra sleigh tools", + "hidden": true, + "inherits": "ci-std", + "cacheVariables": { + "CMAKE_CXX_STANDARD": "17" + } + }, + { + "name": "flags-unix", + "hidden": true, + "cacheVariables": { + "CMAKE_CXX_FLAGS": "-Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wshadow -Wformat=2 -Wundef" + } + }, + { + "name": "flags-windows", + "description": "Note that all the flags after /W4 are required for MSVC to conform to the language standard", + "hidden": true, + "cacheVariables": { + "CMAKE_CXX_FLAGS": "/utf-8 /W4 /permissive- /volatile:iso /Zc:preprocessor /EHsc /Zc:__cplusplus /Zc:externConstexpr /Zc:throwingNew" + } + }, + { + "name": "ci-unix", + "generator": "Unix Makefiles", + "hidden": true, + "inherits": ["flags-unix", "ci-std"], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "ci-win64", + "inherits": ["flags-windows", "ci-std"], + "generator": "Visual Studio 17 2022", + "architecture": "x64", + "hidden": true + }, + { + "name": "coverage-unix", + "binaryDir": "${sourceDir}/build/coverage", + "inherits": "ci-unix", + "hidden": true, + "cacheVariables": { + "ENABLE_COVERAGE": "ON", + "CMAKE_BUILD_TYPE": "Coverage", + "CMAKE_CXX_FLAGS_COVERAGE": "-Og -g --coverage -fkeep-inline-functions -fkeep-static-functions", + "CMAKE_EXE_LINKER_FLAGS_COVERAGE": "--coverage", + "CMAKE_SHARED_LINKER_FLAGS_COVERAGE": "--coverage" + } + }, + { + "name": "ci-coverage", + "inherits": ["coverage-unix", "dev-mode"], + "cacheVariables": { + "COVERAGE_HTML_COMMAND": "" + } + }, + { + "name": "ci-sanitize", + "binaryDir": "${sourceDir}/build/sanitize", + "inherits": ["ci-unix", "dev-mode"], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Sanitize", + "CMAKE_CXX_FLAGS_SANITIZE": "-O2 -g -fsanitize=address,undefined -fno-omit-frame-pointer -fno-common" + } + }, + { + "name": "ci-build", + "binaryDir": "${sourceDir}/build", + "hidden": true + }, + { + "name": "ci-macos", + "inherits": ["ci-build", "ci-unix", "dev-mode"] + }, + { + "name": "ci-ubuntu", + "inherits": ["ci-build", "ci-unix", "dev-mode"] + }, + { + "name": "ci-windows", + "inherits": ["ci-build", "ci-win64", "dev-mode"] + } + ] +} diff --git a/cmake/dev-mode.cmake b/cmake/dev-mode.cmake new file mode 100644 index 000000000..1c05e8c8f --- /dev/null +++ b/cmake/dev-mode.cmake @@ -0,0 +1,14 @@ +include(CTest) +if(BUILD_TESTING) + add_subdirectory(tests) +endif() + +option(sleigh_BUILD_DOCUMENTATION "Build documentation using Doxygen" OFF) +if(sleigh_BUILD_DOCUMENTATION) + include(cmake/docs.cmake) +endif() + +option(ENABLE_COVERAGE "Enable coverage support separate from CTest's" OFF) +if(ENABLE_COVERAGE) + include(cmake/coverage.cmake) +endif() diff --git a/cmake/docs.cmake b/cmake/docs.cmake new file mode 100644 index 000000000..7a11ee424 --- /dev/null +++ b/cmake/docs.cmake @@ -0,0 +1,15 @@ +find_package(Doxygen REQUIRED COMPONENTS dot) + +set( + DOXYGEN_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/docs" + CACHE PATH "Path for the generated Doxygen documentation" +) +# Always run this target because we have no source file tracking for incremental builds +add_custom_target(docs + COMMAND "${CMAKE_COMMAND}" -E remove_directory "${DOXYGEN_OUTPUT_DIRECTORY}/html" + COMMAND Doxygen::doxygen Doxyfile + COMMAND "${CMAKE_COMMAND}" -E copy_directory "${library_root}/../doc" "${DOXYGEN_OUTPUT_DIRECTORY}" + COMMENT "sleigh: Generating the Doxygen documentation" + WORKING_DIRECTORY "${library_root}" + VERBATIM +) diff --git a/cmake/install-config.cmake.in b/cmake/install-config.cmake.in index d3f7141f4..ad2723920 100644 --- a/cmake/install-config.cmake.in +++ b/cmake/install-config.cmake.in @@ -7,3 +7,31 @@ set_and_check(sleigh_INSTALL_SPECDIR "@PACKAGE_sleigh_INSTALL_SPECDIR@") # Helpers exposed by default when finding sleigh include("${CMAKE_CURRENT_LIST_DIR}/modules/sleighCompile.cmake") + +# Find-package component handling +set(_sleigh_supported_components Support ExtraTools) + +set(_sleigh_Support_targets "${CMAKE_CURRENT_LIST_DIR}/sleighSupportTargets.cmake") +set(_sleigh_ExtraTools_targets "${CMAKE_CURRENT_LIST_DIR}/sleighExtraToolsTargets.cmake") + +macro(sleigh_load_component comp) + message(STATUS "Trying to load component: ${comp}") + if(NOT EXISTS "${_sleigh_${comp}_targets}" AND ${sleigh_FIND_REQUIRED_${comp}}) + set(sleigh_NOT_FOUND_MESSAGE + "sleigh `${comp}` component targets were requested but not found.") + set(sleigh_FOUND FALSE) + return() + endif() + if(EXISTS "${_sleigh_${comp}_targets}") + include("${_sleigh_${comp}_targets}") + endif() +endmacro() + +foreach(_comp ${sleigh_FIND_COMPONENTS}) + if (NOT _comp IN_LIST _sleigh_supported_components) + set(sleigh_FOUND False) + set(sleigh_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}") + endif() + message(STATUS "Searching for component: ${_comp}") + sleigh_load_component("${_comp}") +endforeach() diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake new file mode 100644 index 000000000..6b3d1d510 --- /dev/null +++ b/cmake/install-rules.cmake @@ -0,0 +1,96 @@ +if(PROJECT_IS_TOP_LEVEL) + set(CMAKE_INSTALL_INCLUDEDIR include/sleigh CACHE PATH "") +endif() + +include("GNUInstallDirs") + +# Executable binary targets +install( + TARGETS + sleigh_decompiler + sleigh_ghidra + sleigh_sleigh + + EXPORT + sleighTargets +) + +# Library targets +install( + TARGETS + sleigh_sla + sleigh_decomp + + EXPORT + sleighTargets + + INCLUDES DESTINATION + "${CMAKE_INSTALL_INCLUDEDIR}" +) + +install( + FILES ${public_include_header_list} + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/sleigh" +) + +if(sleigh_BUILD_DOCUMENTATION) + install( + DIRECTORY "${DOXYGEN_OUTPUT_DIRECTORY}/html/" + DESTINATION "${CMAKE_INSTALL_DOCDIR}" + ) +endif() + +set( + sleigh_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/sleigh" + CACHE PATH "CMake package config location relative to the install prefix" +) +mark_as_advanced(sleigh_INSTALL_CMAKEDIR) + +install( + EXPORT sleighTargets + DESTINATION "${sleigh_INSTALL_CMAKEDIR}" + NAMESPACE sleigh:: +) + +# Specfiles installation setup +set( + sleigh_INSTALL_DATADIR "${CMAKE_INSTALL_DATADIR}/sleigh" + CACHE PATH "sleigh data installation location relative to the install prefix" +) +mark_as_advanced(sleigh_INSTALL_DATADIR) + +set(sleigh_INSTALL_SPECDIR "${sleigh_INSTALL_DATADIR}/specfiles" + CACHE PATH "sleigh specfile root destination relative to the install prefix" +) +mark_as_advanced(sleigh_INSTALL_SPECDIR) + +# Install the compiled sla files found in 'Ghidra' top-level directory +install( + DIRECTORY "${spec_files_build_dir}/" + DESTINATION "${sleigh_INSTALL_SPECDIR}" +) + +include(CMakePackageConfigHelpers) + +configure_package_config_file(cmake/install-config.cmake.in + ${PROJECT_BINARY_DIR}/install-config.cmake + INSTALL_DESTINATION "${sleigh_INSTALL_CMAKEDIR}" + NO_CHECK_REQUIRED_COMPONENTS_MACRO + PATH_VARS sleigh_INSTALL_SPECDIR +) + +install( + FILES ${PROJECT_BINARY_DIR}/install-config.cmake + RENAME sleighConfig.cmake + DESTINATION "${sleigh_INSTALL_CMAKEDIR}" +) + +install( + FILES cmake/modules/sleighCompile.cmake + DESTINATION "${sleigh_INSTALL_CMAKEDIR}/modules" +) + +if(PROJECT_IS_TOP_LEVEL) + include(cmake/packaging.cmake) + include(CPack) +endif() diff --git a/cmake/options.cmake b/cmake/options.cmake index 8a492f4ef..27051fdb6 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -6,27 +6,57 @@ # the LICENSE file found in the root directory of this source tree. # -option(sleigh_ENABLE_TESTS "Set to true to enable tests" ON) -option(sleigh_ENABLE_EXAMPLES "Set to true to build examples" ON) -option(sleigh_ENABLE_DOCUMENTATION "Set to true to enable the documentation") -option(sleigh_ENABLE_PACKAGING "Set to true to enable packaging") -option(sleigh_ENABLE_SANITIZERS "Set to true to enable sanitizers") - -# Internal debug settings -option(sleigh_OPACTION_DEBUG "Turns on all the action tracing facilities") -option(sleigh_MERGEMULTI_DEBUG "Check for MULTIEQUAL and INDIRECT intersections") -option(sleigh_BLOCKCONSISTENT_DEBUG "Check that block graph structure is consistent") -option(sleigh_DFSVERIFY_DEBUG "Make sure that the block ordering algorithm produces a true depth first traversal of the dominator tree") - -# Additional internal settings -option(sleigh_CPUI_STATISTICS "Turn on collection of cover and cast statistics") -option(sleigh_CPUI_RULECOMPILE "Allow user defined dynamic rules") +# ---- Developer mode ---- + +# Developer mode enables targets and code paths in the CMake scripts that are +# only relevant for the developer(s) of sleigh +# Targets necessary to build the project must be provided unconditionally, so +# consumers can trivially build and package the project +if(PROJECT_IS_TOP_LEVEL) + option(sleigh_DEVELOPER_MODE "Enable developer mode" OFF) + option(BUILD_SHARED_LIBS "Build shared libs. (Untested and not supported)" OFF) +endif() -# Sanity checking -if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") - set(sleigh_ENABLE_DOCUMENTATION OFF CACHE BOOL "Unsupported on Windows" FORCE) +# Add-ons by ToB +option(sleigh_BUILD_SUPPORT "Build ToB support libraries") +option(sleigh_BUILD_EXTRATOOLS "Build extra ToB sleigh tools") +if(sleigh_BUILD_EXTRATOOLS) + set(sleigh_BUILD_SUPPORT ON CACHE BOOL "Build ToB support libraries" FORCE) endif() +# Internal settings +option(sleigh_CPUI_RULECOMPILE "Allow user defined dynamic rules") +option(sleigh_CPUI_STATISTICS "Turn on collection of cover and cast statistics") + +# Internal debug settings (naming is swapped to help with discoverability in CMake options) +option(sleigh_DEBUG_BLOCKCONSISTENT "Check that block graph structure is consistent") +option(sleigh_DEBUG_DFSVERIFY "Make sure that the block ordering algorithm produces a true depth first traversal of the dominator tree") +option(sleigh_DEBUG_MERGEMULTI "Check for MULTIEQUAL and INDIRECT intersections") +option(sleigh_DEBUG_OPACTION "Turns on all the action tracing facilities") + +macro(sleigh_add_optional_defines target visibility) + set(opt_defines "") + if(sleigh_CPUI_RULECOMPILE) + list(APPEND opt_defines "CPUI_RULECOMPILE") + endif() + if(sleigh_CPUI_STATISTICS) + list(APPEND opt_defines "CPUI_STATISTICS") + endif() + if(sleigh_DEBUG_BLOCKCONSISTENT) + list(APPEND opt_defines "BLOCKCONSISTENT_DEBUG") + endif() + if(sleigh_DEBUG_DFSVERIFY) + list(APPEND opt_defines "DFSVERIFY_DEBUG") + endif() + if(sleigh_DEBUG_MERGEMULTI) + list(APPEND opt_defines "MERGEMULTI_DEBUG") + endif() + if(sleigh_DEBUG_OPACTION) + list(APPEND opt_defines "OPACTION_DEBUG") + endif() + target_compile_definitions("${target}" ${visibility} ${opt_defines}) +endmacro() + # ---- Warning guard ---- # target_include_directories with the SYSTEM modifier will request the compiler diff --git a/cmake/prelude.cmake b/cmake/prelude.cmake new file mode 100644 index 000000000..a9454f92e --- /dev/null +++ b/cmake/prelude.cmake @@ -0,0 +1,10 @@ +# ---- In-source guard ---- + +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) + message( + FATAL_ERROR + "In-source builds are not supported. " + "Please read the documentation before trying to build this project. " + "You may need to delete 'CMakeCache.txt' and 'CMakeFiles/' first." + ) +endif() diff --git a/cmake/project-is-top-level.cmake b/cmake/project-is-top-level.cmake new file mode 100644 index 000000000..3435fc0e4 --- /dev/null +++ b/cmake/project-is-top-level.cmake @@ -0,0 +1,6 @@ +# This variable is set by project() in CMake 3.21+ +string( + COMPARE EQUAL + "${CMAKE_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}" + PROJECT_IS_TOP_LEVEL +) diff --git a/include/libsleigh.hh b/include/libsleigh.hh deleted file mode 100644 index a6fd40f15..000000000 --- a/include/libsleigh.hh +++ /dev/null @@ -1,43 +0,0 @@ -/* - Copyright (c) 2021-present, Trail of Bits, Inc. - All rights reserved. - - This source code is licensed in accordance with the terms specified in - the LICENSE file found in the root directory of this source tree. -*/ - -#pragma once -#ifndef _MSC_VER -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated" -#pragma GCC diagnostic ignored "-Wsign-compare" -#pragma GCC diagnostic ignored "-Wunused-parameter" -#endif -#include "address.hh" -#include "context.hh" -#include "emulate.hh" -#include "error.hh" -#include "float.hh" -#include "globalcontext.hh" -#include "loadimage.hh" -#include "memstate.hh" -#include "opbehavior.hh" -#include "opcodes.hh" -#include "partmap.hh" -#include "pcoderaw.hh" -#include "semantics.hh" -#include "sleigh.hh" -#include "sleighbase.hh" -#include "slghpatexpress.hh" -#include "slghpattern.hh" -#include "slghsymbol.hh" -#include "space.hh" -#include "translate.hh" -#include "types.h" -#include "xml.hh" -#ifndef _MSC_VER -#pragma GCC diagnostic pop -#endif - -#include "Support.h" -#include "Version.h" diff --git a/support/CMakeLists.txt b/support/CMakeLists.txt index 3354d9ff2..b9f6b33b6 100644 --- a/support/CMakeLists.txt +++ b/support/CMakeLists.txt @@ -9,7 +9,7 @@ # Generate the build and install directories to use in the support helpers configure_file( "${CMAKE_CURRENT_LIST_DIR}/SpecFilePaths.h.in" - "${CMAKE_CURRENT_BINARY_DIR}/SpecFilePaths.h" + "${CMAKE_CURRENT_BINARY_DIR}/include/sleigh/SpecFilePaths.h" @ONLY ) @@ -23,7 +23,7 @@ configure_file( set(PRE_CONFIGURE_FILE "${CMAKE_CURRENT_LIST_DIR}/Version.cpp.in") set(POST_CONFIGURE_FILE "${CMAKE_CURRENT_BINARY_DIR}/Version.cpp") set(GIT_FAIL_IF_NONZERO_EXIT OFF) -include("${PROJECT_SOURCE_DIR}/cmake/git_watcher.cmake") +include("../cmake/git_watcher.cmake") # Generate GHIDRA version helpers configure_file( @@ -32,26 +32,49 @@ configure_file( @ONLY ) -add_library(support +add_library(sleigh_support Support.cpp "${POST_CONFIGURE_FILE}" "${CMAKE_CURRENT_BINARY_DIR}/GhidraVersion.cpp" ) +add_library(sleigh::support ALIAS sleigh_support) + # Need to explicitly add this dependency because BYPRODUCTS doesn't work under # CMake 3.16 with GNU Makefiles -add_dependencies(support check_git) - -add_library(sleigh::support ALIAS support) +add_dependencies(sleigh_support check_git) -target_compile_features(support PUBLIC - cxx_std_17 +target_compile_features(sleigh_support PUBLIC cxx_std_17) +set_target_properties(sleigh_support PROPERTIES + EXPORT_NAME support + OUTPUT_NAME slaSupport ) - -set_target_properties(support PROPERTIES - INTERFACE_POSITION_INDEPENDENT_CODE ON +target_include_directories(sleigh_support + PUBLIC + "$" + "$" ) -target_include_directories(support PRIVATE - "$" - "$" -) +if(NOT CMAKE_SKIP_INSTALL_RULES) + include(GNUInstallDirs) + + if(PROJECT_IS_TOP_LEVEL) + set(CMAKE_INSTALL_INCLUDEDIR include/sleigh CACHE PATH "") + endif() + + install( + TARGETS sleigh_support + EXPORT sleighSupportTargets + INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + ) + install( + DIRECTORY + include/ + "${CMAKE_CURRENT_BINARY_DIR}/include/" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + ) + install( + EXPORT sleighSupportTargets + DESTINATION "${sleigh_INSTALL_CMAKEDIR}" + NAMESPACE sleigh:: + ) +endif() diff --git a/support/GhidraVersion.cpp.in b/support/GhidraVersion.cpp.in index f565bf0f1..211f7fc73 100644 --- a/support/GhidraVersion.cpp.in +++ b/support/GhidraVersion.cpp.in @@ -6,7 +6,7 @@ the LICENSE file found in the root directory of this source tree. */ -#include "Version.h" +#include "sleigh/Version.h" namespace sleigh { diff --git a/support/SpecFilePaths.h.in b/support/SpecFilePaths.h.in index 7fd173185..ca0ae6902 100644 --- a/support/SpecFilePaths.h.in +++ b/support/SpecFilePaths.h.in @@ -10,7 +10,7 @@ namespace sleigh { -static const char *kSleighSpecInstallDir = "@sleigh_SPEC_INSTALL_DIR@"; -static const char *kSleighSpecBuildDir = "@sleigh_SPEC_BUILD_DIR@"; +static const char *kSleighSpecInstallDir = "@sleigh_INSTALL_SPECDIR@"; +static const char *kSleighSpecBuildDir = "@spec_files_build_dir@"; } // namespace sleigh diff --git a/support/Support.cpp b/support/Support.cpp index 18c5a9317..a19b48bc3 100644 --- a/support/Support.cpp +++ b/support/Support.cpp @@ -6,9 +6,9 @@ the LICENSE file found in the root directory of this source tree. */ -#include "SpecFilePaths.h" +#include "sleigh/Support.h" -#include "Support.h" +#include "sleigh/SpecFilePaths.h" namespace sleigh { diff --git a/support/Version.cpp.in b/support/Version.cpp.in index 26671b53c..75bac9345 100644 --- a/support/Version.cpp.in +++ b/support/Version.cpp.in @@ -31,7 +31,7 @@ SOFTWARE. */ -#include "Version.h" +#include "sleigh/Version.h" namespace sleigh { diff --git a/support/Support.h b/support/include/sleigh/Support.h similarity index 100% rename from support/Support.h rename to support/include/sleigh/Support.h diff --git a/support/Version.h b/support/include/sleigh/Version.h similarity index 100% rename from support/Version.h rename to support/include/sleigh/Version.h diff --git a/support/include/sleigh/libsleigh.hh b/support/include/sleigh/libsleigh.hh new file mode 100644 index 000000000..3751cd6f1 --- /dev/null +++ b/support/include/sleigh/libsleigh.hh @@ -0,0 +1,43 @@ +/* + Copyright (c) 2021-present, Trail of Bits, Inc. + All rights reserved. + + This source code is licensed in accordance with the terms specified in + the LICENSE file found in the root directory of this source tree. +*/ + +#pragma once +#ifndef _MSC_VER +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wunused-parameter" +#endif +#include "sleigh/address.hh" +#include "sleigh/context.hh" +#include "sleigh/emulate.hh" +#include "sleigh/error.hh" +#include "sleigh/float.hh" +#include "sleigh/globalcontext.hh" +#include "sleigh/loadimage.hh" +#include "sleigh/memstate.hh" +#include "sleigh/opbehavior.hh" +#include "sleigh/opcodes.hh" +#include "sleigh/partmap.hh" +#include "sleigh/pcoderaw.hh" +#include "sleigh/semantics.hh" +#include "sleigh/sleigh.hh" +#include "sleigh/sleighbase.hh" +#include "sleigh/slghpatexpress.hh" +#include "sleigh/slghpattern.hh" +#include "sleigh/slghsymbol.hh" +#include "sleigh/space.hh" +#include "sleigh/translate.hh" +#include "sleigh/types.h" +#include "sleigh/xml.hh" +#ifndef _MSC_VER +#pragma GCC diagnostic pop +#endif + +#include "sleigh/Support.h" +#include "sleigh/Version.h" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 000000000..ad3295799 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,37 @@ +# +# Tests from ghidra repo +# + +add_executable(sleigh_ghidra_test + ${sleigh_core_source_list} + ${sleigh_deccore_source_list} + ${sleigh_source_list} + ${sleigh_extra_source_list} + + "${library_root}/test.cc" + + "${library_root}/../unittests/testcirclerange.cc" + "${library_root}/../unittests/testfloatemu.cc" + "${library_root}/../unittests/testtypes.cc" +) + +target_compile_features(sleigh_ghidra_test PRIVATE cxx_std_11) +target_include_directories(sleigh_ghidra_test PRIVATE "${library_root}") +if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + target_compile_definitions(sleigh_ghidra_test PRIVATE + __TERMINAL__ + ) +endif() +sleigh_add_optional_defines(sleigh_ghidra_test PRIVATE) + +add_test( + NAME sleigh_ghidra_unittest + COMMAND sleigh_ghidra_test -sleighpath "${PROJECT_BINARY_DIR}" unittests +) + +add_test( + NAME sleigh_ghidra_datatest + COMMAND sleigh_ghidra_test -sleighpath "${PROJECT_BINARY_DIR}" + -path "${library_root}/../datatests" + datatests +) diff --git a/tests/find_package/CMakeLists.txt b/tests/find_package/CMakeLists.txt index e9d15e08f..feb8bd2e3 100644 --- a/tests/find_package/CMakeLists.txt +++ b/tests/find_package/CMakeLists.txt @@ -9,7 +9,7 @@ cmake_minimum_required(VERSION 3.15.0) project("sleigh_find_package_test") -find_package(sleigh REQUIRED) +find_package(sleigh REQUIRED COMPONENTS Support) add_executable(sleigh_test src/main.cpp diff --git a/tools/sleigh-lift/CMakeLists.txt b/tools/sleigh-lift/CMakeLists.txt index 5c5d1aa30..81f8f7668 100644 --- a/tools/sleigh-lift/CMakeLists.txt +++ b/tools/sleigh-lift/CMakeLists.txt @@ -6,31 +6,31 @@ # the LICENSE file found in the root directory of this source tree. # -add_executable(sleigh-lift +add_executable(sleigh_lift src/main.cpp ) -add_executable(sleigh::sleigh-lift ALIAS sleigh-lift) +add_executable(sleigh::sleigh_lift ALIAS sleigh_lift) -target_link_libraries(sleigh-lift PRIVATE +target_link_libraries(sleigh_lift PRIVATE sleigh::sla sleigh::decomp sleigh::support ) +target_compile_features(sleigh_lift PRIVATE cxx_std_17) +set_target_properties(sleigh_lift PROPERTIES + EXPORT_NAME lift + OUTPUT_NAME sleighLift +) if(NOT CMAKE_SKIP_INSTALL_RULES) + include(GNUInstallDirs) install( - TARGETS - sleigh-lift - - EXPORT - "sleigh" - - DESTINATION - "${CMAKE_INSTALL_BINDIR}" - - PERMISSIONS - OWNER_READ OWNER_WRITE OWNER_EXECUTE - GROUP_READ GROUP_EXECUTE - WORLD_READ WORLD_EXECUTE + TARGETS sleigh_lift + EXPORT sleighExtraToolsTargets + ) + install( + EXPORT sleighExtraToolsTargets + DESTINATION "${sleigh_INSTALL_CMAKEDIR}" + NAMESPACE sleigh:: ) endif() From badccc533452952ffeacc5323f5dffa4cc45a2ec Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Sat, 18 Jun 2022 16:28:04 -0400 Subject: [PATCH 02/37] CI fixes --- .github/workflows/main.yml | 22 +++++++++++----------- cmake/install-rules.cmake | 1 - 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 34beecbb6..6f286a18d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,21 +37,20 @@ jobs: if: runner.os == 'Linux' run: | sudo apt-get update - sudo apt-get install -y \ - clang \ - rpm \ - doxygen \ - xdot \ - graphviz + sudo apt-get install -y rpm # Minimum supported CMake version testing - curl -L "https://github.com/Kitware/CMake/releases/download/v3.15.0/cmake-3.15.0-Linux-$(uname -m).sh" -o /tmp/cmake-install.sh - mkdir -p "${HOME}/.local" - bash /tmp/cmake-install.sh --skip-license --exclude-subdir "--prefix=${HOME}/.local" + #curl -L "https://github.com/Kitware/CMake/releases/download/v3.15.0/cmake-3.15.0-Linux-$(uname -m).sh" -o /tmp/cmake-install.sh + #mkdir -p "${HOME}/.local" + #bash /tmp/cmake-install.sh --skip-license --exclude-subdir "--prefix=${HOME}/.local" + brew install cmake # Use Homebrew for latest build tool version for use in CI brew install \ - ccache + ccache \ + doxygen \ + xdot \ + graphviz - name: Install macOS system dependencies if: runner.os == 'macOS' @@ -65,7 +64,7 @@ jobs: - name: Install Windows system dependencies if: runner.os == 'Windows' - run: choco install ccache + run: choco install ccache doxygen.install - name: Generate cache key id: cache_key @@ -106,6 +105,7 @@ jobs: run: cmake --version - name: Configure the project + shell: pwsh run: cmake "--preset=ci-$("${{ matrix.os }}".split("-")[0])" -Dsleigh_GHIDRA_RELEASE_TYPE=${{ matrix.release }} -Dsleigh_BUILD_DOCUMENTATION=ON diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake index 6b3d1d510..5de32c887 100644 --- a/cmake/install-rules.cmake +++ b/cmake/install-rules.cmake @@ -92,5 +92,4 @@ install( if(PROJECT_IS_TOP_LEVEL) include(cmake/packaging.cmake) - include(CPack) endif() From 72bc1907703278beda12f6df872a1dbc71fd7d90 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Sat, 18 Jun 2022 16:38:40 -0400 Subject: [PATCH 03/37] Fix CMake errors --- cmake/dev-mode.cmake | 1 - cmake/docs.cmake | 4 ---- cmake/options.cmake | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cmake/dev-mode.cmake b/cmake/dev-mode.cmake index 1c05e8c8f..6261d3fdc 100644 --- a/cmake/dev-mode.cmake +++ b/cmake/dev-mode.cmake @@ -3,7 +3,6 @@ if(BUILD_TESTING) add_subdirectory(tests) endif() -option(sleigh_BUILD_DOCUMENTATION "Build documentation using Doxygen" OFF) if(sleigh_BUILD_DOCUMENTATION) include(cmake/docs.cmake) endif() diff --git a/cmake/docs.cmake b/cmake/docs.cmake index 7a11ee424..92e0271fc 100644 --- a/cmake/docs.cmake +++ b/cmake/docs.cmake @@ -1,9 +1,5 @@ find_package(Doxygen REQUIRED COMPONENTS dot) -set( - DOXYGEN_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/docs" - CACHE PATH "Path for the generated Doxygen documentation" -) # Always run this target because we have no source file tracking for incremental builds add_custom_target(docs COMMAND "${CMAKE_COMMAND}" -E remove_directory "${DOXYGEN_OUTPUT_DIRECTORY}/html" diff --git a/cmake/options.cmake b/cmake/options.cmake index 27051fdb6..2c7a57d10 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -17,6 +17,20 @@ if(PROJECT_IS_TOP_LEVEL) option(BUILD_SHARED_LIBS "Build shared libs. (Untested and not supported)" OFF) endif() +if(sleigh_DEVELOPER_MODE) + option(sleigh_BUILD_DOCUMENTATION "Build documentation using Doxygen" OFF) + set( + DOXYGEN_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/docs" + CACHE PATH "Path for the generated Doxygen documentation" + ) +endif() + +set( + DOXYGEN_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/docs" + CACHE PATH "Path for the generated Doxygen documentation" +) + + # Add-ons by ToB option(sleigh_BUILD_SUPPORT "Build ToB support libraries") option(sleigh_BUILD_EXTRATOOLS "Build extra ToB sleigh tools") From 0a0773768f093ba29de71318a953bb4b3a323682 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Sat, 18 Jun 2022 16:42:51 -0400 Subject: [PATCH 04/37] Install graphviz on Windows --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6f286a18d..c2d226b89 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -64,7 +64,7 @@ jobs: - name: Install Windows system dependencies if: runner.os == 'Windows' - run: choco install ccache doxygen.install + run: choco install ccache doxygen.install graphviz - name: Generate cache key id: cache_key From c95d74f4eb62ec0860e9f3feaa6747d2ce542c50 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Sun, 19 Jun 2022 12:49:02 -0400 Subject: [PATCH 05/37] More consistent CMake build types --- .github/workflows/main.yml | 1 + CMakePresets.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c2d226b89..c0547bd27 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -107,6 +107,7 @@ jobs: - name: Configure the project shell: pwsh run: cmake "--preset=ci-$("${{ matrix.os }}".split("-")[0])" + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -Dsleigh_GHIDRA_RELEASE_TYPE=${{ matrix.release }} -Dsleigh_BUILD_DOCUMENTATION=ON diff --git a/CMakePresets.json b/CMakePresets.json index d63525c3d..b0b9cb1a5 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -71,7 +71,7 @@ "hidden": true, "inherits": ["flags-unix", "ci-std"], "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release" + "CMAKE_BUILD_TYPE": "RelWithDebInfo" } }, { From 0bb7f22e078e83349dce276cdd6fa5f6798a1bbf Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Mon, 20 Jun 2022 09:54:23 -0400 Subject: [PATCH 06/37] Fix compiler defines for Windows --- CMakePresets.json | 2 +- cmake/packaging.cmake | 54 +++++++++++++++++++++---------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index b0b9cb1a5..15bbe8b3f 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -62,7 +62,7 @@ "description": "Note that all the flags after /W4 are required for MSVC to conform to the language standard", "hidden": true, "cacheVariables": { - "CMAKE_CXX_FLAGS": "/utf-8 /W4 /permissive- /volatile:iso /Zc:preprocessor /EHsc /Zc:__cplusplus /Zc:externConstexpr /Zc:throwingNew" + "CMAKE_CXX_FLAGS": "/D_WINDOWS /utf-8 /W4 /permissive- /volatile:iso /Zc:preprocessor /EHsc /Zc:__cplusplus /Zc:externConstexpr /Zc:throwingNew" } }, { diff --git a/cmake/packaging.cmake b/cmake/packaging.cmake index 79c52aedb..1501a790c 100644 --- a/cmake/packaging.cmake +++ b/cmake/packaging.cmake @@ -19,36 +19,36 @@ set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/lifting-bits/sleigh") set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}-${PACKAGE_VERSION}.x86_64") set(CPACK_PACKAGE_RELOCATABLE ON) -set(CPACK_DEBIAN_PACKAGE_RELEASE "${PACKAGE_VERSION}") -set(CPACK_DEBIAN_PACKAGE_PRIORITY "extra") -set(CPACK_DEBIAN_PACKAGE_SECTION "default") -set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "${CPACK_PACKAGE_HOMEPAGE_URL}") -set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc-dev-bin (>=2.31)") - -set(CPACK_RPM_PACKAGE_RELEASE_DIST "${PACKAGE_VERSION}") -set(CPACK_RPM_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}") -set(CPACK_RPM_PACKAGE_GROUP "default") -set(CPACK_RPM_PACKAGE_REQUIRES "glibc >= 2.31") - set(CPACK_GENERATOR "TGZ") -unset(rpm_executable_path CACHE) -find_program(rpm_executable_path "rpm") -if("${rpm_executable_path}" STREQUAL "rpm_executable_path-NOTFOUND") - message(WARNING "sleigh: the RPM package generator requires the 'rpm' tool") - -else() - list(APPEND CPACK_GENERATOR "RPM") - message(STATUS "sleigh: the RPM generator has been enabled") -endif() +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") + unset(rpm_executable_path CACHE) + find_program(rpm_executable_path "rpm") + if("${rpm_executable_path}" STREQUAL "rpm_executable_path-NOTFOUND") + message(WARNING "sleigh: the RPM package generator requires the 'rpm' tool") + else() + list(APPEND CPACK_GENERATOR "RPM") + message(STATUS "sleigh: the RPM generator has been enabled") + endif() + set(CPACK_RPM_PACKAGE_RELEASE_DIST "${PACKAGE_VERSION}") + set(CPACK_RPM_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}") + set(CPACK_RPM_PACKAGE_GROUP "default") + set(CPACK_RPM_PACKAGE_REQUIRES "glibc >= 2.31") + + unset(dpkg_executable_path CACHE) + find_program(dpkg_executable_path "dpkg") + if("${dpkg_executable_path}" STREQUAL "dpkg_executable_path-NOTFOUND") + message(WARNING "sleigh: the DEB package generator requires the 'dpkg' tool") + else() + list(APPEND CPACK_GENERATOR "DEB") + message(STATUS "sleigh: the DEB generator has been enabled") + endif() + set(CPACK_DEBIAN_PACKAGE_RELEASE "${PACKAGE_VERSION}") + set(CPACK_DEBIAN_PACKAGE_PRIORITY "extra") + set(CPACK_DEBIAN_PACKAGE_SECTION "default") + set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "${CPACK_PACKAGE_HOMEPAGE_URL}") + set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc-dev-bin (>=2.31)") -unset(dpkg_executable_path CACHE) -find_program(dpkg_executable_path "dpkg") -if("${dpkg_executable_path}" STREQUAL "dpkg_executable_path-NOTFOUND") - message(WARNING "sleigh: the DEB package generator requires the 'dpkg' tool") -else() - list(APPEND CPACK_GENERATOR "DEB") - message(STATUS "sleigh: the DEB generator has been enabled") endif() include(CPack) From 9bba052a57bae19f87253ff0201f0d2303c3d513 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Mon, 20 Jun 2022 10:47:24 -0400 Subject: [PATCH 07/37] Fix more bugs --- .github/workflows/main.yml | 1 - CMakeLists.txt | 16 ++++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c0547bd27..393309576 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -119,7 +119,6 @@ jobs: -v - name: Build the docs - if: runner.os != 'Windows' run: cmake --build build --config ${{ matrix.build_type }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 9dd637838..4aa7399d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -445,20 +445,24 @@ if(PROJECT_IS_TOP_LEVEL) sleigh::decomp ) - add_custom_target(sleigh_example_runner) + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/specfiles/x86.sla" + COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/specfiles" + COMMAND "${CMAKE_COMMAND}" -E create_symlink + "${spec_files_root_dir}/x86/data/languages/x86.sla" + "${CMAKE_CURRENT_BINARY_DIR}/specfiles/x86.sla" + MAIN_DEPENDENCY "${spec_files_root_dir}/x86/data/languages/x86.sla" + ) + add_custom_target(sleigh_example_x86_symlink DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/specfiles/x86.sla") + add_custom_target(sleigh_example_runner) set(example_actions disassemble pcode emulate) foreach(action ${example_actions}) add_custom_target(sleigh_example_${action} - "${CMAKE_COMMAND}" -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/specfiles" - COMMAND "${CMAKE_COMMAND}" -E create_symlink - "${spec_files_root_dir}/x86/data/languages/x86.sla" - "${CMAKE_CURRENT_BINARY_DIR}/specfiles/x86.sla" COMMAND sleigh_example ${action} COMMENT "Running example ${action}" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" ) - add_dependencies(sleigh_example_${action} sleigh_spec_x86) + add_dependencies(sleigh_example_${action} sleigh_example_x86_symlink) add_dependencies(sleigh_example_runner sleigh_example_${action}) endforeach() endif() From 169c2dbe231cedcf0762be2680d9f1d504553ce0 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Tue, 21 Jun 2022 14:17:51 -0400 Subject: [PATCH 08/37] Add standalone tool building support --- .github/workflows/main.yml | 8 +++++ CMakeLists.txt | 14 ++++----- cmake/install-config.cmake.in | 2 -- support/CMakeLists.txt | 14 ++++----- support/include/sleigh/libsleigh.hh | 48 ++++++++++++++--------------- tools/sleigh-lift/CMakeLists.txt | 17 ++++++++++ 6 files changed, 63 insertions(+), 40 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 393309576..1c02a74a9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -148,6 +148,14 @@ jobs: cd build ctest -V -C ${{ matrix.build_type }} + - name: Test tool install directory + working-directory: tools/sleigh-lift + run: | + cmake -B build -S . "-Dsleigh_DIR=${{ github.workspace }}/install/lib/cmake/sleigh" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + cmake --build build -j 2 --config ${{ matrix.build_type }} + ./build/sleighLift --version + ./build/sleighLift disassemble x86-64.sla 4881ecc00f0000 + - name: Create the packages run: cmake --build build diff --git a/CMakeLists.txt b/CMakeLists.txt index 4aa7399d6..a9fb54e24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -195,7 +195,7 @@ add_executable(sleigh_decompiler add_executable(sleigh::decompiler ALIAS sleigh_decompiler) target_compile_features(sleigh_decompiler PUBLIC cxx_std_11) -target_include_directories(sleigh_decompiler PRIVATE $) +target_include_directories(sleigh_decompiler PRIVATE "$") if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") target_compile_definitions(sleigh_decompiler PRIVATE __TERMINAL__ @@ -230,7 +230,7 @@ add_executable(sleigh_ghidra add_executable(sleigh::ghidra ALIAS sleigh_ghidra) target_compile_features(sleigh_ghidra PUBLIC cxx_std_11) -target_include_directories(sleigh_ghidra PRIVATE $) +target_include_directories(sleigh_ghidra PRIVATE "$") target_compile_definitions(sleigh_ghidra PRIVATE $<$:CPUI_DEBUG> ) @@ -254,7 +254,7 @@ add_executable(sleigh_sleigh add_executable(sleigh::sleigh ALIAS sleigh_sleigh) target_compile_features(sleigh_sleigh PUBLIC cxx_std_11) -target_include_directories(sleigh_sleigh PRIVATE $) +target_include_directories(sleigh_sleigh PRIVATE "$") sleigh_add_optional_defines(sleigh_sleigh PRIVATE) set_target_properties(sleigh_sleigh PROPERTIES EXPORT_NAME sleigh @@ -280,11 +280,11 @@ add_library(sleigh::sla ALIAS sleigh_sla) target_compile_features(sleigh_sla PUBLIC cxx_std_11) # Private include search path '#include "..." -target_include_directories(sleigh_sla PRIVATE $) +target_include_directories(sleigh_sla PRIVATE "$") # Public include search path in build directory target_include_directories( sleigh_sla SYSTEM - INTERFACE $ + INTERFACE "$" ) target_compile_definitions(sleigh_sla PRIVATE "$<$:YYDEBUG>") sleigh_add_optional_defines(sleigh_sla PUBLIC) @@ -309,11 +309,11 @@ add_library(sleigh::decomp ALIAS sleigh_decomp) target_compile_features(sleigh_decomp PUBLIC cxx_std_11) # Private include search path '#include "..." -target_include_directories(sleigh_decomp PRIVATE $) +target_include_directories(sleigh_decomp PRIVATE "$") # Public include search path in build directory target_include_directories( sleigh_decomp SYSTEM - INTERFACE $ + INTERFACE "$" ) sleigh_add_optional_defines(sleigh_decomp PUBLIC) diff --git a/cmake/install-config.cmake.in b/cmake/install-config.cmake.in index ad2723920..df11a346e 100644 --- a/cmake/install-config.cmake.in +++ b/cmake/install-config.cmake.in @@ -15,7 +15,6 @@ set(_sleigh_Support_targets "${CMAKE_CURRENT_LIST_DIR}/sleighSupportTargets.cmak set(_sleigh_ExtraTools_targets "${CMAKE_CURRENT_LIST_DIR}/sleighExtraToolsTargets.cmake") macro(sleigh_load_component comp) - message(STATUS "Trying to load component: ${comp}") if(NOT EXISTS "${_sleigh_${comp}_targets}" AND ${sleigh_FIND_REQUIRED_${comp}}) set(sleigh_NOT_FOUND_MESSAGE "sleigh `${comp}` component targets were requested but not found.") @@ -32,6 +31,5 @@ foreach(_comp ${sleigh_FIND_COMPONENTS}) set(sleigh_FOUND False) set(sleigh_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}") endif() - message(STATUS "Searching for component: ${_comp}") sleigh_load_component("${_comp}") endforeach() diff --git a/support/CMakeLists.txt b/support/CMakeLists.txt index b9f6b33b6..7752f7b9e 100644 --- a/support/CMakeLists.txt +++ b/support/CMakeLists.txt @@ -49,18 +49,18 @@ set_target_properties(sleigh_support PROPERTIES OUTPUT_NAME slaSupport ) target_include_directories(sleigh_support + ${warning_guard} PUBLIC - "$" - "$" + "$" +) +target_include_directories(sleigh_support + SYSTEM + PUBLIC + "$" ) if(NOT CMAKE_SKIP_INSTALL_RULES) include(GNUInstallDirs) - - if(PROJECT_IS_TOP_LEVEL) - set(CMAKE_INSTALL_INCLUDEDIR include/sleigh CACHE PATH "") - endif() - install( TARGETS sleigh_support EXPORT sleighSupportTargets diff --git a/support/include/sleigh/libsleigh.hh b/support/include/sleigh/libsleigh.hh index 3751cd6f1..2e123b261 100644 --- a/support/include/sleigh/libsleigh.hh +++ b/support/include/sleigh/libsleigh.hh @@ -13,31 +13,31 @@ #pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wunused-parameter" #endif -#include "sleigh/address.hh" -#include "sleigh/context.hh" -#include "sleigh/emulate.hh" -#include "sleigh/error.hh" -#include "sleigh/float.hh" -#include "sleigh/globalcontext.hh" -#include "sleigh/loadimage.hh" -#include "sleigh/memstate.hh" -#include "sleigh/opbehavior.hh" -#include "sleigh/opcodes.hh" -#include "sleigh/partmap.hh" -#include "sleigh/pcoderaw.hh" -#include "sleigh/semantics.hh" -#include "sleigh/sleigh.hh" -#include "sleigh/sleighbase.hh" -#include "sleigh/slghpatexpress.hh" -#include "sleigh/slghpattern.hh" -#include "sleigh/slghsymbol.hh" -#include "sleigh/space.hh" -#include "sleigh/translate.hh" -#include "sleigh/types.h" -#include "sleigh/xml.hh" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #ifndef _MSC_VER #pragma GCC diagnostic pop #endif -#include "sleigh/Support.h" -#include "sleigh/Version.h" +#include +#include diff --git a/tools/sleigh-lift/CMakeLists.txt b/tools/sleigh-lift/CMakeLists.txt index 81f8f7668..af1fe1dd4 100644 --- a/tools/sleigh-lift/CMakeLists.txt +++ b/tools/sleigh-lift/CMakeLists.txt @@ -6,6 +6,16 @@ # the LICENSE file found in the root directory of this source tree. # +cmake_minimum_required(VERSION 3.15) + +project(sleighLift CXX) + +include(../../cmake/project-is-top-level.cmake) + +if(PROJECT_IS_TOP_LEVEL) + find_package(sleigh REQUIRED COMPONENTS Support) +endif() + add_executable(sleigh_lift src/main.cpp ) @@ -24,6 +34,13 @@ set_target_properties(sleigh_lift PROPERTIES if(NOT CMAKE_SKIP_INSTALL_RULES) include(GNUInstallDirs) + if(PROJECT_IS_TOP_LEVEL) + set( + sleigh_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/sleigh" + CACHE PATH "CMake package config location relative to the install prefix" + ) + mark_as_advanced(sleigh_INSTALL_CMAKEDIR) + endif() install( TARGETS sleigh_lift EXPORT sleighExtraToolsTargets From d7b5cfba4b3d45055ed02bc92887fdfa077cb744 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Tue, 21 Jun 2022 15:18:00 -0400 Subject: [PATCH 09/37] Fix typo --- tools/sleigh-lift/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/sleigh-lift/CMakeLists.txt b/tools/sleigh-lift/CMakeLists.txt index af1fe1dd4..8a0ab97ce 100644 --- a/tools/sleigh-lift/CMakeLists.txt +++ b/tools/sleigh-lift/CMakeLists.txt @@ -19,7 +19,7 @@ endif() add_executable(sleigh_lift src/main.cpp ) -add_executable(sleigh::sleigh_lift ALIAS sleigh_lift) +add_executable(sleigh::lift ALIAS sleigh_lift) target_link_libraries(sleigh_lift PRIVATE sleigh::sla From 1ed9355fbeb0146f9032b0d45e76a389d21e67fd Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Tue, 21 Jun 2022 15:49:46 -0400 Subject: [PATCH 10/37] Update README --- README.md | 28 +++++++++++++--------------- cmake/install-config.cmake.in | 8 +++++++- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 3cc2bf586..221f864df 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,9 @@ This repository provides a CMake-based build project for SLEIGH so that it can b | ---- | ------- | | Linux | Yes | | macOS | Yes | -| Windows | Not yet | +| Windows | *Yes | + +\* Tests do not all work on Windows. See issue [#92](https://github.com/lifting-bits/sleigh/issues/92). ## Dependencies and Prerequisites @@ -19,7 +21,7 @@ This repository provides a CMake-based build project for SLEIGH so that it can b | Name | Version | Linux Package to Install | macOS Homebrew Package to Install | | ---- | ------- | ------------------------ | --------------------------------- | | [Git](https://git-scm.com/) | Latest | git | N/A | -| [CMake](https://cmake.org/) | 3.21+ | cmake | cmake | +| [CMake](https://cmake.org/) | 3.15+ | cmake | cmake | **NOTE**: This CMake project pulls the Ghidra source code from the internet during configuration. See the [note on Ghidra source code section](#note-on-ghidra-source-code) for more details. @@ -57,40 +59,34 @@ Please see [`src/README.md`](./src/README.md) for more information on how to cus ## Packaging -The CMake configuration also supports building packages for SLEIGH. If the `sleigh_ENABLE_PACKAGING` option is set during the configuration step, the build step will generate a tarball containing the SLEIGH installation. Additionally, the build will create an RPM package if it finds `rpm` in the `PATH` and/or a DEB package if it finds `dpkg` in the `PATH`. +The CMake configuration also supports building packages for SLEIGH. For example: ```sh -cmake -B build -S . \ - -Dsleigh_ENABLE_PACKAGING=ON - -# Build SLEIGH -cmake --build build -j - # Package SLEIGH cmake --build build --target package ``` ## API Usage -An example program called `sleigh-lift` has been included to demonstrate how to use the SLEIGH API. It takes a hexadecimal string of bytes and either disassembles it or lifts it to p-code. The program can be invoked like so, where the `action` argument must be either `disassemble` or `pcode`: +An example program called `sleighLift` has been included to demonstrate how to use the SLEIGH API. It takes a hexadecimal string of bytes and either disassembles it or lifts it to p-code. The program can be invoked like so, where the `action` argument must be either `disassemble` or `pcode`: ```sh -sleigh-lift [action] [sla_file] [bytes] [-a address] [-p root_sla_dir] [-s pspec_file] +sleighLift [action] [sla_file] [bytes] [-a address] [-p root_sla_dir] [-s pspec_file] ``` For example, to disassemble the following byte string: ```sh -$ sleigh-lift disassemble x86-64.sla 4881ecc00f0000 +$ sleighLift disassemble x86-64.sla 4881ecc00f0000 0x00000000: SUB RSP,0xfc0 ``` And to lift it to p-code: ```sh -$ sleigh-lift pcode x86-64.sla 4881ecc00f0000 +$ sleighLift pcode x86-64.sla 4881ecc00f0000 (register,0x200,1) = INT_LESS (register,0x20,8) (const,0xfc0,8) (register,0x20b,1) = INT_SBORROW (register,0x20,8) (const,0xfc0,8) (register,0x20,8) = INT_SUB (register,0x20,8) (const,0xfc0,8) @@ -102,7 +98,7 @@ $ sleigh-lift pcode x86-64.sla 4881ecc00f0000 (register,0x202,1) = INT_EQUAL (unique,0x12d00,1) (const,0x0,1) ``` -The `sleigh_ENABLE_EXAMPLES` option must be set to `ON` during the configuration step in order to build `sleigh-lift`. +The `sleigh_BUILD_EXTRATOOLS` option must be set to `ON` during the configuration step in order to build `sleighLift`. ## Helpers @@ -117,13 +113,15 @@ FindSpecFile(std::string_view file_name, The `sleigh::FindSpecFile` function will search the the paths provided by the user via the `search_paths` argument for a spec file with the name `file_name`. The default argument for `search_paths` is `sleigh::gDefaultSearchPaths` which contains the install/build directories that the CMake project was configured with as well as a set of common installation locations. +The `sleigh_BUILD_SUPPORT` option must be set to `ON` during the configuration step in order to build the support library. + ## Integration as a Dependency An installation of sleigh provides a CMake interface that can be used to assist in building your project. An example of how to use the CMake package config file can be found in the [find_package](tests/find_package/CMakeLists.txt) example. -We also provide a CMake helper function [`sleigh_compile`](cmake/modules/sleighCompile.cmake) to compile your own `.slaspec` files using the installed sleigh compiler from this project. +We also provide a CMake helper function [`sleigh_compile`](cmake/modules/sleighCompile.cmake) to compile your own `.slaspec` files using a sleigh compiler. Lastly, the installed compiled sleigh files can be located through the CMake variable `sleigh_INSTALL_SPECDIR`, which is an absolute path to the root directory for where the compiled sleigh files are located---you should manually inspect this to know what to expect. diff --git a/cmake/install-config.cmake.in b/cmake/install-config.cmake.in index df11a346e..0a2543107 100644 --- a/cmake/install-config.cmake.in +++ b/cmake/install-config.cmake.in @@ -1,3 +1,9 @@ +# This file provides access to the installed sleigh targets. +# +# There are two optional components that could also be installed: +# * Support - support library for easier use of sleigh +# * ExtraTools - Extra tools created by Trail of Bits + @PACKAGE_INIT@ include("${CMAKE_CURRENT_LIST_DIR}/sleighTargets.cmake") @@ -8,7 +14,7 @@ set_and_check(sleigh_INSTALL_SPECDIR "@PACKAGE_sleigh_INSTALL_SPECDIR@") # Helpers exposed by default when finding sleigh include("${CMAKE_CURRENT_LIST_DIR}/modules/sleighCompile.cmake") -# Find-package component handling +# Find-package component handling for Support library and ExtraTools set(_sleigh_supported_components Support ExtraTools) set(_sleigh_Support_targets "${CMAKE_CURRENT_LIST_DIR}/sleighSupportTargets.cmake") From 84750f4294c32e4d31a24e44d3919fdd3b5055e5 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Tue, 21 Jun 2022 16:10:14 -0400 Subject: [PATCH 11/37] Install sleighLift before trying to smoketest it --- .github/workflows/main.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1c02a74a9..3facd7d32 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -153,8 +153,9 @@ jobs: run: | cmake -B build -S . "-Dsleigh_DIR=${{ github.workspace }}/install/lib/cmake/sleigh" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} cmake --build build -j 2 --config ${{ matrix.build_type }} - ./build/sleighLift --version - ./build/sleighLift disassemble x86-64.sla 4881ecc00f0000 + cmake --install build --config ${{ matrix.build_type }} --prefix install + ./install/bin/sleighLift --version + ./install/bin/sleighLift disassemble x86-64.sla 4881ecc00f0000 - name: Create the packages run: cmake From 17e1dab1271d37890269a00acb312e6e973603e4 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Tue, 21 Jun 2022 22:52:03 -0400 Subject: [PATCH 12/37] Test coverage preset The compiler option '-fkeep-inline-functions' originally included with the coverage build type causes errors with the message "undefined reference to 'vtable for OpAction*'" for all OpAction subclasses. This StackOverflow answer might help in resolving this? https://stackoverflow.com/a/57504289 --- CMakePresets.json | 2 +- cmake/coverage.cmake | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 cmake/coverage.cmake diff --git a/CMakePresets.json b/CMakePresets.json index 15bbe8b3f..c2f4946e0 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -89,7 +89,7 @@ "cacheVariables": { "ENABLE_COVERAGE": "ON", "CMAKE_BUILD_TYPE": "Coverage", - "CMAKE_CXX_FLAGS_COVERAGE": "-Og -g --coverage -fkeep-inline-functions -fkeep-static-functions", + "CMAKE_CXX_FLAGS_COVERAGE": "-Og -g --coverage -fkeep-static-functions", "CMAKE_EXE_LINKER_FLAGS_COVERAGE": "--coverage", "CMAKE_SHARED_LINKER_FLAGS_COVERAGE": "--coverage" } diff --git a/cmake/coverage.cmake b/cmake/coverage.cmake new file mode 100644 index 000000000..1d1083390 --- /dev/null +++ b/cmake/coverage.cmake @@ -0,0 +1,33 @@ +# ---- Variables ---- + +# We use variables separate from what CTest uses, because those have +# customization issues +set( + COVERAGE_TRACE_COMMAND + lcov -c -q + -o "${PROJECT_BINARY_DIR}/coverage.info" + -d "${PROJECT_BINARY_DIR}" + --include "${library_root}/*" + CACHE STRING + "; separated command to generate a trace for the 'coverage' target" +) + +set( + COVERAGE_HTML_COMMAND + genhtml --legend -f -q + "${PROJECT_BINARY_DIR}/coverage.info" + -p "${library_root}" + -o "${PROJECT_BINARY_DIR}/coverage_html" + CACHE STRING + "; separated command to generate an HTML report for the 'coverage' target" +) + +# ---- Coverage target ---- + +add_custom_target( + coverage + COMMAND ${COVERAGE_TRACE_COMMAND} + COMMAND ${COVERAGE_HTML_COMMAND} + COMMENT "Generating coverage report" + VERBATIM +) From 6fd7614d1159404f7c14100ebf9264e346bc73b9 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Sat, 25 Jun 2022 14:17:04 -0400 Subject: [PATCH 13/37] Build documentation by default with CI presets --- .github/workflows/main.yml | 1 - CMakePresets.json | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3facd7d32..5c667a9c6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -109,7 +109,6 @@ jobs: run: cmake "--preset=ci-$("${{ matrix.os }}".split("-")[0])" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -Dsleigh_GHIDRA_RELEASE_TYPE=${{ matrix.release }} - -Dsleigh_BUILD_DOCUMENTATION=ON - name: Build the project run: cmake diff --git a/CMakePresets.json b/CMakePresets.json index c2f4946e0..43d70db59 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -27,6 +27,7 @@ "inherits": "cmake-pedantic", "cacheVariables": { "sleigh_DEVELOPER_MODE": "ON", + "sleigh_BUILD_DOCUMENTATION": "ON", "sleigh_BUILD_SUPPORT": "ON", "sleigh_BUILD_EXTRATOOLS": "ON" } From 4debffd63f64f5c1851be2322ea617c8e490eeff Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Sat, 25 Jun 2022 15:06:55 -0400 Subject: [PATCH 14/37] Use COMPONENT for install commands This allows for someone to specify which components they want to install if they only want or need a subset --- cmake/install-rules.cmake | 36 +++++++++++++++++++++++--------- support/CMakeLists.txt | 9 ++++++++ tools/sleigh-lift/CMakeLists.txt | 3 +++ 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake index 5de32c887..5d07752a4 100644 --- a/cmake/install-rules.cmake +++ b/cmake/install-rules.cmake @@ -4,26 +4,25 @@ endif() include("GNUInstallDirs") -# Executable binary targets install( TARGETS + # Executable binary targets sleigh_decompiler sleigh_ghidra sleigh_sleigh - EXPORT - sleighTargets -) - -# Library targets -install( - TARGETS + # Library targets sleigh_sla sleigh_decomp - EXPORT sleighTargets - + RUNTIME # + COMPONENT tcmake_Runtime + LIBRARY # + COMPONENT tcmake_Runtime + NAMELINK_COMPONENT tcmake_Development + ARCHIVE # + COMPONENT tcmake_Development INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) @@ -31,12 +30,14 @@ install( install( FILES ${public_include_header_list} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/sleigh" + COMPONENT sleigh_Development ) if(sleigh_BUILD_DOCUMENTATION) install( DIRECTORY "${DOXYGEN_OUTPUT_DIRECTORY}/html/" DESTINATION "${CMAKE_INSTALL_DOCDIR}" + COMPONENT sleigh_Documentation ) endif() @@ -50,6 +51,7 @@ install( EXPORT sleighTargets DESTINATION "${sleigh_INSTALL_CMAKEDIR}" NAMESPACE sleigh:: + COMPONENT sleigh_Development ) # Specfiles installation setup @@ -68,10 +70,22 @@ mark_as_advanced(sleigh_INSTALL_SPECDIR) install( DIRECTORY "${spec_files_build_dir}/" DESTINATION "${sleigh_INSTALL_SPECDIR}" + COMPONENT sleigh_Runtime ) include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "sleighConfigVersion.cmake" + COMPATIBILITY SameMinorVersion +) + +install( + FILES "${PROJECT_BINARY_DIR}/sleighConfigVersion.cmake" + DESTINATION "${sleigh_INSTALL_CMAKEDIR}" + COMPONENT sleigh_Development +) + configure_package_config_file(cmake/install-config.cmake.in ${PROJECT_BINARY_DIR}/install-config.cmake INSTALL_DESTINATION "${sleigh_INSTALL_CMAKEDIR}" @@ -83,11 +97,13 @@ install( FILES ${PROJECT_BINARY_DIR}/install-config.cmake RENAME sleighConfig.cmake DESTINATION "${sleigh_INSTALL_CMAKEDIR}" + COMPONENT sleigh_Development ) install( FILES cmake/modules/sleighCompile.cmake DESTINATION "${sleigh_INSTALL_CMAKEDIR}/modules" + COMPONENT sleigh_Development ) if(PROJECT_IS_TOP_LEVEL) diff --git a/support/CMakeLists.txt b/support/CMakeLists.txt index 7752f7b9e..452cfc5e5 100644 --- a/support/CMakeLists.txt +++ b/support/CMakeLists.txt @@ -64,6 +64,13 @@ if(NOT CMAKE_SKIP_INSTALL_RULES) install( TARGETS sleigh_support EXPORT sleighSupportTargets + RUNTIME # + COMPONENT sleigh_SupportRuntime + LIBRARY # + COMPONENT sleigh_SupportRuntime + NAMELINK_COMPONENT sleigh_SupportDevelopment + ARCHIVE # + COMPONENT sleigh_SupportDevelopment INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) install( @@ -71,10 +78,12 @@ if(NOT CMAKE_SKIP_INSTALL_RULES) include/ "${CMAKE_CURRENT_BINARY_DIR}/include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + COMPONENT sleigh_SupportDevelopment ) install( EXPORT sleighSupportTargets DESTINATION "${sleigh_INSTALL_CMAKEDIR}" NAMESPACE sleigh:: + COMPONENT sleigh_SupportDevelopment ) endif() diff --git a/tools/sleigh-lift/CMakeLists.txt b/tools/sleigh-lift/CMakeLists.txt index 8a0ab97ce..d402a0f85 100644 --- a/tools/sleigh-lift/CMakeLists.txt +++ b/tools/sleigh-lift/CMakeLists.txt @@ -44,10 +44,13 @@ if(NOT CMAKE_SKIP_INSTALL_RULES) install( TARGETS sleigh_lift EXPORT sleighExtraToolsTargets + RUNTIME # + COMPONENT sleigh_ExtraToolsRuntime ) install( EXPORT sleighExtraToolsTargets DESTINATION "${sleigh_INSTALL_CMAKEDIR}" NAMESPACE sleigh:: + COMPONENT sleigh_ExtraToolsDevelopment ) endif() From 7f0d2eb9a8e76d69b989b19815b2bf2f766c67a9 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Sun, 26 Jun 2022 12:27:43 -0400 Subject: [PATCH 15/37] Support cross compiling with host system sleigh compiler --- CMakeLists.txt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9fb54e24..96c2d1a3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -347,6 +347,20 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E make_directory ${spec_files_build_log_dir} ) +# Get the native machine's sleigh compiler or use the one we're about to build +# if not cross compiling +if(CMAKE_CROSSCOMPILING) + find_program( + SLEIGH_EXECUTABLE sleigh + DOC "Path to host system sleigh compiler" + ) +else() + set( + SLEIGH_EXECUTABLE "$" + CACHE FILEPATH "Path to host system sleigh compiler" + ) +endif() + # Start processing all `.slaspec` files individually set(spec_targets) set(spec_files) @@ -386,7 +400,7 @@ foreach(spec_file ${spec_file_list}) # Compile the sla file sleigh_compile( TARGET "${spec_target}" - COMPILER "$" + COMPILER "${SLEIGH_EXECUTABLE}" SLASPEC "${spec_file}" LOG_FILE "${spec_build_log}" OUT_FILE "${spec_out}" From 3bd5011af8ecba41aa6bc931533cf089826d85f2 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Sun, 26 Jun 2022 13:17:24 -0400 Subject: [PATCH 16/37] Various fixes found during review --- .github/workflows/main.yml | 9 ++------- cmake/install-config.cmake.in | 2 +- cmake/install-rules.cmake | 8 ++++---- cmake/options.cmake | 6 +----- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5c667a9c6..1341ffda5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,14 +39,9 @@ jobs: sudo apt-get update sudo apt-get install -y rpm - # Minimum supported CMake version testing - #curl -L "https://github.com/Kitware/CMake/releases/download/v3.15.0/cmake-3.15.0-Linux-$(uname -m).sh" -o /tmp/cmake-install.sh - #mkdir -p "${HOME}/.local" - #bash /tmp/cmake-install.sh --skip-license --exclude-subdir "--prefix=${HOME}/.local" - brew install cmake - - # Use Homebrew for latest build tool version for use in CI + # Use Homebrew for latest build tools for use in CI brew install \ + cmake \ ccache \ doxygen \ xdot \ diff --git a/cmake/install-config.cmake.in b/cmake/install-config.cmake.in index 0a2543107..d8c72018e 100644 --- a/cmake/install-config.cmake.in +++ b/cmake/install-config.cmake.in @@ -34,7 +34,7 @@ endmacro() foreach(_comp ${sleigh_FIND_COMPONENTS}) if (NOT _comp IN_LIST _sleigh_supported_components) - set(sleigh_FOUND False) + set(sleigh_FOUND FALSE) set(sleigh_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}") endif() sleigh_load_component("${_comp}") diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake index 5d07752a4..4deb39f36 100644 --- a/cmake/install-rules.cmake +++ b/cmake/install-rules.cmake @@ -17,12 +17,12 @@ install( EXPORT sleighTargets RUNTIME # - COMPONENT tcmake_Runtime + COMPONENT sleigh_Runtime LIBRARY # - COMPONENT tcmake_Runtime - NAMELINK_COMPONENT tcmake_Development + COMPONENT sleigh_Runtime + NAMELINK_COMPONENT sleigh_Development ARCHIVE # - COMPONENT tcmake_Development + COMPONENT sleigh_Development INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) diff --git a/cmake/options.cmake b/cmake/options.cmake index 2c7a57d10..d3945a417 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -25,11 +25,6 @@ if(sleigh_DEVELOPER_MODE) ) endif() -set( - DOXYGEN_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/docs" - CACHE PATH "Path for the generated Doxygen documentation" -) - # Add-ons by ToB option(sleigh_BUILD_SUPPORT "Build ToB support libraries") @@ -38,6 +33,7 @@ if(sleigh_BUILD_EXTRATOOLS) set(sleigh_BUILD_SUPPORT ON CACHE BOOL "Build ToB support libraries" FORCE) endif() + # Internal settings option(sleigh_CPUI_RULECOMPILE "Allow user defined dynamic rules") option(sleigh_CPUI_STATISTICS "Turn on collection of cover and cast statistics") From a0140b0ebd0c64997b8b5c3a230a5006e60620ac Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Fri, 1 Jul 2022 14:07:55 -0400 Subject: [PATCH 17/37] Move "_WINDOWS" define to CMakeLists.txt file --- CMakeLists.txt | 28 ++++++++++++++++++++++++++++ CMakePresets.json | 2 +- cmake/options.cmake | 23 ----------------------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 96c2d1a3f..cdd6030f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -179,6 +179,34 @@ set(sleigh_slacomp_source_list "${library_root}/slghscan.cc" ) +# +# Common options that apply to all targets +# +macro(sleigh_add_optional_defines target visibility) + set(opt_defines "") + if(sleigh_CPUI_RULECOMPILE) + list(APPEND opt_defines "CPUI_RULECOMPILE") + endif() + if(sleigh_CPUI_STATISTICS) + list(APPEND opt_defines "CPUI_STATISTICS") + endif() + if(sleigh_DEBUG_BLOCKCONSISTENT) + list(APPEND opt_defines "BLOCKCONSISTENT_DEBUG") + endif() + if(sleigh_DEBUG_DFSVERIFY) + list(APPEND opt_defines "DFSVERIFY_DEBUG") + endif() + if(sleigh_DEBUG_MERGEMULTI) + list(APPEND opt_defines "MERGEMULTI_DEBUG") + endif() + if(sleigh_DEBUG_OPACTION) + list(APPEND opt_defines "OPACTION_DEBUG") + endif() + if(WIN32) + list(APPEND opt_defines "_WINDOWS") + endif() + target_compile_definitions("${target}" ${visibility} ${opt_defines}) +endmacro() # # decomp diff --git a/CMakePresets.json b/CMakePresets.json index 43d70db59..d97eb0fc0 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -63,7 +63,7 @@ "description": "Note that all the flags after /W4 are required for MSVC to conform to the language standard", "hidden": true, "cacheVariables": { - "CMAKE_CXX_FLAGS": "/D_WINDOWS /utf-8 /W4 /permissive- /volatile:iso /Zc:preprocessor /EHsc /Zc:__cplusplus /Zc:externConstexpr /Zc:throwingNew" + "CMAKE_CXX_FLAGS": "/utf-8 /W4 /permissive- /volatile:iso /Zc:preprocessor /EHsc /Zc:__cplusplus /Zc:externConstexpr /Zc:throwingNew" } }, { diff --git a/cmake/options.cmake b/cmake/options.cmake index d3945a417..6e69a66f7 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -44,29 +44,6 @@ option(sleigh_DEBUG_DFSVERIFY "Make sure that the block ordering algorithm produ option(sleigh_DEBUG_MERGEMULTI "Check for MULTIEQUAL and INDIRECT intersections") option(sleigh_DEBUG_OPACTION "Turns on all the action tracing facilities") -macro(sleigh_add_optional_defines target visibility) - set(opt_defines "") - if(sleigh_CPUI_RULECOMPILE) - list(APPEND opt_defines "CPUI_RULECOMPILE") - endif() - if(sleigh_CPUI_STATISTICS) - list(APPEND opt_defines "CPUI_STATISTICS") - endif() - if(sleigh_DEBUG_BLOCKCONSISTENT) - list(APPEND opt_defines "BLOCKCONSISTENT_DEBUG") - endif() - if(sleigh_DEBUG_DFSVERIFY) - list(APPEND opt_defines "DFSVERIFY_DEBUG") - endif() - if(sleigh_DEBUG_MERGEMULTI) - list(APPEND opt_defines "MERGEMULTI_DEBUG") - endif() - if(sleigh_DEBUG_OPACTION) - list(APPEND opt_defines "OPACTION_DEBUG") - endif() - target_compile_definitions("${target}" ${visibility} ${opt_defines}) -endmacro() - # ---- Warning guard ---- # target_include_directories with the SYSTEM modifier will request the compiler From 54284aef96a7b72903a72de41e48b9d45fd6c341 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Sat, 2 Jul 2022 15:20:35 -0400 Subject: [PATCH 18/37] Rename ToB 'tools' directory to 'extra-tools' --- CMakeLists.txt | 2 +- {tools => extra-tools}/CMakeLists.txt | 0 {tools => extra-tools}/sleigh-lift/CMakeLists.txt | 0 {tools => extra-tools}/sleigh-lift/src/main.cpp | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename {tools => extra-tools}/CMakeLists.txt (100%) rename {tools => extra-tools}/sleigh-lift/CMakeLists.txt (100%) rename {tools => extra-tools}/sleigh-lift/src/main.cpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index cdd6030f2..3df777251 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -523,7 +523,7 @@ endif() # if(sleigh_BUILD_EXTRATOOLS) - add_subdirectory(tools) + add_subdirectory(extra-tools) endif() if(sleigh_BUILD_SUPPORT) diff --git a/tools/CMakeLists.txt b/extra-tools/CMakeLists.txt similarity index 100% rename from tools/CMakeLists.txt rename to extra-tools/CMakeLists.txt diff --git a/tools/sleigh-lift/CMakeLists.txt b/extra-tools/sleigh-lift/CMakeLists.txt similarity index 100% rename from tools/sleigh-lift/CMakeLists.txt rename to extra-tools/sleigh-lift/CMakeLists.txt diff --git a/tools/sleigh-lift/src/main.cpp b/extra-tools/sleigh-lift/src/main.cpp similarity index 100% rename from tools/sleigh-lift/src/main.cpp rename to extra-tools/sleigh-lift/src/main.cpp From 12c3c0293103d73172004aab46178e56db86fd62 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Mon, 4 Jul 2022 14:40:09 -0400 Subject: [PATCH 19/37] Separate projects for sleigh tools Library is still top-level CMakeLists.txt More options --- .github/workflows/main.yml | 4 +- CMakeLists.txt | 330 +++++++++-------------------- CMakePresets.json | 4 +- cmake/install-config.cmake.in | 8 +- cmake/install-rules.cmake | 23 +- cmake/options.cmake | 29 +-- src/compile_options.cmake | 38 ++++ src/setup-ghidra-source.cmake | 130 +++++++++++- support/CMakeLists.txt | 3 + tests/CMakeLists.txt | 2 +- tools/CMakeLists.txt | 15 ++ tools/decompiler/CMakeLists.txt | 55 +++++ tools/ghidra/CMakeLists.txt | 53 +++++ tools/spec-compiler/CMakeLists.txt | 43 ++++ 14 files changed, 460 insertions(+), 277 deletions(-) create mode 100644 src/compile_options.cmake create mode 100644 tools/CMakeLists.txt create mode 100644 tools/decompiler/CMakeLists.txt create mode 100644 tools/ghidra/CMakeLists.txt create mode 100644 tools/spec-compiler/CMakeLists.txt diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1341ffda5..b06e5a49a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -143,7 +143,7 @@ jobs: ctest -V -C ${{ matrix.build_type }} - name: Test tool install directory - working-directory: tools/sleigh-lift + working-directory: extra-tools/sleigh-lift run: | cmake -B build -S . "-Dsleigh_DIR=${{ github.workspace }}/install/lib/cmake/sleigh" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} cmake --build build -j 2 --config ${{ matrix.build_type }} @@ -233,7 +233,7 @@ jobs: # failure state - name: Run the tests working-directory: build - run: ctest -V -C ${{ matrix.build_type }} + run: ctest -VV -C ${{ matrix.build_type }} - name: ccache stats run: ccache -s --verbose diff --git a/CMakeLists.txt b/CMakeLists.txt index 3df777251..6160fd746 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,29 +26,112 @@ include(cmake/project-is-top-level.cmake) include(cmake/options.cmake) set(public_include_header_list + "${library_root}/action.hh" "${library_root}/address.hh" + "${library_root}/architecture.hh" + "${library_root}/block.hh" + "${library_root}/blockaction.hh" + "${library_root}/callgraph.hh" + "${library_root}/capability.hh" + "${library_root}/cast.hh" + "${library_root}/codedata.hh" + "${library_root}/comment.hh" + "${library_root}/comment_ghidra.hh" + "${library_root}/condexe.hh" "${library_root}/context.hh" + "${library_root}/coreaction.hh" + "${library_root}/cover.hh" + "${library_root}/cpool.hh" + "${library_root}/cpool_ghidra.hh" + "${library_root}/crc32.hh" + "${library_root}/database.hh" + "${library_root}/database_ghidra.hh" + "${library_root}/doccore.hh" + "${library_root}/docmain.hh" + "${library_root}/double.hh" + "${library_root}/dynamic.hh" "${library_root}/emulate.hh" + "${library_root}/emulateutil.hh" "${library_root}/error.hh" + "${library_root}/filemanage.hh" "${library_root}/float.hh" + "${library_root}/flow.hh" + "${library_root}/fspec.hh" + "${library_root}/funcdata.hh" + "${library_root}/ghidra_arch.hh" + "${library_root}/ghidra_context.hh" + "${library_root}/ghidra_process.hh" + "${library_root}/ghidra_translate.hh" "${library_root}/globalcontext.hh" + "${library_root}/grammar.hh" + "${library_root}/graph.hh" + "${library_root}/heritage.hh" + "${library_root}/ifacedecomp.hh" + "${library_root}/ifaceterm.hh" + "${library_root}/inject_ghidra.hh" + "${library_root}/inject_sleigh.hh" + "${library_root}/interface.hh" + "${library_root}/jumptable.hh" + "${library_root}/libdecomp.hh" "${library_root}/loadimage.hh" + "${library_root}/loadimage_ghidra.hh" + "${library_root}/loadimage_xml.hh" "${library_root}/memstate.hh" + "${library_root}/merge.hh" + "${library_root}/op.hh" "${library_root}/opbehavior.hh" "${library_root}/opcodes.hh" + "${library_root}/options.hh" + "${library_root}/override.hh" + "${library_root}/paramid.hh" "${library_root}/partmap.hh" + "${library_root}/pcodecompile.hh" + "${library_root}/pcodeinject.hh" + "${library_root}/pcodeparse.hh" "${library_root}/pcoderaw.hh" + "${library_root}/prefersplit.hh" + "${library_root}/prettyprint.hh" + "${library_root}/printc.hh" + "${library_root}/printjava.hh" + "${library_root}/printlanguage.hh" + "${library_root}/rangemap.hh" + "${library_root}/rangeutil.hh" + "${library_root}/raw_arch.hh" + "${library_root}/ruleaction.hh" + "${library_root}/rulecompile.hh" "${library_root}/semantics.hh" "${library_root}/sleigh.hh" + "${library_root}/sleigh_arch.hh" "${library_root}/sleighbase.hh" + "${library_root}/slgh_compile.hh" + "${library_root}/slghparse.hh" "${library_root}/slghpatexpress.hh" "${library_root}/slghpattern.hh" "${library_root}/slghsymbol.hh" "${library_root}/space.hh" + "${library_root}/string_ghidra.hh" + "${library_root}/stringmanage.hh" + "${library_root}/subflow.hh" + "${library_root}/testfunction.hh" + "${library_root}/transform.hh" "${library_root}/translate.hh" + "${library_root}/type.hh" + "${library_root}/typegrp_ghidra.hh" + "${library_root}/typeop.hh" "${library_root}/types.h" + "${library_root}/unify.hh" + "${library_root}/userop.hh" + "${library_root}/variable.hh" + "${library_root}/varmap.hh" + "${library_root}/varnode.hh" "${library_root}/xml.hh" + "${library_root}/xml_arch.hh" ) +if("${sleigh_GHIDRA_RELEASE_TYPE}" STREQUAL "HEAD") + list(APPEND public_include_header_list + "${library_root}/unionresolve.hh" + ) +endif() # Create custom target so that IDEs know these files are part of the sources add_custom_target(sleigh_all_headers SOURCES ${public_include_header_list}) set(public_headers_dir ${CMAKE_CURRENT_BINARY_DIR}/include) @@ -59,237 +142,6 @@ foreach(public_header ${public_include_header_list}) configure_file("${public_header}" "${public_headers_dir}/sleigh" COPYONLY) endforeach() -set(sleigh_core_source_list - "${library_root}/xml.cc" - "${library_root}/space.cc" - "${library_root}/float.cc" - "${library_root}/address.cc" - "${library_root}/pcoderaw.cc" - "${library_root}/translate.cc" - "${library_root}/opcodes.cc" - "${library_root}/globalcontext.cc" -) - -set(sleigh_deccore_source_list - "${library_root}/capability.cc" - "${library_root}/architecture.cc" - "${library_root}/options.cc" - "${library_root}/graph.cc" - "${library_root}/cover.cc" - "${library_root}/block.cc" - "${library_root}/cast.cc" - "${library_root}/typeop.cc" - "${library_root}/database.cc" - "${library_root}/cpool.cc" - "${library_root}/comment.cc" - "${library_root}/stringmanage.cc" - "${library_root}/fspec.cc" - "${library_root}/action.cc" - "${library_root}/loadimage.cc" - "${library_root}/grammar.cc" - "${library_root}/varnode.cc" - "${library_root}/op.cc" - "${library_root}/type.cc" - "${library_root}/variable.cc" - "${library_root}/varmap.cc" - "${library_root}/jumptable.cc" - "${library_root}/emulate.cc" - "${library_root}/emulateutil.cc" - "${library_root}/flow.cc" - "${library_root}/userop.cc" - "${library_root}/funcdata.cc" - "${library_root}/funcdata_block.cc" - "${library_root}/funcdata_op.cc" - "${library_root}/funcdata_varnode.cc" - "${library_root}/pcodeinject.cc" - "${library_root}/heritage.cc" - "${library_root}/prefersplit.cc" - "${library_root}/rangeutil.cc" - "${library_root}/ruleaction.cc" - "${library_root}/subflow.cc" - "${library_root}/blockaction.cc" - "${library_root}/merge.cc" - "${library_root}/double.cc" - "${library_root}/transform.cc" - "${library_root}/coreaction.cc" - "${library_root}/condexe.cc" - "${library_root}/override.cc" - "${library_root}/dynamic.cc" - "${library_root}/crc32.cc" - "${library_root}/prettyprint.cc" - "${library_root}/printlanguage.cc" - "${library_root}/printc.cc" - "${library_root}/printjava.cc" - "${library_root}/memstate.cc" - "${library_root}/opbehavior.cc" - "${library_root}/paramid.cc" -) -if("${sleigh_GHIDRA_RELEASE_TYPE}" STREQUAL "HEAD") - list(APPEND sleigh_deccore_source_list - "${library_root}/unionresolve.cc" - ) -endif() - -set(sleigh_extra_source_list - "${library_root}/callgraph.cc" - "${library_root}/ifacedecomp.cc" - "${library_root}/ifaceterm.cc" - "${library_root}/inject_sleigh.cc" - "${library_root}/interface.cc" - "${library_root}/libdecomp.cc" - "${library_root}/loadimage_xml.cc" - "${library_root}/raw_arch.cc" - "${library_root}/rulecompile.cc" - "${library_root}/sleigh_arch.cc" - "${library_root}/testfunction.cc" - "${library_root}/unify.cc" - "${library_root}/xml_arch.cc" -) - -set(sleigh_source_list - "${library_root}/sleigh.cc" - "${library_root}/pcodeparse.cc" - "${library_root}/pcodecompile.cc" - "${library_root}/sleighbase.cc" - "${library_root}/slghsymbol.cc" - "${library_root}/slghpatexpress.cc" - "${library_root}/slghpattern.cc" - "${library_root}/semantics.cc" - "${library_root}/context.cc" - "${library_root}/filemanage.cc" -) - -set(sleigh_ghidra_source_list - "${library_root}/ghidra_arch.cc" - "${library_root}/inject_ghidra.cc" - "${library_root}/ghidra_translate.cc" - "${library_root}/loadimage_ghidra.cc" - "${library_root}/typegrp_ghidra.cc" - "${library_root}/database_ghidra.cc" - "${library_root}/ghidra_context.cc" - "${library_root}/cpool_ghidra.cc" - "${library_root}/ghidra_process.cc" - "${library_root}/comment_ghidra.cc" - "${library_root}/string_ghidra.cc" -) - -set(sleigh_slacomp_source_list - "${library_root}/slgh_compile.cc" - "${library_root}/slghparse.cc" - "${library_root}/slghscan.cc" -) - -# -# Common options that apply to all targets -# -macro(sleigh_add_optional_defines target visibility) - set(opt_defines "") - if(sleigh_CPUI_RULECOMPILE) - list(APPEND opt_defines "CPUI_RULECOMPILE") - endif() - if(sleigh_CPUI_STATISTICS) - list(APPEND opt_defines "CPUI_STATISTICS") - endif() - if(sleigh_DEBUG_BLOCKCONSISTENT) - list(APPEND opt_defines "BLOCKCONSISTENT_DEBUG") - endif() - if(sleigh_DEBUG_DFSVERIFY) - list(APPEND opt_defines "DFSVERIFY_DEBUG") - endif() - if(sleigh_DEBUG_MERGEMULTI) - list(APPEND opt_defines "MERGEMULTI_DEBUG") - endif() - if(sleigh_DEBUG_OPACTION) - list(APPEND opt_defines "OPACTION_DEBUG") - endif() - if(WIN32) - list(APPEND opt_defines "_WINDOWS") - endif() - target_compile_definitions("${target}" ${visibility} ${opt_defines}) -endmacro() - -# -# decomp -# - -add_executable(sleigh_decompiler - ${sleigh_core_source_list} - ${sleigh_deccore_source_list} - ${sleigh_extra_source_list} - ${sleigh_source_list} - - "${library_root}/consolemain.cc" -) -add_executable(sleigh::decompiler ALIAS sleigh_decompiler) - -target_compile_features(sleigh_decompiler PUBLIC cxx_std_11) -target_include_directories(sleigh_decompiler PRIVATE "$") -if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") - target_compile_definitions(sleigh_decompiler PRIVATE - __TERMINAL__ - ) -endif() -target_compile_definitions(sleigh_decompiler PRIVATE - $<$:CPUI_DEBUG> -) -sleigh_add_optional_defines(sleigh_decompiler PRIVATE) - -set_target_properties(sleigh_decompiler PROPERTIES - EXPORT_NAME decompiler - OUTPUT_NAME decomp - OUTPUT_NAME_DEBUG decomp_dbg -) - -# -# ghidra -# - -add_executable(sleigh_ghidra - ${sleigh_core_source_list} - ${sleigh_deccore_source_list} - ${sleigh_ghidra_source_list} - - "$<$:${library_root}/callgraph.cc>" - "$<$:${library_root}/ifacedecomp.cc>" - "$<$:${library_root}/ifaceterm.cc>" - "$<$:${library_root}/interface.cc>" - "$<$:${library_root}/testfunction.cc>" -) -add_executable(sleigh::ghidra ALIAS sleigh_ghidra) - -target_compile_features(sleigh_ghidra PUBLIC cxx_std_11) -target_include_directories(sleigh_ghidra PRIVATE "$") -target_compile_definitions(sleigh_ghidra PRIVATE - $<$:CPUI_DEBUG> -) -sleigh_add_optional_defines(sleigh_ghidra PRIVATE) - -set_target_properties(sleigh_ghidra PROPERTIES - EXPORT_NAME ghidra - OUTPUT_NAME ghidra - OUTPUT_NAME_DEBUG ghidra_dbg -) - -# -# sleigh -# - -add_executable(sleigh_sleigh - ${sleigh_core_source_list} - ${sleigh_source_list} - ${sleigh_slacomp_source_list} -) -add_executable(sleigh::sleigh ALIAS sleigh_sleigh) - -target_compile_features(sleigh_sleigh PUBLIC cxx_std_11) -target_include_directories(sleigh_sleigh PRIVATE "$") -sleigh_add_optional_defines(sleigh_sleigh PRIVATE) -set_target_properties(sleigh_sleigh PROPERTIES - EXPORT_NAME sleigh - OUTPUT_NAME sleigh - OUTPUT_NAME_DEBUG sleigh_dbg -) - # # sla # @@ -351,10 +203,16 @@ set_target_properties(sleigh_decomp PROPERTIES OUTPUT_NAME_DEBUG decomp_dbg ) +if(sleigh_BUILD_TOOLS) + add_subdirectory(tools) +endif() + # # Spec files # +if(sleigh_BUILD_SLEIGHSPECS) + # Sets 'spec_file_list' variable if(NOT "${sleigh_GHIDRA_RELEASE_TYPE}" STREQUAL "HEAD") include(spec-files-list/spec_files_stable.cmake) @@ -363,7 +221,7 @@ else() endif() # This prefix should match the Ghidra repo to where the sla spec files are located -set(spec_files_dir_prefix Ghidra/Processors) +set(spec_files_dir_prefix "Ghidra/Processors") # This is the root directory where all individual processor spec file directories will be created set(spec_files_build_dir "${CMAKE_CURRENT_BINARY_DIR}/specfiles") # This is where we will be copying the generated artifacts for each processor @@ -383,6 +241,9 @@ if(CMAKE_CROSSCOMPILING) DOC "Path to host system sleigh compiler" ) else() + if(NOT TARGET sleigh::sleigh) + add_subdirectory(tools/spec-compiler) + endif() set( SLEIGH_EXECUTABLE "$" CACHE FILEPATH "Path to host system sleigh compiler" @@ -469,12 +330,15 @@ add_custom_target(sleigh_all_sla_specs ALL DEPENDS ${spec_targets} ) +endif() # sleigh_BUILD_SLEIGHSPECS + # # Included Example # if(PROJECT_IS_TOP_LEVEL) - option(sleigh_BUILD_EXAMPLE "Build included sleigh example" "${sleigh_DEVELOPER_MODE}") + include(CMakeDependentOption) + cmake_dependent_option(sleigh_BUILD_EXAMPLE "Build included sleigh example" "${sleigh_DEVELOPER_MODE}" "sleigh_BUILD_SLEIGHSPECS" OFF) if(sleigh_BUILD_EXAMPLE) add_executable(sleigh_example "${library_root}/sleighexample.cc" diff --git a/CMakePresets.json b/CMakePresets.json index d97eb0fc0..a6ff20d7b 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -27,9 +27,7 @@ "inherits": "cmake-pedantic", "cacheVariables": { "sleigh_DEVELOPER_MODE": "ON", - "sleigh_BUILD_DOCUMENTATION": "ON", - "sleigh_BUILD_SUPPORT": "ON", - "sleigh_BUILD_EXTRATOOLS": "ON" + "sleigh_BUILD_DOCUMENTATION": "ON" } }, { diff --git a/cmake/install-config.cmake.in b/cmake/install-config.cmake.in index d8c72018e..3ebcb3186 100644 --- a/cmake/install-config.cmake.in +++ b/cmake/install-config.cmake.in @@ -1,7 +1,7 @@ # This file provides access to the installed sleigh targets. # -# There are two optional components that could also be installed: -# * Support - support library for easier use of sleigh +# There are optional components that could also be installed: +# * Support - Support library for easier use of sleigh # * ExtraTools - Extra tools created by Trail of Bits @PACKAGE_INIT@ @@ -9,7 +9,9 @@ include("${CMAKE_CURRENT_LIST_DIR}/sleighTargets.cmake") # Path relative-root to reach installed specfiles directory -set_and_check(sleigh_INSTALL_SPECDIR "@PACKAGE_sleigh_INSTALL_SPECDIR@") +if(EXISTS "@PACKAGE_sleigh_INSTALL_SPECDIR@") + set(sleigh_INSTALL_SPECDIR "@PACKAGE_sleigh_INSTALL_SPECDIR@") +endif() # Helpers exposed by default when finding sleigh include("${CMAKE_CURRENT_LIST_DIR}/modules/sleighCompile.cmake") diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake index 4deb39f36..4470d3834 100644 --- a/cmake/install-rules.cmake +++ b/cmake/install-rules.cmake @@ -6,12 +6,6 @@ include("GNUInstallDirs") install( TARGETS - # Executable binary targets - sleigh_decompiler - sleigh_ghidra - sleigh_sleigh - - # Library targets sleigh_sla sleigh_decomp EXPORT @@ -55,8 +49,7 @@ install( ) # Specfiles installation setup -set( - sleigh_INSTALL_DATADIR "${CMAKE_INSTALL_DATADIR}/sleigh" +set(sleigh_INSTALL_DATADIR "${CMAKE_INSTALL_DATADIR}/sleigh" CACHE PATH "sleigh data installation location relative to the install prefix" ) mark_as_advanced(sleigh_INSTALL_DATADIR) @@ -66,12 +59,14 @@ set(sleigh_INSTALL_SPECDIR "${sleigh_INSTALL_DATADIR}/specfiles" ) mark_as_advanced(sleigh_INSTALL_SPECDIR) -# Install the compiled sla files found in 'Ghidra' top-level directory -install( - DIRECTORY "${spec_files_build_dir}/" - DESTINATION "${sleigh_INSTALL_SPECDIR}" - COMPONENT sleigh_Runtime -) +if(sleigh_BUILD_SLEIGHSPECS) + # Install the compiled sla files found in 'Ghidra' top-level directory + install( + DIRECTORY "${spec_files_build_dir}/" + DESTINATION "${sleigh_INSTALL_SPECDIR}" + COMPONENT sleigh_Runtime + ) +endif() include(CMakePackageConfigHelpers) diff --git a/cmake/options.cmake b/cmake/options.cmake index 6e69a66f7..73a296341 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -13,36 +13,27 @@ # Targets necessary to build the project must be provided unconditionally, so # consumers can trivially build and package the project if(PROJECT_IS_TOP_LEVEL) - option(sleigh_DEVELOPER_MODE "Enable developer mode" OFF) - option(BUILD_SHARED_LIBS "Build shared libs. (Untested and not supported)" OFF) + option(sleigh_DEVELOPER_MODE "Enable developer mode") + option(BUILD_SHARED_LIBS "Build shared libs. (Untested and not supported)") endif() if(sleigh_DEVELOPER_MODE) - option(sleigh_BUILD_DOCUMENTATION "Build documentation using Doxygen" OFF) + option(sleigh_BUILD_DOCUMENTATION "Build documentation using Doxygen") set( DOXYGEN_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/docs" CACHE PATH "Path for the generated Doxygen documentation" ) endif() +include(CMakeDependentOption) -# Add-ons by ToB -option(sleigh_BUILD_SUPPORT "Build ToB support libraries") -option(sleigh_BUILD_EXTRATOOLS "Build extra ToB sleigh tools") -if(sleigh_BUILD_EXTRATOOLS) - set(sleigh_BUILD_SUPPORT ON CACHE BOOL "Build ToB support libraries" FORCE) -endif() - +# Optional project target building +option(sleigh_BUILD_TOOLS "Build and install executable tools" ON) +option(sleigh_BUILD_SLEIGHSPECS "Build and install sleigh spec files" ON) -# Internal settings -option(sleigh_CPUI_RULECOMPILE "Allow user defined dynamic rules") -option(sleigh_CPUI_STATISTICS "Turn on collection of cover and cast statistics") - -# Internal debug settings (naming is swapped to help with discoverability in CMake options) -option(sleigh_DEBUG_BLOCKCONSISTENT "Check that block graph structure is consistent") -option(sleigh_DEBUG_DFSVERIFY "Make sure that the block ordering algorithm produces a true depth first traversal of the dominator tree") -option(sleigh_DEBUG_MERGEMULTI "Check for MULTIEQUAL and INDIRECT intersections") -option(sleigh_DEBUG_OPACTION "Turns on all the action tracing facilities") +# Add-ons by ToB +option(sleigh_BUILD_SUPPORT "Build ToB support libraries" ON) +cmake_dependent_option(sleigh_BUILD_EXTRATOOLS "Build extra ToB sleigh tools" ON "sleigh_BUILD_SUPPORT" OFF) # ---- Warning guard ---- diff --git a/src/compile_options.cmake b/src/compile_options.cmake new file mode 100644 index 000000000..30a0a6897 --- /dev/null +++ b/src/compile_options.cmake @@ -0,0 +1,38 @@ +# Internal settings +option(sleigh_CPUI_RULECOMPILE "Allow user defined dynamic rules") +option(sleigh_CPUI_STATISTICS "Turn on collection of cover and cast statistics") + +# Internal debug settings (naming is swapped to help with discoverability in CMake options) +option(sleigh_DEBUG_BLOCKCONSISTENT "Check that block graph structure is consistent") +option(sleigh_DEBUG_DFSVERIFY "Make sure that the block ordering algorithm produces a true depth first traversal of the dominator tree") +option(sleigh_DEBUG_MERGEMULTI "Check for MULTIEQUAL and INDIRECT intersections") +option(sleigh_DEBUG_OPACTION "Turns on all the action tracing facilities") + +# +# Common options that can apply to all project targets +# +macro(sleigh_add_optional_defines target visibility) + set(opt_defines "") + if(sleigh_CPUI_RULECOMPILE) + list(APPEND opt_defines "CPUI_RULECOMPILE") + endif() + if(sleigh_CPUI_STATISTICS) + list(APPEND opt_defines "CPUI_STATISTICS") + endif() + if(sleigh_DEBUG_BLOCKCONSISTENT) + list(APPEND opt_defines "BLOCKCONSISTENT_DEBUG") + endif() + if(sleigh_DEBUG_DFSVERIFY) + list(APPEND opt_defines "DFSVERIFY_DEBUG") + endif() + if(sleigh_DEBUG_MERGEMULTI) + list(APPEND opt_defines "MERGEMULTI_DEBUG") + endif() + if(sleigh_DEBUG_OPACTION) + list(APPEND opt_defines "OPACTION_DEBUG") + endif() + if(WIN32) + list(APPEND opt_defines "_WINDOWS") + endif() + target_compile_definitions("${target}" ${visibility} ${opt_defines}) +endmacro() diff --git a/src/setup-ghidra-source.cmake b/src/setup-ghidra-source.cmake index 4cb54e722..5d82757f9 100644 --- a/src/setup-ghidra-source.cmake +++ b/src/setup-ghidra-source.cmake @@ -1,4 +1,5 @@ # ---- Setup Ghidra Source code ---- +include_guard(GLOBAL) # Set up Ghidra repo human-readable version settings set(sleigh_GHIDRA_RELEASE_TYPE "stable" CACHE @@ -16,7 +17,7 @@ set(ghidra_shallow TRUE) # pinned stable patches list set(ghidra_patches PATCH_COMMAND git am --ignore-space-change --ignore-whitespace --no-gpg-sign - "${CMAKE_CURRENT_SOURCE_DIR}/patches/stable/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch" + "${CMAKE_CURRENT_LIST_DIR}/../patches/stable/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch" ) # Ghidra pinned commits used for pinning last known working HEAD commit @@ -30,7 +31,7 @@ if("${sleigh_GHIDRA_RELEASE_TYPE}" STREQUAL HEAD) set(ghidra_shallow FALSE) set(ghidra_patches PATCH_COMMAND git am --ignore-space-change --ignore-whitespace --no-gpg-sign - "${CMAKE_CURRENT_SOURCE_DIR}/patches/HEAD/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch" + "${CMAKE_CURRENT_LIST_DIR}/../patches/HEAD/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch" ) string(SUBSTRING "${ghidra_git_tag}" 0 7 ghidra_short_commit) else() @@ -61,3 +62,128 @@ set(library_root "${ghidrasource_SOURCE_DIR}/Ghidra/Features/Decompiler/src/deco if(NOT EXISTS "${library_root}/sleigh.hh") message(FATAL_ERROR "The Ghidra source directory has not been initialized correctly. Could not find '${library_root}'") endif() + +# Source collection variables +set(sleigh_core_source_list + "${library_root}/xml.cc" + "${library_root}/space.cc" + "${library_root}/float.cc" + "${library_root}/address.cc" + "${library_root}/pcoderaw.cc" + "${library_root}/translate.cc" + "${library_root}/opcodes.cc" + "${library_root}/globalcontext.cc" +) + +set(sleigh_deccore_source_list + "${library_root}/capability.cc" + "${library_root}/architecture.cc" + "${library_root}/options.cc" + "${library_root}/graph.cc" + "${library_root}/cover.cc" + "${library_root}/block.cc" + "${library_root}/cast.cc" + "${library_root}/typeop.cc" + "${library_root}/database.cc" + "${library_root}/cpool.cc" + "${library_root}/comment.cc" + "${library_root}/stringmanage.cc" + "${library_root}/fspec.cc" + "${library_root}/action.cc" + "${library_root}/loadimage.cc" + "${library_root}/grammar.cc" + "${library_root}/varnode.cc" + "${library_root}/op.cc" + "${library_root}/type.cc" + "${library_root}/variable.cc" + "${library_root}/varmap.cc" + "${library_root}/jumptable.cc" + "${library_root}/emulate.cc" + "${library_root}/emulateutil.cc" + "${library_root}/flow.cc" + "${library_root}/userop.cc" + "${library_root}/funcdata.cc" + "${library_root}/funcdata_block.cc" + "${library_root}/funcdata_op.cc" + "${library_root}/funcdata_varnode.cc" + "${library_root}/pcodeinject.cc" + "${library_root}/heritage.cc" + "${library_root}/prefersplit.cc" + "${library_root}/rangeutil.cc" + "${library_root}/ruleaction.cc" + "${library_root}/subflow.cc" + "${library_root}/blockaction.cc" + "${library_root}/merge.cc" + "${library_root}/double.cc" + "${library_root}/transform.cc" + "${library_root}/coreaction.cc" + "${library_root}/condexe.cc" + "${library_root}/override.cc" + "${library_root}/dynamic.cc" + "${library_root}/crc32.cc" + "${library_root}/prettyprint.cc" + "${library_root}/printlanguage.cc" + "${library_root}/printc.cc" + "${library_root}/printjava.cc" + "${library_root}/memstate.cc" + "${library_root}/opbehavior.cc" + "${library_root}/paramid.cc" +) +if("${sleigh_GHIDRA_RELEASE_TYPE}" STREQUAL "HEAD") + list(APPEND sleigh_deccore_source_list + "${library_root}/unionresolve.cc" + ) +endif() + +set(sleigh_extra_source_list + "${library_root}/callgraph.cc" + "${library_root}/ifacedecomp.cc" + "${library_root}/ifaceterm.cc" + "${library_root}/inject_sleigh.cc" + "${library_root}/interface.cc" + "${library_root}/libdecomp.cc" + "${library_root}/loadimage_xml.cc" + "${library_root}/raw_arch.cc" + "${library_root}/rulecompile.cc" + "${library_root}/sleigh_arch.cc" + "${library_root}/testfunction.cc" + "${library_root}/unify.cc" + "${library_root}/xml_arch.cc" +) + +set(sleigh_source_list + "${library_root}/sleigh.cc" + "${library_root}/pcodeparse.cc" + "${library_root}/pcodecompile.cc" + "${library_root}/sleighbase.cc" + "${library_root}/slghsymbol.cc" + "${library_root}/slghpatexpress.cc" + "${library_root}/slghpattern.cc" + "${library_root}/semantics.cc" + "${library_root}/context.cc" + "${library_root}/filemanage.cc" +) + +set(sleigh_ghidra_source_list + "${library_root}/ghidra_arch.cc" + "${library_root}/inject_ghidra.cc" + "${library_root}/ghidra_translate.cc" + "${library_root}/loadimage_ghidra.cc" + "${library_root}/typegrp_ghidra.cc" + "${library_root}/database_ghidra.cc" + "${library_root}/ghidra_context.cc" + "${library_root}/cpool_ghidra.cc" + "${library_root}/ghidra_process.cc" + "${library_root}/comment_ghidra.cc" + "${library_root}/string_ghidra.cc" +) + +set(sleigh_slacomp_source_list + "${library_root}/slgh_compile.cc" + "${library_root}/slghparse.cc" + "${library_root}/slghscan.cc" +) + +# Include separate file to make it easier to find user-specified compile +# options +include("${CMAKE_CURRENT_LIST_DIR}/compile_options.cmake") diff --git a/support/CMakeLists.txt b/support/CMakeLists.txt index 452cfc5e5..fffb4d4e2 100644 --- a/support/CMakeLists.txt +++ b/support/CMakeLists.txt @@ -61,6 +61,7 @@ target_include_directories(sleigh_support if(NOT CMAKE_SKIP_INSTALL_RULES) include(GNUInstallDirs) + install( TARGETS sleigh_support EXPORT sleighSupportTargets @@ -73,6 +74,7 @@ if(NOT CMAKE_SKIP_INSTALL_RULES) COMPONENT sleigh_SupportDevelopment INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) + install( DIRECTORY include/ @@ -80,6 +82,7 @@ if(NOT CMAKE_SKIP_INSTALL_RULES) DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT sleigh_SupportDevelopment ) + install( EXPORT sleighSupportTargets DESTINATION "${sleigh_INSTALL_CMAKEDIR}" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ad3295799..5e3eb3f4d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,7 +17,7 @@ add_executable(sleigh_ghidra_test target_compile_features(sleigh_ghidra_test PRIVATE cxx_std_11) target_include_directories(sleigh_ghidra_test PRIVATE "${library_root}") -if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") +if(WIN32) target_compile_definitions(sleigh_ghidra_test PRIVATE __TERMINAL__ ) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 000000000..e2feda0bb --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,15 @@ +option(sleigh_BUILD_SPECCOMPILER "Build the sleigh spec compiler executable" ON) +option(sleigh_BUILD_DECOMPILER "Build the decompiler executable" ON) +option(sleigh_BUILD_GHIDRA "Build the Ghidra executable" ON) + +if(sleigh_BUILD_SPECCOMPILER) + add_subdirectory(spec-compiler) +endif() + +if(sleigh_BUILD_DECOMPILER) + add_subdirectory(decompiler) +endif() + +if(sleigh_BUILD_GHIDRA) + add_subdirectory(ghidra) +endif() diff --git a/tools/decompiler/CMakeLists.txt b/tools/decompiler/CMakeLists.txt new file mode 100644 index 000000000..d824ccdc8 --- /dev/null +++ b/tools/decompiler/CMakeLists.txt @@ -0,0 +1,55 @@ +cmake_minimum_required(VERSION 3.15) + +include(../../cmake/prelude.cmake) +include(../../src/setup-ghidra-source.cmake) + +project(sleigh_decompiler + VERSION "${ghidra_version}" + DESCRIPTION "Sleigh decompiler" + HOMEPAGE_URL "https://github.com/lifting-bits/sleigh" + LANGUAGES CXX +) + +include(../../cmake/project-is-top-level.cmake) + +add_executable(sleigh_decompiler + ${sleigh_core_source_list} + ${sleigh_deccore_source_list} + ${sleigh_extra_source_list} + ${sleigh_source_list} + + "${library_root}/consolemain.cc" +) +add_executable(sleigh::decompiler ALIAS sleigh_decompiler) + +target_compile_features(sleigh_decompiler PUBLIC cxx_std_11) +target_include_directories(sleigh_decompiler PRIVATE "$") +if(WIN32) + target_compile_definitions(sleigh_decompiler PRIVATE + __TERMINAL__ + ) +endif() +target_compile_definitions(sleigh_decompiler PRIVATE + $<$:CPUI_DEBUG> +) +sleigh_add_optional_defines(sleigh_decompiler PRIVATE) + +set_target_properties(sleigh_decompiler PROPERTIES + EXPORT_NAME decompiler + OUTPUT_NAME decomp + OUTPUT_NAME_DEBUG decomp_dbg +) + +if(NOT CMAKE_SKIP_INSTALL_RULES) + include("GNUInstallDirs") + + install( + TARGETS sleigh_decompiler + EXPORT sleighTargets + RUNTIME COMPONENT sleigh_Runtime + ) + + if(PROJECT_IS_TOP_LEVEL) + include(CPack) + endif() +endif() diff --git a/tools/ghidra/CMakeLists.txt b/tools/ghidra/CMakeLists.txt new file mode 100644 index 000000000..eec339056 --- /dev/null +++ b/tools/ghidra/CMakeLists.txt @@ -0,0 +1,53 @@ +cmake_minimum_required(VERSION 3.15) + +include(../../cmake/prelude.cmake) +include(../../src/setup-ghidra-source.cmake) + +project(sleigh_ghidra + VERSION "${ghidra_version}" + DESCRIPTION "Sleigh ghidra service" + HOMEPAGE_URL "https://github.com/lifting-bits/sleigh" + LANGUAGES CXX +) + +include(../../cmake/project-is-top-level.cmake) + +add_executable(sleigh_ghidra + ${sleigh_core_source_list} + ${sleigh_deccore_source_list} + ${sleigh_ghidra_source_list} + + "$<$:${library_root}/callgraph.cc>" + "$<$:${library_root}/ifacedecomp.cc>" + "$<$:${library_root}/ifaceterm.cc>" + "$<$:${library_root}/interface.cc>" + "$<$:${library_root}/testfunction.cc>" +) +add_executable(sleigh::ghidra ALIAS sleigh_ghidra) + +target_compile_features(sleigh_ghidra PUBLIC cxx_std_11) +target_include_directories(sleigh_ghidra PRIVATE "$") +target_compile_definitions(sleigh_ghidra PRIVATE + $<$:CPUI_DEBUG> +) +sleigh_add_optional_defines(sleigh_ghidra PRIVATE) + +set_target_properties(sleigh_ghidra PROPERTIES + EXPORT_NAME ghidra + OUTPUT_NAME ghidra + OUTPUT_NAME_DEBUG ghidra_dbg +) + +if(NOT CMAKE_SKIP_INSTALL_RULES) + include("GNUInstallDirs") + + install( + TARGETS sleigh_ghidra + EXPORT sleighTargets + RUNTIME COMPONENT sleigh_Runtime + ) + + if(PROJECT_IS_TOP_LEVEL) + include(CPack) + endif() +endif() diff --git a/tools/spec-compiler/CMakeLists.txt b/tools/spec-compiler/CMakeLists.txt new file mode 100644 index 000000000..3494dfac9 --- /dev/null +++ b/tools/spec-compiler/CMakeLists.txt @@ -0,0 +1,43 @@ +cmake_minimum_required(VERSION 3.15) + +include(../../cmake/prelude.cmake) +include(../../src/setup-ghidra-source.cmake) + +project(sleigh_sleigh + VERSION "${ghidra_version}" + DESCRIPTION "Sleigh spec compiler" + HOMEPAGE_URL "https://github.com/lifting-bits/sleigh" + LANGUAGES CXX +) + +include(../../cmake/project-is-top-level.cmake) + +add_executable(sleigh_sleigh + ${sleigh_core_source_list} + ${sleigh_source_list} + ${sleigh_slacomp_source_list} +) +add_executable(sleigh::sleigh ALIAS sleigh_sleigh) + +target_compile_features(sleigh_sleigh PUBLIC cxx_std_11) +target_include_directories(sleigh_sleigh PRIVATE "$") +sleigh_add_optional_defines(sleigh_sleigh PRIVATE) +set_target_properties(sleigh_sleigh PROPERTIES + EXPORT_NAME sleigh + OUTPUT_NAME sleigh + OUTPUT_NAME_DEBUG sleigh_dbg +) + +if(NOT CMAKE_SKIP_INSTALL_RULES) + include("GNUInstallDirs") + + install( + TARGETS sleigh_sleigh + EXPORT sleighTargets + RUNTIME COMPONENT sleigh_Runtime + ) + + if(PROJECT_IS_TOP_LEVEL) + include(CPack) + endif() +endif() From 814b41c45dd4ce357bd1982a6c7e01c3dbcc1aa8 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Wed, 6 Jul 2022 20:41:40 -0400 Subject: [PATCH 20/37] CMake find_package(Git) --- src/setup-ghidra-source.cmake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/setup-ghidra-source.cmake b/src/setup-ghidra-source.cmake index 5d82757f9..4a6ca376a 100644 --- a/src/setup-ghidra-source.cmake +++ b/src/setup-ghidra-source.cmake @@ -10,13 +10,15 @@ set_property(CACHE sleigh_GHIDRA_RELEASE_TYPE PROPERTY STRINGS "stable" "HEAD") # **** Setup pinned git info **** +find_package(Git REQUIRED) + # Ghidra pinned stable version commit set(ghidra_version "10.1.4") set(ghidra_git_tag "Ghidra_10.1.4_build") set(ghidra_shallow TRUE) # pinned stable patches list set(ghidra_patches - PATCH_COMMAND git am --ignore-space-change --ignore-whitespace --no-gpg-sign + PATCH_COMMAND "${GIT_EXECUTABLE}" am --ignore-space-change --ignore-whitespace --no-gpg-sign "${CMAKE_CURRENT_LIST_DIR}/../patches/stable/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch" ) @@ -30,7 +32,7 @@ if("${sleigh_GHIDRA_RELEASE_TYPE}" STREQUAL HEAD) set(ghidra_git_tag "${ghidra_head_git_tag}") set(ghidra_shallow FALSE) set(ghidra_patches - PATCH_COMMAND git am --ignore-space-change --ignore-whitespace --no-gpg-sign + PATCH_COMMAND "${GIT_EXECUTABLE}" am --ignore-space-change --ignore-whitespace --no-gpg-sign "${CMAKE_CURRENT_LIST_DIR}/../patches/HEAD/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch" ) string(SUBSTRING "${ghidra_git_tag}" 0 7 ghidra_short_commit) From 2ec6a8fa1622488758e90ed7f0e070bc89996fb2 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Fri, 29 Jul 2022 16:47:35 -0400 Subject: [PATCH 21/37] Fix bad merge for patch paths --- src/setup-ghidra-source.cmake | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/setup-ghidra-source.cmake b/src/setup-ghidra-source.cmake index 9912acf0a..d58436c5c 100644 --- a/src/setup-ghidra-source.cmake +++ b/src/setup-ghidra-source.cmake @@ -24,8 +24,8 @@ set(sleigh_ADDITIONAL_PATCHES "" CACHE STRING # pinned stable patches list set(ghidra_patches PATCH_COMMAND "${GIT_EXECUTABLE}" am --ignore-space-change --ignore-whitespace --no-gpg-sign - "${CMAKE_CURRENT_SOURCE_DIR}/patches/stable/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch" - "${CMAKE_CURRENT_SOURCE_DIR}/patches/stable/0002-Add-include-guards-to-decompiler-C-headers.patch" + "${CMAKE_CURRENT_LIST_DIR}/../patches/stable/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch" + "${CMAKE_CURRENT_LIST_DIR}/../patches/stable/0002-Add-include-guards-to-decompiler-C-headers.patch" ) # Ghidra pinned commits used for pinning last known working HEAD commit @@ -39,9 +39,9 @@ if("${sleigh_RELEASE_TYPE}" STREQUAL "HEAD") set(ghidra_shallow FALSE) set(ghidra_patches PATCH_COMMAND "${GIT_EXECUTABLE}" am --ignore-space-change --ignore-whitespace --no-gpg-sign - "${CMAKE_CURRENT_SOURCE_DIR}/patches/HEAD/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch" - "${CMAKE_CURRENT_SOURCE_DIR}/patches/HEAD/0002-Initialize-ID-lookup-tables-to-fix-sleighexample.patch" - "${CMAKE_CURRENT_SOURCE_DIR}/patches/HEAD/0003-Add-include-guards-to-decompiler-C-headers.patch" + "${CMAKE_CURRENT_LIST_DIR}/../patches/HEAD/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch" + "${CMAKE_CURRENT_LIST_DIR}/../patches/HEAD/0002-Initialize-ID-lookup-tables-to-fix-sleighexample.patch" + "${CMAKE_CURRENT_LIST_DIR}/../patches/HEAD/0003-Add-include-guards-to-decompiler-C-headers.patch" ) string(SUBSTRING "${ghidra_git_tag}" 0 7 ghidra_short_commit) else() From 753e773cbe56672bc5bd5f1f172181e14c7e0c08 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Fri, 29 Jul 2022 17:34:08 -0400 Subject: [PATCH 22/37] Fix missing libconfig.h header install --- CMakeLists.txt | 2 +- cmake/install-rules.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 96915e5b3..343f0b5d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,7 +144,7 @@ endif() add_custom_target(sleigh_all_headers SOURCES ${public_include_header_list}) set(public_headers_dir ${CMAKE_CURRENT_BINARY_DIR}/include) file(MAKE_DIRECTORY "${public_headers_dir}/sleigh") -configure_file(cmake/libconfig.h.in include/sleigh/libconfig.h) +configure_file(cmake/libconfig.h.in "${public_headers_dir}/sleigh/libconfig.h") # Copy the public headers into our build directory so that we can control the layout. # Ideally, we want to let people '#include ' without installing sleigh foreach(public_header ${public_include_header_list}) diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake index 4470d3834..b4fc686da 100644 --- a/cmake/install-rules.cmake +++ b/cmake/install-rules.cmake @@ -22,7 +22,7 @@ install( ) install( - FILES ${public_include_header_list} + DIRECTORY "${public_headers_dir}/sleigh" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/sleigh" COMPONENT sleigh_Development ) From a1f981b03153a9f014f6be5a7216cf5ad8ab7cb7 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Sat, 30 Jul 2022 10:21:47 -0400 Subject: [PATCH 23/37] Fix issues with installation of headers --- CMakeLists.txt | 23 ++++++++++++++--------- cmake/install-rules.cmake | 4 ++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 343f0b5d1..7f2743a24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -210,6 +210,20 @@ set_target_properties(sleigh_decomp PROPERTIES OUTPUT_NAME_DEBUG decomp_dbg ) +# This is the root directory where all individual processor spec file directories will be created. +# NOTE: Needs to be defined here before the install rules +set(spec_files_build_dir "${CMAKE_CURRENT_BINARY_DIR}/specfiles") + +# +# Install rules +# +if(NOT CMAKE_SKIP_INSTALL_RULES) + include(cmake/install-rules.cmake) +endif() + +# +# Build tool projects +# if(sleigh_BUILD_TOOLS) add_subdirectory(tools) endif() @@ -228,8 +242,6 @@ endif() # This prefix should match the Ghidra repo to where the sla spec files are located set(spec_files_dir_prefix "Ghidra/Processors") -# This is the root directory where all individual processor spec file directories will be created -set(spec_files_build_dir "${CMAKE_CURRENT_BINARY_DIR}/specfiles") # This is where we will be copying the generated artifacts for each processor set(spec_files_root_dir "${spec_files_build_dir}/${spec_files_dir_prefix}") @@ -384,13 +396,6 @@ if(PROJECT_IS_TOP_LEVEL) endif() endif() -# -# Install rules -# -if(NOT CMAKE_SKIP_INSTALL_RULES) - include(cmake/install-rules.cmake) -endif() - # # Extras provided by Trail of Bits # diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake index b4fc686da..a506d1147 100644 --- a/cmake/install-rules.cmake +++ b/cmake/install-rules.cmake @@ -22,8 +22,8 @@ install( ) install( - DIRECTORY "${public_headers_dir}/sleigh" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/sleigh" + DIRECTORY "${public_headers_dir}/" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT sleigh_Development ) From 2a662ba697221b1f39466b9348ee0ae69fc558fd Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Mon, 1 Aug 2022 13:37:09 -0400 Subject: [PATCH 24/37] More refactoring --- CMakeLists.txt | 13 +++---------- extra-tools/sleigh-lift/CMakeLists.txt | 2 +- scripts/update_ghidra_head.py | 2 +- {patches => src/patches}/HEAD/.gitkeep | 0 ...ments-to-C-decompiler-testing-from-CLI.patch | 0 ...-ID-lookup-tables-to-fix-sleighexample.patch | 0 ...include-guards-to-decompiler-C-headers.patch | 0 {patches => src/patches}/README.md | 0 {patches => src/patches}/stable/.gitkeep | 0 ...ments-to-C-decompiler-testing-from-CLI.patch | 0 ...include-guards-to-decompiler-C-headers.patch | 0 src/setup-ghidra-source.cmake | 17 ++++++++++++----- {spec-files-list => src}/spec_files_HEAD.cmake | 0 .../spec_files_stable.cmake | 0 tests/find_package/CMakeLists.txt | 2 +- tools/decompiler/CMakeLists.txt | 2 +- tools/ghidra/CMakeLists.txt | 2 +- tools/spec-compiler/CMakeLists.txt | 2 +- 18 files changed, 21 insertions(+), 21 deletions(-) rename {patches => src/patches}/HEAD/.gitkeep (100%) rename {patches => src/patches}/HEAD/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch (100%) rename {patches => src/patches}/HEAD/0002-Initialize-ID-lookup-tables-to-fix-sleighexample.patch (100%) rename {patches => src/patches}/HEAD/0003-Add-include-guards-to-decompiler-C-headers.patch (100%) rename {patches => src/patches}/README.md (100%) rename {patches => src/patches}/stable/.gitkeep (100%) rename {patches => src/patches}/stable/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch (100%) rename {patches => src/patches}/stable/0002-Add-include-guards-to-decompiler-C-headers.patch (100%) rename {spec-files-list => src}/spec_files_HEAD.cmake (100%) rename {spec-files-list => src}/spec_files_stable.cmake (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f2743a24..0f5acf879 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -233,23 +233,16 @@ endif() # if(sleigh_BUILD_SLEIGHSPECS) -# Sets 'spec_file_list' variable -if(sleigh_RELEASE_IS_HEAD) - include(spec-files-list/spec_files_HEAD.cmake) -else() - include(spec-files-list/spec_files_stable.cmake) -endif() - # This prefix should match the Ghidra repo to where the sla spec files are located set(spec_files_dir_prefix "Ghidra/Processors") # This is where we will be copying the generated artifacts for each processor set(spec_files_root_dir "${spec_files_build_dir}/${spec_files_dir_prefix}") -set(spec_files_build_log_dir ${CMAKE_CURRENT_BINARY_DIR}/spec_build_logs) +set(spec_files_build_log_dir "${CMAKE_CURRENT_BINARY_DIR}/spec_build_logs") add_custom_command( - OUTPUT ${spec_files_build_log_dir} - COMMAND ${CMAKE_COMMAND} -E make_directory ${spec_files_build_log_dir} + OUTPUT "${spec_files_build_log_dir}" + COMMAND ${CMAKE_COMMAND} -E make_directory "${spec_files_build_log_dir}" ) # Get the native machine's sleigh compiler or use the one we're about to build diff --git a/extra-tools/sleigh-lift/CMakeLists.txt b/extra-tools/sleigh-lift/CMakeLists.txt index d402a0f85..0b52c5bf4 100644 --- a/extra-tools/sleigh-lift/CMakeLists.txt +++ b/extra-tools/sleigh-lift/CMakeLists.txt @@ -6,7 +6,7 @@ # the LICENSE file found in the root directory of this source tree. # -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.18) project(sleighLift CXX) diff --git a/scripts/update_ghidra_head.py b/scripts/update_ghidra_head.py index 1247ad920..a2fcf11ba 100644 --- a/scripts/update_ghidra_head.py +++ b/scripts/update_ghidra_head.py @@ -8,7 +8,7 @@ from typing import AnyStr, Union PROJECT_ROOT = pathlib.Path(__file__).parent.parent.resolve() -HEAD_SPEC_FILE = PROJECT_ROOT / "spec-files-list" / "spec_files_HEAD.cmake" +HEAD_SPEC_FILE = PROJECT_ROOT / "src" / "spec_files_HEAD.cmake" assert HEAD_SPEC_FILE.exists() SETUP_GHIDRA_FILE = PROJECT_ROOT / "src" / "setup-ghidra-source.cmake" assert SETUP_GHIDRA_FILE.exists() diff --git a/patches/HEAD/.gitkeep b/src/patches/HEAD/.gitkeep similarity index 100% rename from patches/HEAD/.gitkeep rename to src/patches/HEAD/.gitkeep diff --git a/patches/HEAD/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch b/src/patches/HEAD/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch similarity index 100% rename from patches/HEAD/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch rename to src/patches/HEAD/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch diff --git a/patches/HEAD/0002-Initialize-ID-lookup-tables-to-fix-sleighexample.patch b/src/patches/HEAD/0002-Initialize-ID-lookup-tables-to-fix-sleighexample.patch similarity index 100% rename from patches/HEAD/0002-Initialize-ID-lookup-tables-to-fix-sleighexample.patch rename to src/patches/HEAD/0002-Initialize-ID-lookup-tables-to-fix-sleighexample.patch diff --git a/patches/HEAD/0003-Add-include-guards-to-decompiler-C-headers.patch b/src/patches/HEAD/0003-Add-include-guards-to-decompiler-C-headers.patch similarity index 100% rename from patches/HEAD/0003-Add-include-guards-to-decompiler-C-headers.patch rename to src/patches/HEAD/0003-Add-include-guards-to-decompiler-C-headers.patch diff --git a/patches/README.md b/src/patches/README.md similarity index 100% rename from patches/README.md rename to src/patches/README.md diff --git a/patches/stable/.gitkeep b/src/patches/stable/.gitkeep similarity index 100% rename from patches/stable/.gitkeep rename to src/patches/stable/.gitkeep diff --git a/patches/stable/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch b/src/patches/stable/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch similarity index 100% rename from patches/stable/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch rename to src/patches/stable/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch diff --git a/patches/stable/0002-Add-include-guards-to-decompiler-C-headers.patch b/src/patches/stable/0002-Add-include-guards-to-decompiler-C-headers.patch similarity index 100% rename from patches/stable/0002-Add-include-guards-to-decompiler-C-headers.patch rename to src/patches/stable/0002-Add-include-guards-to-decompiler-C-headers.patch diff --git a/src/setup-ghidra-source.cmake b/src/setup-ghidra-source.cmake index d58436c5c..bf15d9f77 100644 --- a/src/setup-ghidra-source.cmake +++ b/src/setup-ghidra-source.cmake @@ -24,8 +24,8 @@ set(sleigh_ADDITIONAL_PATCHES "" CACHE STRING # pinned stable patches list set(ghidra_patches PATCH_COMMAND "${GIT_EXECUTABLE}" am --ignore-space-change --ignore-whitespace --no-gpg-sign - "${CMAKE_CURRENT_LIST_DIR}/../patches/stable/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch" - "${CMAKE_CURRENT_LIST_DIR}/../patches/stable/0002-Add-include-guards-to-decompiler-C-headers.patch" + "${CMAKE_CURRENT_LIST_DIR}/patches/stable/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch" + "${CMAKE_CURRENT_LIST_DIR}/patches/stable/0002-Add-include-guards-to-decompiler-C-headers.patch" ) # Ghidra pinned commits used for pinning last known working HEAD commit @@ -39,9 +39,9 @@ if("${sleigh_RELEASE_TYPE}" STREQUAL "HEAD") set(ghidra_shallow FALSE) set(ghidra_patches PATCH_COMMAND "${GIT_EXECUTABLE}" am --ignore-space-change --ignore-whitespace --no-gpg-sign - "${CMAKE_CURRENT_LIST_DIR}/../patches/HEAD/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch" - "${CMAKE_CURRENT_LIST_DIR}/../patches/HEAD/0002-Initialize-ID-lookup-tables-to-fix-sleighexample.patch" - "${CMAKE_CURRENT_LIST_DIR}/../patches/HEAD/0003-Add-include-guards-to-decompiler-C-headers.patch" + "${CMAKE_CURRENT_LIST_DIR}/patches/HEAD/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch" + "${CMAKE_CURRENT_LIST_DIR}/patches/HEAD/0002-Initialize-ID-lookup-tables-to-fix-sleighexample.patch" + "${CMAKE_CURRENT_LIST_DIR}/patches/HEAD/0003-Add-include-guards-to-decompiler-C-headers.patch" ) string(SUBSTRING "${ghidra_git_tag}" 0 7 ghidra_short_commit) else() @@ -205,3 +205,10 @@ set(sleigh_slacomp_source_list # Include separate file to make it easier to find user-specified compile # options include("${CMAKE_CURRENT_LIST_DIR}/compile_options.cmake") + +# Sets 'spec_file_list' variable +if(sleigh_RELEASE_IS_HEAD) + include("${CMAKE_CURRENT_LIST_DIR}/spec_files_HEAD.cmake") +else() + include("${CMAKE_CURRENT_LIST_DIR}/spec_files_stable.cmake") +endif() diff --git a/spec-files-list/spec_files_HEAD.cmake b/src/spec_files_HEAD.cmake similarity index 100% rename from spec-files-list/spec_files_HEAD.cmake rename to src/spec_files_HEAD.cmake diff --git a/spec-files-list/spec_files_stable.cmake b/src/spec_files_stable.cmake similarity index 100% rename from spec-files-list/spec_files_stable.cmake rename to src/spec_files_stable.cmake diff --git a/tests/find_package/CMakeLists.txt b/tests/find_package/CMakeLists.txt index feb8bd2e3..d13f4ca1a 100644 --- a/tests/find_package/CMakeLists.txt +++ b/tests/find_package/CMakeLists.txt @@ -6,7 +6,7 @@ # the LICENSE file found in the root directory of this source tree. # -cmake_minimum_required(VERSION 3.15.0) +cmake_minimum_required(VERSION 3.18) project("sleigh_find_package_test") find_package(sleigh REQUIRED COMPONENTS Support) diff --git a/tools/decompiler/CMakeLists.txt b/tools/decompiler/CMakeLists.txt index d824ccdc8..405ffca2b 100644 --- a/tools/decompiler/CMakeLists.txt +++ b/tools/decompiler/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.18) include(../../cmake/prelude.cmake) include(../../src/setup-ghidra-source.cmake) diff --git a/tools/ghidra/CMakeLists.txt b/tools/ghidra/CMakeLists.txt index eec339056..2aa3cc76e 100644 --- a/tools/ghidra/CMakeLists.txt +++ b/tools/ghidra/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.18) include(../../cmake/prelude.cmake) include(../../src/setup-ghidra-source.cmake) diff --git a/tools/spec-compiler/CMakeLists.txt b/tools/spec-compiler/CMakeLists.txt index 3494dfac9..cd8ca0efd 100644 --- a/tools/spec-compiler/CMakeLists.txt +++ b/tools/spec-compiler/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.18) include(../../cmake/prelude.cmake) include(../../src/setup-ghidra-source.cmake) From 91088341a68cbd36b04e6a31e2c0271db7c928d7 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Mon, 1 Aug 2022 14:17:51 -0400 Subject: [PATCH 25/37] Refactor sleighexample into its own project/directory --- CMakeLists.txt | 32 +--------------- example/CMakeLists.txt | 86 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 31 deletions(-) create mode 100644 example/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f5acf879..e7f26717d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -355,37 +355,7 @@ if(PROJECT_IS_TOP_LEVEL) include(CMakeDependentOption) cmake_dependent_option(sleigh_BUILD_EXAMPLE "Build included sleigh example" "${sleigh_DEVELOPER_MODE}" "sleigh_BUILD_SLEIGHSPECS" OFF) if(sleigh_BUILD_EXAMPLE) - add_executable(sleigh_example - "${library_root}/sleighexample.cc" - ) - - target_compile_features(sleigh_example PRIVATE cxx_std_11) - sleigh_add_optional_defines(sleigh_example PRIVATE) - target_link_libraries(sleigh_example PRIVATE - sleigh::sla - sleigh::decomp - ) - - add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/specfiles/x86.sla" - COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/specfiles" - COMMAND "${CMAKE_COMMAND}" -E create_symlink - "${spec_files_root_dir}/x86/data/languages/x86.sla" - "${CMAKE_CURRENT_BINARY_DIR}/specfiles/x86.sla" - MAIN_DEPENDENCY "${spec_files_root_dir}/x86/data/languages/x86.sla" - ) - add_custom_target(sleigh_example_x86_symlink DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/specfiles/x86.sla") - - add_custom_target(sleigh_example_runner) - set(example_actions disassemble pcode emulate) - foreach(action ${example_actions}) - add_custom_target(sleigh_example_${action} - COMMAND sleigh_example ${action} - COMMENT "Running example ${action}" - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" - ) - add_dependencies(sleigh_example_${action} sleigh_example_x86_symlink) - add_dependencies(sleigh_example_runner sleigh_example_${action}) - endforeach() + add_subdirectory(example) endif() endif() diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt new file mode 100644 index 000000000..46358551c --- /dev/null +++ b/example/CMakeLists.txt @@ -0,0 +1,86 @@ +cmake_minimum_required(VERSION 3.18) + +include(../cmake/prelude.cmake) +include(../src/setup-ghidra-source.cmake) + +project(sleigh_example + VERSION "${ghidra_version}" + DESCRIPTION "Sleigh example" + HOMEPAGE_URL "https://github.com/lifting-bits/sleigh" + LANGUAGES CXX +) + +include(../cmake/project-is-top-level.cmake) + +if(PROJECT_IS_TOP_LEVEL) + find_package(sleigh) + if(sleigh_NOT_FOUND) + message(WARNING "Could not find sleigh, building from source") + endif() +endif() + +if(NOT TARGET sleigh::sla) + add_subdirectory(.. sleigh EXCLUDE_FROM_ALL) +endif() + +add_executable(sleigh_example + "${library_root}/sleighexample.cc" +) + +target_compile_features(sleigh_example PRIVATE cxx_std_11) +sleigh_add_optional_defines(sleigh_example PRIVATE) +target_link_libraries(sleigh_example PRIVATE + sleigh::sla +) + +# +# Compile our required sleigh spec file +# +# Get the native machine's sleigh compiler or use the one we're about to build +# if not cross compiling +if(CMAKE_CROSSCOMPILING) + find_program( + SLEIGH_EXECUTABLE sleigh + DOC "Path to host system sleigh compiler" + ) +else() + if(NOT TARGET sleigh::sleigh) + add_subdirectory(../tools/spec-compiler) + endif() + set( + SLEIGH_EXECUTABLE "$" + CACHE FILEPATH "Path to host system sleigh compiler" + ) +endif() + +if(NOT DEFINED sleigh_compile) + include(../cmake/modules/sleighCompile.cmake) +endif() + +# Compile the sla file +sleigh_compile( + TARGET sleigh_example_sleigh_spec_x86 + COMPILER "${SLEIGH_EXECUTABLE}" + SLASPEC "${ghidrasource_SOURCE_DIR}/Ghidra/Processors/x86/data/languages/x86.slaspec" + LOG_FILE "${CMAKE_CURRENT_BINARY_DIR}/specfiles/x86.sla.log" + OUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/specfiles/x86.sla" +) +set_property( + TARGET sleigh_example_sleigh_spec_x86 + PROPERTY EXCLUDE_FROM_ALL FALSE +) + +# +# Run the example +# +add_custom_target(sleigh_example_runner) +set(example_actions disassemble pcode emulate) +foreach(action ${example_actions}) + add_custom_target(sleigh_example_${action} + COMMAND sleigh_example ${action} + COMMENT "Running example ${action}" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" + ) + add_dependencies(sleigh_example_${action} sleigh_example_sleigh_spec_x86) + add_dependencies(sleigh_example_runner sleigh_example_${action}) +endforeach() From e2e482f024854b65b0b5e8aed69dc566eeced65f Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Mon, 1 Aug 2022 16:28:11 -0400 Subject: [PATCH 26/37] Refactor specfiles building into separate project/directory --- CMakeLists.txt | 115 +------------------- cmake/install-config.cmake.in | 6 +- cmake/install-rules.cmake | 25 +---- example/CMakeLists.txt | 2 +- sleighspecs/CMakeLists.txt | 185 +++++++++++++++++++++++++++++++++ sleighspecs/specfiles.cmake.in | 4 + 6 files changed, 195 insertions(+), 142 deletions(-) create mode 100644 sleighspecs/CMakeLists.txt create mode 100644 sleighspecs/specfiles.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index e7f26717d..01e852c27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -232,122 +232,9 @@ endif() # Spec files # if(sleigh_BUILD_SLEIGHSPECS) - -# This prefix should match the Ghidra repo to where the sla spec files are located -set(spec_files_dir_prefix "Ghidra/Processors") - -# This is where we will be copying the generated artifacts for each processor -set(spec_files_root_dir "${spec_files_build_dir}/${spec_files_dir_prefix}") -set(spec_files_build_log_dir "${CMAKE_CURRENT_BINARY_DIR}/spec_build_logs") - -add_custom_command( - OUTPUT "${spec_files_build_log_dir}" - COMMAND ${CMAKE_COMMAND} -E make_directory "${spec_files_build_log_dir}" -) - -# Get the native machine's sleigh compiler or use the one we're about to build -# if not cross compiling -if(CMAKE_CROSSCOMPILING) - find_program( - SLEIGH_EXECUTABLE sleigh - DOC "Path to host system sleigh compiler" - ) -else() - if(NOT TARGET sleigh::sleigh) - add_subdirectory(tools/spec-compiler) - endif() - set( - SLEIGH_EXECUTABLE "$" - CACHE FILEPATH "Path to host system sleigh compiler" - ) + add_subdirectory(sleighspecs) endif() -# Start processing all `.slaspec` files individually -set(spec_targets) -set(spec_files) -set(spec_dirs) -include(cmake/modules/sleighCompile.cmake) - -# Example: '/Ghidra/Processors/8051/data/languages/mx51.slaspec' -foreach(spec_file ${spec_file_list}) - # Get 'mx51' - get_filename_component(spec_name "${spec_file}" NAME_WLE) - - # Get '/Ghidra/Processors/8051/data/languages' - get_filename_component(spec_dir "${spec_file}" DIRECTORY) - - # Get '8051/data/languages' - file(RELATIVE_PATH spec_proc_dir - "${ghidrasource_SOURCE_DIR}/${spec_files_dir_prefix}" - "${spec_dir}" - ) - - # Add relative spec processor directory for later processing - list(APPEND spec_dirs ${spec_proc_dir}) - - # Get '8051' - get_filename_component(proc_name "${spec_proc_dir}" DIRECTORY) - get_filename_component(proc_name "${proc_name}" DIRECTORY) - - set(spec_build_log "${spec_files_build_log_dir}/${spec_name}_build.log") - - # Combine back again for the build directory output like - # '/Ghidra/Processors/8051/data/languages' - set(spec_out_dir "${spec_files_root_dir}/${spec_proc_dir}") - - # '/Ghidra/Processors/8051/data/languages/mx51.sla' - set(spec_out "${spec_out_dir}/${spec_name}.sla") - - string(REPLACE "." "_" spec_target_name ${spec_name}) - set(spec_target "sleigh_spec_${spec_target_name}") - - # Compile the sla file - sleigh_compile( - TARGET "${spec_target}" - COMPILER "${SLEIGH_EXECUTABLE}" - SLASPEC "${spec_file}" - LOG_FILE "${spec_build_log}" - OUT_FILE "${spec_out}" - ) - add_dependencies(${spec_target} sleigh_copy_${proc_name}_dir) - - list(APPEND spec_targets ${spec_target}) - list(APPEND spec_files ${spec_out}) -endforeach() - -# Copy and create specfile directories -list(REMOVE_DUPLICATES spec_dirs) - -foreach(spec_dir ${spec_dirs}) - set(spec_src_dir "${ghidrasource_SOURCE_DIR}/${spec_files_dir_prefix}/${spec_dir}") - set(spec_out_dir "${spec_files_root_dir}/${spec_dir}") - - # Get the processor directory name - get_filename_component(proc_name "${spec_dir}" DIRECTORY) - get_filename_component(proc_name "${proc_name}" DIRECTORY) - - # Copy all other files from the slaspec source directory: - # '/Ghidra/Processors/8051/data/languages' - # NOTE: This only copies the directory once, so you will need to remove the - # whole directory if you update any of the other files, like '*.cspec' or - # '*.ldef' files - # CMake only guarantees update monitoring for files listed explicitly - add_custom_command( - OUTPUT "${spec_out_dir}" - COMMAND ${CMAKE_COMMAND} -E copy_directory "${spec_src_dir}" "${spec_out_dir}" - ) - add_custom_target(sleigh_copy_${proc_name}_dir - DEPENDS "${spec_out_dir}" - ) -endforeach() - -# All of the sla spec targets are combined into this one -add_custom_target(sleigh_all_sla_specs ALL DEPENDS - ${spec_targets} -) - -endif() # sleigh_BUILD_SLEIGHSPECS - # # Included Example # diff --git a/cmake/install-config.cmake.in b/cmake/install-config.cmake.in index 0949d6b02..a480902eb 100644 --- a/cmake/install-config.cmake.in +++ b/cmake/install-config.cmake.in @@ -8,10 +8,8 @@ include("${CMAKE_CURRENT_LIST_DIR}/sleighTargets.cmake") -# Path relative-root to reach installed specfiles directory -if(EXISTS "@PACKAGE_sleigh_INSTALL_SPECDIR@") - set(sleigh_INSTALL_SPECDIR "@PACKAGE_sleigh_INSTALL_SPECDIR@") -endif() +# Populate CMake variable(s) related to specfiles +include("${CMAKE_CURRENT_LIST_DIR}/specfiles.cmake" OPTIONAL) # Extra version details. Either 'stable' or 'HEAD' set(sleigh_RELEASE_IS_HEAD "@sleigh_RELEASE_IS_HEAD@") diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake index a506d1147..5b4c9da77 100644 --- a/cmake/install-rules.cmake +++ b/cmake/install-rules.cmake @@ -48,26 +48,6 @@ install( COMPONENT sleigh_Development ) -# Specfiles installation setup -set(sleigh_INSTALL_DATADIR "${CMAKE_INSTALL_DATADIR}/sleigh" - CACHE PATH "sleigh data installation location relative to the install prefix" -) -mark_as_advanced(sleigh_INSTALL_DATADIR) - -set(sleigh_INSTALL_SPECDIR "${sleigh_INSTALL_DATADIR}/specfiles" - CACHE PATH "sleigh specfile root destination relative to the install prefix" -) -mark_as_advanced(sleigh_INSTALL_SPECDIR) - -if(sleigh_BUILD_SLEIGHSPECS) - # Install the compiled sla files found in 'Ghidra' top-level directory - install( - DIRECTORY "${spec_files_build_dir}/" - DESTINATION "${sleigh_INSTALL_SPECDIR}" - COMPONENT sleigh_Runtime - ) -endif() - include(CMakePackageConfigHelpers) write_basic_package_version_file( @@ -82,14 +62,13 @@ install( ) configure_package_config_file(cmake/install-config.cmake.in - ${PROJECT_BINARY_DIR}/install-config.cmake + "${PROJECT_BINARY_DIR}/install-config.cmake" INSTALL_DESTINATION "${sleigh_INSTALL_CMAKEDIR}" NO_CHECK_REQUIRED_COMPONENTS_MACRO - PATH_VARS sleigh_INSTALL_SPECDIR ) install( - FILES ${PROJECT_BINARY_DIR}/install-config.cmake + FILES "${PROJECT_BINARY_DIR}/install-config.cmake" RENAME sleighConfig.cmake DESTINATION "${sleigh_INSTALL_CMAKEDIR}" COMPONENT sleigh_Development diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 46358551c..44ad91ec2 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -14,7 +14,7 @@ include(../cmake/project-is-top-level.cmake) if(PROJECT_IS_TOP_LEVEL) find_package(sleigh) - if(sleigh_NOT_FOUND) + if(NOT sleigh_FOUND) message(WARNING "Could not find sleigh, building from source") endif() endif() diff --git a/sleighspecs/CMakeLists.txt b/sleighspecs/CMakeLists.txt new file mode 100644 index 000000000..d001abc52 --- /dev/null +++ b/sleighspecs/CMakeLists.txt @@ -0,0 +1,185 @@ +cmake_minimum_required(VERSION 3.18) + +include(../cmake/prelude.cmake) +include(../src/setup-ghidra-source.cmake) + +project(sleigh_specs + VERSION "${ghidra_version}" + DESCRIPTION "Sleigh specifications" + HOMEPAGE_URL "https://github.com/lifting-bits/sleigh" + LANGUAGES NONE +) + +include(../cmake/project-is-top-level.cmake) + +# This is the root directory where all individual processor spec file directories will be created. +if(NOT DEFINED spec_files_build_dir) + set(spec_files_build_dir "${CMAKE_CURRENT_BINARY_DIR}/specfiles") +endif() + +# This prefix should match the Ghidra repo to where the sla spec files are located +set(spec_files_dir_prefix "Ghidra/Processors") + +# This is where we will be copying the generated artifacts for each processor +set(spec_files_root_dir "${spec_files_build_dir}/${spec_files_dir_prefix}") +set(spec_files_build_log_dir "${CMAKE_CURRENT_BINARY_DIR}/spec_build_logs") + +add_custom_command( + OUTPUT "${spec_files_build_log_dir}" + COMMAND ${CMAKE_COMMAND} -E make_directory "${spec_files_build_log_dir}" +) + +# Get the native machine's sleigh compiler or use the one we're about to build +# if not cross compiling +if(CMAKE_CROSSCOMPILING) + find_program( + SLEIGH_EXECUTABLE sleigh + DOC "Path to host system sleigh compiler" + ) +else() + if(PROJECT_IS_TOP_LEVEL) + find_package(sleigh QUIET) + if(NOT sleigh_FOUND) + message(WARNING "Could not find sleigh, building from source") + endif() + endif() + + if(NOT TARGET sleigh::sleigh) + add_subdirectory(../tools/spec-compiler spec-compiler EXCLUDE_FROM_ALL) + endif() + + set( + SLEIGH_EXECUTABLE "$" + CACHE FILEPATH "Path to host system sleigh compiler" + ) +endif() + +# Start processing all `.slaspec` files individually +set(spec_targets) +set(spec_files) +set(spec_dirs) +include(../cmake/modules/sleighCompile.cmake) + +# Example: '/Ghidra/Processors/8051/data/languages/mx51.slaspec' +foreach(spec_file ${spec_file_list}) + # Get 'mx51' + get_filename_component(spec_name "${spec_file}" NAME_WLE) + + # Get '/Ghidra/Processors/8051/data/languages' + get_filename_component(spec_dir "${spec_file}" DIRECTORY) + + # Get '8051/data/languages' + file(RELATIVE_PATH spec_proc_dir + "${ghidrasource_SOURCE_DIR}/${spec_files_dir_prefix}" + "${spec_dir}" + ) + + # Add relative spec processor directory for later processing + list(APPEND spec_dirs ${spec_proc_dir}) + + # Get '8051' + get_filename_component(proc_name "${spec_proc_dir}" DIRECTORY) + get_filename_component(proc_name "${proc_name}" DIRECTORY) + + set(spec_build_log "${spec_files_build_log_dir}/${spec_name}_build.log") + + # Combine back again for the build directory output like + # '/Ghidra/Processors/8051/data/languages' + set(spec_out_dir "${spec_files_root_dir}/${spec_proc_dir}") + + # '/Ghidra/Processors/8051/data/languages/mx51.sla' + set(spec_out "${spec_out_dir}/${spec_name}.sla") + + string(REPLACE "." "_" spec_target_name ${spec_name}) + set(spec_target "sleigh_spec_${spec_target_name}") + + # Compile the sla file + sleigh_compile( + TARGET "${spec_target}" + COMPILER "${SLEIGH_EXECUTABLE}" + SLASPEC "${spec_file}" + LOG_FILE "${spec_build_log}" + OUT_FILE "${spec_out}" + ) + add_dependencies(${spec_target} sleigh_copy_${proc_name}_dir) + + list(APPEND spec_targets ${spec_target}) + list(APPEND spec_files ${spec_out}) +endforeach() + +# Copy and create specfile directories +list(REMOVE_DUPLICATES spec_dirs) + +foreach(spec_dir ${spec_dirs}) + set(spec_src_dir "${ghidrasource_SOURCE_DIR}/${spec_files_dir_prefix}/${spec_dir}") + set(spec_out_dir "${spec_files_root_dir}/${spec_dir}") + + # Get the processor directory name + get_filename_component(proc_name "${spec_dir}" DIRECTORY) + get_filename_component(proc_name "${proc_name}" DIRECTORY) + + # Copy all other files from the slaspec source directory: + # '/Ghidra/Processors/8051/data/languages' + # NOTE: This only copies the directory once, so you will need to remove the + # whole directory if you update any of the other files, like '*.cspec' or + # '*.ldef' files + # CMake only guarantees update monitoring for files listed explicitly + add_custom_command( + OUTPUT "${spec_out_dir}" + COMMAND ${CMAKE_COMMAND} -E copy_directory "${spec_src_dir}" "${spec_out_dir}" + ) + add_custom_target(sleigh_copy_${proc_name}_dir + DEPENDS "${spec_out_dir}" + ) +endforeach() + +# All of the sla spec targets are combined into this one +add_custom_target(sleigh_all_sla_specs ALL DEPENDS + ${spec_targets} +) + +if(NOT CMAKE_SKIP_INSTALL_RULES) + include("GNUInstallDirs") + + # Specfiles installation setup + set(sleigh_INSTALL_DATADIR "${CMAKE_INSTALL_DATADIR}/sleigh" + CACHE PATH "sleigh data installation location relative to the install prefix" + ) + mark_as_advanced(sleigh_INSTALL_DATADIR) + + set(sleigh_INSTALL_SPECDIR "${sleigh_INSTALL_DATADIR}/specfiles" + CACHE PATH "sleigh specfile root destination relative to the install prefix" + ) + mark_as_advanced(sleigh_INSTALL_SPECDIR) + + # Install the compiled sla files found in 'Ghidra' top-level directory + install( + DIRECTORY "${spec_files_build_dir}/" + DESTINATION "${sleigh_INSTALL_SPECDIR}" + COMPONENT sleigh_Runtime + ) + + set( + sleigh_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/sleigh" + CACHE PATH "CMake package config location relative to the install prefix" + ) + mark_as_advanced(sleigh_INSTALL_CMAKEDIR) + + include(CMakePackageConfigHelpers) + configure_package_config_file(specfiles.cmake.in + "${PROJECT_BINARY_DIR}/specfiles.cmake" + INSTALL_DESTINATION "${sleigh_INSTALL_CMAKEDIR}" + NO_CHECK_REQUIRED_COMPONENTS_MACRO + PATH_VARS sleigh_INSTALL_SPECDIR + ) + + install( + FILES "${PROJECT_BINARY_DIR}/specfiles.cmake" + DESTINATION "${sleigh_INSTALL_CMAKEDIR}" + COMPONENT sleigh_Development + ) + + if(PROJECT_IS_TOP_LEVEL) + include(CPack) + endif() +endif() diff --git a/sleighspecs/specfiles.cmake.in b/sleighspecs/specfiles.cmake.in new file mode 100644 index 000000000..9af546a0b --- /dev/null +++ b/sleighspecs/specfiles.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +# Path relative-root to reach installed specfiles directory +set_and_check(sleigh_INSTALL_SPECDIR "@PACKAGE_sleigh_INSTALL_SPECDIR@") From 1a865c2ac2e0d23173babe9a7de5d1ff678b2e6f Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Mon, 1 Aug 2022 17:03:50 -0400 Subject: [PATCH 27/37] Check for termios.h header and set define if found --- tests/CMakeLists.txt | 4 +++- tools/decompiler/CMakeLists.txt | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5e3eb3f4d..675f24a34 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,7 +17,9 @@ add_executable(sleigh_ghidra_test target_compile_features(sleigh_ghidra_test PRIVATE cxx_std_11) target_include_directories(sleigh_ghidra_test PRIVATE "${library_root}") -if(WIN32) +include(CheckIncludeFileCXX) +check_include_file_cxx(termios.h HAVE_TERMIOS_H) +if(HAVE_TERMIOS_H) target_compile_definitions(sleigh_ghidra_test PRIVATE __TERMINAL__ ) diff --git a/tools/decompiler/CMakeLists.txt b/tools/decompiler/CMakeLists.txt index 405ffca2b..886d27f95 100644 --- a/tools/decompiler/CMakeLists.txt +++ b/tools/decompiler/CMakeLists.txt @@ -24,7 +24,9 @@ add_executable(sleigh::decompiler ALIAS sleigh_decompiler) target_compile_features(sleigh_decompiler PUBLIC cxx_std_11) target_include_directories(sleigh_decompiler PRIVATE "$") -if(WIN32) +include(CheckIncludeFileCXX) +check_include_file_cxx(termios.h HAVE_TERMIOS_H) +if(HAVE_TERMIOS_H) target_compile_definitions(sleigh_decompiler PRIVATE __TERMINAL__ ) From 98c439d1591087998414ea130513620e48021d69 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Mon, 1 Aug 2022 18:07:41 -0400 Subject: [PATCH 28/37] Update READMEs --- README.md | 42 ++++++++++++++++++++++-------------------- src/README.md | 34 +++++++++++++++++----------------- 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 5885df3aa..87dfa560e 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# SLEIGH Library +# Sleigh Library -[SLEIGH](https://ghidra.re/courses/languages/html/sleigh.html) is a language used to describe the semantics of instruction sets of general-purpose microprocessors, with enough detail to facilitate the reverse engineering of software compiled for these architectures. It is part of the [GHIDRA reverse engineering platform](https://github.com/NationalSecurityAgency/ghidra), and underpins two of its major components: its disassembly and decompilation engines. +[Sleigh](https://ghidra.re/courses/languages/html/sleigh.html) is a language used to describe the semantics of instruction sets of general-purpose microprocessors, with enough detail to facilitate the reverse engineering of software compiled for these architectures. It is part of the [Ghidra reverse engineering platform](https://github.com/NationalSecurityAgency/ghidra) and underpins two of its major components: its disassembly and decompilation engines. -This repository provides a CMake-based build project for SLEIGH so that it can be built and packaged as a standalone library, and be reused in projects other than GHIDRA. +This repository provides a CMake-based build project for Sleigh so that it can be built and packaged as a standalone library and be reused in projects other than Ghidra. ## Supported Platforms @@ -12,7 +12,7 @@ This repository provides a CMake-based build project for SLEIGH so that it can b | macOS | Yes | | Windows | *Yes | -\* Tests do not all work on Windows. See issue [#92](https://github.com/lifting-bits/sleigh/issues/92). +\* Not all tests work on Windows. See issue [#92](https://github.com/lifting-bits/sleigh/issues/92). ## Dependencies and Prerequisites @@ -20,7 +20,7 @@ This repository provides a CMake-based build project for SLEIGH so that it can b | Name | Version | Linux Package to Install | macOS Homebrew Package to Install | | ---- | ------- | ------------------------ | --------------------------------- | -| [Git](https://git-scm.com/) | Latest | git | N/A | +| [Git](https://git-scm.com/) | Latest | git | git | | [CMake](https://cmake.org/) | 3.18+ | cmake | cmake | **NOTE**: This CMake project pulls the Ghidra source code from the internet during configuration. See the [note on Ghidra source code section](#note-on-ghidra-source-code) for more details. @@ -37,7 +37,7 @@ For building documentation: ## Build and Install the SLEIGH Library ```sh -# Clone this repository (CMake project for SLEIGH) +# Clone this repository (CMake project for sleigh) git clone https://github.com/lifting-bits/sleigh.git cd sleigh @@ -45,17 +45,17 @@ cd sleigh cmake -B build -S . # Build SLEIGH -cmake --build build -j +cmake --build build --parallel 8 # Install SLEIGH -cmake --install build --prefix +cmake --install build --prefix ./install ``` ### Note on Ghidra source code The Ghidra source code is not actually included in this git repo, and by default, CMake will automatically pull a stable version from the internet for you. -Please see [`src/README.md`](./src/README.md) for more information on how to customize which Ghidra source code commit will be used/compiled, including specifying your own local copy of the Ghidra source. +Please see [`src/README.md`](src/README.md) for more information on how to customize which Ghidra source code commit will be used/compiled, including specifying your own local copy of the Ghidra source. ## Packaging @@ -70,7 +70,7 @@ cmake --build build --target package ## API Usage -An example program called `sleighLift` has been included to demonstrate how to use the SLEIGH API. It takes a hexadecimal string of bytes and either disassembles it or lifts it to p-code. The program can be invoked like so, where the `action` argument must be either `disassemble` or `pcode`: +An example program called `sleighLift` has been included to demonstrate how to use the Sleigh API. It takes a hexadecimal string of bytes and can disassemble it or lift it to p-code. The program can be invoked as follows, where the `action` argument must be either `disassemble` or `pcode`: ```sh sleighLift [action] [sla_file] [bytes] [-a address] [-p root_sla_dir] [-s pspec_file] @@ -98,11 +98,11 @@ $ sleighLift pcode x86-64.sla 4881ecc00f0000 (register,0x202,1) = INT_EQUAL (unique,0x12d00,1) (const,0x0,1) ``` -The `sleigh_BUILD_EXTRATOOLS` option must be set to `ON` during the configuration step in order to build `sleighLift`. +If you do not want to build `sleighLift`, you must set the CMake variable `sleigh_BUILD_EXTRATOOLS` option to `OFF` during CMake configuration. ## Helpers -This repository contains a helper that is not part of SLEIGH/GHIDRA, which can be found under `support/`. It has the following signature and can help the user find the location of a given spec file on the system: +This repository contains a helper not part of Sleigh/Ghidra, which you can find in the `support` directory. It has the following signature and can help the user find the location of a given spec file on the system: ```c++ std::optional @@ -111,22 +111,24 @@ FindSpecFile(std::string_view file_name, gDefaultSearchPaths); ``` -The `sleigh::FindSpecFile` function will search the the paths provided by the user via the `search_paths` argument for a spec file with the name `file_name`. The default argument for `search_paths` is `sleigh::gDefaultSearchPaths` which contains the install/build directories that the CMake project was configured with as well as a set of common installation locations. +The `sleigh::FindSpecFile` function will search the paths provided by the user via the `search_paths` argument for a spec file with the name `file_name`. The default argument for `search_paths` is `sleigh::gDefaultSearchPaths` which contains the install/build directories generated during CMake configuration and a set of common installation locations. -The `sleigh_BUILD_SUPPORT` option must be set to `ON` during the configuration step in order to build the support library. +If you do not want to build the helpers, you must set the CMake variable `sleigh_BUILD_SUPPORT` option to `OFF` during CMake configuration. ## Integration as a Dependency -An installation of sleigh provides a CMake interface that can be used to assist in building your project. +An installation of Sleigh provides a CMake interface that you can use when building your project. -An example of how to use the CMake package config file can be found in the [find_package](tests/find_package/CMakeLists.txt) example. +You can find an example of how to use the CMake package config file in the [find_package](tests/find_package/CMakeLists.txt) example. -We also provide a CMake helper function [`sleigh_compile`](cmake/modules/sleighCompile.cmake) to compile your own `.slaspec` files using a sleigh compiler. +We also provide a CMake helper function [`sleigh_compile`](cmake/modules/sleighCompile.cmake) to compile your `.slaspec` files using a sleigh compiler. -Lastly, the installed compiled sleigh files can be located through the CMake variable `sleigh_INSTALL_SPECDIR`, which is an absolute path to the root directory for where the compiled sleigh files are located---you should manually inspect this to know what to expect. +You can find a more complex CMake example with compiling Sleigh specifications in the [`example`](example/CMakeLists.txt) directory, which uses the upstream-provided sleigh example source code. -Referencing the [CMake config file](cmake/install-config.cmake.in) is also suggested for learning more about the exposed CMake variables and modules. +Lastly, you can locate the installed compiled sleigh files through the CMake variable `sleigh_INSTALL_SPECDIR`, which is an absolute path to the root directory for the compiled sleigh files---you should manually inspect this to know what to expect. + +Referencing the [CMake config file](cmake/install-config.cmake.in) and [`specfiles` CMake file](sleighspecs/specfiles.cmake.in) is also suggested for learning more about the exposed CMake variables and modules. ## License -See the LICENSE file in the top directory of this repo. +See the [LICENSE file](LICENSE). diff --git a/src/README.md b/src/README.md index 88512bc85..a43908b1a 100644 --- a/src/README.md +++ b/src/README.md @@ -1,45 +1,45 @@ # Ghidra Source code -This project uses CMake's [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) module to set up the Ghidra source tree. This means we can apply [patches](../patches) that live only in this repo for small changes to features like packaging or running tests. +This project uses CMake's [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) module to set up the Ghidra source tree. Using `FetchContent` means we can apply [patches](patches) that live only in this repo for minor changes that affect usage, packaging, or running tests. -By default, CMake pulls a stable version of Ghidra. You may use a more recent commit by specifying `-Dsleigh_RELEASE_TYPE=HEAD` during CMake configuration. - -See the `sleigh_GHIDRA_*` CMake cache variable comments for more details on how to customize your Ghidra source checkout. +By default, CMake pulls a stable version of Ghidra. During CMake configuration, you may use a more recent commit by specifying `-Dsleigh_RELEASE_TYPE=HEAD`. ## Advanced Usage Notes -Always reference the [CMake Documentation](https://cmake.org/cmake/help/latest/) for explanation of features and cache variable usages/effects. +Always reference the [CMake Documentation](https://cmake.org/cmake/help/latest/) and check CMake cache variables with `ccmake build` to discover all available options. ### Using your own Ghidra checkout -This method is useful for developing new features on top of the latest commits in Ghidra's default branch. If the commit(s) at the tip of Ghidra's default branch are not supported by this repo, we welcome pull requests to update support and pin that commit. +This method helps develop new features on top of the latest commits in Ghidra's default branch. Please open an issue or pull request if the commit at the tip of Ghidra's default branch does not build. -**Arbitrary Ghidra checkouts are not officially supported.** +**Arbitrary Ghidra checkouts/commits are not officially supported.** -If you want to use your own Ghidra source checkout, then set the following during CMake configuration: +Set the following during CMake configuration if you want to use your own Ghidra source checkout: * `-Dsleigh_RELEASE_TYPE=HEAD` if using commits on Ghidra's default branch (`master`) or any branch that may be incompatible with the current stable version. -* `-DFETCHCONTENT_SOURCE_DIR_GHIDRASOURCE=`. Remember, no existing [patches](../patches/HEAD) will be applied to your own source directory. +* `-DFETCHCONTENT_SOURCE_DIR_GHIDRASOURCE=`. Remember, CMake will not apply any [patches](patches/HEAD) to the specified source directory. ```bash git clone https://github.com/NationalSecurityAgency/ghidra src/ghidra cmake -B build-dev-head -S . \ -Dsleigh_RELEASE_TYPE=HEAD \ - -DFETCHCONTENT_SOURCE_DIR_GHIDRASOURCE="$(pwd)/src/ghidra" + "-DFETCHCONTENT_SOURCE_DIR_GHIDRASOURCE=$PWD/src/ghidra" ``` ### Reusing Downloaded Ghidra Source -If you want to share a single Ghidra source checkout/clone for multiple build directories, the [_FetchContent Base Directory_](https://cmake.org/cmake/help/latest/module/FetchContent.html#variable:FETCHCONTENT_BASE_DIR) (`FETCHCONTENT_BASE_DIR`) should encode the build generator name and be located outside of the build directory (the name would look something like `cmake_fc_ghidra_${sleigh_RELEASE_TYPE}_${CMAKE_GENERATOR}`). +The following scenario is discouraged. It can be brittle if everything does not match up. It is only helpful if you do not want to apply Ghidra source patches yourself. + +Suppose you want to share a single Ghidra source checkout/clone for multiple build directories. In that case, the _FetchContent Base Directory_ (`FETCHCONTENT_BASE_DIR`) should encode the build generator name and be located outside of the build directory (the name would look something like `cmake_fc_ghidra_${sleigh_RELEASE_TYPE}_${CMAKE_GENERATOR}`). -Initially, this means that every new build generator used for building the project will have to re-download the ghidra source tree, but any subsequent run with an already-initialize generator should be faster and skip the download. +Initially, this means that every new build generator used for building the project will have to re-download the Ghidra source tree. Still, any subsequent run with an already-initialize generator should be faster and skip the download. ```bash $ cmake -B build-release -S . -G Ninja \ -DCMAKE_BUILD_TYPE=Release \ - -DFETCHCONTENT_BASE_DIR=./src/cmake_fc_ghidra_stable_Ninja + "-DFETCHCONTENT_BASE_DIR=$PWD/src/cmake_fc_ghidra_stable_Ninja" -- Using Ghidra version 10.0.4 at commit 5b07797 -- Populating ghidrasource -- Configuring done @@ -69,7 +69,7 @@ HEAD is now at 5b07797cb Updated 10.0.4 Change History $ cmake -B build-debug -S . -G Ninja \ -DCMAKE_BUILD_TYPE=Debug \ - -DFETCHCONTENT_BASE_DIR=./src/cmake_fc_ghidra_stable_Ninja + "-DFETCHCONTENT_BASE_DIR=$PWD/src/cmake_fc_ghidra_stable_Ninja" -- Using Ghidra version 10.0.4 at commit 5b07797 -- Populating ghidrasource -- Configuring done @@ -88,19 +88,19 @@ $ cmake -B build-debug -S . -G Ninja \ ... ``` -The above also works when using `HEAD` commit of Ghidra. +The above also works when using the `HEAD` commit of Ghidra. ```bash $ cmake -B build-head-release -S . -G Ninja \ -DCMAKE_BUILD_TYPE=Release \ -Dsleigh_RELEASE_TYPE=HEAD \ - -DFETCHCONTENT_BASE_DIR=./src/cmake_fc_ghidra_HEAD_Ninja + "-DFETCHCONTENT_BASE_DIR=$PWD/src/cmake_fc_ghidra_HEAD_Ninja" ... $ cmake -B build-head-debug -S . -G Ninja \ -DCMAKE_BUILD_TYPE=Debug \ -Dsleigh_RELEASE_TYPE=HEAD \ - -DFETCHCONTENT_BASE_DIR=./src/cmake_fc_ghidra_HEAD_Ninja + "-DFETCHCONTENT_BASE_DIR=$PWD/src/cmake_fc_ghidra_HEAD_Ninja" ... ``` From efbf47a901ff6ba45c991aac08d1da8d383fc292 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Tue, 2 Aug 2022 09:50:15 -0400 Subject: [PATCH 29/37] Better consistency with install rules --- cmake/install-rules.cmake | 2 +- extra-tools/sleigh-lift/CMakeLists.txt | 14 +++++++------- support/CMakeLists.txt | 4 ++++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake index 5b4c9da77..3aecbefb5 100644 --- a/cmake/install-rules.cmake +++ b/cmake/install-rules.cmake @@ -2,7 +2,7 @@ if(PROJECT_IS_TOP_LEVEL) set(CMAKE_INSTALL_INCLUDEDIR include/sleigh CACHE PATH "") endif() -include("GNUInstallDirs") +include(GNUInstallDirs) install( TARGETS diff --git a/extra-tools/sleigh-lift/CMakeLists.txt b/extra-tools/sleigh-lift/CMakeLists.txt index 0b52c5bf4..e00318281 100644 --- a/extra-tools/sleigh-lift/CMakeLists.txt +++ b/extra-tools/sleigh-lift/CMakeLists.txt @@ -34,13 +34,13 @@ set_target_properties(sleigh_lift PROPERTIES if(NOT CMAKE_SKIP_INSTALL_RULES) include(GNUInstallDirs) - if(PROJECT_IS_TOP_LEVEL) - set( - sleigh_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/sleigh" - CACHE PATH "CMake package config location relative to the install prefix" - ) - mark_as_advanced(sleigh_INSTALL_CMAKEDIR) - endif() + + set( + sleigh_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/sleigh" + CACHE PATH "CMake package config location relative to the install prefix" + ) + mark_as_advanced(sleigh_INSTALL_CMAKEDIR) + install( TARGETS sleigh_lift EXPORT sleighExtraToolsTargets diff --git a/support/CMakeLists.txt b/support/CMakeLists.txt index 26ee8a565..1043af353 100644 --- a/support/CMakeLists.txt +++ b/support/CMakeLists.txt @@ -62,6 +62,10 @@ target_include_directories(sleigh_support ) if(NOT CMAKE_SKIP_INSTALL_RULES) + if(PROJECT_IS_TOP_LEVEL) + set(CMAKE_INSTALL_INCLUDEDIR include/sleigh CACHE PATH "") + endif() + include(GNUInstallDirs) install( From 8eb2b68536079711c9fc5be6defa9dad65afadd3 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Wed, 3 Aug 2022 15:19:15 -0400 Subject: [PATCH 30/37] Build sleighLift as a standalone project with added source --- CMakeLists.txt | 10 +++++----- example/CMakeLists.txt | 1 + extra-tools/sleigh-lift/CMakeLists.txt | 15 ++++++++++++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 01e852c27..4e5d292ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -246,6 +246,11 @@ if(PROJECT_IS_TOP_LEVEL) endif() endif() +if(sleigh_BUILD_SUPPORT) + # Add support library before configuring install targets + add_subdirectory(support) +endif() + # # Extras provided by Trail of Bits # @@ -253,11 +258,6 @@ if(sleigh_BUILD_EXTRATOOLS) add_subdirectory(extra-tools) endif() -if(sleigh_BUILD_SUPPORT) - # Add support library before configuring install targets - add_subdirectory(support) -endif() - # # Developer mode # diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 44ad91ec2..272fc2f84 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -19,6 +19,7 @@ if(PROJECT_IS_TOP_LEVEL) endif() endif() +# Build from source if we don't have targets if(NOT TARGET sleigh::sla) add_subdirectory(.. sleigh EXCLUDE_FROM_ALL) endif() diff --git a/extra-tools/sleigh-lift/CMakeLists.txt b/extra-tools/sleigh-lift/CMakeLists.txt index e00318281..3d8980b51 100644 --- a/extra-tools/sleigh-lift/CMakeLists.txt +++ b/extra-tools/sleigh-lift/CMakeLists.txt @@ -13,7 +13,20 @@ project(sleighLift CXX) include(../../cmake/project-is-top-level.cmake) if(PROJECT_IS_TOP_LEVEL) - find_package(sleigh REQUIRED COMPONENTS Support) + find_package(sleigh) + if(NOT sleigh_FOUND) + message(WARNING "Could not find sleigh, building from source") + else() + find_package(sleigh REQUIRED COMPONENTS Support) + endif() +endif() + +# Build from source if we don't have targets +if(NOT TARGET sleigh::sla OR + NOT TARGET sleigh::decomp OR + NOT TARGET sleigh::support) + set(sleigh_BUILD_EXTRATOOLS OFF CACHE BOOL "" FORCE) + add_subdirectory(../.. sleigh EXCLUDE_FROM_ALL) endif() add_executable(sleigh_lift From 04db45f0b73372aa038e79b7e3fc44c3eb14732b Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Thu, 4 Aug 2022 16:15:12 -0400 Subject: [PATCH 31/37] More changes to CMake subprojects * Also add "Specs" component to sleigh installation config * Try to be better at bootstrapping subprojects (hopefully this doesn't bite us, but if it does, I'm happy to remove it and say "not supported") --- CMakeLists.txt | 3 ++ cmake/install-config.cmake.in | 8 ++-- cmake/options.cmake | 8 ++-- example/CMakeLists.txt | 52 ++++++++++++++++++-------- extra-tools/sleigh-lift/CMakeLists.txt | 18 +++------ sleighspecs/CMakeLists.txt | 40 ++++++++++++-------- 6 files changed, 78 insertions(+), 51 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e5d292ed..7bacf9a34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -246,6 +246,9 @@ if(PROJECT_IS_TOP_LEVEL) endif() endif() +# +# Support library provided by Trail of Bits +# if(sleigh_BUILD_SUPPORT) # Add support library before configuring install targets add_subdirectory(support) diff --git a/cmake/install-config.cmake.in b/cmake/install-config.cmake.in index a480902eb..ca14a3a26 100644 --- a/cmake/install-config.cmake.in +++ b/cmake/install-config.cmake.in @@ -1,6 +1,7 @@ # This file provides access to the installed sleigh targets. # # There are optional components that could also be installed: +# * Specs - Compiled sleigh specification files # * Support - Support library for easier use of sleigh # * ExtraTools - Extra tools created by Trail of Bits @@ -8,9 +9,6 @@ include("${CMAKE_CURRENT_LIST_DIR}/sleighTargets.cmake") -# Populate CMake variable(s) related to specfiles -include("${CMAKE_CURRENT_LIST_DIR}/specfiles.cmake" OPTIONAL) - # Extra version details. Either 'stable' or 'HEAD' set(sleigh_RELEASE_IS_HEAD "@sleigh_RELEASE_IS_HEAD@") @@ -18,8 +16,10 @@ set(sleigh_RELEASE_IS_HEAD "@sleigh_RELEASE_IS_HEAD@") include("${CMAKE_CURRENT_LIST_DIR}/modules/sleighCompile.cmake") # Find-package component handling for Support library and ExtraTools -set(_sleigh_supported_components Support ExtraTools) +set(_sleigh_supported_components Specs Support ExtraTools) +# Specs just sets a variable to the directory of installation +set(_sleigh_Specs_targets "${CMAKE_CURRENT_LIST_DIR}/specfiles.cmake") set(_sleigh_Support_targets "${CMAKE_CURRENT_LIST_DIR}/sleighSupportTargets.cmake") set(_sleigh_ExtraTools_targets "${CMAKE_CURRENT_LIST_DIR}/sleighExtraToolsTargets.cmake") diff --git a/cmake/options.cmake b/cmake/options.cmake index d42b56758..5dfc4e156 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -28,12 +28,12 @@ endif() include(CMakeDependentOption) # Optional project target building -option(sleigh_BUILD_TOOLS "Build and install executable tools" ON) -option(sleigh_BUILD_SLEIGHSPECS "Build and install sleigh spec files" ON) +option(sleigh_BUILD_TOOLS "Build and install executable tools" "${PROJECT_IS_TOP_LEVEL}") +option(sleigh_BUILD_SLEIGHSPECS "Build and install sleigh spec files" "${PROJECT_IS_TOP_LEVEL}") # Add-ons by ToB -option(sleigh_BUILD_SUPPORT "Build ToB support libraries" ON) -cmake_dependent_option(sleigh_BUILD_EXTRATOOLS "Build extra ToB sleigh tools" ON "sleigh_BUILD_SUPPORT" OFF) +option(sleigh_BUILD_SUPPORT "Build ToB support libraries" "${PROJECT_IS_TOP_LEVEL}") +cmake_dependent_option(sleigh_BUILD_EXTRATOOLS "Build extra ToB sleigh tools" "${PROJECT_IS_TOP_LEVEL}" "sleigh_BUILD_SUPPORT" OFF) # ---- Warning guard ---- diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 272fc2f84..500e6fdc2 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.18) include(../cmake/prelude.cmake) + +# We include this because the source code for this example is in upstream include(../src/setup-ghidra-source.cmake) project(sleigh_example @@ -12,18 +14,16 @@ project(sleigh_example include(../cmake/project-is-top-level.cmake) -if(PROJECT_IS_TOP_LEVEL) +if(NOT TARGET sleigh::sla) find_package(sleigh) if(NOT sleigh_FOUND) - message(WARNING "Could not find sleigh, building from source") + message(WARNING "Could not find sleigh library, building from source") + # Exclude from all because there are no install rules for the example + # See sleighLift for example with install rules + add_subdirectory(.. sleigh EXCLUDE_FROM_ALL) endif() endif() -# Build from source if we don't have targets -if(NOT TARGET sleigh::sla) - add_subdirectory(.. sleigh EXCLUDE_FROM_ALL) -endif() - add_executable(sleigh_example "${library_root}/sleighexample.cc" ) @@ -34,6 +34,10 @@ target_link_libraries(sleigh_example PRIVATE sleigh::sla ) +set_target_properties(sleigh_example PROPERTIES + OUTPUT_NAME sleighexample +) + # # Compile our required sleigh spec file # @@ -43,25 +47,41 @@ if(CMAKE_CROSSCOMPILING) find_program( SLEIGH_EXECUTABLE sleigh DOC "Path to host system sleigh compiler" + REQUIRED ) + set(sleigh_compiler "${SLEIGH_EXECUTABLE}") else() + # Try to find/acquire or bootstrap the sleigh spec compiler + # Logic is repeated in sleighspecs/CMakeLists.txt if(NOT TARGET sleigh::sleigh) - add_subdirectory(../tools/spec-compiler) + find_package(sleigh QUIET) + if(NOT sleigh_FOUND OR NOT TARGET sleigh::sleigh) + find_program( + SLEIGH_EXECUTABLE sleigh + DOC "Path to host system sleigh compiler" + ) + if(NOT SLEIGH_EXECUTABLE) + message(WARNING "Could not find sleigh compiler, building from source") + set(saved_skip_install_rules "${CMAKE_SKIP_INSTALL_RULES}") + set(CMAKE_SKIP_INSTALL_RULES TRUE) + add_subdirectory(../tools/spec-compiler spec-compiler EXCLUDE_FROM_ALL) + set(CMAKE_SKIP_INSTALL_RULES "${saved_skip_install_rules}") + endif() + endif() endif() - set( - SLEIGH_EXECUTABLE "$" - CACHE FILEPATH "Path to host system sleigh compiler" - ) endif() - -if(NOT DEFINED sleigh_compile) - include(../cmake/modules/sleighCompile.cmake) +if(SLEIGH_EXECUTABLE) + set(sleigh_compiler "${SLEIGH_EXECUTABLE}") +else() + set(sleigh_compiler "$") endif() # Compile the sla file +include(../cmake/modules/sleighCompile.cmake) + sleigh_compile( TARGET sleigh_example_sleigh_spec_x86 - COMPILER "${SLEIGH_EXECUTABLE}" + COMPILER "${sleigh_compiler}" SLASPEC "${ghidrasource_SOURCE_DIR}/Ghidra/Processors/x86/data/languages/x86.slaspec" LOG_FILE "${CMAKE_CURRENT_BINARY_DIR}/specfiles/x86.sla.log" OUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/specfiles/x86.sla" diff --git a/extra-tools/sleigh-lift/CMakeLists.txt b/extra-tools/sleigh-lift/CMakeLists.txt index 3d8980b51..5a8792eb8 100644 --- a/extra-tools/sleigh-lift/CMakeLists.txt +++ b/extra-tools/sleigh-lift/CMakeLists.txt @@ -10,25 +10,19 @@ cmake_minimum_required(VERSION 3.18) project(sleighLift CXX) -include(../../cmake/project-is-top-level.cmake) - -if(PROJECT_IS_TOP_LEVEL) +set(build_from_source FALSE) +if(NOT TARGET sleigh::support) find_package(sleigh) if(NOT sleigh_FOUND) message(WARNING "Could not find sleigh, building from source") + set(sleigh_BUILD_SUPPORT ON CACHE BOOL "" FORCE) + set(sleigh_BUILD_SLEIGHSPECS ON CACHE BOOL "" FORCE) + add_subdirectory(../.. sleigh) else() - find_package(sleigh REQUIRED COMPONENTS Support) + find_package(sleigh REQUIRED COMPONENTS Support Specs) endif() endif() -# Build from source if we don't have targets -if(NOT TARGET sleigh::sla OR - NOT TARGET sleigh::decomp OR - NOT TARGET sleigh::support) - set(sleigh_BUILD_EXTRATOOLS OFF CACHE BOOL "" FORCE) - add_subdirectory(../.. sleigh EXCLUDE_FROM_ALL) -endif() - add_executable(sleigh_lift src/main.cpp ) diff --git a/sleighspecs/CMakeLists.txt b/sleighspecs/CMakeLists.txt index d001abc52..bbb5136ca 100644 --- a/sleighspecs/CMakeLists.txt +++ b/sleighspecs/CMakeLists.txt @@ -7,7 +7,8 @@ project(sleigh_specs VERSION "${ghidra_version}" DESCRIPTION "Sleigh specifications" HOMEPAGE_URL "https://github.com/lifting-bits/sleigh" - LANGUAGES NONE + # Language is for installing the helper CMake file + LANGUAGES CXX ) include(../cmake/project-is-top-level.cmake) @@ -35,23 +36,32 @@ if(CMAKE_CROSSCOMPILING) find_program( SLEIGH_EXECUTABLE sleigh DOC "Path to host system sleigh compiler" + REQUIRED ) else() - if(PROJECT_IS_TOP_LEVEL) + # Try to find/acquire or bootstrap the sleigh spec compiler + # Logic is repeated in example/CMakeLists.txt + if(NOT TARGET sleigh::sleigh) find_package(sleigh QUIET) - if(NOT sleigh_FOUND) - message(WARNING "Could not find sleigh, building from source") + if(NOT sleigh_FOUND OR NOT TARGET sleigh::sleigh) + find_program( + SLEIGH_EXECUTABLE sleigh + DOC "Path to host system sleigh compiler" + ) + if(NOT SLEIGH_EXECUTABLE) + message(WARNING "Could not find sleigh compiler, building from source") + set(saved_skip_install_rules "${CMAKE_SKIP_INSTALL_RULES}") + set(CMAKE_SKIP_INSTALL_RULES TRUE) + add_subdirectory(../tools/spec-compiler spec-compiler EXCLUDE_FROM_ALL) + set(CMAKE_SKIP_INSTALL_RULES "${saved_skip_install_rules}") + endif() endif() endif() - - if(NOT TARGET sleigh::sleigh) - add_subdirectory(../tools/spec-compiler spec-compiler EXCLUDE_FROM_ALL) - endif() - - set( - SLEIGH_EXECUTABLE "$" - CACHE FILEPATH "Path to host system sleigh compiler" - ) +endif() +if(SLEIGH_EXECUTABLE) + set(sleigh_compiler "${SLEIGH_EXECUTABLE}") +else() + set(sleigh_compiler "$") endif() # Start processing all `.slaspec` files individually @@ -96,7 +106,7 @@ foreach(spec_file ${spec_file_list}) # Compile the sla file sleigh_compile( TARGET "${spec_target}" - COMPILER "${SLEIGH_EXECUTABLE}" + COMPILER "${sleigh_compiler}" SLASPEC "${spec_file}" LOG_FILE "${spec_build_log}" OUT_FILE "${spec_out}" @@ -139,7 +149,7 @@ add_custom_target(sleigh_all_sla_specs ALL DEPENDS ) if(NOT CMAKE_SKIP_INSTALL_RULES) - include("GNUInstallDirs") + include(GNUInstallDirs) # Specfiles installation setup set(sleigh_INSTALL_DATADIR "${CMAKE_INSTALL_DATADIR}/sleigh" From 5b51d7532729d5d8c911faf83019bdaebe3b87dc Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Wed, 17 Aug 2022 09:43:28 -0700 Subject: [PATCH 32/37] Address some code review --- .github/workflows/main.yml | 6 +++--- README.md | 12 ++++++------ example/CMakeLists.txt | 2 +- extra-tools/sleigh-lift/CMakeLists.txt | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 69aaff722..858c1f011 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -132,7 +132,7 @@ jobs: --prefix install - name: Smoketest sleigh lift - run: ./install/bin/sleighLift disassemble x86-64.sla 4881ecc00f0000 + run: ./install/bin/sleigh-lift disassemble x86-64.sla 4881ecc00f0000 - name: Test install directory working-directory: tests/find_package @@ -148,8 +148,8 @@ jobs: cmake -B build -S . "-Dsleigh_DIR=${{ github.workspace }}/install/lib/cmake/sleigh" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} cmake --build build -j 2 --config ${{ matrix.build_type }} cmake --install build --config ${{ matrix.build_type }} --prefix install - ./install/bin/sleighLift --version - ./install/bin/sleighLift disassemble x86-64.sla 4881ecc00f0000 + ./install/bin/sleigh-lift --version + ./install/bin/sleigh-lift disassemble x86-64.sla 4881ecc00f0000 - name: Create the packages run: cmake diff --git a/README.md b/README.md index 4879761c9..b0752325b 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ This repository provides a CMake-based build project for Sleigh so that it can b | Name | Version | Linux Package to Install | macOS Homebrew Package to Install | | ---- | ------- | ------------------------ | --------------------------------- | -| [Git](https://git-scm.com/) | Latest | git | git | +| [Git](https://git-scm.com/) | Latest | git | N/A | | [CMake](https://cmake.org/) | 3.18+ | cmake | cmake | **NOTE**: This CMake project pulls the Ghidra source code from the internet during configuration. See the [note on Ghidra source code section](#note-on-ghidra-source-code) for more details. @@ -68,23 +68,23 @@ cmake --build build --target package ## API Usage -An example program called `sleighLift` has been included to demonstrate how to use the Sleigh API. It takes a hexadecimal string of bytes and can disassemble it or lift it to p-code. The program can be invoked as follows, where the `action` argument must be either `disassemble` or `pcode`: +An example program called `sleigh-lift` has been included to demonstrate how to use the Sleigh API. It takes a hexadecimal string of bytes and can disassemble it or lift it to p-code. The program can be invoked as follows, where the `action` argument must be either `disassemble` or `pcode`: ```sh -sleighLift [action] [sla_file] [bytes] [-a address] [-p root_sla_dir] [-s pspec_file] +sleigh-lift [action] [sla_file] [bytes] [-a address] [-p root_sla_dir] [-s pspec_file] ``` For example, to disassemble the following byte string: ```sh -$ sleighLift disassemble x86-64.sla 4881ecc00f0000 +$ sleigh-lift disassemble x86-64.sla 4881ecc00f0000 0x00000000: SUB RSP,0xfc0 ``` And to lift it to p-code: ```sh -$ sleighLift pcode x86-64.sla 4881ecc00f0000 +$ sleigh-lift pcode x86-64.sla 4881ecc00f0000 (register,0x200,1) = INT_LESS (register,0x20,8) (const,0xfc0,8) (register,0x20b,1) = INT_SBORROW (register,0x20,8) (const,0xfc0,8) (register,0x20,8) = INT_SUB (register,0x20,8) (const,0xfc0,8) @@ -96,7 +96,7 @@ $ sleighLift pcode x86-64.sla 4881ecc00f0000 (register,0x202,1) = INT_EQUAL (unique,0x12d00,1) (const,0x0,1) ``` -If you do not want to build `sleighLift`, you must set the CMake variable `sleigh_BUILD_EXTRATOOLS` option to `OFF` during CMake configuration. +If you do not want to build `sleigh-lift`, you must set the CMake variable `sleigh_BUILD_EXTRATOOLS` option to `OFF` during CMake configuration. ## Helpers diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 500e6fdc2..1d46ff26e 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -19,7 +19,7 @@ if(NOT TARGET sleigh::sla) if(NOT sleigh_FOUND) message(WARNING "Could not find sleigh library, building from source") # Exclude from all because there are no install rules for the example - # See sleighLift for example with install rules + # See sleigh-lift for example with install rules add_subdirectory(.. sleigh EXCLUDE_FROM_ALL) endif() endif() diff --git a/extra-tools/sleigh-lift/CMakeLists.txt b/extra-tools/sleigh-lift/CMakeLists.txt index 5a8792eb8..b6ecc0edc 100644 --- a/extra-tools/sleigh-lift/CMakeLists.txt +++ b/extra-tools/sleigh-lift/CMakeLists.txt @@ -36,7 +36,7 @@ target_link_libraries(sleigh_lift PRIVATE target_compile_features(sleigh_lift PRIVATE cxx_std_17) set_target_properties(sleigh_lift PROPERTIES EXPORT_NAME lift - OUTPUT_NAME sleighLift + OUTPUT_NAME sleigh-lift ) if(NOT CMAKE_SKIP_INSTALL_RULES) From df13e4743783c82703275faebec23a568009179f Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Wed, 17 Aug 2022 13:29:32 -0700 Subject: [PATCH 33/37] Add project sleigh_tool for tool subdirectory Could make it easier to build just the tools --- tools/CMakeLists.txt | 12 ++++++++++++ tools/decompiler/CMakeLists.txt | 8 ++++---- tools/ghidra/CMakeLists.txt | 8 ++++---- tools/spec-compiler/CMakeLists.txt | 8 ++++---- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index e2feda0bb..bb08728e9 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,3 +1,15 @@ +cmake_minimum_required(VERSION 3.18) + +include(../cmake/prelude.cmake) +include(../src/setup-ghidra-source.cmake) + +project(sleigh_tools + VERSION "${ghidra_version}" + DESCRIPTION "Sleigh tools" + HOMEPAGE_URL "https://github.com/lifting-bits/sleigh" + LANGUAGES CXX +) + option(sleigh_BUILD_SPECCOMPILER "Build the sleigh spec compiler executable" ON) option(sleigh_BUILD_DECOMPILER "Build the decompiler executable" ON) option(sleigh_BUILD_GHIDRA "Build the Ghidra executable" ON) diff --git a/tools/decompiler/CMakeLists.txt b/tools/decompiler/CMakeLists.txt index 886d27f95..8b7b539db 100644 --- a/tools/decompiler/CMakeLists.txt +++ b/tools/decompiler/CMakeLists.txt @@ -4,10 +4,10 @@ include(../../cmake/prelude.cmake) include(../../src/setup-ghidra-source.cmake) project(sleigh_decompiler - VERSION "${ghidra_version}" - DESCRIPTION "Sleigh decompiler" - HOMEPAGE_URL "https://github.com/lifting-bits/sleigh" - LANGUAGES CXX + VERSION "${ghidra_version}" + DESCRIPTION "Sleigh decompiler" + HOMEPAGE_URL "https://github.com/lifting-bits/sleigh" + LANGUAGES CXX ) include(../../cmake/project-is-top-level.cmake) diff --git a/tools/ghidra/CMakeLists.txt b/tools/ghidra/CMakeLists.txt index 2aa3cc76e..0bd112708 100644 --- a/tools/ghidra/CMakeLists.txt +++ b/tools/ghidra/CMakeLists.txt @@ -4,10 +4,10 @@ include(../../cmake/prelude.cmake) include(../../src/setup-ghidra-source.cmake) project(sleigh_ghidra - VERSION "${ghidra_version}" - DESCRIPTION "Sleigh ghidra service" - HOMEPAGE_URL "https://github.com/lifting-bits/sleigh" - LANGUAGES CXX + VERSION "${ghidra_version}" + DESCRIPTION "Sleigh ghidra service" + HOMEPAGE_URL "https://github.com/lifting-bits/sleigh" + LANGUAGES CXX ) include(../../cmake/project-is-top-level.cmake) diff --git a/tools/spec-compiler/CMakeLists.txt b/tools/spec-compiler/CMakeLists.txt index cd8ca0efd..a075461db 100644 --- a/tools/spec-compiler/CMakeLists.txt +++ b/tools/spec-compiler/CMakeLists.txt @@ -4,10 +4,10 @@ include(../../cmake/prelude.cmake) include(../../src/setup-ghidra-source.cmake) project(sleigh_sleigh - VERSION "${ghidra_version}" - DESCRIPTION "Sleigh spec compiler" - HOMEPAGE_URL "https://github.com/lifting-bits/sleigh" - LANGUAGES CXX + VERSION "${ghidra_version}" + DESCRIPTION "Sleigh spec compiler" + HOMEPAGE_URL "https://github.com/lifting-bits/sleigh" + LANGUAGES CXX ) include(../../cmake/project-is-top-level.cmake) From 79a2b17384cffc11bdd06092ab9b12421924812f Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Wed, 17 Aug 2022 13:52:29 -0700 Subject: [PATCH 34/37] Add help text to name the tool executable name --- tools/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index bb08728e9..5a4ac266e 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -10,9 +10,9 @@ project(sleigh_tools LANGUAGES CXX ) -option(sleigh_BUILD_SPECCOMPILER "Build the sleigh spec compiler executable" ON) -option(sleigh_BUILD_DECOMPILER "Build the decompiler executable" ON) -option(sleigh_BUILD_GHIDRA "Build the Ghidra executable" ON) +option(sleigh_BUILD_SPECCOMPILER "Build the sleigh spec compiler executable (\"sleigh\")" ON) +option(sleigh_BUILD_DECOMPILER "Build the decompiler executable (\"decomp\")" ON) +option(sleigh_BUILD_GHIDRA "Build the Ghidra executable (\"ghidra\")" ON) if(sleigh_BUILD_SPECCOMPILER) add_subdirectory(spec-compiler) From 83b4e2f91e08145920a8006e9e9035bc06ee36b3 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Thu, 18 Aug 2022 09:42:54 -0700 Subject: [PATCH 35/37] Add license notice to CMake files --- cmake/install-config.cmake.in | 8 ++++++++ cmake/install-rules.cmake | 8 ++++++++ cmake/libconfig.h.in | 8 ++++++++ example/CMakeLists.txt | 8 ++++++++ extra-tools/CMakeLists.txt | 2 +- sleighspecs/CMakeLists.txt | 8 ++++++++ sleighspecs/specfiles.cmake.in | 8 ++++++++ src/compile_options.cmake | 8 ++++++++ src/setup-ghidra-source.cmake | 8 ++++++++ src/spec_files_HEAD.cmake | 8 ++++++++ src/spec_files_stable.cmake | 8 ++++++++ tests/CMakeLists.txt | 8 ++++++++ tools/CMakeLists.txt | 8 ++++++++ tools/decompiler/CMakeLists.txt | 8 ++++++++ tools/ghidra/CMakeLists.txt | 8 ++++++++ tools/spec-compiler/CMakeLists.txt | 8 ++++++++ 16 files changed, 121 insertions(+), 1 deletion(-) diff --git a/cmake/install-config.cmake.in b/cmake/install-config.cmake.in index ca14a3a26..15c65d996 100644 --- a/cmake/install-config.cmake.in +++ b/cmake/install-config.cmake.in @@ -1,3 +1,11 @@ +# +# Copyright (c) 2022-present, Trail of Bits, Inc. +# All rights reserved. +# +# This source code is licensed in accordance with the terms specified in +# the LICENSE file found in the root directory of this source tree. +# + # This file provides access to the installed sleigh targets. # # There are optional components that could also be installed: diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake index 3aecbefb5..234c4e93c 100644 --- a/cmake/install-rules.cmake +++ b/cmake/install-rules.cmake @@ -1,3 +1,11 @@ +# +# Copyright (c) 2022-present, Trail of Bits, Inc. +# All rights reserved. +# +# This source code is licensed in accordance with the terms specified in +# the LICENSE file found in the root directory of this source tree. +# + if(PROJECT_IS_TOP_LEVEL) set(CMAKE_INSTALL_INCLUDEDIR include/sleigh CACHE PATH "") endif() diff --git a/cmake/libconfig.h.in b/cmake/libconfig.h.in index 2981d2cb3..750339bde 100644 --- a/cmake/libconfig.h.in +++ b/cmake/libconfig.h.in @@ -1,3 +1,11 @@ +/* + Copyright (c) 2022-present, Trail of Bits, Inc. + All rights reserved. + + This source code is licensed in accordance with the terms specified in + the LICENSE file found in the root directory of this source tree. +*/ + #ifndef SLEIGH_LIBCONFIG_H #define SLEIGH_LIBCONFIG_H diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 1d46ff26e..15546bdc8 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,3 +1,11 @@ +# +# Copyright (c) 2022-present, Trail of Bits, Inc. +# All rights reserved. +# +# This source code is licensed in accordance with the terms specified in +# the LICENSE file found in the root directory of this source tree. +# + cmake_minimum_required(VERSION 3.18) include(../cmake/prelude.cmake) diff --git a/extra-tools/CMakeLists.txt b/extra-tools/CMakeLists.txt index a6a7c89a4..46a66f841 100644 --- a/extra-tools/CMakeLists.txt +++ b/extra-tools/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2021-present, Trail of Bits, Inc. +# Copyright (c) 2022-present, Trail of Bits, Inc. # All rights reserved. # # This source code is licensed in accordance with the terms specified in diff --git a/sleighspecs/CMakeLists.txt b/sleighspecs/CMakeLists.txt index bbb5136ca..5daec1312 100644 --- a/sleighspecs/CMakeLists.txt +++ b/sleighspecs/CMakeLists.txt @@ -1,3 +1,11 @@ +# +# Copyright (c) 2022-present, Trail of Bits, Inc. +# All rights reserved. +# +# This source code is licensed in accordance with the terms specified in +# the LICENSE file found in the root directory of this source tree. +# + cmake_minimum_required(VERSION 3.18) include(../cmake/prelude.cmake) diff --git a/sleighspecs/specfiles.cmake.in b/sleighspecs/specfiles.cmake.in index 9af546a0b..6dbf70b21 100644 --- a/sleighspecs/specfiles.cmake.in +++ b/sleighspecs/specfiles.cmake.in @@ -1,3 +1,11 @@ +# +# Copyright (c) 2022-present, Trail of Bits, Inc. +# All rights reserved. +# +# This source code is licensed in accordance with the terms specified in +# the LICENSE file found in the root directory of this source tree. +# + @PACKAGE_INIT@ # Path relative-root to reach installed specfiles directory diff --git a/src/compile_options.cmake b/src/compile_options.cmake index 30a0a6897..24bd9f4a3 100644 --- a/src/compile_options.cmake +++ b/src/compile_options.cmake @@ -1,3 +1,11 @@ +# +# Copyright (c) 2022-present, Trail of Bits, Inc. +# All rights reserved. +# +# This source code is licensed in accordance with the terms specified in +# the LICENSE file found in the root directory of this source tree. +# + # Internal settings option(sleigh_CPUI_RULECOMPILE "Allow user defined dynamic rules") option(sleigh_CPUI_STATISTICS "Turn on collection of cover and cast statistics") diff --git a/src/setup-ghidra-source.cmake b/src/setup-ghidra-source.cmake index a8e59f630..0ddbe6267 100644 --- a/src/setup-ghidra-source.cmake +++ b/src/setup-ghidra-source.cmake @@ -1,3 +1,11 @@ +# +# Copyright (c) 2022-present, Trail of Bits, Inc. +# All rights reserved. +# +# This source code is licensed in accordance with the terms specified in +# the LICENSE file found in the root directory of this source tree. +# + # ---- Setup Ghidra Source code ---- include_guard(GLOBAL) diff --git a/src/spec_files_HEAD.cmake b/src/spec_files_HEAD.cmake index af907ee3f..65472ee4f 100644 --- a/src/spec_files_HEAD.cmake +++ b/src/spec_files_HEAD.cmake @@ -1,3 +1,11 @@ +# +# Copyright (c) 2022-present, Trail of Bits, Inc. +# All rights reserved. +# +# This source code is licensed in accordance with the terms specified in +# the LICENSE file found in the root directory of this source tree. +# + set(spec_file_list "${ghidrasource_SOURCE_DIR}/Ghidra/Processors/6502/data/languages/6502.slaspec" "${ghidrasource_SOURCE_DIR}/Ghidra/Processors/6502/data/languages/65c02.slaspec" diff --git a/src/spec_files_stable.cmake b/src/spec_files_stable.cmake index 407ce2c10..39e710475 100644 --- a/src/spec_files_stable.cmake +++ b/src/spec_files_stable.cmake @@ -1,3 +1,11 @@ +# +# Copyright (c) 2022-present, Trail of Bits, Inc. +# All rights reserved. +# +# This source code is licensed in accordance with the terms specified in +# the LICENSE file found in the root directory of this source tree. +# + set(spec_file_list "${ghidrasource_SOURCE_DIR}/Ghidra/Processors/6502/data/languages/6502.slaspec" "${ghidrasource_SOURCE_DIR}/Ghidra/Processors/6502/data/languages/65c02.slaspec" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 675f24a34..25bf13a89 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,3 +1,11 @@ +# +# Copyright (c) 2022-present, Trail of Bits, Inc. +# All rights reserved. +# +# This source code is licensed in accordance with the terms specified in +# the LICENSE file found in the root directory of this source tree. +# + # # Tests from ghidra repo # diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 5a4ac266e..2c4ac79d8 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,3 +1,11 @@ +# +# Copyright (c) 2022-present, Trail of Bits, Inc. +# All rights reserved. +# +# This source code is licensed in accordance with the terms specified in +# the LICENSE file found in the root directory of this source tree. +# + cmake_minimum_required(VERSION 3.18) include(../cmake/prelude.cmake) diff --git a/tools/decompiler/CMakeLists.txt b/tools/decompiler/CMakeLists.txt index 8b7b539db..eb9500244 100644 --- a/tools/decompiler/CMakeLists.txt +++ b/tools/decompiler/CMakeLists.txt @@ -1,3 +1,11 @@ +# +# Copyright (c) 2022-present, Trail of Bits, Inc. +# All rights reserved. +# +# This source code is licensed in accordance with the terms specified in +# the LICENSE file found in the root directory of this source tree. +# + cmake_minimum_required(VERSION 3.18) include(../../cmake/prelude.cmake) diff --git a/tools/ghidra/CMakeLists.txt b/tools/ghidra/CMakeLists.txt index 0bd112708..604536d54 100644 --- a/tools/ghidra/CMakeLists.txt +++ b/tools/ghidra/CMakeLists.txt @@ -1,3 +1,11 @@ +# +# Copyright (c) 2022-present, Trail of Bits, Inc. +# All rights reserved. +# +# This source code is licensed in accordance with the terms specified in +# the LICENSE file found in the root directory of this source tree. +# + cmake_minimum_required(VERSION 3.18) include(../../cmake/prelude.cmake) diff --git a/tools/spec-compiler/CMakeLists.txt b/tools/spec-compiler/CMakeLists.txt index a075461db..2a22f6da0 100644 --- a/tools/spec-compiler/CMakeLists.txt +++ b/tools/spec-compiler/CMakeLists.txt @@ -1,3 +1,11 @@ +# +# Copyright (c) 2022-present, Trail of Bits, Inc. +# All rights reserved. +# +# This source code is licensed in accordance with the terms specified in +# the LICENSE file found in the root directory of this source tree. +# + cmake_minimum_required(VERSION 3.18) include(../../cmake/prelude.cmake) From cc4d7d209e5b7947f4c28ffb84db722bc750df8d Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Thu, 18 Aug 2022 09:49:17 -0700 Subject: [PATCH 36/37] Fix/Remove too specific CPack packaging configuration --- cmake/packaging.cmake | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cmake/packaging.cmake b/cmake/packaging.cmake index d93d7c05b..e0f674eb9 100644 --- a/cmake/packaging.cmake +++ b/cmake/packaging.cmake @@ -16,7 +16,7 @@ set(CPACK_PACKAGE_NAME "sleigh") set(CPACK_PACKAGE_VENDOR "Trail of Bits") set(CPACK_PACKAGE_CONTACT "info@trailofbits.com") set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/lifting-bits/sleigh") -set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}-${PACKAGE_VERSION}.x86_64") +set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}-${PACKAGE_VERSION}.${CMAKE_SYSTEM_PROCESSOR}") set(CPACK_PACKAGE_RELOCATABLE ON) set(CPACK_GENERATOR "TGZ") @@ -33,7 +33,6 @@ if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") set(CPACK_RPM_PACKAGE_RELEASE_DIST "${PACKAGE_VERSION}") set(CPACK_RPM_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}") set(CPACK_RPM_PACKAGE_GROUP "default") - set(CPACK_RPM_PACKAGE_REQUIRES "glibc >= 2.31") unset(dpkg_executable_path CACHE) find_program(dpkg_executable_path "dpkg") @@ -47,8 +46,6 @@ if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") set(CPACK_DEBIAN_PACKAGE_PRIORITY "extra") set(CPACK_DEBIAN_PACKAGE_SECTION "default") set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "${CPACK_PACKAGE_HOMEPAGE_URL}") - set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc-dev-bin (>=2.31)") - endif() include(CPack) From b69ea127aa5da179684652f2c1ccccf1cd263f99 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Fri, 19 Aug 2022 07:05:47 -0700 Subject: [PATCH 37/37] Consistent capitalization of Sleigh --- CMakeLists.txt | 2 +- README.md | 10 +++++----- cmake/packaging.cmake | 2 +- extra-tools/sleigh-lift/src/main.cpp | 4 ++-- support/Support.cpp | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bacf9a34..2414c3ceb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ endif() project(sleigh VERSION "${ghidra_version}" - DESCRIPTION "Unofficial CMake build for Ghidra SLEIGH" + DESCRIPTION "Unofficial CMake build for Ghidra Sleigh" HOMEPAGE_URL "https://github.com/lifting-bits/sleigh" LANGUAGES CXX ) diff --git a/README.md b/README.md index b0752325b..7b48d34f2 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ For building documentation: | [Doxygen](https://www.doxygen.nl/) | Latest | doxygen | doxygen | | [GraphViz](https://graphviz.org/) | Latest | graphviz | graphviz | -## Build and Install the SLEIGH Library +## Build and Install the Sleigh Library ```sh # Clone this repository (CMake project for sleigh) @@ -42,10 +42,10 @@ cd sleigh # Configure CMake cmake -B build -S . -# Build SLEIGH +# Build Sleigh cmake --build build --parallel 8 -# Install SLEIGH +# Install Sleigh cmake --install build --prefix ./install ``` @@ -57,12 +57,12 @@ Please see [`src/README.md`](src/README.md) for more information on how to custo ## Packaging -The CMake configuration also supports building packages for SLEIGH. +The CMake configuration also supports building packages for Sleigh. For example: ```sh -# Package SLEIGH +# Package Sleigh cmake --build build --target package ``` diff --git a/cmake/packaging.cmake b/cmake/packaging.cmake index e0f674eb9..54545da5c 100644 --- a/cmake/packaging.cmake +++ b/cmake/packaging.cmake @@ -11,7 +11,7 @@ if("${sleigh_RELEASE_TYPE}" STREQUAL "HEAD") set(PACKAGE_VERSION "DEV.${ghidra_short_commit}") endif() -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "SLEIGH was designed for the GHIDRA reverse engineering platform built by the National Security Agency and is used to describe microprocessors with enough detail to facilitate two major components of GHIDRA, the disassembly and decompilation engines. This is an unofficial release by Trail of Bits.") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Sleigh was designed for the Ghidra reverse engineering platform built by the National Security Agency and is used to describe microprocessors with enough detail to facilitate two major components of Ghidra, the disassembly and decompilation engines. This is an unofficial release by Trail of Bits.") set(CPACK_PACKAGE_NAME "sleigh") set(CPACK_PACKAGE_VENDOR "Trail of Bits") set(CPACK_PACKAGE_CONTACT "info@trailofbits.com") diff --git a/extra-tools/sleigh-lift/src/main.cpp b/extra-tools/sleigh-lift/src/main.cpp index 420c2f49a..3f64c7bed 100644 --- a/extra-tools/sleigh-lift/src/main.cpp +++ b/extra-tools/sleigh-lift/src/main.cpp @@ -256,7 +256,7 @@ int main(int argc, char *argv[]) { << std::endl; return EXIT_FAILURE; } - // Put together SLEIGH components + // Put together Sleigh components #ifdef sleigh_RELEASE_IS_HEAD AttributeId::initialize(); ElementId::initialize(); @@ -328,7 +328,7 @@ int main(int argc, char *argv[]) { } // In order to parse and validate the byte string properly, we need to get the - // address size from SLEIGH. Therefore this needs to happen after + // address size from Sleigh. Therefore this needs to happen after // initialization. // // Ensure that we don't start disassembling until we've set the image buffer. diff --git a/support/Support.cpp b/support/Support.cpp index a19b48bc3..1e021d737 100644 --- a/support/Support.cpp +++ b/support/Support.cpp @@ -18,7 +18,7 @@ std::optional FindSpecFileInSearchPath(std::string_view file_name, std::filesystem::path search_path) { search_path.append("Ghidra").append("Processors"); - // Check whether a SLEIGH installation exists at this path + // Check whether a Sleigh installation exists at this path if (!std::filesystem::is_directory(search_path)) { return {}; }