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] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend #92460

Merged
merged 47 commits into from
Jul 9, 2024

Conversation

cjappl
Copy link
Contributor

@cjappl cjappl commented May 16, 2024

Introducing the main runtime of realtime sanitizer. For more information, please see the discourse thread. We have also put together a reviewer support document to show what our intention is.

This review introduces the sanitizer backend. This includes:

  • CMake build files (largely adapted from asan).
  • Main RTSan architecture (the external API, thread local context, stack).
  • Interceptors.
  • Many unit tests.

Please see the reviewer support document for what our next steps are. We are moving in lockstep with this PR #84983 for the codegen coming up next.

Note to reviewers: If you see support documentation mention "RADSan", this was the "old acronym" for the realtime sanitizer, they refer to the same thing. If you see it let us know and we can correct it (especially in the llvm codebase)

Copy link

⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.
Please turn off Keep my email addresses private setting in your account.
See LLVM Discourse for more information.

Copy link

github-actions bot commented May 16, 2024

✅ With the latest revision this PR passed the Python code formatter.

Copy link

github-actions bot commented May 16, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@@ -1382,6 +1382,10 @@ collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
StaticRuntimes.push_back("asan_cxx");
}

if (!SanArgs.needsSharedRt() && SanArgs.needsRadsanRt()) {
StaticRuntimes.push_back("radsan");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One question we have here: What is the SharedRuntimes vs StaticRuntimes? Why would we need to support both? This is one change we "eyeballed" based on the other sanitizers.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, if I can summarize the important bits in my own words:

Different platforms have different defaults they use for the sanitizers, some (Darwin, for example) use shared, others (clang on Linux) use static.

A user can specify and override the default with the flags -[shared|static]-libsan.

To support the most possible configurations, do you think we should add back in the ability to link the shared library in this file? In Darwin.cpp we already show the ability to link the shared runtime, so it seemingly would be as simple as adding in a:

    if (SanArgs.needsRadsanRt())
      SharedRuntimes.push_back("radsan");

To the block above. Any advice?

@@ -32,6 +32,9 @@ set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
${LOONGARCH64})
set(ALL_ASAN_ABI_SUPPORTED_ARCH ${X86_64} ${ARM64} ${ARM64_32})
set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${LOONGARCH64})
set(ALL_RADSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
${LOONGARCH64})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was copied from ASAN, is this acceptable? We don't have all architectures to test, although we think that our interceptors are simple enough to work on any machine (no platform specific assembly in our code, for example)

@cjappl
Copy link
Contributor Author

cjappl commented May 16, 2024

Pinging possibly interested parties for review.

@yln @vitalybuka @Sirraide @AaronBallman @dougsonos @davidtrevelyan

Please feel free to add more, we don't know who all may be interested. Thanks in advance

@cjappl cjappl closed this May 16, 2024
@cjappl cjappl reopened this May 16, 2024
@cjappl cjappl changed the title Realtime Sanitizer: Introduce RADSan backend [compiler-rt] Realtime Sanitizer: Introduce RADSan backend May 16, 2024
compiler-rt/test/radsan/lit.cfg.py Outdated Show resolved Hide resolved
compiler-rt/test/radsan/lit.cfg.py Outdated Show resolved Hide resolved
compiler-rt/lib/radsan/radsan_stack.cpp Outdated Show resolved Hide resolved
compiler-rt/lib/radsan/radsan_context.h Outdated Show resolved Hide resolved

namespace detail {

static pthread_key_t Key;
Copy link
Member

Choose a reason for hiding this comment

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

Avoid VariableName in new compiler-rt code.

Use the recommended variable_name like asan/hwasan/lsan. Some new compiler-rt subprojects used Variable as cargo culting llvm/ and clang/, which is a pity (you can also read https://llvm.org/docs/Proposals/VariableNames.html for more history)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great thanks!! Before I go through and edit these, snake_case is preferred for variables in all contexts?

Really appreciate the review. Pushing up most of your requested changes now.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, variable_name and FunctionName.. Sorry if this change may take a while.
asan/hwasan/lsan are good examples to follow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No apology necessary! Happy to do this right the first time.

Does this also apply to lambdas?

  auto Func = [&vec]() { vec.push_back(0.4f); };

Should this become:

  auto func = [&vec]() { vec.push_back(0.4f); };

Or remain "function case"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pushed the change for all non-lambda variable names, happy to change the lambdas too based on your feedback.

compiler-rt/lib/radsan/radsan_stack.cpp Outdated Show resolved Hide resolved
compiler-rt/lib/radsan/radsan_interceptors.cpp Outdated Show resolved Hide resolved
compiler-rt/lib/radsan/radsan.h Outdated Show resolved Hide resolved
@MaskRay
Copy link
Member

MaskRay commented May 21, 2024

https://discourse.llvm.org/t/rfc-nolock-and-noalloc-attributes/76837/75 contains a discussion about the subproject name.
Do you have opinions? @llvm/pr-subscribers-sanitizer @compnerd @petrhosek @isanbard

@cjappl
Copy link
Contributor Author

cjappl commented May 23, 2024

Weekly ping of reviewers

@yln @vitalybuka @Sirraide @AaronBallman @zygoloid @compnerd @petrhosek @isanbard

Looking for weighing in on any of the code as it stands now, or the naming question posed by MaskRay here, so far there seems to be support for rtsan over radsan :)

@cjappl
Copy link
Contributor Author

cjappl commented May 30, 2024

@dougsonos
Copy link
Contributor

Looking for weighing in on any of the code as it stands now, or the naming question posed by MaskRay here, so far there seems to be support for rtsan over radsan :)

+1 for rtsan

@cjappl cjappl changed the title [compiler-rt] Realtime Sanitizer: Introduce RADSan backend [compiler-rt] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend Jun 3, 2024
@vitalybuka
Copy link
Collaborator

If you want another round, make sure to click re-request review

@vitalybuka vitalybuka requested a review from MaskRay June 5, 2024 01:45
@cjappl
Copy link
Contributor Author

cjappl commented Jun 21, 2024

Pinging reviewers, after we had more conversations on the overall structure and usefulness of RTSan, and it was approved.

@zygoloid @vitalybuka @MaskRay

Details of the aforementioned discussion are around here in the discourse thread:
https://discourse.llvm.org/t/rfc-nolock-and-noalloc-attributes/76837/82

@cjappl
Copy link
Contributor Author

cjappl commented Jun 26, 2024

Bumped the branch to resolve the conflict in config-ix.cmake

@cjappl
Copy link
Contributor Author

cjappl commented Jul 1, 2024

Pinging reviewers @vitalybuka @MaskRay @zygoloid

All the comments on this PR have been addressed, looking for more feedback, or approval/merge if we are getting close! Thanks in advance :)

@cjappl cjappl requested a review from vitalybuka July 1, 2024 13:35
@MaskRay
Copy link
Member

MaskRay commented Jul 3, 2024

This is PR 1/?? (3? 4?) introducing the main guts of the realtime sanitizer. For more information, please see the discourse thread. We have also put together a reviewer support document to show what our intention is.

clangDriver changes are usually the last. The expectation is that if -fsanitize=realtime does not return an error, there should be some basic functionality.

  • clangCodeGen , testing with %clang_cc1
  • clangDriver, testing with %clang

We typically split clangDriver and compiler-rt changes. Runtime compiler-rt tests often expose minor issues that only fail on certain platforms. Keeping it separate prevents us from potentially reverting the compiler-rt code, leading to unnecessary churn.
The recent numerical stability sanitizer did not do a good job for this aspect. I apologize for that as a reviewer.)

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.

Sorry for the delay. I have a really huge code review backlog...

compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp Outdated Show resolved Hide resolved
compiler-rt/test/rtsan/lit.cfg.py Outdated Show resolved Hide resolved
compiler-rt/test/rtsan/lit.cfg.py Outdated Show resolved Hide resolved
compiler-rt/lib/rtsan/rtsan_context.cpp Outdated Show resolved Hide resolved
compiler-rt/lib/rtsan/rtsan_context.cpp Outdated Show resolved Hide resolved
compiler-rt/lib/rtsan/rtsan_stack.cpp Outdated Show resolved Hide resolved
compiler-rt/lib/rtsan/rtsan_interceptors.cpp Outdated Show resolved Hide resolved
@MaskRay
Copy link
Member

MaskRay commented Jul 3, 2024

In the meantime, I commented out compilation of our unit tests that required the -fsanitize flag, let me know if you'd prefer to see them removed until later. These unit tests are paired with the code introduced here, so I think at least by subject it makes sense to introduce them here, even if they are briefly not being compiled.

Yeah, disabling the testsuite should be safe. The tests can be enabled after clangCodeGen and clangDriver patches landed.

- remove empty initializers
- better namespace compliance with LLVM standards
- Fix lit.cfg.py to remove crufty elements not needed
- Change name of InternalFree, add explainer comment
@cjappl
Copy link
Contributor Author

cjappl commented Jul 8, 2024

Pinging reviewers @vitalybuka @zygoloid

State of the review: 1 approval from MaskRay, all open comments have been addressed. Looking for more feedback, or more approval or a merge if this is looking good.

Thanks much! :)

@@ -67,3 +67,7 @@ D: ThreadSanitizer
N: Bill Wendling
E: isanbard@gmail.com
D: Profile runtime library

Copy link
Collaborator

Choose a reason for hiding this comment

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

BTW @alexander-shaposhnikov NSAN is missing from here.

// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
Copy link
Collaborator

Choose a reason for hiding this comment

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

In my experience LIT tests in are easier to maintain in LLVM environment

TEST(TestRtsan, are internals test, so probably fine to keep as GTEST

However TEST(TestRtsanInterceptors are likely better as regular LIT tests

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually even TestRtsan mostly can be done as LIT

BTW. Why I don't like GTEST in LLVM?

LIT is easier to reproduce and experiment and debug than with a particular test case of.

Also I don't trust incremental builds with GTEST, some times I am not sure that my changes are used in tests.

A couple of time CMakes bugs caused compiler-rt GTEST not executed on bots and it was unnoticed for a long time. LIT is majority, so unlikely it could happen with them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems reasonable to convert these to lit! I propose leaving this for this commit, and we convert them in the near future. Specifically this next commit will introduce the -fsanitize=realtime flag, and come with a bunch of the lit tests that we have written, so it will be easier to convert them once that infrastructure has landed.

One clarifying question, for when that work is done:

Should we have a lit test for every intereceptor? The reason we did it in gtest unit tests is that adding a new interceptor's test is a few lines, as opposed to a brand new file with the lit boilerplate. This makes it easy to make sure that every interceptor does what we think it does. We worried about the "cost" of the new file for every interceptor. In our demo branch, as we have it laid out, the lit tests test on the full end-to-end system level, while these tests actually hit every interceptor.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we have a lit test for every intereceptor?

I don't have strong preference. For other sanitizer default interceptor behavior is to crash, so we usually create a test per interceptor.

The reason we did it in gtest unit tests is that adding a new interceptor's test is a few lines, as opposed to a brand new file with the lit boilerplate. This makes it easy to make sure that every interceptor does what we think it does. We worried about the "cost" of the new file for every interceptor. In our demo branch, as we have it laid out, the lit tests test on the full end-to-end system level, while these tests actually hit every interceptor.

Yes, boilerplate of LIT is not nice. So there is a trade off. I guess you can wait and see.

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.

LGTM. but I suggest to rework test into LIT, before or either commit.

@cjappl
Copy link
Contributor Author

cjappl commented Jul 9, 2024

Also, just as a heads up, neither of the authors have commit access as we are new to LLVM. If this is OK to go in we will need help with that step.

@vitalybuka vitalybuka merged commit 1adb55b into llvm:main Jul 9, 2024
6 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 9, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-gcc-ubuntu running on sie-linux-worker3 while building compiler-rt at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/174/builds/1332

Here is the relevant piece of the build log for the reference:

Step 6 (test-build-unified-tree-check-all) failure: test (failure)
...
0.109 [4/4/23] Building CXX object compiler-rt/lib/hwasan/CMakeFiles/RTHwasan_dynamic_version_script_dummy.x86_64.dir/dummy.cpp.o
0.123 [2/5/24] Building CXX object compiler-rt/lib/memprof/CMakeFiles/RTMemprof_dynamic_version_script_dummy.x86_64.dir/dummy.cpp.o
0.124 [1/5/25] Building CXX object compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic_version_script_dummy.x86_64.dir/dummy.cpp.o
0.142 [0/5/26] Linking CXX shared library /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/lib/clang/19/lib/x86_64-unknown-linux-gnu/libclang_rt.ubsan_standalone.so
0.164 [0/4/27] Linking CXX shared library /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/lib/clang/19/lib/x86_64-unknown-linux-gnu/libclang_rt.hwasan.so
0.166 [0/3/28] Linking CXX shared library /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/lib/clang/19/lib/x86_64-unknown-linux-gnu/libclang_rt.hwasan_aliases.so
0.182 [0/2/29] Linking CXX shared library /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/lib/clang/19/lib/x86_64-unknown-linux-gnu/libclang_rt.memprof.so
0.194 [0/1/30] Linking CXX shared library /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/lib/clang/19/lib/x86_64-unknown-linux-gnu/libclang_rt.asan.so
1.400 [3/1/7] cd /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/runtimes/runtimes-bins && /usr/bin/cmake/bin/cmake --build /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/runtimes/runtimes-bins/ --target runtimes-test-depends --config Release
ninja: error: 'compiler-rt/lib/rtsan/tests/llvm_gtest', needed by 'compiler-rt/lib/rtsan/tests/RtsanNoInstTestObjects.rtsan_preinit.cpp.x86_64.o', missing and no known rule to make it
FAILED: runtimes/CMakeFiles/runtimes-test-depends /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/runtimes/CMakeFiles/runtimes-test-depends 
cd /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/runtimes/runtimes-bins && /usr/bin/cmake/bin/cmake --build /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/runtimes/runtimes-bins/ --target runtimes-test-depends --config Release
ninja: build stopped: subcommand failed.

@vitalybuka
Copy link
Collaborator

I can reproduce and will debug in an hour.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 9, 2024

LLVM Buildbot has detected a new failure on builder sanitizer-ppc64le-linux running on ppc64le-sanitizer while building compiler-rt at step 2 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/72/builds/974

Here is the relevant piece of the build log for the reference:

Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure)
...
-- check-cfi does nothing.
-- check-cfi-and-supported does nothing.
-- Generated Sanitizer SUPPORTED_TOOLS list on "Linux" is "asan;lsan;msan;tsan;ubsan"
-- sanitizer_common tests on "Linux" will run against "asan;lsan;msan;tsan;ubsan"
-- check-shadowcallstack does nothing.
-- Configuring done (1.9s)
-- Generating done (0.5s)
-- Build files have been written to: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/runtimes-bins
[6/7] cd /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/runtimes-bins && /home/buildbots/llvm-external-buildbots/cmake-3.28.2/bin/cmake --build /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/runtimes-bins/ --target check-compiler-rt --config Release
ninja: error: 'compiler-rt/lib/rtsan/tests/llvm_gtest', needed by 'compiler-rt/lib/rtsan/tests/RtsanNoInstTestObjects.rtsan_preinit.cpp.powerpc64le.o', missing and no known rule to make it
FAILED: runtimes/CMakeFiles/check-compiler-rt /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/CMakeFiles/check-compiler-rt 
cd /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/runtimes-bins && /home/buildbots/llvm-external-buildbots/cmake-3.28.2/bin/cmake --build /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/runtimes-bins/ --target check-compiler-rt --config Release
ninja: build stopped: subcommand failed.
+ build_failure
+ echo
+ echo 'How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild'
+ echo
+ sleep 5

How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild

+ echo @@@STEP_FAILURE@@@
+ [[ '' == \1 ]]
+ [[ ! -v BUILDBOT_BUILDERNAME ]]
@@@STEP_FAILURE@@@
+ CMAKE_COMMON_OPTIONS+=' -DCMAKE_C_COMPILER=/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm_build0/bin/clang -DCMAKE_CXX_COMPILER=/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm_build0/bin/clang++'
+ CMAKE_COMMON_OPTIONS+=' -DLLVM_ENABLE_WERROR=ON'
+ '[' 0 == 1 ']'
+ LIT_FILTER_OUT='(AddressSanitizer|asan|ubsan)'
+ build_and_test debug -DCOMPILER_RT_DEBUG=ON
+ build debug -DCOMPILER_RT_DEBUG=ON
+ local build_dir=build_debug
+ echo '@@@BUILD_STEP build compiler-rt debug@@@'
+ [[ ! -f build_debug/delete_next_time ]]
+ mkdir -p build_debug
@@@BUILD_STEP build compiler-rt debug@@@
+ cmake -B build_debug -DLLVM_APPEND_VC_REV=OFF -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_CCACHE_BUILD=ON -DLLVM_USE_LINKER=lld -DLLVM_TARGETS_TO_BUILD=PowerPC -DLLVM_LIT_ARGS=-vj256 '-DLLVM_ENABLE_PROJECTS=clang;lld' '-DLLVM_ENABLE_RUNTIMES=libcxx;libcxxabi;compiler-rt;libunwind' -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF -DCMAKE_C_COMPILER=/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm_build0/bin/clang -DCMAKE_CXX_COMPILER=/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm_build0/bin/clang++ -DLLVM_ENABLE_WERROR=ON -DCOMPILER_RT_DEBUG=ON /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/llvm
CMake Deprecation Warning at /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):
  The OLD behavior for policy CMP0114 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  CMakeLists.txt:6 (include)


Step 9 (test compiler-rt gcc) failure: test compiler-rt gcc (failure)
...
-- check-cfi does nothing.
-- check-cfi-and-supported does nothing.
-- Generated Sanitizer SUPPORTED_TOOLS list on "Linux" is "asan;lsan;msan;tsan;ubsan"
-- sanitizer_common tests on "Linux" will run against "asan;lsan;msan;tsan;ubsan"
-- check-shadowcallstack does nothing.
-- Configuring done (1.9s)
-- Generating done (0.5s)
-- Build files have been written to: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/runtimes-bins
[6/7] cd /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/runtimes-bins && /home/buildbots/llvm-external-buildbots/cmake-3.28.2/bin/cmake --build /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/runtimes-bins/ --target check-compiler-rt --config Release
ninja: error: 'compiler-rt/lib/rtsan/tests/llvm_gtest', needed by 'compiler-rt/lib/rtsan/tests/RtsanNoInstTestObjects.rtsan_preinit.cpp.powerpc64le.o', missing and no known rule to make it
FAILED: runtimes/CMakeFiles/check-compiler-rt /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/CMakeFiles/check-compiler-rt 
cd /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/runtimes-bins && /home/buildbots/llvm-external-buildbots/cmake-3.28.2/bin/cmake --build /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/runtimes-bins/ --target check-compiler-rt --config Release
ninja: build stopped: subcommand failed.
+ build_failure
+ echo
+ echo 'How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild'
+ echo
+ sleep 5

How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild
+ echo @@@STEP_FAILURE@@@
+ [[ '' == \1 ]]
+ [[ ! -v BUILDBOT_BUILDERNAME ]]
+ CMAKE_COMMON_OPTIONS+=' -DCMAKE_C_COMPILER=/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm_build0/bin/clang -DCMAKE_CXX_COMPILER=/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm_build0/bin/clang++'
+ CMAKE_COMMON_OPTIONS+=' -DLLVM_ENABLE_WERROR=ON'
+ '[' 0 == 1 ']'
+ LIT_FILTER_OUT='(AddressSanitizer|asan|ubsan)'
+ build_and_test debug -DCOMPILER_RT_DEBUG=ON
+ build debug -DCOMPILER_RT_DEBUG=ON
+ local build_dir=build_debug
+ echo '@@@BUILD_STEP build compiler-rt debug@@@'
+ [[ ! -f build_debug/delete_next_time ]]
+ mkdir -p build_debug
Step 11 (test compiler-rt debug) failure: test compiler-rt debug (failure)
...
-- check-cfi does nothing.
-- check-cfi-and-supported does nothing.
-- Generated Sanitizer SUPPORTED_TOOLS list on "Linux" is "asan;lsan;msan;tsan;ubsan"
-- sanitizer_common tests on "Linux" will run against "asan;lsan;msan;tsan;ubsan"
-- check-shadowcallstack does nothing.
-- Configuring done (1.3s)
-- Generating done (0.3s)
-- Build files have been written to: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_debug/runtimes/runtimes-bins
[6/7] cd /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_debug/runtimes/runtimes-bins && /home/buildbots/llvm-external-buildbots/cmake-3.28.2/bin/cmake --build /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_debug/runtimes/runtimes-bins/ --target check-compiler-rt --config Release
ninja: error: 'compiler-rt/lib/rtsan/tests/llvm_gtest', needed by 'compiler-rt/lib/rtsan/tests/RtsanNoInstTestObjects.rtsan_preinit.cpp.powerpc64le.o', missing and no known rule to make it
FAILED: runtimes/CMakeFiles/check-compiler-rt /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_debug/runtimes/CMakeFiles/check-compiler-rt 
cd /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_debug/runtimes/runtimes-bins && /home/buildbots/llvm-external-buildbots/cmake-3.28.2/bin/cmake --build /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_debug/runtimes/runtimes-bins/ --target check-compiler-rt --config Release
ninja: build stopped: subcommand failed.
+ build_failure
+ echo
+ echo 'How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild'
+ echo
+ sleep 5

How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild
+ echo @@@STEP_FAILURE@@@
+ [[ '' == \1 ]]
+ [[ ! -v BUILDBOT_BUILDERNAME ]]
+ build tsan_debug '-DCOMPILER_RT_DEBUG=ON -DCOMPILER_RT_TSAN_DEBUG_OUTPUT=ON -DLLVM_INCLUDE_TESTS=OFF'
+ local build_dir=build_tsan_debug
+ echo '@@@BUILD_STEP build compiler-rt tsan_debug@@@'
+ [[ ! -f build_tsan_debug/delete_next_time ]]
+ mkdir -p build_tsan_debug
Step 14 (test compiler-rt default) failure: test compiler-rt default (failure)
...
-- check-cfi does nothing.
-- check-cfi-and-supported does nothing.
-- Generated Sanitizer SUPPORTED_TOOLS list on "Linux" is "asan;lsan;msan;tsan;ubsan"
-- sanitizer_common tests on "Linux" will run against "asan;lsan;msan;tsan;ubsan"
-- check-shadowcallstack does nothing.
-- Configuring done (1.3s)
-- Generating done (0.3s)
-- Build files have been written to: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins
[6/7] cd /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins && /home/buildbots/llvm-external-buildbots/cmake-3.28.2/bin/cmake --build /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins/ --target check-compiler-rt --config Release
ninja: error: 'compiler-rt/lib/rtsan/tests/llvm_gtest', needed by 'compiler-rt/lib/rtsan/tests/RtsanNoInstTestObjects.rtsan_preinit.cpp.powerpc64le.o', missing and no known rule to make it
FAILED: runtimes/CMakeFiles/check-compiler-rt /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/CMakeFiles/check-compiler-rt 
cd /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins && /home/buildbots/llvm-external-buildbots/cmake-3.28.2/bin/cmake --build /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/runtimes/runtimes-bins/ --target check-compiler-rt --config Release
ninja: build stopped: subcommand failed.
+ build_failure
+ echo
+ echo 'How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild'
+ echo
+ sleep 5

How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild
+ echo @@@STEP_FAILURE@@@
+ [[ '' == \1 ]]
+ [[ ! -v BUILDBOT_BUILDERNAME ]]
Step 16 (test standalone compiler-rt) failure: test standalone compiler-rt (failure)
@@@BUILD_STEP test standalone compiler-rt@@@
ninja: Entering directory `compiler_rt_build'
ninja: error: 'lib/rtsan/tests/llvm_gtest', needed by 'lib/rtsan/tests/RtsanNoInstTestObjects.rtsan_preinit.cpp.powerpc64le.o', missing and no known rule to make it
+ build_failure
+ echo
+ echo 'How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild'

How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild
+ echo
+ sleep 5
+ echo @@@STEP_FAILURE@@@
+ [[ '' == \1 ]]
+ [[ ! -v BUILDBOT_BUILDERNAME ]]
+ '[' 0 == 1 ']'
+ cleanup
+ [[ -v BUILDBOT_BUILDERNAME ]]
+ echo @@@BUILD_STEP cleanup@@@

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 9, 2024

LLVM Buildbot has detected a new failure on builder premerge-monolithic-linux running on premerge-linux-1 while building compiler-rt at step 7 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/2414

Here is the relevant piece of the build log for the reference:

Step 7 (test-build-unified-tree-check-all) failure: test (failure)
...
0.089 [4/4/23] Building CXX object compiler-rt/lib/memprof/CMakeFiles/RTMemprof_dynamic_version_script_dummy.x86_64.dir/dummy.cpp.o
0.091 [3/4/24] Building CXX object compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic_version_script_dummy.x86_64.dir/dummy.cpp.o
0.095 [2/4/25] Building CXX object compiler-rt/lib/hwasan/CMakeFiles/RTHwasan_dynamic_version_script_dummy.x86_64.dir/dummy.cpp.o
0.114 [0/5/26] Linking CXX shared library /build/buildbot/premerge-monolithic-linux/build/lib/clang/19/lib/x86_64-unknown-linux-gnu/libclang_rt.ubsan_standalone.so
0.140 [0/4/27] Linking CXX shared library /build/buildbot/premerge-monolithic-linux/build/lib/clang/19/lib/x86_64-unknown-linux-gnu/libclang_rt.memprof.so
0.141 [0/3/28] Linking CXX shared library /build/buildbot/premerge-monolithic-linux/build/lib/clang/19/lib/x86_64-unknown-linux-gnu/libclang_rt.hwasan_aliases.so
0.143 [0/2/29] Linking CXX shared library /build/buildbot/premerge-monolithic-linux/build/lib/clang/19/lib/x86_64-unknown-linux-gnu/libclang_rt.hwasan.so
0.149 [0/1/30] Linking CXX shared library /build/buildbot/premerge-monolithic-linux/build/lib/clang/19/lib/x86_64-unknown-linux-gnu/libclang_rt.asan.so
24.463 [3/1/1371] cd /build/buildbot/premerge-monolithic-linux/build/runtimes/runtimes-bins && /etc/cmake/bin/cmake --build /build/buildbot/premerge-monolithic-linux/build/runtimes/runtimes-bins/ --target runtimes-test-depends --config Release
ninja: error: 'compiler-rt/lib/rtsan/tests/llvm_gtest', needed by 'compiler-rt/lib/rtsan/tests/RtsanNoInstTestObjects.rtsan_preinit.cpp.x86_64.o', missing and no known rule to make it
FAILED: runtimes/CMakeFiles/runtimes-test-depends /build/buildbot/premerge-monolithic-linux/build/runtimes/CMakeFiles/runtimes-test-depends 
cd /build/buildbot/premerge-monolithic-linux/build/runtimes/runtimes-bins && /etc/cmake/bin/cmake --build /build/buildbot/premerge-monolithic-linux/build/runtimes/runtimes-bins/ --target runtimes-test-depends --config Release
ninja: build stopped: subcommand failed.

@cjappl
Copy link
Contributor Author

cjappl commented Jul 9, 2024

I can reproduce and will debug in an hour.

Thanks for the help @vitalybuka , I am looking into this as well, but very grateful for more experienced eyes on the matter too. I'll keep you posted here if I find anything

@cjappl
Copy link
Contributor Author

cjappl commented Jul 9, 2024

There are 3 errors I see:

  1. llvm_gtest issue (vast majority of the problems we are seeing):
ninja: error: 'compiler-rt/lib/rtsan/tests/llvm_gtest', needed by 'compiler-rt/lib/rtsan/tests/RtsanNoInstTestObjects.rtsan_preinit.cpp.x86_64.o', missing and no known rule to make it
  1. Fuchsia parameter type issue:
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/compiler-rt/lib/rtsan/rtsan_interceptors.cpp:55:22: error: use of undeclared identifier '__unsanitized_open'; did you mean '__unsanitized_memset'?
   55 |   const int result = REAL(open)(path, oflag, mode);
      |                      ^~~~~~~~~~
      |                      __unsanitized_memset
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/compiler-rt/lib/rtsan/../interception/interception.h:241:18: note: expanded from macro 'REAL'
  241 | # define REAL(x) __unsanitized_##x
      |                  ^
<scratch space>:138:1: note: expanded from here
  138 | __unsanitized_open
      | ^
/usr/local/fuchsia/sdk/arch/x64/sysroot/include/zircon/sanitizer.h:34:18: note: '__unsanitized_memset' declared here
   34 | __typeof(memset) __unsanitized_memset;
      |                  ^
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/compiler-rt/lib/rtsan/rtsan_interceptors.cpp:55:33: error: cannot initialize a parameter of type 'void *' with an lvalue of type 'const char *'
   55 |   const int result = REAL(open)(path, oflag, mode);
      |                                 ^~~~
/usr/local/fuchsia/sdk/arch/x64/sysroot/include/zircon/sanitizer.h:34:18: note: passing argument to parameter here
   34 | __typeof(memset) __unsanitized_memset;
      |                  ^
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/compiler-rt/lib/rtsan/rtsan_interceptors.cpp:69:22: error: use of undeclared identifier '__unsanitized_openat'
   69 |   const int result = REAL(openat)(fd, path, oflag, mode);
      |                      ^
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/compiler-rt/lib/rtsan/../interception/interception.h:241:18: note: expanded from macro 'REAL'
  241 | # define REAL(x) __unsanitized_##x
      |                  ^
<scratch space>:141:1: note: expanded from here
  141 | __unsanitized_openat
      | ^
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/compiler-rt/lib/rtsan/rtsan_interceptors.cpp:77:22: error: use of undeclared identifier '__unsanitized_creat'
   77 |   const int result = REAL(creat)(path, mode);
      |                      ^
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/compiler-rt/lib/rtsan/../interception/interception.h:241:18: note: expanded from macro 'REAL'
  241 | # define REAL(x) __unsanitized_##x
      |                  ^
<scratch space>:144:1: note: expanded from here
  144 | __unsanitized_creat
      | ^
Step 6 (build) failure: build (failure)
...
  1. On windows no pthread (which I think we should just disable support for, for now):
C:\b\slave\sanitizer-windows\llvm-project\compiler-rt\lib\rtsan\rtsan_context.cpp(19): fatal error C1083: Cannot open include file: 'pthread.h': No such file or directory

Working to see if I can fix the llvm_gtest issue right now. I would love advice on Fuchsia and disabling rtsan for windows.

@cjappl
Copy link
Contributor Author

cjappl commented Jul 9, 2024

This patch I have a strong hunch fixes issue 1 in my comment above. This patch compiles and runs on my linux container and my mac, proving it doesn't affect compilation on those two systems.

diff --git a/compiler-rt/lib/rtsan/tests/CMakeLists.txt b/compiler-rt/lib/rtsan/tests/CMakeLists.txt
index d96e538b255f..e539ebc387e0 100644
--- a/compiler-rt/lib/rtsan/tests/CMakeLists.txt
+++ b/compiler-rt/lib/rtsan/tests/CMakeLists.txt
@@ -60,7 +60,7 @@ foreach(arch ${RTSAN_TEST_ARCH})
   #  RtsanUnitTests "Rtsan-${arch}-Test" ${arch}
   #  COMPILE_DEPS ${RTSAN_UNITTEST_HEADERS}
   #  SOURCES ${RTSAN_INST_TEST_SOURCES} ${COMPILER_RT_GOOGLETEST_SOURCES}
-  #  DEPS llvm_gtest rtsan
+  #  DEPS rtsan
   #  CFLAGS ${RTSAN_UNITTEST_CFLAGS} -fsanitize=realtime
   #  LINK_FLAGS ${RTSAN_UNITTEST_LINK_FLAGS} -fsanitize=realtime)

@@ -94,7 +94,6 @@ foreach(arch ${RTSAN_TEST_ARCH})
     COMPILE_DEPS ${RTSAN_UNITTEST_HEADERS}
     SOURCES ${RTSAN_NOINST_TEST_SOURCES}
             ${COMPILER_RT_GOOGLETEST_SOURCES}
-    DEPS llvm_gtest
     CFLAGS ${RTSAN_UNITTEST_CFLAGS}
     LINK_FLAGS ${RTSAN_UNITTEST_LINK_FLAGS}
     RUNTIME ${RTSAN_TEST_RUNTIME})

This also better matches the other sanitizers, llvm_gtest is a dependency in llvm, anything in compiler-rt using gtest just uses the sources directly as seen in:

SOURCES ${RTSAN_NOINST_TEST_SOURCES}
             ${COMPILER_RT_GOOGLETEST_SOURCES}

vitalybuka added a commit that referenced this pull request Jul 9, 2024
Follow up to #92460

DEPS llvm_gtest is not used by compiler-rt,
compiler-rt compiles them with COMPILER_RT_GOOGLETEST_SOURCES.

This reverts commit e217f98.
@glandium
Copy link
Contributor

glandium commented Jul 10, 2024

This also breaks building the compiler-rt for older android versions, because pthread_spinlock_t is only defined when __ANDROID_API__ >= 24.

@cjappl
Copy link
Contributor Author

cjappl commented Jul 10, 2024

This also breaks building the compiler-rt for older android versions, because pthread_spinlock_t is only defined when __ANDROID_API__ >= 24.

Thanks for reporting this @glandium ! I am in the process of disabling this for android as we speak. Let me know if you see anything else fishy

vitalybuka pushed a commit that referenced this pull request Jul 10, 2024
Follow on to #92460 (reporting old android builds failing) and #98264
(powerpc failing to discover gtests).

Getting back to stability by getting back down to a very basic set of
supported arches and OS's. In the future if there is demand we can build
it back up. Especially when I understand how to test these systems, or
have people who want to do the work on them.

---------

Co-authored-by: David Trevelyan <david.trevelyan@gmail.com>
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
…) backend (llvm#92460)

Introducing the main runtime of realtime sanitizer. For more
information, please see the [discourse
thread](https://discourse.llvm.org/t/rfc-nolock-and-noalloc-attributes/76837).
We have also put together a [reviewer support
document](https://github.com/realtime-sanitizer/radsan/blob/doc/review-support/doc/review.md)
to show what our intention is.

This review introduces the sanitizer backend. This includes:
* CMake build files (largely adapted from asan).
* Main RTSan architecture (the external API, thread local context,
stack).
* Interceptors.
* Many unit tests.

Please see the [reviewer support
document](https://github.com/realtime-sanitizer/radsan/blob/doc/review-support/doc/review.md)
for what our next steps are. We are moving in lockstep with this PR
llvm#84983 for the codegen coming up next.

Note to reviewers: If you see support documentation mention "RADSan",
this was the "old acronym" for the realtime sanitizer, they refer to the
same thing. If you see it let us know and we can correct it (especially
in the llvm codebase)

---------

Co-authored-by: David Trevelyan <david.trevelyan@gmail.com>
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
Follow up to llvm#92460

DEPS llvm_gtest is not used by compiler-rt,
compiler-rt compiles them with COMPILER_RT_GOOGLETEST_SOURCES.

This reverts commit e217f98.
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
Follow on to llvm#92460 (reporting old android builds failing) and llvm#98264
(powerpc failing to discover gtests).

Getting back to stability by getting back down to a very basic set of
supported arches and OS's. In the future if there is demand we can build
it back up. Especially when I understand how to test these systems, or
have people who want to do the work on them.

---------

Co-authored-by: David Trevelyan <david.trevelyan@gmail.com>
@cjappl cjappl deleted the RadsanBackend branch July 23, 2024 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants