diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt --- a/compiler-rt/lib/builtins/CMakeLists.txt +++ b/compiler-rt/lib/builtins/CMakeLists.txt @@ -895,9 +895,14 @@ add_dependencies(compiler-rt builtins-standalone-atomic) endif() +# TODO: COMPILER_RT_BUILD_CRT used to be a cached variable so we need to unset +# it first so cmake_dependent_option can set the local variable of the same +# name. This statement can be removed in the future. +unset(COMPILER_RT_BUILD_CRT CACHE) + cmake_dependent_option(COMPILER_RT_BUILD_CRT "Build crtbegin.o/crtend.o" ON "COMPILER_RT_HAS_CRT" OFF) -if(COMPILER_RT_BUILD_CRT) +if (COMPILER_RT_BUILD_CRT) add_compiler_rt_component(crt) option(COMPILER_RT_CRT_USE_EH_FRAME_REGISTRY "Use eh_frame in crtbegin.o/crtend.o" ON) diff --git a/compiler-rt/test/builtins/CMakeLists.txt b/compiler-rt/test/builtins/CMakeLists.txt --- a/compiler-rt/test/builtins/CMakeLists.txt +++ b/compiler-rt/test/builtins/CMakeLists.txt @@ -13,9 +13,10 @@ include(builtin-config-ix) -if (COMPILER_RT_HAS_CRT) +if (COMPILER_RT_BUILD_CRT) list(APPEND BUILTINS_TEST_DEPS crt) endif() +pythonize_bool(COMPILER_RT_BUILD_CRT) # Indicate if this is an MSVC environment. pythonize_bool(MSVC) diff --git a/compiler-rt/test/builtins/Unit/ctor_dtor.c b/compiler-rt/test/builtins/Unit/ctor_dtor.c --- a/compiler-rt/test/builtins/Unit/ctor_dtor.c +++ b/compiler-rt/test/builtins/Unit/ctor_dtor.c @@ -1,4 +1,4 @@ -// REQUIRES: linux +// REQUIRES: crt // RUN: %clang -fno-use-init-array -g -c %s -o %t.o // RUN: %clang -o %t -no-pie -nostdlib %crt1 %crti %crtbegin %t.o -lc %libgcc %crtend %crtn diff --git a/compiler-rt/test/builtins/Unit/dso_handle.cpp b/compiler-rt/test/builtins/Unit/dso_handle.cpp --- a/compiler-rt/test/builtins/Unit/dso_handle.cpp +++ b/compiler-rt/test/builtins/Unit/dso_handle.cpp @@ -1,4 +1,4 @@ -// REQUIRES: linux +// REQUIRES: crt // RUN: %clangxx -g -fno-exceptions -DCRT_SHARED -c %s -fPIC -o %tshared.o // RUN: %clangxx -g -fno-exceptions -c %s -fPIC -o %t.o diff --git a/compiler-rt/test/builtins/Unit/lit.cfg.py b/compiler-rt/test/builtins/Unit/lit.cfg.py --- a/compiler-rt/test/builtins/Unit/lit.cfg.py +++ b/compiler-rt/test/builtins/Unit/lit.cfg.py @@ -106,26 +106,29 @@ base_lib = base_lib.replace("\\", "/") config.substitutions.append(("%librt ", base_lib + " -lc -lm ")) - if config.host_os == "Linux": - base_obj = os.path.join( - config.compiler_rt_libdir, "clang_rt.%%s%s.o" % config.target_suffix - ) - if sys.platform in ["win32"] and execute_external: - # Don't pass dosish path separator to msys bash.exe. - base_obj = base_obj.replace("\\", "/") +builtins_build_crt = get_required_attr(config, "builtins_build_crt") +if builtins_build_crt: + base_obj = os.path.join( + config.compiler_rt_libdir, "clang_rt.%%s%s.o" % config.target_suffix + ) + if sys.platform in ["win32"] and execute_external: + # Don't pass dosish path separator to msys bash.exe. + base_obj = base_obj.replace("\\", "/") - config.substitutions.append(("%crtbegin", base_obj % "crtbegin")) - config.substitutions.append(("%crtend", base_obj % "crtend")) + config.substitutions.append(("%crtbegin", base_obj % "crtbegin")) + config.substitutions.append(("%crtend", base_obj % "crtend")) - config.substitutions.append(("%crt1", get_library_path("crt1.o"))) - config.substitutions.append(("%crti", get_library_path("crti.o"))) - config.substitutions.append(("%crtn", get_library_path("crtn.o"))) + config.substitutions.append(("%crt1", get_library_path("crt1.o"))) + config.substitutions.append(("%crti", get_library_path("crti.o"))) + config.substitutions.append(("%crtn", get_library_path("crtn.o"))) - config.substitutions.append(("%libgcc", get_libgcc_file_name())) + config.substitutions.append(("%libgcc", get_libgcc_file_name())) - config.substitutions.append( - ("%libstdcxx", "-l" + config.sanitizer_cxx_lib.lstrip("lib")) - ) + config.substitutions.append( + ("%libstdcxx", "-l" + config.sanitizer_cxx_lib.lstrip("lib")) + ) + + config.available_features.add("crt") builtins_source_dir = os.path.join( get_required_attr(config, "compiler_rt_src_root"), "lib", "builtins" diff --git a/compiler-rt/test/builtins/Unit/lit.site.cfg.py.in b/compiler-rt/test/builtins/Unit/lit.site.cfg.py.in --- a/compiler-rt/test/builtins/Unit/lit.site.cfg.py.in +++ b/compiler-rt/test/builtins/Unit/lit.site.cfg.py.in @@ -5,6 +5,7 @@ config.target_cflags = "@BUILTINS_TEST_TARGET_CFLAGS@" config.target_arch = "@BUILTINS_TEST_TARGET_ARCH@" config.sanitizer_cxx_lib = "@SANITIZER_TEST_CXX_LIBNAME@" +config.builtins_build_crt = @COMPILER_RT_BUILD_CRT_PYBOOL@ config.is_msvc = @MSVC_PYBOOL@ config.builtins_is_msvc = @BUILTINS_IS_MSVC_PYBOOL@ config.builtins_lit_source_features = "@BUILTINS_LIT_SOURCE_FEATURES@"