[tsan][test] Remaining tests requiring weak symbols for dyld64

Differential Revision: https://reviews.llvm.org/D130917

GitOrigin-RevId: 3879d3edef89879112080f57f0a9edf15d8d92a4
diff --git a/test/tsan/Darwin/debug_external.cpp b/test/tsan/Darwin/debug_external.cpp
index 399663c..6539a18 100644
--- a/test/tsan/Darwin/debug_external.cpp
+++ b/test/tsan/Darwin/debug_external.cpp
@@ -42,7 +42,12 @@
   return 0;
 }
 
-__attribute__((disable_sanitizer_instrumentation)) void
+// Required for dyld macOS 12.0+
+#if (__APPLE__)
+__attribute__((weak))
+#endif
+__attribute__((disable_sanitizer_instrumentation))
+extern "C" void
 __tsan_on_report(void *report) {
   const char *type;
   void *addr;
diff --git a/test/tsan/Darwin/main_tid.mm b/test/tsan/Darwin/main_tid.mm
index 886880e..5f42c41 100644
--- a/test/tsan/Darwin/main_tid.mm
+++ b/test/tsan/Darwin/main_tid.mm
@@ -13,8 +13,13 @@
                              unsigned long trace_size);
 }
 
+// Required for dyld macOS 12.0+
+#if (__APPLE__)
+__attribute__((weak))
+#endif
 __attribute__((disable_sanitizer_instrumentation))
-void __tsan_on_report(void *report) {
+extern "C" void
+__tsan_on_report(void *report) {
   fprintf(stderr, "__tsan_on_report(%p)\n", report);
 
   int tid;
diff --git a/test/tsan/debugging.cpp b/test/tsan/debugging.cpp
index be0a0c7..9d247a2 100644
--- a/test/tsan/debugging.cpp
+++ b/test/tsan/debugging.cpp
@@ -46,7 +46,12 @@
   fprintf(stderr, "Done.\n");
 }
 
-__attribute__((disable_sanitizer_instrumentation)) void
+// Required for dyld macOS 12.0+
+#if (__APPLE__)
+__attribute__((weak))
+#endif
+__attribute__((disable_sanitizer_instrumentation))
+extern "C" void
 __tsan_on_report(void *report) {
   fprintf(stderr, "__tsan_on_report(%p)\n", report);
   fprintf(stderr, "__tsan_get_current_report() = %p\n",
diff --git a/test/tsan/libdispatch/dispatch_once_deadlock.c b/test/tsan/libdispatch/dispatch_once_deadlock.c
index 4e8785b..70faa60 100644
--- a/test/tsan/libdispatch/dispatch_once_deadlock.c
+++ b/test/tsan/libdispatch/dispatch_once_deadlock.c
@@ -22,8 +22,13 @@
   h++;
 }
 
+// Required for dyld macOS 12.0+
+#if (__APPLE__)
+__attribute__((weak))
+#endif
 __attribute__((disable_sanitizer_instrumentation))
-void __tsan_on_report() {
+extern void
+__tsan_on_report() {
   fprintf(stderr, "Report.\n");
 
   // Without these annotations this test deadlocks for COMPILER_RT_DEBUG=ON