Revert "Reapply "[compiler-rt] Remove %T from shared object substitutions (#155302)""

This reverts commit 7624197dacfde71d21e3c88c308696ebb6f49f94.

This is causing more buildbot failures that probably need some offline
investigation:
1. https://lab.llvm.org/buildbot/#/builders/186/builds/11923
GitOrigin-RevId: 36ca6748bc9150f8c56df6ba15deb118ff700e4a
diff --git a/test/asan/TestCases/Linux/coverage-missing.cpp b/test/asan/TestCases/Linux/coverage-missing.cpp
index b38333e..10acef9 100644
--- a/test/asan/TestCases/Linux/coverage-missing.cpp
+++ b/test/asan/TestCases/Linux/coverage-missing.cpp
@@ -1,17 +1,19 @@
 // Test for "sancov.py missing ...".
 
 // First case: coverage from executable. main() is called on every code path.
-// RUN: rm -rf %t.dir && mkdir -p %t.dir && cd %t.dir
 // RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard %s -o %t -DFOOBAR -DMAIN
-// RUN: %env_asan_opts=coverage=1:coverage_dir=%t.dir %run %t
+// RUN: rm -rf %t-dir
+// RUN: mkdir -p %t-dir
+// RUN: cd %t-dir
+// RUN: %env_asan_opts=coverage=1:coverage_dir=%t-dir %run %t
 // RUN: %sancov print *.sancov > main.txt
 // RUN: rm *.sancov
 // RUN: count 1 < main.txt
-// RUN: %env_asan_opts=coverage=1:coverage_dir=%t.dir %run %t x
+// RUN: %env_asan_opts=coverage=1:coverage_dir=%t-dir %run %t x
 // RUN: %sancov print *.sancov > foo.txt
 // RUN: rm *.sancov
 // RUN: count 3 < foo.txt
-// RUN: %env_asan_opts=coverage=1:coverage_dir=%t.dir %run %t x x
+// RUN: %env_asan_opts=coverage=1:coverage_dir=%t-dir %run %t x x
 // RUN: %sancov print *.sancov > bar.txt
 // RUN: rm *.sancov
 // RUN: count 4 < bar.txt
@@ -24,15 +26,18 @@
 // RUN: not grep "^<" %t.log
 
 // Second case: coverage from DSO.
-// RUN: cd ..
-// RUN: rm -rf %t.dir && mkdir -p %t.dir && cd %t.dir
+// cd %t-dir
 // RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard %s -o %dynamiclib -DFOOBAR -shared -fPIC
 // RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard %s %dynamiclib -o %t -DMAIN
-// RUN: %env_asan_opts=coverage=1:coverage_dir=%t.dir %run %t x
+// RUN: cd ..
+// RUN: rm -rf %t-dir
+// RUN: mkdir -p %t-dir
+// RUN: cd %t-dir
+// RUN: %env_asan_opts=coverage=1:coverage_dir=%t-dir %run %t x
 // RUN: %sancov print %xdynamiclib_filename.*.sancov > foo.txt
 // RUN: rm *.sancov
 // RUN: count 2 < foo.txt
-// RUN: %env_asan_opts=coverage=1:coverage_dir=%t.dir %run %t x x
+// RUN: %env_asan_opts=coverage=1:coverage_dir=%t-dir %run %t x x
 // RUN: %sancov print %xdynamiclib_filename.*.sancov > bar.txt
 // RUN: rm *.sancov
 // RUN: count 3 < bar.txt
diff --git a/test/asan/TestCases/Linux/local_alias.cpp b/test/asan/TestCases/Linux/local_alias.cpp
index 2fec529..a8b3d75 100644
--- a/test/asan/TestCases/Linux/local_alias.cpp
+++ b/test/asan/TestCases/Linux/local_alias.cpp
@@ -4,7 +4,6 @@
 // false positive global-buffer-overflow due to sanitized library poisons
 // globals from non-sanitized one.
 //
-// RUN: mkdir -p %t.dir && cd %t.dir
 // RUN: %clangxx_asan -DBUILD_INSTRUMENTED_DSO=1 -fPIC -shared -mllvm -asan-use-private-alias %s -o %dynamiclib1
 // RUN: %clangxx -DBUILD_UNINSTRUMENTED_DSO=1 -fPIC -shared %s -o %dynamiclib2
 // RUN: %clangxx %s -c -mllvm -asan-use-private-alias -o %t.o
diff --git a/test/asan/TestCases/Linux/odr-violation.cpp b/test/asan/TestCases/Linux/odr-violation.cpp
index 0073084..b16f42c 100644
--- a/test/asan/TestCases/Linux/odr-violation.cpp
+++ b/test/asan/TestCases/Linux/odr-violation.cpp
@@ -10,39 +10,38 @@
 // -fno-sanitize-address-use-odr-indicator turns off both.
 //
 // Different size: detect a bug if detect_odr_violation>=1
-// RUN: mkdir -p %t.dir && cd %t.dir
 // RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared -fno-sanitize-address-use-odr-indicator %s -o %dynamiclib
-// RUN: %clangxx_asan -g -fno-sanitize-address-use-odr-indicator %s %ld_flags_rpath_exe -o %t.dir/ODR-EXE
-// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1 not %run %t.dir/ODR-EXE 2>&1 | FileCheck %s
-// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t.dir/ODR-EXE 2>&1 | FileCheck %s
-// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=0     %run %t.dir/ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
-// RUN: %env_asan_opts=fast_unwind_on_malloc=0                        not %run %t.dir/ODR-EXE 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -g -fno-sanitize-address-use-odr-indicator %s %ld_flags_rpath_exe -o %t-ODR-EXE
+// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1 not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=0     %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: %env_asan_opts=fast_unwind_on_malloc=0                        not %run %t-ODR-EXE 2>&1 | FileCheck %s
 //
 // Same size: report a bug only if detect_odr_violation>=2.
 // RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared -fno-sanitize-address-use-odr-indicator %s -o %dynamiclib -DSZ=100
-// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1     %run %t.dir/ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
-// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t.dir/ODR-EXE 2>&1 | FileCheck %s
-// RUN: %env_asan_opts=fast_unwind_on_malloc=0                        not %run %t.dir/ODR-EXE 2>&1 | FileCheck %s
-// RUN: echo "odr_violation:foo::ZZZ" > %t.dir/supp
-// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2:suppressions=%t.dir/supp  not %run %t.dir/ODR-EXE 2>&1 | FileCheck %s
-// RUN: echo "odr_violation:foo::G" > %t.dir/supp
-// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2:suppressions=%t.dir/supp      %run %t.dir/ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
-// RUN: rm -f %t.dir/supp
+// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1     %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: %env_asan_opts=fast_unwind_on_malloc=0                        not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: echo "odr_violation:foo::ZZZ" > %t.supp
+// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2:suppressions=%t.supp  not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: echo "odr_violation:foo::G" > %t.supp
+// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2:suppressions=%t.supp      %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: rm -f %t.supp
 //
 // Use private aliases for global variables without indicator symbol.
 // RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared -mllvm -asan-use-odr-indicator=0 %s -o %dynamiclib -DSZ=100
-// RUN: %clangxx_asan -g -mllvm -asan-use-odr-indicator=0 %s %ld_flags_rpath_exe -o %t.dir/ODR-EXE
-// RUN: %env_asan_opts=fast_unwind_on_malloc=0 %run %t.dir/ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: %clangxx_asan -g -mllvm -asan-use-odr-indicator=0 %s %ld_flags_rpath_exe -o %t-ODR-EXE
+// RUN: %env_asan_opts=fast_unwind_on_malloc=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
 
 // Use private aliases for global variables: use indicator symbol to detect ODR violation.
 // RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared %s -o %dynamiclib -DSZ=100
-// RUN: %clangxx_asan -g %s %ld_flags_rpath_exe -o %t.dir/ODR-EXE
-// RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t.dir/ODR-EXE 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -g %s %ld_flags_rpath_exe -o %t-ODR-EXE
+// RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s
 
 // Same as above but with clang switches.
 // RUN: %clangxx_asan -g -DBUILD_SO=1 -fPIC -shared -fsanitize-address-use-odr-indicator %s -o %dynamiclib -DSZ=100
-// RUN: %clangxx_asan -g -fsanitize-address-use-odr-indicator %s %ld_flags_rpath_exe -o %t.dir/ODR-EXE
-// RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t.dir/ODR-EXE 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -g -fsanitize-address-use-odr-indicator %s %ld_flags_rpath_exe -o %t-ODR-EXE
+// RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s
 
 // GNU driver doesn't handle .so files properly.
 // REQUIRES: Clang
@@ -59,7 +58,7 @@
 #include <stdio.h>
 namespace foo { char G[100]; }
 // CHECK: ERROR: AddressSanitizer: odr-violation
-// CHECK: size=100 'foo::G' {{.*}}odr-violation.cpp:[[@LINE-2]] in {{.*}}/ODR-EXE
+// CHECK: size=100 'foo::G' {{.*}}odr-violation.cpp:[[@LINE-2]] in {{.*}}.tmp-ODR-EXE
 // CHECK: size={{4|100}} 'foo::G'
 int main(int argc, char **argv) {
   printf("PASS: %p\n", &foo::G);
diff --git a/test/asan/TestCases/Linux/odr-vtable.cpp b/test/asan/TestCases/Linux/odr-vtable.cpp
index 6fa706f..aee5d2a 100644
--- a/test/asan/TestCases/Linux/odr-vtable.cpp
+++ b/test/asan/TestCases/Linux/odr-vtable.cpp
@@ -4,7 +4,6 @@
 // REQUIRES: shared_cxxabi
 
 /// Not using private alias or enabling ODR indicator can detect ODR issues.
-// RUN: mkdir -p %t.dir && cd %t.dir
 // RUN: %clangxx_asan -fno-rtti -DBUILD_SO1 -fPIC -shared -mllvm -asan-use-private-alias=0 %s -o %dynamiclib1
 // RUN: %clangxx_asan -fno-rtti -DBUILD_SO2 -fPIC -shared -mllvm -asan-use-private-alias=0 %s -o %dynamiclib2
 // RUN: %clangxx_asan -fno-rtti %s %ld_flags_rpath_exe1 %ld_flags_rpath_exe2 -o %t
diff --git a/test/asan/TestCases/Linux/odr_c_test.c b/test/asan/TestCases/Linux/odr_c_test.c
index f8a3eae..4aafe68 100644
--- a/test/asan/TestCases/Linux/odr_c_test.c
+++ b/test/asan/TestCases/Linux/odr_c_test.c
@@ -1,15 +1,14 @@
 // Test that we can properly report an ODR violation between an instrumented
 // global and a non-instrumented global if not using private aliases.
 
-// RUN: mkdir -p %t.dir && cd %t.dir
 // RUN: %clang_asan -fcommon %s -fPIC -shared -mllvm -asan-use-private-alias=0 -o %dynamiclib1  -DFILE1
 // RUN: %clang_asan -fcommon %s -fPIC -shared -mllvm -asan-use-private-alias=0 -o %dynamiclib2  -DFILE2
-// RUN: %clang_asan -fcommon %s -fPIE %ld_flags_rpath_exe1 %ld_flags_rpath_exe2 -o %t.dir/exe
-// RUN: not %run %t.dir/exe 2>&1 | FileCheck %s
+// RUN: %clang_asan -fcommon %s -fPIE %ld_flags_rpath_exe1 %ld_flags_rpath_exe2 -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
 
 // RUN: %clang_asan -fcommon %s -fPIC -shared -mllvm -asan-use-private-alias=1 -o %dynamiclib1  -DFILE1
 // RUN: %clang_asan -fcommon %s -fPIC -shared -mllvm -asan-use-private-alias=1 -o %dynamiclib2  -DFILE2
-// RUN: %run %t.dir/exe 2>&1 | count 0
+// RUN: %run %t 2>&1 | count 0
 
 // Unaligned accesses don't work on strict-alignment targets like SPARC.
 // UNSUPPORTED: sparc-target-arch
diff --git a/test/asan/TestCases/Linux/preinit_test.cpp b/test/asan/TestCases/Linux/preinit_test.cpp
index bebaad6..f8c2b6b 100644
--- a/test/asan/TestCases/Linux/preinit_test.cpp
+++ b/test/asan/TestCases/Linux/preinit_test.cpp
@@ -1,4 +1,3 @@
-// RUN: mkdir -p %t.dir && cd %t.dir
 // RUN: %clangxx -DFUNC=zzzz %s -shared -o %dynamiclib -fPIC
 // RUN: %clangxx_asan -DFUNC=main %s -o %t %ld_flags_rpath_exe
 // RUN: %run %t
diff --git a/test/asan/TestCases/Posix/coverage-module-unloaded.cpp b/test/asan/TestCases/Posix/coverage-module-unloaded.cpp
index 3681346..d301bb5 100644
--- a/test/asan/TestCases/Posix/coverage-module-unloaded.cpp
+++ b/test/asan/TestCases/Posix/coverage-module-unloaded.cpp
@@ -1,6 +1,5 @@
 // Check that unloading a module doesn't break coverage dumping for remaining
 // modules.
-// RUN: mkdir -p %t.dir && cd %t.dir
 // RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard -DSHARED %s -shared -o %dynamiclib1 -fPIC
 // RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard -DSHARED %s -shared -o %dynamiclib2 -fPIC
 // RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard %s %libdl -o %t.exe
diff --git a/test/asan/TestCases/Posix/coverage-reset.cpp b/test/asan/TestCases/Posix/coverage-reset.cpp
index 645a959..e89181c 100644
--- a/test/asan/TestCases/Posix/coverage-reset.cpp
+++ b/test/asan/TestCases/Posix/coverage-reset.cpp
@@ -1,6 +1,6 @@
-// RUN: rm -rf %t.dir && mkdir -p %t.dir && cd %t.dir
 // RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard -DSHARED %s -shared -o %dynamiclib -fPIC %ld_flags_rpath_so
 // RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard %s %ld_flags_rpath_exe -o %t
+// RUN: rm -rf %t-dir && mkdir -p %t-dir && cd %t-dir
 // RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t 2>&1 | FileCheck %s
 //
 // UNSUPPORTED: ios
diff --git a/test/asan/TestCases/Posix/coverage.cpp b/test/asan/TestCases/Posix/coverage.cpp
index 8e3952b..12a8840 100644
--- a/test/asan/TestCases/Posix/coverage.cpp
+++ b/test/asan/TestCases/Posix/coverage.cpp
@@ -1,6 +1,6 @@
-// RUN:rm -rf %t.dir && mkdir -p %t.dir && cd %t.dir
 // RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard -DSHARED %s -shared -o %dynamiclib -fPIC %ld_flags_rpath_so
 // RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard %s %ld_flags_rpath_exe -o %t
+// RUN: rm -rf %t-dir && mkdir -p %t-dir && cd %t-dir
 // RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t 2>&1         | FileCheck %s --check-prefix=CHECK-main
 // RUN: %sancov print coverage.*sancov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV1
 // RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t foo 2>&1     | FileCheck %s --check-prefix=CHECK-foo
@@ -14,6 +14,7 @@
 // RUN: %sancov print merged-cov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
 // RUN: %env_asan_opts=coverage=1:verbosity=1 not %run %t foo bar 4    2>&1 | FileCheck %s --check-prefix=CHECK-report
 // RUN: %env_asan_opts=coverage=1:verbosity=1 not %run %t foo bar 4 5  2>&1 | FileCheck %s --check-prefix=CHECK-segv
+// RUN: cd .. && rm -rf %t-dir
 //
 // https://code.google.com/p/address-sanitizer/issues/detail?id=263
 // XFAIL: android
diff --git a/test/asan/TestCases/Posix/interception-in-shared-lib-test.cpp b/test/asan/TestCases/Posix/interception-in-shared-lib-test.cpp
index 3a6d5db..b592edb 100644
--- a/test/asan/TestCases/Posix/interception-in-shared-lib-test.cpp
+++ b/test/asan/TestCases/Posix/interception-in-shared-lib-test.cpp
@@ -1,5 +1,5 @@
 // Check that memset() call from a shared library gets intercepted.
-// RUN: mkdir -p %t.dir && cd %t.dir
+
 // RUN: %clangxx_asan -O0 %s -DSHARED_LIB \
 // RUN:     -shared -o %dynamiclib -fPIC %ld_flags_rpath_so
 // RUN: %clangxx_asan -O0 %s -o %t %ld_flags_rpath_exe && \
diff --git a/test/asan/TestCases/suppressions-library.cpp b/test/asan/TestCases/suppressions-library.cpp
index 604faf1..5427122 100644
--- a/test/asan/TestCases/suppressions-library.cpp
+++ b/test/asan/TestCases/suppressions-library.cpp
@@ -1,4 +1,3 @@
-// RUN: mkdir -p %t.dir && cd %t.dir
 // RUN: %clangxx_asan -O0 -DSHARED_LIB %s %fPIC -shared -o %dynamiclib %ld_flags_rpath_so
 // RUN: %clangxx_asan -O0 %s -o %t %ld_flags_rpath_exe
 
diff --git a/test/cfi/cross-dso-diagnostic.cpp b/test/cfi/cross-dso-diagnostic.cpp
index b6b7e6f..f0a2ab4 100644
--- a/test/cfi/cross-dso-diagnostic.cpp
+++ b/test/cfi/cross-dso-diagnostic.cpp
@@ -1,6 +1,5 @@
 // Check that cross-DSO diagnostics print the names of both modules
 
-// RUN: mkdir -p %t.dir && cd %t.dir
 // RUN: %clangxx_cfi_diag -g -DSHARED_LIB -fPIC -shared -o %dynamiclib %s %ld_flags_rpath_so
 // RUN: %clangxx_cfi_diag -g -o %t_exe_suffix %s %ld_flags_rpath_exe
 // RUN: %t_exe_suffix 2>&1 | FileCheck -DDSONAME=%xdynamiclib_namespec %s
diff --git a/test/cfi/cross-dso/icall/diag.cpp b/test/cfi/cross-dso/icall/diag.cpp
index 2921b69..579ee83 100644
--- a/test/cfi/cross-dso/icall/diag.cpp
+++ b/test/cfi/cross-dso/icall/diag.cpp
@@ -6,7 +6,6 @@
 // * otherwise, the callee decides between trap/recover/norecover.
 
 // Full-recover.
-// RUN: mkdir -p %t.dir && cd %t.dir
 // RUN: %clangxx_cfi_dso_diag -g -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
 // RUN: %clangxx_cfi_dso_diag -g %s -o %t %ld_flags_rpath_exe
 
diff --git a/test/cfi/cross-dso/icall/icall-from-dso.cpp b/test/cfi/cross-dso/icall/icall-from-dso.cpp
index 53dcc56..125e030 100644
--- a/test/cfi/cross-dso/icall/icall-from-dso.cpp
+++ b/test/cfi/cross-dso/icall/icall-from-dso.cpp
@@ -1,4 +1,3 @@
-// RUN: mkdir -p %t.dir && cd %t.dir
 // RUN: %clangxx_cfi_dso -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
 // RUN: %clangxx_cfi_dso %s -o %t %ld_flags_rpath_exe && %expect_crash %t 2>&1 | FileCheck %s
 
diff --git a/test/cfi/cross-dso/icall/icall.cpp b/test/cfi/cross-dso/icall/icall.cpp
index 8666047..9e9bfd0 100644
--- a/test/cfi/cross-dso/icall/icall.cpp
+++ b/test/cfi/cross-dso/icall/icall.cpp
@@ -1,4 +1,3 @@
-// RUN: mkdir -p %t.dir && cd %t.dir
 // RUN: %clangxx_cfi_dso -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
 // RUN: %clangxx_cfi_dso %s -o %t %ld_flags_rpath_exe && %expect_crash %t 2>&1 | FileCheck %s
 
diff --git a/test/cfi/cross-dso/simple-fail.cpp b/test/cfi/cross-dso/simple-fail.cpp
index dfe2628..93503eb 100644
--- a/test/cfi/cross-dso/simple-fail.cpp
+++ b/test/cfi/cross-dso/simple-fail.cpp
@@ -1,4 +1,3 @@
-// RUN: mkdir -p %t.dir && cd %t.dir
 // RUN: %clangxx_cfi_dso -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
 // RUN: %clangxx_cfi_dso %s -o %t %ld_flags_rpath_exe
 // RUN: %expect_crash %t 2>&1 | FileCheck --check-prefix=CFI %s
diff --git a/test/cfi/cross-dso/simple-pass.cpp b/test/cfi/cross-dso/simple-pass.cpp
index 2176263..6ce6471 100644
--- a/test/cfi/cross-dso/simple-pass.cpp
+++ b/test/cfi/cross-dso/simple-pass.cpp
@@ -1,4 +1,3 @@
-// RUN: mkdir -p %t.dir && cd %t.dir
 // RUN: %clangxx_cfi_dso -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
 // RUN: %clangxx_cfi_dso -g %s -o %t %ld_flags_rpath_exe
 // RUN: %t 2>&1 | FileCheck --check-prefix=CFI %s
diff --git a/test/cfi/target_uninstrumented.cpp b/test/cfi/target_uninstrumented.cpp
index d61b6dd..8543fda 100644
--- a/test/cfi/target_uninstrumented.cpp
+++ b/test/cfi/target_uninstrumented.cpp
@@ -1,4 +1,3 @@
-// RUN: mkdir -p %t.dir && cd %t.dir
 // RUN: %clangxx -g -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
 // RUN: %clangxx_cfi_diag -g %s -o %t %ld_flags_rpath_exe
 // RUN: %run %t 2>&1 | FileCheck %s
diff --git a/test/fuzzer/coverage.test b/test/fuzzer/coverage.test
index 9c5d525..ccbc3dc 100644
--- a/test/fuzzer/coverage.test
+++ b/test/fuzzer/coverage.test
@@ -2,7 +2,6 @@
 UNSUPPORTED: target={{.*windows.*}}
 # FIXME: CreatePCArray() emits PLT stub addresses for entry blocks, which are ignored by TracePC::PrintCoverage().
 UNSUPPORTED: target=s390x{{.*}}
-RUN: mkdir -p %t.dir && cd %t.dir
 RUN: %cpp_compiler -mllvm -use-unknown-locations=Disable  %S/NullDerefTest.cpp -o %t-NullDerefTest
 RUN: %cpp_compiler -mllvm -use-unknown-locations=Disable %S/DSO1.cpp -fPIC %ld_flags_rpath_so1 -O0 -shared -o %dynamiclib1
 RUN: %cpp_compiler -mllvm -use-unknown-locations=Disable %S/DSO2.cpp -fPIC %ld_flags_rpath_so2 -O0 -shared -o %dynamiclib2
diff --git a/test/fuzzer/dso.test b/test/fuzzer/dso.test
index 836f13f..b302720 100644
--- a/test/fuzzer/dso.test
+++ b/test/fuzzer/dso.test
@@ -1,6 +1,5 @@
 # FIXME: Disabled on Windows because -fPIC cannot be used to compile for Windows.
 UNSUPPORTED: target={{.*windows.*}}
-RUN: mkdir -p %t.dir && cd %t.dir
 RUN: %cpp_compiler %S/DSO1.cpp -fPIC %ld_flags_rpath_so1 -shared -o %dynamiclib1
 RUN: %cpp_compiler %S/DSO2.cpp -fPIC %ld_flags_rpath_so2 -shared -o %dynamiclib2
 RUN: %cpp_compiler %S/DSOTestMain.cpp %S/DSOTestExtra.cpp %ld_flags_rpath_exe1 %ld_flags_rpath_exe2 -o %t-DSOTest
diff --git a/test/fuzzer/full-coverage.test b/test/fuzzer/full-coverage.test
index 2ba6742..f189962 100644
--- a/test/fuzzer/full-coverage.test
+++ b/test/fuzzer/full-coverage.test
@@ -2,7 +2,6 @@
 UNSUPPORTED: target={{.*windows.*}}
 # FIXME: See coverage.test.  Using UNSUPPORTED here due to random failures.
 UNSUPPORTED: target=s390x{{.*}}
-RUN: mkdir -p %t.dir && cd %t.dir
 RUN: %cpp_compiler %S/DSO1.cpp -fPIC %ld_flags_rpath_so1 -O0 -shared -o %dynamiclib1
 RUN: %cpp_compiler %S/DSO2.cpp -fPIC %ld_flags_rpath_so2 -O0 -shared -o %dynamiclib2
 RUN: %cpp_compiler %S/DSOTestMain.cpp %S/DSOTestExtra.cpp %ld_flags_rpath_exe1 %ld_flags_rpath_exe2 -o %t-DSOTest
diff --git a/test/lit.common.cfg.py b/test/lit.common.cfg.py
index 02959a4..e2e8154 100644
--- a/test/lit.common.cfg.py
+++ b/test/lit.common.cfg.py
@@ -888,7 +888,7 @@
         config.substitutions.append(
             (
                 "%ld_flags_rpath_exe" + postfix,
-                r"-Wl,-z,origin -Wl,-rpath,\$ORIGIN -L%t.dir -l%xdynamiclib_namespec"
+                r"-Wl,-z,origin -Wl,-rpath,\$ORIGIN -L%T -l%xdynamiclib_namespec"
                 + postfix,
             )
         )
@@ -897,7 +897,7 @@
         config.substitutions.append(
             (
                 "%ld_flags_rpath_exe" + postfix,
-                r"-Wl,-rpath,\$ORIGIN -L%t.dir -l%xdynamiclib_namespec" + postfix,
+                r"-Wl,-rpath,\$ORIGIN -L%T -l%xdynamiclib_namespec" + postfix,
             )
         )
         config.substitutions.append(("%ld_flags_rpath_so" + postfix, ""))
@@ -905,14 +905,14 @@
         config.substitutions.append(
             (
                 "%ld_flags_rpath_exe" + postfix,
-                r"-Wl,-R\$ORIGIN -L%t.dir -l%xdynamiclib_namespec" + postfix,
+                r"-Wl,-R\$ORIGIN -L%T -l%xdynamiclib_namespec" + postfix,
             )
         )
         config.substitutions.append(("%ld_flags_rpath_so" + postfix, ""))
 
     # Must be defined after the substitutions that use %dynamiclib.
     config.substitutions.append(
-        ("%dynamiclib" + postfix, "%t.dir/%xdynamiclib_filename" + postfix)
+        ("%dynamiclib" + postfix, "%T/%xdynamiclib_filename" + postfix)
     )
     config.substitutions.append(
         (
diff --git a/test/tsan/on_initialize_finalize_hooks.cpp b/test/tsan/on_initialize_finalize_hooks.cpp
index ef746dd..3f7b56b 100644
--- a/test/tsan/on_initialize_finalize_hooks.cpp
+++ b/test/tsan/on_initialize_finalize_hooks.cpp
@@ -1,4 +1,3 @@
-// RUN: mkdir -p %t.dir && cd %t.dir
 // RUN: %clang_tsan -O1 %s -DBUILD_LIB=1 -fno-sanitize=thread -shared -fPIC -o %dynamiclib %ld_flags_rpath_so
 // RUN: %clang_tsan -O1 %s -o %t %ld_flags_rpath_exe
 // RUN: %run %t | FileCheck %s
diff --git a/test/ubsan/TestCases/TypeCheck/Function/function.cpp b/test/ubsan/TestCases/TypeCheck/Function/function.cpp
index 5b74d41..ddd6933 100644
--- a/test/ubsan/TestCases/TypeCheck/Function/function.cpp
+++ b/test/ubsan/TestCases/TypeCheck/Function/function.cpp
@@ -1,4 +1,3 @@
-// RUN: mkdir -p %t.dir && cd %t.dir
 // RUN: %clangxx -std=c++17 -fsanitize=function %s -O3 -g -DSHARED_LIB -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
 // RUN: %clangxx -std=c++17 -fsanitize=function %s -O3 -g -o %t %ld_flags_rpath_exe
 // RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
diff --git a/test/ubsan/TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp b/test/ubsan/TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp
index 5a9d4fd..76be179 100644
--- a/test/ubsan/TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp
+++ b/test/ubsan/TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp
@@ -1,4 +1,3 @@
-// RUN: mkdir -p %t.dir && cd %t.dir
 // RUN: %clangxx -frtti -fsanitize=vptr -fno-sanitize-recover=vptr -I%p/Helpers -g %s -fPIC -shared -o %dynamiclib -DBUILD_SO %ld_flags_rpath_so
 // RUN: %clangxx -frtti -fsanitize=vptr -fno-sanitize-recover=vptr -I%p/Helpers -g %s -O3 -o %t %ld_flags_rpath_exe
 // RUN: %run %t