From b392ec696b6add15c72181569c2591652d936c40 Mon Sep 17 00:00:00 2001 From: Rafael Auler Date: Thu, 23 Dec 2021 05:59:35 -0800 Subject: [PATCH] Re-enable Windows build and fix issues Summary: Fix missing string header file inclusion and link_fdata find problem in lit tests. Change root-level tests to require linux. Re-enable Windows in our root CMakeLists.txt. (cherry picked from FBD33296290) --- bolt/CMakeLists.txt | 140 +++++++++--------- .../bolt/Passes/InstrumentationSummary.h | 1 + bolt/lib/RuntimeLibs/RuntimeLibrary.cpp | 2 +- bolt/test/CMakeLists.txt | 22 +-- bolt/test/bolt-icf.test | 2 + bolt/test/keep-aranges.test | 3 + bolt/test/lit.cfg.py | 4 +- bolt/test/non-empty-debug-line.test | 2 + bolt/tools/driver/CMakeLists.txt | 2 + bolt/tools/merge-fdata/CMakeLists.txt | 1 + 10 files changed, 95 insertions(+), 84 deletions(-) diff --git a/bolt/CMakeLists.txt b/bolt/CMakeLists.txt index 81ce790ed1f8..1107bd42d24b 100644 --- a/bolt/CMakeLists.txt +++ b/bolt/CMakeLists.txt @@ -4,81 +4,77 @@ set(BOLT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(BOLT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) set(CMAKE_CXX_STANDARD 14) -if (NOT CMAKE_HOST_SYSTEM_NAME MATCHES Linux) - message(WARNING "Not building BOLT on unsupported platform") -else() - set(BOLT_ENABLE_RUNTIME OFF) - if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64") - set(BOLT_ENABLE_RUNTIME ON) - endif() +set(BOLT_ENABLE_RUNTIME OFF) +if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64") + set(BOLT_ENABLE_RUNTIME ON) +endif() - set(BOLT_INCLUDE_TESTS OFF) - if (LLVM_INCLUDE_TESTS) - string(FIND "${LLVM_ENABLE_PROJECTS}" "clang" POSITION) +set(BOLT_INCLUDE_TESTS OFF) +if (LLVM_INCLUDE_TESTS) + string(FIND "${LLVM_ENABLE_PROJECTS}" "clang" POSITION) + if (NOT ${POSITION} EQUAL -1) + string(FIND "${LLVM_ENABLE_PROJECTS}" "lld" POSITION) if (NOT ${POSITION} EQUAL -1) - string(FIND "${LLVM_ENABLE_PROJECTS}" "lld" POSITION) - if (NOT ${POSITION} EQUAL -1) - set(BOLT_INCLUDE_TESTS ON) - else() - message(WARNING "Not including BOLT tests since lld is disabled") - endif() + set(BOLT_INCLUDE_TESTS ON) else() - message(WARNING "Not including BOLT tests since clang is disabled") + message(WARNING "Not including BOLT tests since lld is disabled") endif() - endif() - - if (BOLT_ENABLE_RUNTIME) - message(STATUS "Building BOLT runtime libraries for X86") - ExternalProject_Add(bolt_rt - SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/runtime" - STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-stamps - BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins - CMAKE_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} - -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} - -DCMAKE_BUILD_TYPE=Release - -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} - -DCMAKE_INSTALL_PREFIX=${LLVM_BINARY_DIR} - BUILD_ALWAYS True - ) - install(CODE "execute_process\(COMMAND \${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} -P ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins/cmake_install.cmake \)" - COMPONENT bolt) - add_llvm_install_targets(install-bolt_rt - DEPENDS bolt_rt bolt - COMPONENT bolt) - endif() - - # Get the current git revision for BOLT. - find_program(git_executable NAMES git git.exe git.cmd) - if (git_executable) - execute_process(COMMAND ${git_executable} rev-parse HEAD - WORKING_DIRECTORY ${LLVM_MAIN_SRC_DIR} - TIMEOUT 5 - RESULT_VARIABLE git_result - OUTPUT_VARIABLE git_output) - if( git_result EQUAL 0 ) - string(STRIP "${git_output}" git_ref_id) - set(BOLT_REVISION "${git_ref_id}") - endif() - endif() - - # If we can't find a revision, set it to "". - if (NOT BOLT_REVISION) - set(BOLT_REVISION "") - endif() - - configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/include/bolt/Utils/BoltRevision.inc.in - ${CMAKE_CURRENT_BINARY_DIR}/include/bolt/Utils/BoltRevision.inc) - - include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${CMAKE_CURRENT_BINARY_DIR}/include - ) - - add_subdirectory(lib) - add_subdirectory(tools) - - if (BOLT_INCLUDE_TESTS) - add_subdirectory(test) + else() + message(WARNING "Not including BOLT tests since clang is disabled") endif() endif() + +if (BOLT_ENABLE_RUNTIME) + message(STATUS "Building BOLT runtime libraries for X86") + ExternalProject_Add(bolt_rt + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/runtime" + STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-stamps + BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins + CMAKE_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_BUILD_TYPE=Release + -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} + -DCMAKE_INSTALL_PREFIX=${LLVM_BINARY_DIR} + BUILD_ALWAYS True + ) + install(CODE "execute_process\(COMMAND \${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} -P ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins/cmake_install.cmake \)" + COMPONENT bolt) + add_llvm_install_targets(install-bolt_rt + DEPENDS bolt_rt bolt + COMPONENT bolt) +endif() + +# Get the current git revision for BOLT. +find_program(git_executable NAMES git git.exe git.cmd) +if (git_executable) + execute_process(COMMAND ${git_executable} rev-parse HEAD + WORKING_DIRECTORY ${LLVM_MAIN_SRC_DIR} + TIMEOUT 5 + RESULT_VARIABLE git_result + OUTPUT_VARIABLE git_output) + if( git_result EQUAL 0 ) + string(STRIP "${git_output}" git_ref_id) + set(BOLT_REVISION "${git_ref_id}") + endif() +endif() + +# If we can't find a revision, set it to "". +if (NOT BOLT_REVISION) + set(BOLT_REVISION "") +endif() + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/include/bolt/Utils/BoltRevision.inc.in + ${CMAKE_CURRENT_BINARY_DIR}/include/bolt/Utils/BoltRevision.inc) + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_BINARY_DIR}/include + ) + +add_subdirectory(lib) +add_subdirectory(tools) + +if (BOLT_INCLUDE_TESTS) + add_subdirectory(test) +endif() diff --git a/bolt/include/bolt/Passes/InstrumentationSummary.h b/bolt/include/bolt/Passes/InstrumentationSummary.h index 6a074b590857..8e991d1f78ff 100644 --- a/bolt/include/bolt/Passes/InstrumentationSummary.h +++ b/bolt/include/bolt/Passes/InstrumentationSummary.h @@ -16,6 +16,7 @@ #define BOLT_PASSES_INSTRUMENTATION_SUMMARY_H #include "llvm/ADT/DenseSet.h" +#include #include namespace llvm { diff --git a/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp b/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp index a697e42a7e53..bc904ebf88da 100644 --- a/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp +++ b/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp @@ -45,7 +45,7 @@ std::string RuntimeLibrary::getLibPath(StringRef ToolPath, void RuntimeLibrary::loadLibrary(StringRef LibPath, RuntimeDyld &RTDyld) { ErrorOr> MaybeBuf = - MemoryBuffer::getFile(LibPath, -1, false); + MemoryBuffer::getFile(LibPath, false, false); check_error(MaybeBuf.getError(), LibPath); std::unique_ptr B = std::move(MaybeBuf.get()); file_magic Magic = identify_magic(B->getBuffer()); diff --git a/bolt/test/CMakeLists.txt b/bolt/test/CMakeLists.txt index 7c9523de8558..f4d19f03a79a 100644 --- a/bolt/test/CMakeLists.txt +++ b/bolt/test/CMakeLists.txt @@ -14,28 +14,30 @@ set(BOLT_TEST_PARAMS ) list(APPEND BOLT_TEST_DEPS + clang + count + FileCheck llc + lld llvm-config - FileCheck count not llvm-bolt llvm-boltdiff - perf2bolt - merge-fdata + llvm-dwarfdump + llvm-mc llvm-nm llvm-objdump llvm-readelf llvm-readobj - yaml2obj llvm-strip - llvm-dwarfdump - llvm-mc llvm-objcopy - clang - lld + merge-fdata + not + perf2bolt + yaml2obj ) add_custom_target(bolt-test-depends DEPENDS ${BOLT_TEST_DEPS}) -set_target_properties(bolt-test-depends PROPERTIES FOLDER "BOLT tests") +set_target_properties(bolt-test-depends PROPERTIES FOLDER "BOLT") add_lit_testsuite(check-bolt "Running the BOLT regression tests" ${CMAKE_CURRENT_BINARY_DIR} @@ -43,7 +45,7 @@ add_lit_testsuite(check-bolt "Running the BOLT regression tests" DEPENDS ${BOLT_TEST_DEPS} ARGS ${BOLT_TEST_EXTRA_ARGS} ) -set_target_properties(check-bolt PROPERTIES FOLDER "BOLT tests") +set_target_properties(check-bolt PROPERTIES FOLDER "BOLT") add_lit_testsuites(BOLT ${CMAKE_CURRENT_SOURCE_DIR} PARAMS ${BOLT_TEST_PARAMS} diff --git a/bolt/test/bolt-icf.test b/bolt/test/bolt-icf.test index d4a101fcbd80..ebbe28b6d680 100644 --- a/bolt/test/bolt-icf.test +++ b/bolt/test/bolt-icf.test @@ -1,5 +1,7 @@ # Check for the replacement of calls to identical functions. +REQUIRES: system-linux + RUN: %clangxx %p/Inputs/bolt_icf.cpp -g -Wl,-q -o %t.exe RUN: llvm-bolt %t.exe -relocs -o %t -icf 2>&1 | FileCheck %s RUN: llvm-nm -n %t | FileCheck %s -check-prefix=CHECK-SYM diff --git a/bolt/test/keep-aranges.test b/bolt/test/keep-aranges.test index 4bae998cbefa..8b93f19ea31a 100644 --- a/bolt/test/keep-aranges.test +++ b/bolt/test/keep-aranges.test @@ -1,5 +1,8 @@ # Check that BOLT generates .debug_aranges section for an input # where it was removed when .gdb_index was generated. + +REQUIRES: system-linux + RUN: %clang %S/Inputs/icf_baz.c %S/Inputs/icf_main.c -Wl,--icf=all,--gdb-index \ RUN: -g -o %t.exe -fuse-ld=lld RUN: llvm-bolt %t.exe -o %t -update-debug-sections -keep-aranges diff --git a/bolt/test/lit.cfg.py b/bolt/test/lit.cfg.py index 6bfb22a6fd93..20285b0d46b2 100644 --- a/bolt/test/lit.cfg.py +++ b/bolt/test/lit.cfg.py @@ -61,6 +61,8 @@ llvm_config.use_lld() config.substitutions.append(('%cflags', '-no-pie')) config.substitutions.append(('%cxxflags', '-no-pie')) +link_fdata_cmd = os.path.join(config.test_source_root, 'link_fdata.py') + tool_dirs = [config.llvm_tools_dir, config.test_source_root] @@ -77,7 +79,7 @@ tools = [ ToolSubst('llvm-objcopy', unresolved='fatal'), ToolSubst('llvm-strip', unresolved='fatal'), ToolSubst('llvm-readelf', unresolved='fatal'), - ToolSubst('link_fdata', command=FindTool('link_fdata.py'), unresolved='fatal'), + ToolSubst('link_fdata', command=link_fdata_cmd, unresolved='fatal'), ToolSubst('merge-fdata', unresolved='fatal'), ] llvm_config.add_tool_substitutions(tools, tool_dirs) diff --git a/bolt/test/non-empty-debug-line.test b/bolt/test/non-empty-debug-line.test index 0922adede523..28c86be320e8 100644 --- a/bolt/test/non-empty-debug-line.test +++ b/bolt/test/non-empty-debug-line.test @@ -1,6 +1,8 @@ # Verifies that BOLT emits DWARF line table with the same size if # no functions with debug info were modified. +REQUIRES: system-linux + RUN: %clang %S/Inputs/hello.c -g -o %t RUN: llvm-bolt %t -o %t1 -update-debug-sections -funcs=_start RUN: llvm-readobj -S %t > %t2 diff --git a/bolt/tools/driver/CMakeLists.txt b/bolt/tools/driver/CMakeLists.txt index 264a89f65e1c..c8027197b056 100644 --- a/bolt/tools/driver/CMakeLists.txt +++ b/bolt/tools/driver/CMakeLists.txt @@ -42,5 +42,7 @@ install(PROGRAMS COMPONENT bolt ) add_llvm_install_targets(install-bolt DEPENDS bolt COMPONENT bolt) +set_target_properties(bolt PROPERTIES FOLDER "BOLT") +set_target_properties(install-bolt PROPERTIES FOLDER "BOLT") include_directories( ${BOLT_SOURCE_DIR}/lib ) diff --git a/bolt/tools/merge-fdata/CMakeLists.txt b/bolt/tools/merge-fdata/CMakeLists.txt index 235a3d33cbfa..18910ff8d982 100644 --- a/bolt/tools/merge-fdata/CMakeLists.txt +++ b/bolt/tools/merge-fdata/CMakeLists.txt @@ -6,6 +6,7 @@ add_llvm_tool(merge-fdata DEPENDS intrinsics_gen ) +set_target_properties(merge-fdata PROPERTIES FOLDER "BOLT") # Emit relocations for BOLT meta test (bolt/test/runtime/meta-merge-fdata.test) if (UNIX AND NOT APPLE)