Skip to content

Commit b667153

Browse files
committedJan 28, 2019
[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
1 parent fd31bf9 commit b667153

File tree

5 files changed

+5
-5
lines changed

5 files changed

+5
-5
lines changed
 

‎compiler-rt/cmake/config-ix.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function(check_linker_flag flag out_var)
1212
cmake_pop_check_state()
1313
endfunction()
1414

15-
check_library_exists(c fopen "" COMPILER_RT_HAS_LIBC)
15+
check_library_exists(c __libc_start_main "" COMPILER_RT_HAS_LIBC)
1616
if (COMPILER_RT_USE_BUILTINS_LIBRARY)
1717
include(HandleCompilerRT)
1818
find_compiler_rt_library(builtins COMPILER_RT_BUILTINS_LIBRARY)

‎libcxx/cmake/config-ix.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if(WIN32 AND NOT MINGW)
77
# let the default linking take care of that.
88
set(LIBCXX_HAS_C_LIB NO)
99
else()
10-
check_library_exists(c fopen "" LIBCXX_HAS_C_LIB)
10+
check_library_exists(c __libc_start_main "" LIBCXX_HAS_C_LIB)
1111
endif()
1212

1313
if (NOT LIBCXX_USE_COMPILER_RT)

‎libcxxabi/cmake/config-ix.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ include(CheckLibraryExists)
22
include(CheckCCompilerFlag)
33
include(CheckCXXCompilerFlag)
44

5-
check_library_exists(c fopen "" LIBCXXABI_HAS_C_LIB)
5+
check_library_exists(c __libc_start_main "" LIBCXXABI_HAS_C_LIB)
66
if (NOT LIBCXXABI_USE_COMPILER_RT)
77
check_library_exists(gcc_s __gcc_personality_v0 "" LIBCXXABI_HAS_GCC_S_LIB)
88
endif ()

‎libunwind/cmake/config-ix.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include(CheckCCompilerFlag)
33
include(CheckCXXCompilerFlag)
44
include(CheckLibraryExists)
55

6-
check_library_exists(c fopen "" LIBUNWIND_HAS_C_LIB)
6+
check_library_exists(c __libc_start_main "" LIBUNWIND_HAS_C_LIB)
77

88
if (NOT LIBUNWIND_USE_COMPILER_RT)
99
check_library_exists(gcc_s __gcc_personality_v0 "" LIBUNWIND_HAS_GCC_S_LIB)

‎llvm/runtimes/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
9898
include(CheckLibraryExists)
9999
include(CheckCCompilerFlag)
100100

101-
check_library_exists(c fopen "" LLVM_HAS_C_LIB)
101+
check_library_exists(c __libc_start_main "" LLVM_HAS_C_LIB)
102102
check_c_compiler_flag(-nodefaultlibs LLVM_HAS_NODEFAULTLIBS_FLAG)
103103
if(LLVM_HAS_NODEFAULTLIBS_FLAG)
104104
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")

0 commit comments

Comments
 (0)
Please sign in to comment.