[CMake] Use COMPILER_RT_BUILD_CRT in the condition for test
authorPetr Hosek <phosek@google.com>
Wed, 12 Jul 2023 17:41:16 +0000 (17:41 +0000)
committerPetr Hosek <phosek@google.com>
Wed, 12 Jul 2023 22:30:43 +0000 (22:30 +0000)
Unlike COMPILER_RT_HAS_CRT this handles the case where CRT is available
but has been disabled by setting COMPILER_RT_BUILD_CRT. This addresses
an issue reported on D153989.

Differential Revision: https://reviews.llvm.org/D155126

compiler-rt/lib/builtins/CMakeLists.txt
compiler-rt/test/builtins/CMakeLists.txt
compiler-rt/test/builtins/Unit/ctor_dtor.c
compiler-rt/test/builtins/Unit/dso_handle.cpp
compiler-rt/test/builtins/Unit/lit.cfg.py
compiler-rt/test/builtins/Unit/lit.site.cfg.py.in

index 45d68fd..7f00391 100644 (file)
@@ -895,9 +895,14 @@ if(COMPILER_RT_BUILD_STANDALONE_LIBATOMIC)
   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)
index 2d0cc24..7c0469a 100644 (file)
@@ -13,9 +13,10 @@ configure_lit_site_cfg(
 
 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)
index 2fdd2f7..4756072 100644 (file)
@@ -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
index 00c5491..7967469 100644 (file)
@@ -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
index 16d5a46..f63d159 100644 (file)
@@ -106,26 +106,29 @@ else:
         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"
index 920c915..a42d5c1 100644 (file)
@@ -5,6 +5,7 @@ config.builtins_lit_source_dir = "@BUILTINS_LIT_SOURCE_DIR@/Unit"
 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@"