[compiler-rt] [compiler-rt] Allow running tests without installing first (PR #83088)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 8 03:26:09 PDT 2024


================
@@ -168,10 +169,51 @@ def push_dynamic_library_lookup_path(config, new_path):
             r"/i386(?=-[^/]+$)", "/x86_64", config.compiler_rt_libdir
         )
 
+
+# Check if the test compiler resource dir matches the local build directory
+# (which happens with -DLLVM_ENABLE_PROJECTS=clang;compiler-rt) or if we are
+# using an installed clang to test compiler-rt standalone. In the latter case
+# we may need to override the resource dir to match the path of the just-built
+# compiler-rt libraries.
+test_cc_resource_dir, _ = get_path_from_clang(
+    shlex.split(config.target_cflags) + ["-print-resource-dir"], allow_failure=True
+)
+# Normalize the path for comparison
+if test_cc_resource_dir is not None:
+    test_cc_resource_dir = os.path.realpath(test_cc_resource_dir)
+if lit_config.debug:
+    lit_config.note(f"Resource dir for {config.clang} is {test_cc_resource_dir}")
+local_build_resource_dir = os.path.realpath(config.compiler_rt_output_dir)
+if test_cc_resource_dir != local_build_resource_dir and config.test_standalone_build_libs:
+    if config.compiler_id == "Clang":
+        if lit_config.debug:
+            lit_config.note(
+                f"Overriding test compiler resource dir to use "
+                f'libraries in "{config.compiler_rt_libdir}"'
+            )
+        # Ensure that we use the just-built static libraries when linking by
+        # overriding the Clang resource directory. Additionally, we want to use
+        # the builtin headers shipped with clang (e.g. stdint.h), so we
+        # explicitly add this as an include path (since the headers are not
+        # going to be in the current compiler-rt build directory).
+        # We also tell the linker to add an RPATH entry for the local library
+        # directory so that the just-built shared libraries are used.
+        config.target_cflags += f" -nobuiltininc"
+        config.target_cflags += f" -I{config.compiler_rt_src_root}/include"
+        config.target_cflags += f" -idirafter {test_cc_resource_dir}/include"
+        config.target_cflags += f" -resource-dir={config.compiler_rt_output_dir}"
+        config.target_cflags += f" -Wl,-rpath,{config.compiler_rt_libdir}"
----------------
mstorsjo wrote:

In addition to the fix for Windows that was made in 10b1864dff816174cd83fb2d3bc622e25fcf0f8a, this bit here also would need a similar condition - otherwise testing fails with the same error, see e.g. https://github.com/mstorsjo/llvm-mingw/actions/runs/8592846078/job/23549755414.

I see that this whole PR was reverted later, but when preparing for a reland, make sure to conditionalize this case of `-Wl,-rpath` as well.

https://github.com/llvm/llvm-project/pull/83088


More information about the llvm-commits mailing list