Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Conversation

arichardson
Copy link
Member

@arichardson arichardson commented Feb 27, 2024

Currently, the testsuite uses the default runtimes path to find the
runtimes libraries which may or may not match the just-built runtimes.
This change uses the -resource-dir flag for clang whenever
COMPILER_RT_TEST_STANDALONE_BUILD_LIBS is set to ensure that we are
actually testing the currently built libraries rather than the ones
bundled with ${COMPILER_RT_TEST_COMPILER}.

The existing logic works fine when clang and compiler-rt share the same
build directory ``-DLLVM_ENABLE_PROJECTS=clang;compiler-rt`, but when
building compiler-rt separately we need to tell the compiler used for
the tests where it can find the just-built libraries.

This reduces the fixes check-all failures to one in my configuration:

cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -G Ninja
-DCMAKE_C_COMPILER=$HOME/output/upstream-llvm/bin/clang
-DCMAKE_CXX_COMPILER=$HOME/output/upstream-llvm/bin/clang++
-DCOMPILER_RT_INCLUDE_TESTS=ON
-DLLVM_EXTERNAL_LIT=$HOME/build/upstream-llvm-project-build/bin/llvm-lit
-DLLVM_CMAKE_DIR=$HOME/output/upstream-llvm
-DCOMPILER_RT_DEBUG=OFF
-S $HOME/src/upstream-llvm-project/compiler-rt
-B $HOME/src/upstream-llvm-project/compiler-rt/cmake-build-all-sanitizers

@llvmbot
Copy link
Member

llvmbot commented Feb 27, 2024

@llvm/pr-subscribers-xray

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Alexander Richardson (arichardson)

Changes

Currently, the testsuite uses the default runtimes path to find the
runtimes libraries which may or may not match the just-built runtimes.
This change uses the -resource-dir flag for clang whenever
COMPILER_RT_TEST_STANDALONE_BUILD_LIBS is set to ensure that we are
actually testing the currently built libraries rather than the ones
bundled with ${COMPILER_RT_TEST_COMPILER}.

This mostly fixes check-all in my configuration:

cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -G Ninja
-DCMAKE_C_COMPILER=$HOME/output/upstream-llvm/bin/clang
-DCMAKE_CXX_COMPILER=$HOME/output/upstream-llvm/bin/clang++
-DCOMPILER_RT_INCLUDE_TESTS=ON
-DLLVM_EXTERNAL_LIT=$HOME/build/upstream-llvm-project-build/bin/llvm-lit
-DLLVM_CMAKE_DIR=$HOME/output/upstream-llvm
-DCOMPILER_RT_DEBUG=OFF
-S $HOME/src/upstream-llvm-project/compiler-rt
-B $HOME/src/upstream-llvm-project/compiler-rt/cmake-build-all-sanitizers

I am still seeing two test failures due to an msan error inside
__gxx_personality_v0, but that is most likely due to an uninstrumented
/lib/x86_64-linux-gnu/libgcc_s.so.1 being used by these tests.


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

5 Files Affected:

  • (modified) compiler-rt/CMakeLists.txt (+24)
  • (modified) compiler-rt/test/CMakeLists.txt (-8)
  • (modified) compiler-rt/test/fuzzer/lit.cfg.py (+1)
  • (modified) compiler-rt/test/lit.common.cfg.py (+35-21)
  • (modified) compiler-rt/test/safestack/lit.cfg.py (+2-2)
diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index bbb4e8d7c333e4..68ed37498587c6 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -571,6 +571,30 @@ string(APPEND COMPILER_RT_TEST_COMPILER_CFLAGS " ${stdlib_flag}")
 string(REPLACE " " ";" COMPILER_RT_UNITTEST_CFLAGS "${COMPILER_RT_TEST_COMPILER_CFLAGS}")
 set(COMPILER_RT_UNITTEST_LINK_FLAGS ${COMPILER_RT_UNITTEST_CFLAGS})
 
+option(COMPILER_RT_TEST_STANDALONE_BUILD_LIBS
+  "When set to ON and testing in a standalone build, test the runtime \
+  libraries built by this standalone build rather than the runtime libraries \
+  shipped with the compiler (used for testing). When set to OFF and testing \
+  in a standalone build, test the runtime libraries shipped with the compiler \
+  (used for testing). This option has no effect if the compiler and this \
+  build are configured to use the same runtime library path."
+  ON)
+if (COMPILER_RT_TEST_STANDALONE_BUILD_LIBS)
+  # Ensure that the unit tests can find the sanitizer headers prior to installation.
+  list(APPEND COMPILER_RT_UNITTEST_CFLAGS "-I${CMAKE_CURRENT_LIST_DIR}/include")
+  # Ensure that unit tests link against the just-built runtime libraries instead
+  # of the ones bundled with the compiler by overriding the resource directory.
+  #
+  if ("${COMPILER_RT_TEST_COMPILER_ID}" MATCHES "Clang")
+    list(APPEND COMPILER_RT_UNITTEST_LINK_FLAGS "-resource-dir=${CMAKE_CURRENT_BINARY_DIR}")
+  endif()
+  get_compiler_rt_output_dir(${COMPILER_RT_DEFAULT_TARGET_ARCH} output_dir)
+  list(APPEND COMPILER_RT_UNITTEST_LINK_FLAGS "-Wl,-rpath,${output_dir}")
+endif()
+message(WARNING "COMPILER_RT_UNITTEST_LINK_FLAGS=${COMPILER_RT_UNITTEST_LINK_FLAGS}, COMPILER_RT_TEST_STANDALONE_BUILD_LIBS=${COMPILER_RT_TEST_STANDALONE_BUILD_LIBS} COMPILER_RT_TEST_COMPILER_ID=${COMPILER_RT_TEST_COMPILER_ID}")
+
+
+
 if(COMPILER_RT_USE_LLVM_UNWINDER)
   # We're linking directly against the libunwind that we're building so don't
   # try to link in the toolchain's default libunwind which may be missing.
diff --git a/compiler-rt/test/CMakeLists.txt b/compiler-rt/test/CMakeLists.txt
index c186be1e44fd9a..edc007aaf477a7 100644
--- a/compiler-rt/test/CMakeLists.txt
+++ b/compiler-rt/test/CMakeLists.txt
@@ -1,14 +1,6 @@
 # Needed for lit support in standalone builds.
 include(AddLLVM)
 
-option(COMPILER_RT_TEST_STANDALONE_BUILD_LIBS
-  "When set to ON and testing in a standalone build, test the runtime \
-  libraries built by this standalone build rather than the runtime libraries \
-  shipped with the compiler (used for testing). When set to OFF and testing \
-  in a standalone build, test the runtime libraries shipped with the compiler \
-  (used for testing). This option has no effect if the compiler and this \
-  build are configured to use the same runtime library path."
-  ON)
 pythonize_bool(COMPILER_RT_TEST_STANDALONE_BUILD_LIBS)
 
 pythonize_bool(LLVM_ENABLE_EXPENSIVE_CHECKS)
diff --git a/compiler-rt/test/fuzzer/lit.cfg.py b/compiler-rt/test/fuzzer/lit.cfg.py
index 4e203236b16708..29fd45dbc02fa4 100644
--- a/compiler-rt/test/fuzzer/lit.cfg.py
+++ b/compiler-rt/test/fuzzer/lit.cfg.py
@@ -101,6 +101,7 @@ def generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True, msan_enabled=False):
     return " ".join(
         [
             compiler_cmd,
+            config.target_cflags,
             std_cmd,
             "-O2 -gline-tables-only",
             sanitizers_cmd,
diff --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py
index 113777b0ea8a19..6753389ec5bf27 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/compiler-rt/test/lit.common.cfg.py
@@ -14,6 +14,26 @@
 import lit.util
 
 
+def get_path_from_clang(args, allow_failure):
+    clang_cmd = [
+        config.clang.strip(),
+        f"--target={config.target_triple}",
+        *args,
+    ]
+    path = None
+    try:
+        result = subprocess.run(
+            clang_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True
+        )
+        path = result.stdout.decode().strip()
+    except subprocess.CalledProcessError as e:
+        msg = f"Failed to run {clang_cmd}\nrc:{e.returncode}\nstdout:{e.stdout}\ne.stderr{e.stderr}"
+        if allow_failure:
+            lit_config.warning(msg)
+        else:
+            lit_config.fatal(msg)
+    return path, clang_cmd
+
 def find_compiler_libdir():
     """
     Returns the path to library resource directory used
@@ -26,26 +46,6 @@ def find_compiler_libdir():
         # TODO: Support other compilers.
         return None
 
-    def get_path_from_clang(args, allow_failure):
-        clang_cmd = [
-            config.clang.strip(),
-            f"--target={config.target_triple}",
-        ]
-        clang_cmd.extend(args)
-        path = None
-        try:
-            result = subprocess.run(
-                clang_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True
-            )
-            path = result.stdout.decode().strip()
-        except subprocess.CalledProcessError as e:
-            msg = f"Failed to run {clang_cmd}\nrc:{e.returncode}\nstdout:{e.stdout}\ne.stderr{e.stderr}"
-            if allow_failure:
-                lit_config.warning(msg)
-            else:
-                lit_config.fatal(msg)
-        return path, clang_cmd
-
     # Try using `-print-runtime-dir`. This is only supported by very new versions of Clang.
     # so allow failure here.
     runtime_dir, clang_cmd = get_path_from_clang(
@@ -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}"
 compiler_libdir = find_compiler_libdir()
 if compiler_libdir:
     compiler_rt_libdir_real = os.path.realpath(config.compiler_rt_libdir)
@@ -182,7 +196,7 @@ def push_dynamic_library_lookup_path(config, new_path):
             f'compiler-rt libdir:  "{compiler_rt_libdir_real}"'
         )
         if config.test_standalone_build_libs:
-            # Use just built runtime libraries, i.e. the the libraries this built just built.
+            # Use just built runtime libraries, i.e. the libraries this build just built.
             if not config.test_suite_supports_overriding_runtime_lib_path:
                 # Test suite doesn't support this configuration.
                 # TODO(dliew): This should be an error but it seems several bots are
diff --git a/compiler-rt/test/safestack/lit.cfg.py b/compiler-rt/test/safestack/lit.cfg.py
index adf27a0d7e5eab..bdc316e2f6bc74 100644
--- a/compiler-rt/test/safestack/lit.cfg.py
+++ b/compiler-rt/test/safestack/lit.cfg.py
@@ -13,10 +13,10 @@
 
 # Add clang substitutions.
 config.substitutions.append(
-    ("%clang_nosafestack ", config.clang + " -O0 -fno-sanitize=safe-stack ")
+    ("%clang_nosafestack ", config.clang + config.target_cflags + " -O0 -fno-sanitize=safe-stack ")
 )
 config.substitutions.append(
-    ("%clang_safestack ", config.clang + " -O0 -fsanitize=safe-stack ")
+    ("%clang_safestack ", config.clang + config.target_cflags + " -O0 -fsanitize=safe-stack ")
 )
 
 if config.lto_supported:

Copy link
Contributor

@delcypher delcypher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the [𝘀𝗽𝗿] initial version commit message about?

# 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. It's been a while since I looked at this code. If you use a different resource directory why can't the compiler use the header files in that resource directory?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm overriding the resource directory to point at the compiler-rt build directory. Unlike the clang install dir it won't contain the builtin headers (e.g. stdint.h, stddef.h, etc.). I could copy those files, but using this approach is less error prone.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarified comment, should hopefully address this.

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}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flags below create kind of a odd mix

  • Some external clang that has its own independent resource directory.
  • The external clang is being forced to use a different resource directory than what it was shipped with
  • The external clang is being forced to use a different set of headers than what it was shipped with

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arichardson To be clear. I'm not necessarily against your change but I'm a bit concerned about your change being on the default path given that it's not normally necessary.

Copy link
Member Author

@arichardson arichardson Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic has been updated now to only add these flags when using the non-LLVM_ENABLE_PROJECTS=clang;compiler-rt build.

@arichardson
Copy link
Member Author

What is the [𝘀𝗽𝗿] initial version commit message about?

I'm trying to use getcord/spr for stacked pull requests and it appears this is what it does to the commit messages when uploading them.

Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
@MaskRay
Copy link
Member

MaskRay commented Feb 27, 2024

wants to merge 2 commits into users/arichardson/spr/main.compiler-rt-allow-running-tests-without-installing-first

Note: since the base branch is not main, "Squash and merge" will not merge the patch to "main", but you can manually push it to main after approved. You can still click "Squash and merge" so that the PR shows "merged".

Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a regular clang build at /tmp/Rel. If I create a standalone compiler-rt build at /tmp/out/crt, I see that with this PR, clang invoked by llvm-lit will get -resource-dir=/tmp/out/crt -Wl,-rpath,/tmp/out/crt/lib/linux, which utilizes include/sanitizer/*_interface.h (used by certain asan tests) and runtime libraries.

#include <sanitizer/allocator_interface.h>
#include "sanitizer/asan_interface.h"

@arichardson
Copy link
Member Author

wants to merge 2 commits into users/arichardson/spr/main.compiler-rt-allow-running-tests-without-installing-first

Note: since the base branch is not main, "Squash and merge" will not merge the patch to "main", but you can manually push it to main after approved. You can still click "Squash and merge" so that the PR shows "merged".

Thanks, trying to get my head around using spr, but I'm a bit scared of spr land, so I will probably edit the base branch of the PR in the web UI and land from there.

# 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"
Copy link
Member

@MaskRay MaskRay Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered whether target_cflags can be made to a list instead of space-separated str, but I think it doesn't really improve.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this would be cleaner, I will submit an independent cleanup PR.

@arichardson arichardson changed the base branch from users/arichardson/spr/main.compiler-rt-allow-running-tests-without-installing-first to main February 27, 2024 21:27
Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
@llvmbot llvmbot added compiler-rt:asan Address sanitizer compiler-rt:tsan Thread sanitizer compiler-rt:scudo Scudo Hardened Allocator xray labels Mar 2, 2024
arichardson added a commit to arichardson/upstream-llvm-project that referenced this pull request Mar 7, 2024
Since this standalone build configuration uses the runtime libraries that
are being built just now, we need to ensure that e.g. the TSan unit tests
depend on the tsan runtime library. Also fix TSAN_DEPS being overridden
to not include the tsan runtime (commit .....).
This change fixes a build race seen in the CI checks for
TsanRtlTest-x86_64-Test in llvm#83088.

Pull Request: llvm#83650
arichardson added a commit to arichardson/upstream-llvm-project that referenced this pull request Mar 7, 2024
With llvm#83088, we now need the
runtimes to be built before running test if
COMPILER_RT_TEST_STANDALONE_BUILD_LIBS is true, since otherwise we
get failures running `ninja check-all` such as the following:
```
/usr/bin/ld: cannot find .../compiler-rt/cmake-build-all-sanitizers/lib/linux/libclang_rt.fuzzer-x86_64.a: No such file or directory
/usr/bin/ld: cannot find .../compiler-rt/cmake-build-all-sanitizers/lib/linux/libclang_rt.xray-x86_64.a: No such file or directory
/usr/bin/ld: cannot find .../compiler-rt/cmake-build-all-sanitizers/lib/linux/libclang_rt.xray-basic-x86_64.a: No such file or directory
/usr/bin/ld: cannot find .../compiler-rt/cmake-build-all-sanitizers/lib/linux/libclang_rt.xray-fdr-x86_64.a: No such file or directory
```

This is a follow-up to 058e9b0 which started removing these checks
and it should make it easier to stop forcing COMPILER_RT_STANDALONE_BUILD
for runtimes builds in the future.

Pull Request: llvm#83651
arichardson added a commit to arichardson/upstream-llvm-project that referenced this pull request Mar 7, 2024
Currently, the testsuite uses the default runtimes path to find the
runtimes libraries which may or may not match the just-built runtimes.
This change uses the -resource-dir flag for clang whenever
COMPILER_RT_TEST_STANDALONE_BUILD_LIBS is set to ensure that we are
actually testing the currently built libraries rather than the ones
bundled with ${COMPILER_RT_TEST_COMPILER}.

The existing logic works fine when clang and compiler-rt share the same
build directory -DLLVM_ENABLE_PROJECTS=clang;compiler-rt, but when building
compiler-rt separately we need to tell the compiler used for the tests
where it can find the just-built libraries.


This mostly fixes check-all in my configuration:
```
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -G Ninja
-DCMAKE_C_COMPILER=$HOME/output/upstream-llvm/bin/clang
-DCMAKE_CXX_COMPILER=$HOME/output/upstream-llvm/bin/clang++
-DCOMPILER_RT_INCLUDE_TESTS=ON
-DLLVM_EXTERNAL_LIT=$HOME/build/upstream-llvm-project-build/bin/llvm-lit
-DLLVM_CMAKE_DIR=$HOME/output/upstream-llvm
-DCOMPILER_RT_DEBUG=OFF
-S $HOME/src/upstream-llvm-project/compiler-rt
-B $HOME/src/upstream-llvm-project/compiler-rt/cmake-build-all-sanitizers
```

I am still seeing two test failures due to an msan error inside
__gxx_personality_v0, but that is most likely due to an uninstrumented
`/lib/x86_64-linux-gnu/libgcc_s.so.1` being used by these tests.

Pull Request: llvm#83088
Copy link
Collaborator

@vitalybuka vitalybuka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there are a bunch of CMAKE related patches from you.
If possible, please try to land them with delay in-between for easier reverts if needed.

Copy link
Contributor

@delcypher delcypher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing my feedback. I have a minor nit that you can address if you feel its worth it. When landing please make sure you squash your commits into a single commit and rewrite the commit message to be something that conforms to LLVM's style for commit messages.

@arichardson
Copy link
Member Author

Looks like there are a bunch of CMAKE related patches from you. If possible, please try to land them with delay in-between for easier reverts if needed.

Thanks, I'll make sure to leave enough delays for buildbots to shout at me when landing these changes :)

arichardson added a commit that referenced this pull request Mar 18, 2024
With #83088, we now need the
runtimes to be built before running test if
COMPILER_RT_TEST_STANDALONE_BUILD_LIBS is true, since otherwise we
get failures running `ninja check-all` such as the following:
```
/usr/bin/ld: cannot find .../compiler-rt/cmake-build-all-sanitizers/lib/linux/libclang_rt.fuzzer-x86_64.a: No such file or directory
/usr/bin/ld: cannot find .../compiler-rt/cmake-build-all-sanitizers/lib/linux/libclang_rt.xray-x86_64.a: No such file or directory
/usr/bin/ld: cannot find .../compiler-rt/cmake-build-all-sanitizers/lib/linux/libclang_rt.xray-basic-x86_64.a: No such file or directory
/usr/bin/ld: cannot find .../compiler-rt/cmake-build-all-sanitizers/lib/linux/libclang_rt.xray-fdr-x86_64.a: No such file or directory
```

This is a follow-up to 058e9b0 which started removing these checks
and it should make it easier to stop forcing COMPILER_RT_STANDALONE_BUILD
for runtimes builds in the future.

Reviewed By: vitalybuka

Pull Request: #83651
arichardson added a commit that referenced this pull request Mar 21, 2024
Since this standalone build configuration uses the runtime libraries that
are being built just now, we need to ensure that e.g. the TSan unit tests
depend on the tsan runtime library. Also fix TSAN_DEPS being overridden
to not include the tsan runtime (commit .....).
This change fixes a build race seen in the CI checks for
TsanRtlTest-x86_64-Test in #83088.

Reviewed By: vitalybuka

Pull Request: #83650
Created using spr 1.3.6-beta.1

[skip ci]
Created using spr 1.3.6-beta.1
chencha3 pushed a commit to chencha3/llvm-project that referenced this pull request Mar 23, 2024
With llvm#83088, we now need the
runtimes to be built before running test if
COMPILER_RT_TEST_STANDALONE_BUILD_LIBS is true, since otherwise we
get failures running `ninja check-all` such as the following:
```
/usr/bin/ld: cannot find .../compiler-rt/cmake-build-all-sanitizers/lib/linux/libclang_rt.fuzzer-x86_64.a: No such file or directory
/usr/bin/ld: cannot find .../compiler-rt/cmake-build-all-sanitizers/lib/linux/libclang_rt.xray-x86_64.a: No such file or directory
/usr/bin/ld: cannot find .../compiler-rt/cmake-build-all-sanitizers/lib/linux/libclang_rt.xray-basic-x86_64.a: No such file or directory
/usr/bin/ld: cannot find .../compiler-rt/cmake-build-all-sanitizers/lib/linux/libclang_rt.xray-fdr-x86_64.a: No such file or directory
```

This is a follow-up to 058e9b0 which started removing these checks
and it should make it easier to stop forcing COMPILER_RT_STANDALONE_BUILD
for runtimes builds in the future.

Reviewed By: vitalybuka

Pull Request: llvm#83651
chencha3 pushed a commit to chencha3/llvm-project that referenced this pull request Mar 23, 2024
Since this standalone build configuration uses the runtime libraries that
are being built just now, we need to ensure that e.g. the TSan unit tests
depend on the tsan runtime library. Also fix TSAN_DEPS being overridden
to not include the tsan runtime (commit .....).
This change fixes a build race seen in the CI checks for
TsanRtlTest-x86_64-Test in llvm#83088.

Reviewed By: vitalybuka

Pull Request: llvm#83650
goldsteinn and others added 3 commits April 6, 2024 17:52
Created using spr 1.3.6-beta.1

[skip ci]
Created using spr 1.3.6-beta.1
@arichardson arichardson changed the base branch from users/arichardson/spr/main.compiler-rt-allow-running-tests-without-installing-first-3 to main April 7, 2024 16:50
@arichardson arichardson merged commit c91254d into main Apr 7, 2024
3 checks passed
@arichardson arichardson deleted the users/arichardson/spr/compiler-rt-allow-running-tests-without-installing-first branch April 7, 2024 16:50
@jplehr
Copy link
Contributor

jplehr commented Apr 7, 2024

Hi. This may have caused a breakage on one of our buildbots https://lab.llvm.org/buildbot/#/builders/165/builds/51837
Let me know if you need some assistance.

@dyung
Copy link
Collaborator

dyung commented Apr 7, 2024

We are also seeing similar problems with our internal builder after this commit:

FAILED: projects/compiler-rt/lib/memprof/tests/MemProfUnitTests 
: && /usr/lib/ccache/g++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -O3 -DNDEBUG -fuse-ld=gold    -resource-dir=/home/jenkins/j/w/workspace/opensource/opensource_build/build/./lib/../lib/clang/19 -Wl,-rpath,/home/jenkins/j/w/workspace/opensource/opensource_build/build/./lib/../lib/clang/19/lib/x86_64-unknown-linux-gnu -pthread <snip>
g++: error: unrecognized command line option ‘-resource-dir=/home/jenkins/j/w/workspace/opensource/opensource_build/build/./lib/../lib/clang/19’

@saiislam
Copy link
Contributor

saiislam commented Apr 8, 2024

Hey @arichardson

I had to just revert this patch with 2084a07 because it was breaking the buildbot as mentioned by @jplehr earlier along with our local builds.

In both cases, the error was the same : unrecognized command-line option ‘-resource-dir=

Let me or @jplehr know if we can assist you in anyway.

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}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the fix for Windows that was made in 10b1864, 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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Unfortunately I don't have a way of testing this on Windows, and I was hoping the pre-commit CI would have caught it but I guess that does not include mingw.

@arichardson
Copy link
Member Author

We are also seeing similar problems with our internal builder after this commit:

FAILED: projects/compiler-rt/lib/memprof/tests/MemProfUnitTests 
: && /usr/lib/ccache/g++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -O3 -DNDEBUG -fuse-ld=gold    -resource-dir=/home/jenkins/j/w/workspace/opensource/opensource_build/build/./lib/../lib/clang/19 -Wl,-rpath,/home/jenkins/j/w/workspace/opensource/opensource_build/build/./lib/../lib/clang/19/lib/x86_64-unknown-linux-gnu -pthread <snip>
g++: error: unrecognized command line option ‘-resource-dir=/home/jenkins/j/w/workspace/opensource/opensource_build/build/./lib/../lib/clang/19’

That sounds like a either a misconfigured build-bot or a bug in compiler-rt tests using the host compiler instead of the test compiler for this target? This flag will only be added if COMPILER_RT_TEST_COMPILER_ID==Clang, so it definitely should not be added for GCC.

@dyung
Copy link
Collaborator

dyung commented Apr 8, 2024

We are also seeing similar problems with our internal builder after this commit:

FAILED: projects/compiler-rt/lib/memprof/tests/MemProfUnitTests 
: && /usr/lib/ccache/g++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -O3 -DNDEBUG -fuse-ld=gold    -resource-dir=/home/jenkins/j/w/workspace/opensource/opensource_build/build/./lib/../lib/clang/19 -Wl,-rpath,/home/jenkins/j/w/workspace/opensource/opensource_build/build/./lib/../lib/clang/19/lib/x86_64-unknown-linux-gnu -pthread <snip>
g++: error: unrecognized command line option ‘-resource-dir=/home/jenkins/j/w/workspace/opensource/opensource_build/build/./lib/../lib/clang/19’

That sounds like a either a misconfigured build-bot or a bug in compiler-rt tests using the host compiler instead of the test compiler for this target? This flag will only be added if COMPILER_RT_TEST_COMPILER_ID==Clang, so it definitely should not be added for GCC.

It was working before your change, and it is a similar failure as what @jplehr's buildbot reported (they seem to be using /usr/bin/c++ as the compiler, not clang).

@vitalybuka
Copy link
Collaborator

vitalybuka commented Apr 8, 2024

Build bot still uses '-DLLVM_ENABLE_PROJECTS=clang;lld;clang-tools-extra;compiler-rt'
compiler-rt should go to DLLVM_ENABLE_RUNTIMES

can be updated here https://github.com/llvm/llvm-zorg/blob/3ed3d915a9d4de7967dd20a35a9a266b09cdba86/zorg/buildbot/builders/annotated/hip-build.sh#L82

@arichardson
Copy link
Member Author

We are also seeing similar problems with our internal builder after this commit:

FAILED: projects/compiler-rt/lib/memprof/tests/MemProfUnitTests 
: && /usr/lib/ccache/g++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -O3 -DNDEBUG -fuse-ld=gold    -resource-dir=/home/jenkins/j/w/workspace/opensource/opensource_build/build/./lib/../lib/clang/19 -Wl,-rpath,/home/jenkins/j/w/workspace/opensource/opensource_build/build/./lib/../lib/clang/19/lib/x86_64-unknown-linux-gnu -pthread <snip>
g++: error: unrecognized command line option ‘-resource-dir=/home/jenkins/j/w/workspace/opensource/opensource_build/build/./lib/../lib/clang/19’

That sounds like a either a misconfigured build-bot or a bug in compiler-rt tests using the host compiler instead of the test compiler for this target? This flag will only be added if COMPILER_RT_TEST_COMPILER_ID==Clang, so it definitely should not be added for GCC.

It was working before your change, and it is a similar failure as what @jplehr's buildbot reported (they seem to be using /usr/bin/c++ as the compiler, not clang).

Should be fixed by #88074. This was a pre-existing bug that just happened to be exposed by this change.

@dyung
Copy link
Collaborator

dyung commented Apr 9, 2024

We are also seeing similar problems with our internal builder after this commit:

FAILED: projects/compiler-rt/lib/memprof/tests/MemProfUnitTests 
: && /usr/lib/ccache/g++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -O3 -DNDEBUG -fuse-ld=gold    -resource-dir=/home/jenkins/j/w/workspace/opensource/opensource_build/build/./lib/../lib/clang/19 -Wl,-rpath,/home/jenkins/j/w/workspace/opensource/opensource_build/build/./lib/../lib/clang/19/lib/x86_64-unknown-linux-gnu -pthread <snip>
g++: error: unrecognized command line option ‘-resource-dir=/home/jenkins/j/w/workspace/opensource/opensource_build/build/./lib/../lib/clang/19’

That sounds like a either a misconfigured build-bot or a bug in compiler-rt tests using the host compiler instead of the test compiler for this target? This flag will only be added if COMPILER_RT_TEST_COMPILER_ID==Clang, so it definitely should not be added for GCC.

It was working before your change, and it is a similar failure as what @jplehr's buildbot reported (they seem to be using /usr/bin/c++ as the compiler, not clang).

Should be fixed by #88074. This was a pre-existing bug that just happened to be exposed by this change.

Thanks! I'm also updating our internal builder to use -DLLVM_ENABLE_RUNTIMES as @vitalybuka indicated. Our bot was setup a long time ago and seems to have gotten out of date.

arichardson added a commit that referenced this pull request Apr 9, 2024
Unlike the other compiler-rt unit tests MemProf was not using the
`generate_compiler_rt_tests()` helper that ensures the test is compiled
using the test compiler (generally the Clang binary built earlier).
This was exposed by #83088
because it started adding Clang-specific flags to
COMPILER_RT_UNITTEST_CFLAGS if the compiler ID matched "Clang".

This change should fix the buildbots that compile compiler-rt using
a GCC compiler with LLVM_ENABLE_PROJECTS=compiler-rt.

Reviewed By: vitalybuka

Pull Request: #88074
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants