From b667153cf65e66dd5e14e6a715fb33e6200e91de Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Mon, 28 Jan 2019 04:12:54 +0000 Subject: [PATCH] [CMake] Use __libc_start_main rather than fopen when checking for C library The check_library_exists CMake uses a custom symbol definition. This is a problem when checking for C library symbols because Clang recognizes many of them as builtins, and returns the -Wbuiltin-requires-header (or -Wincompatible-library-redeclaration) error. When building with -Werror which is the default, this causes the check_library_exists check fail making the build think that C library isn't available. To avoid this issue, we should use a symbol that isn't recognized by Clang and wouldn't cause the same issue. __libc_start_main seems like reasonable choice that fits the bill. Differential Revision: https://reviews.llvm.org/D57142 llvm-svn: 352341 --- compiler-rt/cmake/config-ix.cmake | 2 +- libcxx/cmake/config-ix.cmake | 2 +- libcxxabi/cmake/config-ix.cmake | 2 +- libunwind/cmake/config-ix.cmake | 2 +- llvm/runtimes/CMakeLists.txt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake index ec52882665bf..9aaf90bbcaa2 100644 --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -12,7 +12,7 @@ function(check_linker_flag flag out_var) cmake_pop_check_state() endfunction() -check_library_exists(c fopen "" COMPILER_RT_HAS_LIBC) +check_library_exists(c __libc_start_main "" COMPILER_RT_HAS_LIBC) if (COMPILER_RT_USE_BUILTINS_LIBRARY) include(HandleCompilerRT) find_compiler_rt_library(builtins COMPILER_RT_BUILTINS_LIBRARY) diff --git a/libcxx/cmake/config-ix.cmake b/libcxx/cmake/config-ix.cmake index 730ee7e164a6..657b036dc24d 100644 --- a/libcxx/cmake/config-ix.cmake +++ b/libcxx/cmake/config-ix.cmake @@ -7,7 +7,7 @@ if(WIN32 AND NOT MINGW) # let the default linking take care of that. set(LIBCXX_HAS_C_LIB NO) else() - check_library_exists(c fopen "" LIBCXX_HAS_C_LIB) + check_library_exists(c __libc_start_main "" LIBCXX_HAS_C_LIB) endif() if (NOT LIBCXX_USE_COMPILER_RT) diff --git a/libcxxabi/cmake/config-ix.cmake b/libcxxabi/cmake/config-ix.cmake index 379b55477497..4be7adc81dd4 100644 --- a/libcxxabi/cmake/config-ix.cmake +++ b/libcxxabi/cmake/config-ix.cmake @@ -2,7 +2,7 @@ include(CheckLibraryExists) include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) -check_library_exists(c fopen "" LIBCXXABI_HAS_C_LIB) +check_library_exists(c __libc_start_main "" LIBCXXABI_HAS_C_LIB) if (NOT LIBCXXABI_USE_COMPILER_RT) check_library_exists(gcc_s __gcc_personality_v0 "" LIBCXXABI_HAS_GCC_S_LIB) endif () diff --git a/libunwind/cmake/config-ix.cmake b/libunwind/cmake/config-ix.cmake index 670c31f2d092..c0c9a53be1fa 100644 --- a/libunwind/cmake/config-ix.cmake +++ b/libunwind/cmake/config-ix.cmake @@ -3,7 +3,7 @@ include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) include(CheckLibraryExists) -check_library_exists(c fopen "" LIBUNWIND_HAS_C_LIB) +check_library_exists(c __libc_start_main "" LIBUNWIND_HAS_C_LIB) if (NOT LIBUNWIND_USE_COMPILER_RT) check_library_exists(gcc_s __gcc_personality_v0 "" LIBUNWIND_HAS_GCC_S_LIB) diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt index 42842409dca5..49fbe6ae4ac7 100644 --- a/llvm/runtimes/CMakeLists.txt +++ b/llvm/runtimes/CMakeLists.txt @@ -98,7 +98,7 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) include(CheckLibraryExists) include(CheckCCompilerFlag) - check_library_exists(c fopen "" LLVM_HAS_C_LIB) + check_library_exists(c __libc_start_main "" LLVM_HAS_C_LIB) check_c_compiler_flag(-nodefaultlibs LLVM_HAS_NODEFAULTLIBS_FLAG) if(LLVM_HAS_NODEFAULTLIBS_FLAG) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")