Skip to content

Commit

Permalink
Reinstate LLVMCheckCompilerLinkerFlag, to correctly encapsulate link …
Browse files Browse the repository at this point in the history
…flag check

This partially reverts commit 1515c2c.

Co-Authored-By: Ryan Prichard <[email protected]>
  • Loading branch information
h-vetinari and rprichard committed Jul 25, 2024
1 parent b416b5e commit 2f3fd55
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 28 deletions.
23 changes: 23 additions & 0 deletions cmake/Modules/LLVMCheckCompilerLinkerFlag.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
include(CMakePushCheckState)

include(CheckCompilerFlag OPTIONAL)

if(NOT COMMAND check_compiler_flag)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
endif()

This comment has been minimized.

Copy link
@rprichard

rprichard Jul 25, 2024

Author Contributor

This can be simplified, too, to just:

include(CMakePushCheckState)
include(CheckCompilerFlag)

CheckCompilerFlag is always available in CMake 3.19+, and the code doesn't use CheckCCompilerFlag / CheckCXXCompilerFlag anymore.

This comment has been minimized.

Copy link
@h-vetinari

h-vetinari Jul 25, 2024

Author Contributor

Yeah, I didn't pay attention to this part of the revert... Thanks!


function(llvm_check_compiler_linker_flag lang flag out_var)
# If testing a flag with check_c_compiler_flag, it gets added to the compile

This comment has been minimized.

Copy link
@rprichard

rprichard Jul 25, 2024

Author Contributor

check_c_compiler_flag -> check_compiler_flag

# command only, but not to the linker command in that test. If the flag
# is vital for linking to succeed, the test would fail even if it would
# have succeeded if it was included on both commands.
#
# Therefore, try adding the flag to CMAKE_REQUIRED_FLAGS, which gets
# added to both compiling and linking commands in the tests.

cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}")
check_compiler_flag("${lang}" "" ${out_var})
cmake_pop_check_state()
endfunction()
16 changes: 8 additions & 8 deletions compiler-rt/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
include(CMakePushCheckState)
include(AddLLVM)
include(CheckCompilerFlag)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CheckIncludeFiles)
include(CheckLibraryExists)
include(LLVMCheckCompilerLinkerFlag)
include(CheckSymbolExists)
include(TestBigEndian)

Expand All @@ -15,7 +15,7 @@ include(TestBigEndian)
# libunwind (and the compiler implicit -lunwind wouldn't succeed as the newly
# built libunwind isn't installed yet). For those cases, it'd be good to
# link with --unwindlib=none. Check if that option works.
check_compiler_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_NONE_FLAG)
llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_NONE_FLAG)

check_library_exists(c fopen "" COMPILER_RT_HAS_LIBC)
if (COMPILER_RT_USE_BUILTINS_LIBRARY)
Expand Down Expand Up @@ -190,12 +190,12 @@ check_library_exists(c++ __cxa_throw "" COMPILER_RT_HAS_LIBCXX)
check_library_exists(stdc++ __cxa_throw "" COMPILER_RT_HAS_LIBSTDCXX)

# Linker flags.
check_compiler_flag(C "-Wl,-z,text" COMPILER_RT_HAS_Z_TEXT)
check_compiler_flag(C "-fuse-ld=lld" COMPILER_RT_HAS_FUSE_LD_LLD_FLAG)
llvm_check_compiler_linker_flag(C "-Wl,-z,text" COMPILER_RT_HAS_Z_TEXT)
llvm_check_compiler_linker_flag(C "-fuse-ld=lld" COMPILER_RT_HAS_FUSE_LD_LLD_FLAG)

if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND LLVM_LINKER_IS_SOLARISLD)
set(VERS_COMPAT_OPTION "-Wl,-z,gnu-version-script-compat")
check_compiler_flag(C "${VERS_COMPAT_OPTION}" COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT)
llvm_check_compiler_linker_flag(C "${VERS_COMPAT_OPTION}" COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT)
endif()

set(DUMMY_VERS ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/dummy.vers)
Expand All @@ -206,10 +206,10 @@ if(COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT)
# -z gnu-version-script-compat.
string(APPEND VERS_OPTION " ${VERS_COMPAT_OPTION}")
endif()
check_compiler_flag(C "${VERS_OPTION}" COMPILER_RT_HAS_VERSION_SCRIPT)
llvm_check_compiler_linker_flag(C "${VERS_OPTION}" COMPILER_RT_HAS_VERSION_SCRIPT)

if(ANDROID)
check_compiler_flag(C "-Wl,-z,global" COMPILER_RT_HAS_Z_GLOBAL)
llvm_check_compiler_linker_flag(C "-Wl,-z,global" COMPILER_RT_HAS_Z_GLOBAL)
check_library_exists(log __android_log_write "" COMPILER_RT_HAS_LIBLOG)
endif()

Expand Down Expand Up @@ -494,7 +494,7 @@ if(APPLE)
-lc++
-lc++abi)

check_compiler_flag(C "-fapplication-extension" COMPILER_RT_HAS_APP_EXTENSION)
llvm_check_compiler_linker_flag(C "-fapplication-extension" COMPILER_RT_HAS_APP_EXTENSION)
if(COMPILER_RT_HAS_APP_EXTENSION)
list(APPEND DARWIN_COMMON_LINK_FLAGS "-fapplication-extension")
endif()
Expand Down
4 changes: 2 additions & 2 deletions libcxx/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include(CMakePushCheckState)
include(CheckLibraryExists)
include(CheckSymbolExists)
include(CheckCompilerFlag)
include(LLVMCheckCompilerLinkerFlag)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CheckCSourceCompiles)
Expand All @@ -13,7 +13,7 @@ include(CheckCSourceCompiles)
# libunwind (and the compiler implicit -lunwind wouldn't succeed as the newly
# built libunwind isn't installed yet). For those cases, it'd be good to
# link with --unwindlib=none. Check if that option works.
check_compiler_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)

if (NOT LIBCXX_USE_COMPILER_RT)
if(WIN32 AND NOT MINGW)
Expand Down
8 changes: 4 additions & 4 deletions libunwind/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ include(CMakePushCheckState)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CheckLibraryExists)
include(CheckCompilerFlag)
include(LLVMCheckCompilerLinkerFlag)
include(CheckSymbolExists)
include(CheckCSourceCompiles)

# The compiler driver may be implicitly trying to link against libunwind, which
# might not work if libunwind doesn't exist yet. Try to check if
# --unwindlib=none is supported, and use that if possible.
check_compiler_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)

if (HAIKU)
check_library_exists(root fopen "" LIBUNWIND_HAS_ROOT_LIB)
Expand All @@ -35,11 +35,11 @@ endif()
# required for the link to go through. We remove sanitizers from the
# configuration checks to avoid spurious link errors.

check_compiler_flag(CXX "-nostdlib++" CXX_SUPPORTS_NOSTDLIBXX_FLAG)
llvm_check_compiler_linker_flag(CXX "-nostdlib++" CXX_SUPPORTS_NOSTDLIBXX_FLAG)
if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
else()
check_compiler_flag(C "-nodefaultlibs" C_SUPPORTS_NODEFAULTLIBS_FLAG)
llvm_check_compiler_linker_flag(C "-nodefaultlibs" C_SUPPORTS_NODEFAULTLIBS_FLAG)
if (C_SUPPORTS_NODEFAULTLIBS_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
endif()
Expand Down
4 changes: 2 additions & 2 deletions offload/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ endmacro()

if(OPENMP_STANDALONE_BUILD OR TARGET omp)
# Check LIBOMP_HAVE_VERSION_SCRIPT_FLAG
include(CheckCompilerFlag)
include(LLVMCheckCompilerLinkerFlag)
if(NOT APPLE)
check_compiler_flag(C "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/../openmp/runtime/src/exports_test_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
llvm_check_compiler_linker_flag(C "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/../openmp/runtime/src/exports_test_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
endif()
endif()

Expand Down
18 changes: 9 additions & 9 deletions openmp/runtime/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#//===----------------------------------------------------------------------===//
#

include(CheckCompilerFlag)
include(CheckCCompilerFlag)
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
Expand All @@ -18,6 +17,7 @@ include(CheckLibraryExists)
include(CheckIncludeFiles)
include(CheckSymbolExists)
include(LibompCheckFortranFlag)
include(LLVMCheckCompilerLinkerFlag)

# Check for versioned symbols
function(libomp_check_version_symbols retval)
Expand Down Expand Up @@ -128,13 +128,13 @@ check_symbol_exists(_aligned_malloc "malloc.h" LIBOMP_HAVE__ALIGNED_MALLOC)

# Check linker flags
if(WIN32)
check_compiler_flag(C /SAFESEH LIBOMP_HAVE_SAFESEH_FLAG)
llvm_check_compiler_linker_flag(C /SAFESEH LIBOMP_HAVE_SAFESEH_FLAG)
elseif(NOT APPLE)
check_compiler_flag(C -Wl,-x LIBOMP_HAVE_X_FLAG)
check_compiler_flag(C -Wl,--as-needed LIBOMP_HAVE_AS_NEEDED_FLAG)
check_compiler_flag(C "-Wl,--version-script=${LIBOMP_SRC_DIR}/exports_test_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
check_compiler_flag(C -static-libgcc LIBOMP_HAVE_STATIC_LIBGCC_FLAG)
check_compiler_flag(C -Wl,-z,noexecstack LIBOMP_HAVE_Z_NOEXECSTACK_FLAG)
llvm_check_compiler_linker_flag(C -Wl,-x LIBOMP_HAVE_X_FLAG)
llvm_check_compiler_linker_flag(C -Wl,--as-needed LIBOMP_HAVE_AS_NEEDED_FLAG)
llvm_check_compiler_linker_flag(C "-Wl,--version-script=${LIBOMP_SRC_DIR}/exports_test_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
llvm_check_compiler_linker_flag(C -static-libgcc LIBOMP_HAVE_STATIC_LIBGCC_FLAG)
llvm_check_compiler_linker_flag(C -Wl,-z,noexecstack LIBOMP_HAVE_Z_NOEXECSTACK_FLAG)
endif()

# Check Intel(R) C Compiler specific flags
Expand All @@ -145,8 +145,8 @@ if(CMAKE_C_COMPILER_ID STREQUAL "Intel" OR CMAKE_C_COMPILER_ID STREQUAL "IntelLL
check_cxx_compiler_flag(-Qoption,cpp,--extended_float_types LIBOMP_HAVE_EXTENDED_FLOAT_TYPES_FLAG)
check_cxx_compiler_flag(-falign-stack=maintain-16-byte LIBOMP_HAVE_FALIGN_STACK_FLAG)
check_cxx_compiler_flag("-opt-streaming-stores never" LIBOMP_HAVE_OPT_STREAMING_STORES_FLAG)
check_compiler_flag(C -static-intel LIBOMP_HAVE_STATIC_INTEL_FLAG)
check_compiler_flag(C -no-intel-extensions LIBOMP_HAVE_NO_INTEL_EXTENSIONS_FLAG)
llvm_check_compiler_linker_flag(C -static-intel LIBOMP_HAVE_STATIC_INTEL_FLAG)
llvm_check_compiler_linker_flag(C -no-intel-extensions LIBOMP_HAVE_NO_INTEL_EXTENSIONS_FLAG)
check_library_exists(irc_pic _intel_fast_memcpy "" LIBOMP_HAVE_IRC_PIC_LIBRARY)
endif()

Expand Down
6 changes: 3 additions & 3 deletions runtimes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ set(LLVM_CMAKE_DIR ${LLVM_MAIN_SRC_DIR}/cmake/modules)
set(LLVM_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../llvm)

include(CheckLibraryExists)
include(CheckCompilerFlag)
include(LLVMCheckCompilerLinkerFlag)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)

Expand Down Expand Up @@ -114,7 +114,7 @@ filter_prefixed("${CMAKE_ASM_IMPLICIT_INCLUDE_DIRECTORIES}" ${LLVM_BINARY_DIR} C
# Currently, we counteract this issue by adding -fno-sanitize=all flag in
# the project specific code within */cmake/config-ix.cmake files but that's
# brittle. We should ideally move this to runtimes/CMakeLists.txt.
check_compiler_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --unwindlib=none")
Expand Down Expand Up @@ -143,7 +143,7 @@ endif()
# Check for -nostdlib++ first; if there's no C++ standard library yet,
# all check_cxx_compiler_flag commands will fail until we add -nostdlib++
# (or -nodefaultlibs).
check_compiler_flag(CXX "-nostdlib++" CXX_SUPPORTS_NOSTDLIBXX_FLAG)
llvm_check_compiler_linker_flag(CXX "-nostdlib++" CXX_SUPPORTS_NOSTDLIBXX_FLAG)
if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
endif()
Expand Down

0 comments on commit 2f3fd55

Please sign in to comment.