Skip to content

Conversation

@thetruestblue
Copy link
Contributor

@thetruestblue thetruestblue commented Jan 29, 2025

The two tests commented out here are failing apple internal builds. I plan on disabling these for now in Apple's fork. But am curious if there's a way we can help you test this?

rdar://142496236
rdar://142500404

The two tests commented out here are failing apple internal builds. These seems specific to macOS, but I am not familiar with how to disable these gtests only in our downstream. And am curious if there's a way we can help you test this?

rdar://142496236
rdar://142500404
@llvmbot
Copy link
Member

llvmbot commented Jan 29, 2025

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

Author: None (thetruestblue)

Changes

The two tests commented out here are failing apple internal builds. These seems specific to macOS, but I am not familiar with how to disable these gtests only in our downstream. And am curious if there's a way we can help you test this?

rdar://142496236
rdar://142500404


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

2 Files Affected:

  • (modified) compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp (+17-17)
  • (modified) compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp (+12-12)
diff --git a/compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp b/compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp
index e05d7ae78b5d99..c6664683f19a57 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp
@@ -170,23 +170,23 @@ TEST(TestRtsan, CopyingALambdaWithLargeCaptureDiesWhenRealtime) {
   ExpectNonRealtimeSurvival(Func);
 }
 
-TEST(TestRtsan, AccessingALargeAtomicVariableDiesWhenRealtime) {
-  std::atomic<float> small_atomic{0.0f};
-  ASSERT_TRUE(small_atomic.is_lock_free());
-  RealtimeInvoke([&small_atomic]() {
-    float x = small_atomic.load();
-    return x;
-  });
-
-  std::atomic<std::array<float, 2048>> large_atomic;
-  ASSERT_FALSE(large_atomic.is_lock_free());
-  auto Func = [&]() {
-    std::array<float, 2048> x = large_atomic.load();
-    return x;
-  };
-  ExpectRealtimeDeath(Func);
-  ExpectNonRealtimeSurvival(Func);
-}
+// TEST(TestRtsan, AccessingALargeAtomicVariableDiesWhenRealtime) {
+//   std::atomic<float> small_atomic{0.0f};
+//   ASSERT_TRUE(small_atomic.is_lock_free());
+//   RealtimeInvoke([&small_atomic]() {
+//     float x = small_atomic.load();
+//     return x;
+//   });
+
+//   std::atomic<std::array<float, 2048>> large_atomic;
+//   ASSERT_FALSE(large_atomic.is_lock_free());
+//   auto Func = [&]() {
+//     std::array<float, 2048> x = large_atomic.load();
+//     return x;
+//   };
+//   ExpectRealtimeDeath(Func);
+//   ExpectNonRealtimeSurvival(Func);
+// }
 
 TEST(TestRtsan, FirstCoutDiesWhenRealtime) {
   auto Func = []() { std::cout << "Hello, world!" << std::endl; };
diff --git a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
index 59663776366bb3..05044f84dd0eca 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -1037,18 +1037,18 @@ TEST(TestRtsanInterceptors, PthreadJoinDiesWhenRealtime) {
 
 #if SANITIZER_APPLE
 
-#pragma clang diagnostic push
-// OSSpinLockLock is deprecated, but still in use in libc++
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-TEST(TestRtsanInterceptors, OsSpinLockLockDiesWhenRealtime) {
-  auto Func = []() {
-    OSSpinLock spin_lock{};
-    OSSpinLockLock(&spin_lock);
-  };
-  ExpectRealtimeDeath(Func, "OSSpinLockLock");
-  ExpectNonRealtimeSurvival(Func);
-}
-#pragma clang diagnostic pop
+// #pragma clang diagnostic push
+// // OSSpinLockLock is deprecated, but still in use in libc++
+// #pragma clang diagnostic ignored "-Wdeprecated-declarations"
+// TEST(TestRtsanInterceptors, OsSpinLockLockDiesWhenRealtime) {
+//   auto Func = []() {
+//     OSSpinLock spin_lock{};
+//     OSSpinLockLock(&spin_lock);
+//   };
+//   ExpectRealtimeDeath(Func, "OSSpinLockLock");
+//   ExpectNonRealtimeSurvival(Func);
+// }
+// #pragma clang diagnostic pop
 
 TEST(TestRtsanInterceptors, OsUnfairLockLockDiesWhenRealtime) {
   auto Func = []() {

@cjappl
Copy link
Contributor

cjappl commented Jan 29, 2025

Hi @thetruestblue! Thanks for reporting this! Happy to help figure out what is going on.

Would you post the test output of the failing tests for us to look at?

Also, is this a new failure? Do you know the commit that caused it?

@jroelofs
Copy link
Contributor

but I am not familiar with how to disable these gtests only in our downstream

The two usual approaches are GTEST_SKIP(); or prepending DISABLED_ on the test names. But that should happen in our fork, not upstream.

https://google.github.io/googletest/advanced.html#skipping-test-execution
https://github.com/google/googletest/blob/main/docs/advanced.md#temporarily-disabling-tests

// #pragma clang diagnostic push
// // OSSpinLockLock is deprecated, but still in use in libc++
// #pragma clang diagnostic ignored "-Wdeprecated-declarations"
// TEST(TestRtsanInterceptors, OsSpinLockLockDiesWhenRealtime) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For this test, is it possible that your internal build of MacOS completely killed off OsSpinLock, and this call no longer does anything? That's my very naive hunch seeing as it's wrapped in in -Wno-deprecated-declarations

Copy link
Contributor Author

@thetruestblue thetruestblue Jan 29, 2025

Choose a reason for hiding this comment

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

Ah, I think I have an explanation for this one. The locks were changed to macros that point to other locking mechanisms
See: a34159f

// });

// std::atomic<std::array<float, 2048>> large_atomic;
// ASSERT_FALSE(large_atomic.is_lock_free());
Copy link
Contributor

Choose a reason for hiding this comment

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

To explain what is going on here (just being explicit so you have as much info as possible, you may know any/all of this).

Small types which are made atomics don't need locks, they rely on arch specific instructions. Luckily for us real-time programmers, C++ standard added the .is_lock_free assertion so we could sanity check ourselves before using these in timing critical code.

The first half of these test determines that a basic float may be used atomically without an underlying lock happening, we don't intercept anything and don't die.

The second half test uses a mega 2048 float buffer, which cannot be atomically updated without a lock (on any arch I know of). We then test that we intercept the lock call that happens implicitly under the hood. On my mac this intercepts a pthread_mutex_lock I believe.

This passes on my mac, at least, but perhaps Apple changed the internal implementation of the STL to use a different type of lock we don't currently intercept? That fix would be easy enough to do, we could just add the new call into our interceptors.

If you have found some way to make an atomic update of 2048 floats at once with NO LOCKS, please share the secret sauce 👀

@thetruestblue
Copy link
Contributor Author

thetruestblue commented Jan 29, 2025

Hi @thetruestblue! Thanks for reporting this! Happy to help figure out what is going on.

Would you post the test output of the failing tests for us to look at?

Also, is this a new failure? Do you know the commit that caused it?

********************
FAIL: RealtimeSanitizer-Unit :: ./Rtsan-arm64-Test/14/17 (24 of 41)
******************** TEST 'RealtimeSanitizer-Unit :: ./Rtsan-arm64-Test/14/17' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/Users/blueg/srcctl/github/llvm/build/projects/compiler-rt/lib/rtsan/tests/./Rtsan-arm64-Test-RealtimeSanitizer-Unit-55446-14-17.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=17 GTEST_SHARD_INDEX=14 /Users/blueg/srcctl/github/llvm/build/projects/compiler-rt/lib/rtsan/tests/./Rtsan-arm64-Test
--

Script:
--
/Users/blueg/srcctl/github/llvm/build/projects/compiler-rt/lib/rtsan/tests/./Rtsan-arm64-Test --gtest_filter=TestRtsan.AccessingALargeAtomicVariableDiesWhenRealtime
--
/Users/blueg/srcctl/github/llvm/llvm-project/compiler-rt/lib/rtsan/tests/rtsan_test_utilities.h:41: Failure
Death test: RealtimeInvoke(std::forward<Function>(Func))
    Result: failed to die.
 Error msg:
[  DEATH   ] 


/Users/blueg/srcctl/github/llvm/llvm-project/compiler-rt/lib/rtsan/tests/rtsan_test_utilities.h:41
Death test: RealtimeInvoke(std::forward<Function>(Func))
    Result: failed to die.
 Error msg:
[  DEATH   ] 

both test failures just fail to die. I can try to look for a commit to blame, but primary scanning shows it's been failing for a while.

@thetruestblue
Copy link
Contributor Author

thetruestblue commented Jan 29, 2025

Ah!

[ RUN ] TestRtsan.AccessingALargeAtomicVariableDiesWhenRealtime dyld: lazy symbol binding failed: Symbol not found: ___atomic_is_lock_free Referenced from: /....../Rtsan-arm64-Test Expected in: /usr/lib/libSystem.B.dylib

@cjappl
Copy link
Contributor

cjappl commented Jan 29, 2025

Ah!

[ RUN ] TestRtsan.AccessingALargeAtomicVariableDiesWhenRealtime dyld: lazy symbol binding failed: Symbol not found: ___atomic_is_lock_free Referenced from: /....../Rtsan-arm64-Test Expected in: /usr/lib/libSystem.B.dylib

Hmm, that's strange!! This should be a symbol available in the C++ runtime:

https://en.cppreference.com/w/cpp/atomic/atomic/is_lock_free

I just pulled latest master and ran on my mac and things are green there. Let me know if you have any more leads, happy to provide any more assistance.

@cjappl
Copy link
Contributor

cjappl commented Jan 29, 2025

Would you elaborate on what was going wrong for future info? I'm curious!

@thetruestblue
Copy link
Contributor Author

Would you elaborate on what was going wrong for future info? I'm curious!

To @jroelofs point I just skipped these internally for now. I think the OSSpinLock behavior is likely explained by how you're forward declaring the symbol, and how there are situations where we are replacing these with a macro, our TSan tests started failing in the same way recently (I pointed you to the TSan fix). I don't have a good explanation for the ___atomic_is_lock_free not being available at this point (though in one of our jobs this fails without that error). I'm going to schedule some time to look into this, and I'll put up a PR when I have a chance to actually investigate.

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.

4 participants