Dont link -lrt in the testsuite on linux unless using sanitizers.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@248986 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/libcxx/test/config.py b/test/libcxx/test/config.py
index f66b831..f8f336d 100644
--- a/test/libcxx/test/config.py
+++ b/test/libcxx/test/config.py
@@ -529,7 +529,6 @@
             self.cxx.link_flags += ['-lc', '-lm']
             if enable_threads:
                 self.cxx.link_flags += ['-lpthread']
-            self.cxx.link_flags += ['-lrt']
             if llvm_unwinder:
                 self.cxx.link_flags += ['-lunwind', '-ldl']
             else:
@@ -604,7 +603,10 @@
             # Setup the sanitizer compile flags
             self.cxx.flags += ['-g', '-fno-omit-frame-pointer']
             if self.target_info.platform() == 'linux':
-                self.cxx.link_flags += ['-ldl']
+                # The libraries and their order are taken from the
+                # linkSanitizerRuntimeDeps function in
+                # clang/lib/Driver/Tools.cpp
+                self.cxx.link_flags += ['-lpthread', '-lrt', '-lm', '-ldl']
             if san == 'Address':
                 self.cxx.flags += ['-fsanitize=address']
                 if llvm_symbolizer is not None: