From d7af79629968df3afab12c0ef6378c2289487b3d Mon Sep 17 00:00:00 2001 From: thetruestblue Date: Wed, 22 Jan 2025 09:57:53 -0800 Subject: [PATCH 1/2] [Darwin][Sanitizers][CrashReporter] Adopt initializer for Crash Reporter Annotations struct An initializer for the Crash Reporter Annotatoins struct was added in version 5. For the simplicity of not needing to always update the struct in subsequent versions, this patchs checks for the initializer before attempting to redefine the struct on its own. rdar://136156203 --- .../lib/sanitizer_common/sanitizer_mac.cpp | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp index c8a0afccb254e..ead3d7123e8a1 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp @@ -45,7 +45,7 @@ extern char **environ; # define SANITIZER_OS_TRACE 0 # endif -// import new crash reporting api +// Integrate with CrashReporter library if available # if defined(__has_include) && __has_include() # define HAVE_CRASHREPORTERCLIENT_H 1 # include @@ -796,8 +796,13 @@ static char crashreporter_info_buff[__sanitizer::kErrorMessageBufferSize] = {}; static Mutex crashreporter_info_mutex; extern "C" { -// Integrate with crash reporter libraries. + #if HAVE_CRASHREPORTERCLIENT_H +// Available in CRASHREPORTER_ANNOTATIONS_VERSION 5+ +# ifdef CRASHREPORTER_ANNOTATIONS_INITIALIZER +CRASHREPORTER_ANNOTATIONS_INITIALIZER() +# else +// Support for older CrashRerporter annotiations CRASH_REPORTER_CLIENT_HIDDEN struct crashreporter_annotations_t gCRAnnotations __attribute__((section("__DATA," CRASHREPORTER_ANNOTATIONS_SECTION))) = { @@ -808,17 +813,17 @@ struct crashreporter_annotations_t gCRAnnotations 0, 0, 0, -#if CRASHREPORTER_ANNOTATIONS_VERSION > 4 +# if CRASHREPORTER_ANNOTATIONS_VERSION > 4 0, -#endif +# endif }; - -#else -// fall back to old crashreporter api +# endif +# else +// Revert to previous crash reporter API if client is not available static const char *__crashreporter_info__ __attribute__((__used__)) = &crashreporter_info_buff[0]; asm(".desc ___crashreporter_info__, 0x10"); -#endif +#endif // HAVE_CRASHREPORTERCLIENT_H } // extern "C" From 576a920d6c4bec849a826b5a3cef963217c06a81 Mon Sep 17 00:00:00 2001 From: thetruestblue Date: Thu, 23 Jan 2025 10:37:34 -0800 Subject: [PATCH 2/2] Update compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp Co-authored-by: Julian Lettner --- compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp index ead3d7123e8a1..d15f30c61b586 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp @@ -819,7 +819,7 @@ struct crashreporter_annotations_t gCRAnnotations }; # endif # else -// Revert to previous crash reporter API if client is not available +// Revert to previous crash reporter API if client header is not available static const char *__crashreporter_info__ __attribute__((__used__)) = &crashreporter_info_buff[0]; asm(".desc ___crashreporter_info__, 0x10");