summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Hosek <phosek@chromium.org>2019-05-30 04:40:21 +0000
committerPetr Hosek <phosek@chromium.org>2019-05-30 04:40:21 +0000
commit789b7f0828b08f5c4bf9ff1ff7ef733c73ecdc0a (patch)
tree529f48a2d6693be385cf978860ec04995e6dfe86
parent2c91c3b7af7cd4da64f1babde3798d65522a21e4 (diff)
downloadbcm5719-llvm-789b7f0828b08f5c4bf9ff1ff7ef733c73ecdc0a.tar.gz
bcm5719-llvm-789b7f0828b08f5c4bf9ff1ff7ef733c73ecdc0a.zip
[runtimes] Check if pragma comment(lib, ...) is supported first
This fixes the issue introduced by r362048 where we always use pragma comment(lib, ...) for dependent libraries when the compiler is Clang, but older Clang versions don't support this pragma so we need to check first if it's supported before using it. llvm-svn: 362055
-rw-r--r--libcxx/CMakeLists.txt4
-rw-r--r--libcxx/cmake/config-ix.cmake10
-rw-r--r--libcxx/src/algorithm.cpp2
-rw-r--r--libcxx/src/chrono.cpp2
-rw-r--r--libcxx/src/debug.cpp2
-rw-r--r--libcxx/src/experimental/memory_resource.cpp2
-rw-r--r--libcxx/src/filesystem/operations.cpp2
-rw-r--r--libcxx/src/mutex.cpp2
-rw-r--r--libcxx/src/shared_mutex.cpp2
-rw-r--r--libcxx/src/thread.cpp2
-rw-r--r--libcxxabi/CMakeLists.txt4
-rw-r--r--libcxxabi/cmake/config-ix.cmake9
-rw-r--r--libcxxabi/src/cxa_exception_storage.cpp4
-rw-r--r--libcxxabi/src/cxa_guard_impl.h2
-rw-r--r--libcxxabi/src/cxa_thread_atexit.cpp2
-rw-r--r--libcxxabi/src/fallback_malloc.cpp2
-rw-r--r--libunwind/CMakeLists.txt4
-rw-r--r--libunwind/cmake/config-ix.cmake11
-rw-r--r--libunwind/src/AddressSpace.hpp2
-rw-r--r--libunwind/src/RWMutex.hpp2
20 files changed, 56 insertions, 16 deletions
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 1096898d055..50ccbf6c426 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -552,6 +552,10 @@ if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS)
add_definitions(-D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS)
endif()
+if (LIBCXX_HAS_COMMENT_LIB_PRAGMA)
+ add_definitions(-D_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
+endif()
+
# Warning flags ===============================================================
add_definitions(-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
add_compile_flags_if_supported(
diff --git a/libcxx/cmake/config-ix.cmake b/libcxx/cmake/config-ix.cmake
index 23ae71025e5..b2d275bbb25 100644
--- a/libcxx/cmake/config-ix.cmake
+++ b/libcxx/cmake/config-ix.cmake
@@ -1,6 +1,7 @@
include(CheckLibraryExists)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
+include(CheckCSourceCompiles)
if(WIN32 AND NOT MINGW)
# NOTE(compnerd) this is technically a lie, there is msvcrt, but for now, lets
@@ -59,6 +60,14 @@ if (LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG)
endif ()
endif ()
+# Check compiler pragmas
+if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ check_c_source_compiles("
+#pragma comment(lib, \"c\")
+int main() { return 0; }
+" LIBCXX_HAS_COMMENT_LIB_PRAGMA)
+endif()
+
if(NOT WIN32 OR MINGW)
include(CheckLibcxxAtomic)
endif()
@@ -72,7 +81,6 @@ check_cxx_compiler_flag(/EHs- LIBCXX_HAS_NO_EHS_FLAG)
check_cxx_compiler_flag(/EHa- LIBCXX_HAS_NO_EHA_FLAG)
check_cxx_compiler_flag(/GR- LIBCXX_HAS_NO_GR_FLAG)
-
# Check libraries
if(WIN32 AND NOT MINGW)
# TODO(compnerd) do we want to support an emulation layer that allows for the
diff --git a/libcxx/src/algorithm.cpp b/libcxx/src/algorithm.cpp
index 5ce2a23b464..a110ae8b1a6 100644
--- a/libcxx/src/algorithm.cpp
+++ b/libcxx/src/algorithm.cpp
@@ -10,7 +10,7 @@
#include "random"
#ifndef _LIBCPP_HAS_NO_THREADS
#include "mutex"
-#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
#pragma comment(lib, "pthread")
#endif
#endif
diff --git a/libcxx/src/chrono.cpp b/libcxx/src/chrono.cpp
index a2f88c94c07..8f533f1059e 100644
--- a/libcxx/src/chrono.cpp
+++ b/libcxx/src/chrono.cpp
@@ -37,7 +37,7 @@
#endif
#endif
-#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
#pragma comment(lib, "rt")
#endif
diff --git a/libcxx/src/debug.cpp b/libcxx/src/debug.cpp
index 95024131011..c4cc281d586 100644
--- a/libcxx/src/debug.cpp
+++ b/libcxx/src/debug.cpp
@@ -15,7 +15,7 @@
#include "__hash_table"
#ifndef _LIBCPP_HAS_NO_THREADS
#include "mutex"
-#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
#pragma comment(lib, "pthread")
#endif
#endif
diff --git a/libcxx/src/experimental/memory_resource.cpp b/libcxx/src/experimental/memory_resource.cpp
index 84c95080496..9aa077942b0 100644
--- a/libcxx/src/experimental/memory_resource.cpp
+++ b/libcxx/src/experimental/memory_resource.cpp
@@ -12,7 +12,7 @@
#include "atomic"
#elif !defined(_LIBCPP_HAS_NO_THREADS)
#include "mutex"
-#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
#pragma comment(lib, "pthread")
#endif
#endif
diff --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp
index 319d9f65d73..69350ddfe9d 100644
--- a/libcxx/src/filesystem/operations.cpp
+++ b/libcxx/src/filesystem/operations.cpp
@@ -44,7 +44,7 @@
#include <sys/time.h> // for gettimeofday and timeval
#endif // !defined(CLOCK_REALTIME)
-#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
#pragma comment(lib, "rt")
#endif
diff --git a/libcxx/src/mutex.cpp b/libcxx/src/mutex.cpp
index d100f2df233..33a8197dadf 100644
--- a/libcxx/src/mutex.cpp
+++ b/libcxx/src/mutex.cpp
@@ -13,7 +13,7 @@
#include "__undef_macros"
#ifndef _LIBCPP_HAS_NO_THREADS
-#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
#pragma comment(lib, "pthread")
#endif
#endif
diff --git a/libcxx/src/shared_mutex.cpp b/libcxx/src/shared_mutex.cpp
index 3f1aecfdfe1..eb3f5f3506f 100644
--- a/libcxx/src/shared_mutex.cpp
+++ b/libcxx/src/shared_mutex.cpp
@@ -10,7 +10,7 @@
#ifndef _LIBCPP_HAS_NO_THREADS
#include "shared_mutex"
-#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
#pragma comment(lib, "pthread")
#endif
diff --git a/libcxx/src/thread.cpp b/libcxx/src/thread.cpp
index 92690f66798..39bb9e9bac6 100644
--- a/libcxx/src/thread.cpp
+++ b/libcxx/src/thread.cpp
@@ -35,7 +35,7 @@
#include <windows.h>
#endif
-#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
#pragma comment(lib, "pthread")
#endif
diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index 75c83cc79cf..e1977278fc8 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -441,6 +441,10 @@ if (LIBCXXABI_BAREMETAL)
add_definitions(-DLIBCXXABI_BAREMETAL)
endif()
+if (LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
+ add_definitions(-D_LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
+endif()
+
string(REPLACE ";" " " LIBCXXABI_CXX_FLAGS "${LIBCXXABI_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXXABI_CXX_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBCXXABI_C_FLAGS}")
diff --git a/libcxxabi/cmake/config-ix.cmake b/libcxxabi/cmake/config-ix.cmake
index 379b5547749..30d2ae237d1 100644
--- a/libcxxabi/cmake/config-ix.cmake
+++ b/libcxxabi/cmake/config-ix.cmake
@@ -1,6 +1,7 @@
include(CheckLibraryExists)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
+include(CheckCSourceCompiles)
check_library_exists(c fopen "" LIBCXXABI_HAS_C_LIB)
if (NOT LIBCXXABI_USE_COMPILER_RT)
@@ -48,6 +49,14 @@ if (LIBCXXABI_HAS_NODEFAULTLIBS_FLAG)
endif ()
endif ()
+# Check compiler pragmas
+if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ check_c_source_compiles("
+#pragma comment(lib, \"c\")
+int main() { return 0; }
+" LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
+endif()
+
# Check compiler flags
check_c_compiler_flag(-funwind-tables LIBCXXABI_HAS_FUNWIND_TABLES)
check_cxx_compiler_flag(-fno-exceptions LIBCXXABI_HAS_NO_EXCEPTIONS_FLAG)
diff --git a/libcxxabi/src/cxa_exception_storage.cpp b/libcxxabi/src/cxa_exception_storage.cpp
index 93506ac5c58..81ba5f0207a 100644
--- a/libcxxabi/src/cxa_exception_storage.cpp
+++ b/libcxxabi/src/cxa_exception_storage.cpp
@@ -46,6 +46,10 @@ extern "C" {
#include "abort_message.h"
#include "fallback_malloc.h"
+#if defined(__unix__) && defined(__ELF__) && defined(_LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
+#pragma comment(lib, "pthread")
+#endif
+
// In general, we treat all threading errors as fatal.
// We cannot call std::terminate() because that will in turn
// call __cxa_get_globals() and cause infinite recursion.
diff --git a/libcxxabi/src/cxa_guard_impl.h b/libcxxabi/src/cxa_guard_impl.h
index bd6b15fce6a..935ba80d85c 100644
--- a/libcxxabi/src/cxa_guard_impl.h
+++ b/libcxxabi/src/cxa_guard_impl.h
@@ -50,7 +50,7 @@
#include <stdlib.h>
#include <__threading_support>
#ifndef _LIBCXXABI_HAS_NO_THREADS
-#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) && defined(__ELF__) && defined(_LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
#pragma comment(lib, "pthread")
#endif
#endif
diff --git a/libcxxabi/src/cxa_thread_atexit.cpp b/libcxxabi/src/cxa_thread_atexit.cpp
index 38787f18fe3..3b60c2919f4 100644
--- a/libcxxabi/src/cxa_thread_atexit.cpp
+++ b/libcxxabi/src/cxa_thread_atexit.cpp
@@ -10,7 +10,7 @@
#include "cxxabi.h"
#include <__threading_support>
#ifndef _LIBCXXABI_HAS_NO_THREADS
-#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) && defined(__ELF__) && defined(_LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
#pragma comment(lib, "pthread")
#endif
#endif
diff --git a/libcxxabi/src/fallback_malloc.cpp b/libcxxabi/src/fallback_malloc.cpp
index bae0fa4ac23..73ea28ed824 100644
--- a/libcxxabi/src/fallback_malloc.cpp
+++ b/libcxxabi/src/fallback_malloc.cpp
@@ -13,7 +13,7 @@
#include <__threading_support>
#ifndef _LIBCXXABI_HAS_NO_THREADS
-#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) && defined(__ELF__) && defined(_LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
#pragma comment(lib, "pthread")
#endif
#endif
diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index 65cd5b2c672..16bfb9a8202 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -362,6 +362,10 @@ if (WIN32 AND LIBUNWIND_ENABLE_STATIC AND NOT LIBUNWIND_ENABLE_SHARED)
add_definitions(-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
endif()
+if (LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
+ add_definitions(-D_LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
+endif()
+
#===============================================================================
# Setup Source Code
#===============================================================================
diff --git a/libunwind/cmake/config-ix.cmake b/libunwind/cmake/config-ix.cmake
index 670c31f2d09..2c27ecf5207 100644
--- a/libunwind/cmake/config-ix.cmake
+++ b/libunwind/cmake/config-ix.cmake
@@ -1,7 +1,7 @@
-
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CheckLibraryExists)
+include(CheckCSourceCompiles)
check_library_exists(c fopen "" LIBUNWIND_HAS_C_LIB)
@@ -55,6 +55,14 @@ if (LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
endif ()
endif ()
+# Check compiler pragmas
+if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ check_c_source_compiles("
+#pragma comment(lib, \"c\")
+int main() { return 0; }
+" LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
+endif()
+
# Check compiler flags
check_c_compiler_flag(-funwind-tables LIBUNWIND_HAS_FUNWIND_TABLES)
check_cxx_compiler_flag(-fno-exceptions LIBUNWIND_HAS_NO_EXCEPTIONS_FLAG)
@@ -96,4 +104,3 @@ endif()
check_library_exists(dl dladdr "" LIBUNWIND_HAS_DL_LIB)
check_library_exists(pthread pthread_once "" LIBUNWIND_HAS_PTHREAD_LIB)
-
diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index 66439530309..fb07c807db9 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -27,7 +27,7 @@
#if _LIBUNWIND_USE_DLADDR
#include <dlfcn.h>
-#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) && defined(__ELF__) && defined(_LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
#pragma comment(lib, "dl")
#endif
#endif
diff --git a/libunwind/src/RWMutex.hpp b/libunwind/src/RWMutex.hpp
index 4f234a77edf..a37ac77144f 100644
--- a/libunwind/src/RWMutex.hpp
+++ b/libunwind/src/RWMutex.hpp
@@ -17,7 +17,7 @@
#include <windows.h>
#elif !defined(_LIBUNWIND_HAS_NO_THREADS)
#include <pthread.h>
-#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) && defined(__ELF__) && defined(_LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
#pragma comment(lib, "pthread")
#endif
#endif
OpenPOWER on IntegriCloud