Skip to content

[rtsan] Ensure pthread is initialized in test #108040

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

Merged
merged 1 commit into from
Sep 10, 2024

Conversation

cjappl
Copy link
Contributor

@cjappl cjappl commented Sep 10, 2024

From #107988 One of the reports was:

I use Red Hat Enterprise Linux 9.0 (Plow) and Ubuntu 22.04 LTS, and the following code will work fine with Ubuntu and will segment fault for the redhat.

#include <pthread.h>
int main() {
pthread_t thread{};
pthread_join(thread, nullptr);
return 0;

I think this could be that we are trying to join a null thread that was never created.

@llvmbot
Copy link
Member

llvmbot commented Sep 10, 2024

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

Author: Chris Apple (cjappl)

Changes

From #107988 One of the reports was:

>
> I use Red Hat Enterprise Linux 9.0 (Plow) and Ubuntu 22.04 LTS, and the following code will work fine with Ubuntu and will segment fault for the redhat.
>
> #include <pthread.h>
> int main() {
> pthread_t thread{};
> pthread_join(thread, nullptr);
> return 0;
>

I think this could be that we are trying to join a null thread that was never created.


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

1 Files Affected:

  • (modified) compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp (+6-5)
diff --git a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp
index 0eeaf9da67098e..1ef4c66a28de88 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp
@@ -472,11 +472,12 @@ TEST_F(PthreadMutexLockTest, PthreadMutexUnlockSurvivesWhenNotRealtime) {
   ExpectNonRealtimeSurvival(Func);
 }
 
-TEST(TestRtsanInterceptors, PthreadMutexJoinDiesWhenRealtime) {
-  auto Func = []() {
-    pthread_t thread{};
-    pthread_join(thread, nullptr);
-  };
+TEST(TestRtsanInterceptors, PthreadJoinDiesWhenRealtime) {
+  pthread_t thread{};
+  ASSERT_EQ(0,
+            pthread_create(&thread, nullptr, &FakeThreadEntryPoint, nullptr));
+
+  auto Func = [&thread]() { pthread_join(thread, nullptr); };
 
   ExpectRealtimeDeath(Func, "pthread_join");
   ExpectNonRealtimeSurvival(Func);

@cjappl
Copy link
Contributor Author

cjappl commented Sep 10, 2024

CC @davidtrevelyan for review

@yingcong-wu could you apply this patch and make sure that it fixes that crash for you?

@cjappl cjappl requested a review from mgorny September 10, 2024 16:06
Copy link
Member

@mgorny mgorny left a comment

Choose a reason for hiding this comment

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

This fixes the SEGV for me, thanks!

Copy link
Contributor

@davidtrevelyan davidtrevelyan left a comment

Choose a reason for hiding this comment

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

LGTM!

@cjappl cjappl merged commit 0b12cd2 into llvm:main Sep 10, 2024
10 checks passed
@cjappl cjappl deleted the initialize_pthread_for_join branch September 10, 2024 20:02
@yingcong-wu
Copy link
Contributor

This fix works for me too. Thank you.

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.

5 participants