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

[rtsan] Add include guards around posix interceptors, tests #113188

Merged
merged 1 commit into from
Oct 23, 2024

Conversation

cjappl
Copy link
Contributor

@cjappl cjappl commented Oct 21, 2024

This is another in preparation for windows exploration, trying to get all the sub-pieces in place

@cjappl
Copy link
Contributor Author

cjappl commented Oct 21, 2024

CC @jatinchowdhury18

@llvmbot
Copy link
Member

llvmbot commented Oct 21, 2024

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

Author: Chris Apple (cjappl)

Changes

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

2 Files Affected:

  • (modified) compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp (+5-1)
  • (modified) compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp (+5-1)
diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
index 63b0ca28a1f409..890d6c11c40762 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -8,12 +8,14 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "sanitizer_common/sanitizer_platform.h"
+#if SANITIZER_POSIX
+
 #include "rtsan/rtsan_interceptors.h"
 
 #include "interception/interception.h"
 #include "sanitizer_common/sanitizer_allocator_dlsym.h"
 #include "sanitizer_common/sanitizer_allocator_internal.h"
-#include "sanitizer_common/sanitizer_platform.h"
 #include "sanitizer_common/sanitizer_platform_interceptors.h"
 
 #include "interception/interception.h"
@@ -608,3 +610,5 @@ void __rtsan::InitializeInterceptors() {
   INTERCEPT_FUNCTION(recvfrom);
   INTERCEPT_FUNCTION(shutdown);
 }
+
+#endif // SANITIZER_POSIX
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 f7a281f13e2ff6..6233c3e91800e1 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -8,9 +8,11 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "sanitizer_common/sanitizer_platform.h"
+#if SANITIZER_POSIX
+
 #include "gtest/gtest.h"
 
-#include "sanitizer_common/sanitizer_platform.h"
 #include "sanitizer_common/sanitizer_platform_interceptors.h"
 
 #include "rtsan_test_utilities.h"
@@ -704,3 +706,5 @@ TEST(TestRtsanInterceptors, ShutdownOnASocketDiesWhenRealtime) {
   ExpectRealtimeDeath(Func, "shutdown");
   ExpectNonRealtimeSurvival(Func);
 }
+
+#endif // SANITIZER_POSIX

@davidtrevelyan
Copy link
Contributor

Is there strong motivation for doing this in the source rather than in the CMake configuration?

@cjappl
Copy link
Contributor Author

cjappl commented Oct 21, 2024

Is there strong motivation for doing this in the source rather than in the CMake configuration?

There seems to be strong precedent to do it via ifdefs. Take for instance the platform specific malloc files in asan:

#if SANITIZER_FREEBSD || SANITIZER_FUCHSIA || SANITIZER_LINUX || \

I'm not opposed to doing this in CMake (and it would be my first gut reaction in a project I controlled) but this seems to be the way I've seen around the codebase.

@davidtrevelyan
Copy link
Contributor

Is there strong motivation for doing this in the source rather than in the CMake configuration?

There seems to be strong precedent to do it via ifdefs. Take for instance the platform specific malloc files in asan:

#if SANITIZER_FREEBSD || SANITIZER_FUCHSIA || SANITIZER_LINUX || \

I'm not opposed to doing this in CMake (and it would be my first gut reaction in a project I controlled) but this seems to be the way I've seen around the codebase.

OK cool - thanks for summarising these. I'll leave it to others with more experience in the codebase to weigh in here then :)

@cjappl cjappl merged commit 9ed6f7f into llvm:main Oct 23, 2024
10 checks passed
@cjappl cjappl deleted the includeguard branch October 23, 2024 22:40
@frobtech frobtech mentioned this pull request Oct 25, 2024
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
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