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

Alexander Richardson via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Feb 27 08:47:18 PST 2024


================
@@ -172,6 +172,20 @@ def push_dynamic_library_lookup_path(config, new_path):
 # doesn't match config.compiler_rt_libdir then it means we might be testing the
 # compiler's own runtime libraries rather than the ones we just built.
 # Warn about about this and handle appropriately.
+if config.test_standalone_build_libs:
+    if config.compiler_id == "Clang":
+        # Ensure that we use the just-built libraries when linking by overriding
+        # the Clang resource directory. However, this also means that we can no
+        # longer find the builtin headers from that path, so we explicitly add
+        # the builtin headers as an include path.
+        resource_dir, _ = get_path_from_clang(
+            shlex.split(config.target_cflags) + ["-print-resource-dir"], allow_failure=False
+        )
+        config.target_cflags += f" -nobuiltininc"
+        config.target_cflags += f" -I{config.compiler_rt_src_root}/include"
+        config.target_cflags += f" -idirafter {resource_dir}/include"
+        config.target_cflags += f" -resource-dir={config.compiler_rt_obj_root}"
+        config.target_cflags += f" -Wl,--rpath={config.compiler_rt_libdir}"
----------------
arichardson wrote:

> The flags below create kind of a odd mix
> 
> * Some external clang that has its own independent resource directory.
In my case it is actually a clang built from the same monorepo commit hash, but it should also work with a system-provided clang.
> * The external clang is being forced to use a different resource directory than what it was shipped with
The intention of this change is to test the libraries that we actually built just now rather than whatever happened to be installed to clang's resource directory. There is absolutely no guarantee that those match.
> * The external clang is being forced to use a different set of headers than what it was shipped with
The whole point of this extra `-idirafter` is to make sure that the external clang uses its set of headers (the resource_dir variable points to the non-overriden directory).

> 
> I'm not sure that combination is guaranteed to work given that compiler-rt can be tightly coupled with clang.
> 
> If I've read this code correctly the change you've made is on the common path (because `COMPILER_RT_TEST_STANDALONE_BUILD_LIBS` is `ON` by default) but AFAIK your change was never needed before because normally you would build compiler-rt with a just built clang which I think should mean there's no difference between what `-print-resource-dir` reports and `config.compiler_rt_obj_root`. Or have I misunderstood something?

The resource directories will only match if you build everything in on go (I believe with `LLVM_ENABLE_PROJECTS=clang;compiler-rt`). However, I am installing clang first and then building *only* compiler-rt (using the cmake invocation listed above), so the clang resource directory points to where clang was installed.

I order to not affect the all-in-one build I will update the check to not add flags if the resource-dir matches the compiler_rt_objdir. Hopefully that addresses your concerns.



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


More information about the llvm-branch-commits mailing list