[libcxx{,abi}] Emit deplibs only when detected by CMake

This is a followup to 35bc5276ca3.  It fixes the dependent libs usage
in libcxx and libcxxabi to link pthread and rt libraries only if CMake
detects them, rather than based on explicit platform blacklist.

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

Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: a9b5fff591d462f1f22e44ab1a269b82b8f2a664
diff --git a/src/cxa_exception_storage.cpp b/src/cxa_exception_storage.cpp
index 28c0122..24ff55e 100644
--- a/src/cxa_exception_storage.cpp
+++ b/src/cxa_exception_storage.cpp
@@ -46,7 +46,7 @@
 #include "abort_message.h"
 #include "fallback_malloc.h"
 
-#if defined(__unix__) && !defined(__ANDROID__) && defined(__ELF__) && defined(_LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
+#if defined(__ELF__) && defined(_LIBCXXABI_LINK_PTHREAD_LIB)
 #pragma comment(lib, "pthread")
 #endif
 
diff --git a/src/cxa_guard_impl.h b/src/cxa_guard_impl.h
index 98e42ba..a8ec0b7 100644
--- a/src/cxa_guard_impl.h
+++ b/src/cxa_guard_impl.h
@@ -50,7 +50,7 @@
 #include <stdlib.h>
 #include <__threading_support>
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-#if defined(__unix__) && !defined(__ANDROID__) && defined(__ELF__) && defined(_LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
+#if defined(__ELF__) && defined(_LIBCXXABI_LINK_PTHREAD_LIB)
 #pragma comment(lib, "pthread")
 #endif
 #endif
diff --git a/src/cxa_thread_atexit.cpp b/src/cxa_thread_atexit.cpp
index 923b265..a940eaf 100644
--- a/src/cxa_thread_atexit.cpp
+++ b/src/cxa_thread_atexit.cpp
@@ -10,7 +10,7 @@
 #include "cxxabi.h"
 #include <__threading_support>
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-#if defined(__unix__) && !defined(__ANDROID__) && defined(__ELF__) && defined(_LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
+#if defined(__ELF__) && defined(_LIBCXXABI_LINK_PTHREAD_LIB)
 #pragma comment(lib, "pthread")
 #endif
 #endif
diff --git a/src/fallback_malloc.cpp b/src/fallback_malloc.cpp
index 8f301bc..fdae407 100644
--- a/src/fallback_malloc.cpp
+++ b/src/fallback_malloc.cpp
@@ -13,7 +13,7 @@
 
 #include <__threading_support>
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-#if defined(__unix__) && !defined(__ANDROID__) && defined(__ELF__) && defined(_LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
+#if defined(__ELF__) && defined(_LIBCXXABI_LINK_PTHREAD_LIB)
 #pragma comment(lib, "pthread")
 #endif
 #endif