From: Hubert Tong Date: Thu, 7 Mar 2019 21:28:33 +0000 (+0000) Subject: Add secondary libstdc++ 4.8 and 5.1 detection mechanisms X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=60af31346f230c371e9f3dc053fe2f3604d3b832;p=llvm Add secondary libstdc++ 4.8 and 5.1 detection mechanisms Summary: The date-based approach to detecting unsupported versions of libstdc++ does not handle bug fix releases of older versions. As an example, the `__GLIBCXX__` value associated with version 5.1, `20150422`, is less than the values associated with versions 4.8.5 and 4.9.3. This patch adds secondary checks based on certain properties in sufficiently new versions of libstdc++. Reviewers: jfb, tstellar, rnk, sfertile, nemanjai Reviewed By: jfb Subscribers: mgorny, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D58682 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355638 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/cmake/modules/CheckCompilerVersion.cmake b/cmake/modules/CheckCompilerVersion.cmake index b1cb5527422..125a9537e61 100644 --- a/cmake/modules/CheckCompilerVersion.cmake +++ b/cmake/modules/CheckCompilerVersion.cmake @@ -58,6 +58,8 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++0x") + # Test for libstdc++ version of at least 4.8 by checking for _ZNKSt17bad_function_call4whatEv. + # Note: We should check _GLIBCXX_RELEASE when possible (i.e., for GCC 7.1 and up). check_cxx_source_compiles(" #include #if defined(__GLIBCXX__) @@ -65,12 +67,20 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") #error Unsupported libstdc++ version #endif #endif -int main() { return 0; } +#if defined(__GLIBCXX__) +extern const char _ZNKSt17bad_function_call4whatEv[]; +const char *chk = _ZNKSt17bad_function_call4whatEv; +#else +const char *chk = \"\"; +#endif +int main() { ++chk; return 0; } " LLVM_LIBSTDCXX_MIN) if(NOT LLVM_LIBSTDCXX_MIN) message(FATAL_ERROR "libstdc++ version must be at least ${GCC_MIN}.") endif() + # Test for libstdc++ version of at least 5.1 by checking for std::iostream_category(). + # Note: We should check _GLIBCXX_RELEASE when possible (i.e., for GCC 7.1 and up). check_cxx_source_compiles(" #include #if defined(__GLIBCXX__) @@ -78,6 +88,10 @@ int main() { return 0; } #error Unsupported libstdc++ version #endif #endif +#if defined(__GLIBCXX__) +#include +void foo(void) { (void) std::iostream_category(); } +#endif int main() { return 0; } " LLVM_LIBSTDCXX_SOFT_ERROR)