[infra] Adjust rpath so TSAN works with shards not having resources at the same absolute path.

Change-Id: I3629f4b9de1270cef648dc938084ecf73ba1863e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447420
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn
index baa52f0..31bbe76 100644
--- a/build/config/compiler/BUILD.gn
+++ b/build/config/compiler/BUILD.gn
@@ -112,12 +112,6 @@
     if (is_asan) {
       cflags += [ "-fsanitize=address" ]
       ldflags += [ "-fsanitize=address" ]
-      if (is_mac) {
-        ldflags += [
-          "-rpath",
-          "buildtools/mac-$host_cpu/clang/lib/clang/21/lib/darwin",
-        ]
-      }
     }
     if (is_hwasan && is_android && current_cpu == "arm64") {
       cflags += [ "-fsanitize=hwaddress" ]
@@ -148,6 +142,13 @@
       ]
     }
 
+    if (is_mac && (is_asan || is_lsan || is_tsan || is_ubsan)) {
+      ldflags += [
+        "-rpath",
+        "buildtools/mac-$host_cpu/clang/lib/clang/21/lib/darwin",
+      ]
+    }
+
     if (use_custom_libcxx) {
       cflags_cc += [ "-nostdinc++" ]
       include_dirs = [