Skip to content

Commit b1be213

Browse files
authored
[runtimes] Allow building against an installed LLVM tree
I am currently trying to test the LLVM runtimes (including compiler-rt) against an installed LLVM tree rather than a build tree (since that is no longer available). Currently, the runtimes build of compiler-rt assumes that LLVM_BINARY_DIR is writable since it uses configure_file() to write there during the CMake configure stage. Instead, generate this file inside CMAKE_CURRENT_BINARY_DIR, which will match LLVM_BINARY_DIR when invoked from llvm/runtimes/CMakeLists.txt. I also needed to make a minor change to the hwasan tests: hwasan_symbolize was previously found in the LLVM_BINARY_DIR, but since it is generated as part of the compiler-rt build it is now inside the CMake build directory instead. I fixed this by passing the output directory to lit as config.compiler_rt_bindir and using llvm_config.add_tool_substitutions(). For testing that we no longer write to the LLVM install directory as part of testing or configuration, I created a read-only bind mount and configured the runtimes builds as follows: ``` $ sudo mount --bind --read-only ~/llvm-install /tmp/upstream-llvm-readonly $ cmake -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_C_COMPILER=/tmp/upstream-llvm-readonly/bin/clang \ -DCMAKE_CXX_COMPILER=/tmp/upstream-llvm-readonly/bin/clang++ \ -DLLVM_INCLUDE_TESTS=TRUE -DLLVM_ENABLE_ASSERTIONS=TRUE \ -DCOMPILER_RT_INCLUDE_TESTS=TRUE -DCOMPILER_RT_DEBUG=OFF \ -DLLVM_ENABLE_RUNTIMES=compiler-rt \ -DLLVM_BINARY_DIR=/tmp/upstream-llvm-readonly \ -G Ninja -S ~/upstream-llvm-project/runtimes \ -B ~/upstream-llvm-project/runtimes/cmake-build-debug-llvm-git ``` Reviewed By: ldionne Pull Request: #86209
1 parent 25909b8 commit b1be213

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

compiler-rt/cmake/Modules/AddCompilerRT.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ function(configure_compiler_rt_lit_site_cfg input output)
773773

774774
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} COMPILER_RT_RESOLVED_TEST_COMPILER ${COMPILER_RT_TEST_COMPILER})
775775
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} COMPILER_RT_RESOLVED_OUTPUT_DIR ${COMPILER_RT_OUTPUT_DIR})
776+
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} COMPILER_RT_RESOLVED_EXEC_OUTPUT_DIR ${COMPILER_RT_EXEC_OUTPUT_DIR})
776777
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} COMPILER_RT_RESOLVED_LIBRARY_OUTPUT_DIR ${output_dir})
777778

778779
configure_lit_site_cfg(${input} ${output})

compiler-rt/test/hwasan/lit.cfg.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import os
44

5+
from lit.llvm import llvm_config
6+
from lit.llvm.subst import ToolSubst, FindTool
7+
58
# Setup config name.
69
config.name = "HWAddressSanitizer" + getattr(config, "name_suffix", "default")
710

@@ -74,6 +77,12 @@ def build_invocation(compile_flags):
7477
("%env_hwasan_opts=", "env HWASAN_OPTIONS=" + default_hwasan_opts_str)
7578
)
7679

80+
# Ensure that we can use hwasan_symbolize from the expected location
81+
llvm_config.add_tool_substitutions(
82+
[ToolSubst("hwasan_symbolize", unresolved="fatal")],
83+
search_dirs=[config.compiler_rt_bindir],
84+
)
85+
7786
# Default test suffixes.
7887
config.suffixes = [".c", ".cpp"]
7988

compiler-rt/test/lit.common.configured.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ set_default("python_executable", "@Python3_EXECUTABLE@")
2828
set_default("compiler_rt_debug", @COMPILER_RT_DEBUG_PYBOOL@)
2929
set_default("compiler_rt_intercept_libdispatch", @COMPILER_RT_INTERCEPT_LIBDISPATCH_PYBOOL@)
3030
set_default("compiler_rt_output_dir", "@COMPILER_RT_RESOLVED_OUTPUT_DIR@")
31+
set_default("compiler_rt_bindir", "@COMPILER_RT_RESOLVED_EXEC_OUTPUT_DIR@")
3132
set_default("compiler_rt_libdir", "@COMPILER_RT_RESOLVED_LIBRARY_OUTPUT_DIR@")
3233
set_default("emulator", "@COMPILER_RT_EMULATOR@")
3334
set_default("asan_shadow_scale", "@COMPILER_RT_ASAN_SHADOW_SCALE@")

runtimes/CMakeLists.txt

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,23 @@ foreach(entry ${runtimes})
243243
endforeach()
244244

245245
if(LLVM_INCLUDE_TESTS)
246+
# If built with the runtimes build (rooted at runtimes/CMakeLists.txt), we
247+
# won't have llvm-lit. If built with the bootstrapping build (rooted at
248+
# llvm/CMakeLists.txt), the top-level llvm CMake invocation already generated
249+
# the llvm-lit script.
250+
if (NOT HAVE_LLVM_LIT)
251+
# Add lit before adding any runtimes since their CMake tests configuration
252+
# might depend on lit being present.
253+
set(LLVM_LIT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin)
254+
add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit
255+
${CMAKE_CURRENT_BINARY_DIR}/llvm-lit)
256+
# Ensure that the testsuites use the local lit rather than
257+
# ${LLVM_INSTALL_DIR}/bin/llvm-lit (which may not exist if LLVM_BINARY_DIR
258+
# points at an installed LLVM tree rather than a build tree).
259+
get_llvm_lit_path(_base_dir _file_name)
260+
set(LLVM_EXTERNAL_LIT "${_base_dir}/${_file_name}" CACHE STRING "Command used to spawn lit" FORCE)
261+
endif()
262+
246263
set(LIT_ARGS_DEFAULT "-sv --show-xfail --show-unsupported")
247264
if (MSVC OR XCODE)
248265
set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
@@ -276,14 +293,6 @@ if(LLVM_INCLUDE_TESTS)
276293
# and we know the total set of lit testsuites.
277294
umbrella_lit_testsuite_end(check-runtimes)
278295

279-
if (NOT HAVE_LLVM_LIT)
280-
# If built by manually invoking cmake on this directory, we don't have
281-
# llvm-lit. If invoked via llvm/runtimes, the toplevel llvm cmake
282-
# invocation already generated the llvm-lit script.
283-
add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit
284-
${CMAKE_CURRENT_BINARY_DIR}/llvm-lit)
285-
endif()
286-
287296
get_property(LLVM_RUNTIMES_LIT_TESTSUITES GLOBAL PROPERTY LLVM_RUNTIMES_LIT_TESTSUITES)
288297
string(REPLACE ";" "\n" LLVM_RUNTIMES_LIT_TESTSUITES "${LLVM_RUNTIMES_LIT_TESTSUITES}")
289298
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/lit.tests ${LLVM_RUNTIMES_LIT_TESTSUITES})
@@ -313,10 +322,10 @@ if(SUB_COMPONENTS)
313322
if(LLVM_RUNTIMES_TARGET)
314323
configure_file(
315324
${CMAKE_CURRENT_SOURCE_DIR}/Components.cmake.in
316-
${LLVM_BINARY_DIR}/runtimes/${LLVM_RUNTIMES_TARGET}/Components.cmake)
325+
${CMAKE_CURRENT_BINARY_DIR}/runtimes/${LLVM_RUNTIMES_TARGET}/Components.cmake)
317326
else()
318327
configure_file(
319328
${CMAKE_CURRENT_SOURCE_DIR}/Components.cmake.in
320-
${LLVM_BINARY_DIR}/runtimes/Components.cmake)
329+
${CMAKE_CURRENT_BINARY_DIR}/runtimes/Components.cmake)
321330
endif()
322331
endif()

0 commit comments

Comments
 (0)