Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[runtimes] Probe for -nostdlib++ and -nostdinc++ with the C compiler #108357

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

mstorsjo
Copy link
Member

While these flags semantically are relevant only for C++, we do add them to CMAKE_REQUIRED_FLAGS if they are detected. All flags in that variable are used both when testing compilation of C and C++ (and for detecting libraries, which uses the C compiler driver).

Therefore, to be sure we safely can add the flags to CMAKE_REQUIRED_FLAGS, test for the option with the C language.

This should fix compilation with GCC; newer versions of GCC do support the -nostdlib++ option, but it's only supported by the C++ compiler driver, not the C driver. (However, many builds of GCC also do accept the option with the C driver, if GCC was compiled with Ada support enabled, see [1]. That's why this issue isn't noticed in all configurations with GCC.)

Clang does support these options in both C and C++ driver modes.

This should fix #90332.

[1] #90332 (comment)

While these flags semantically are relevant only for C++, we do
add them to CMAKE_REQUIRED_FLAGS if they are detected. All flags
in that variable are used both when testing compilation of C and C++
(and for detecting libraries, which uses the C compiler driver).

Therefore, to be sure we safely can add the flags to
CMAKE_REQUIRED_FLAGS, test for the option with the C language.

This should fix compilation with GCC; newer versions of GCC do
support the -nostdlib++ option, but it's only supported by the
C++ compiler driver, not the C driver. (However, many builds of
GCC also do accept the option with the C driver, if GCC was
compiled with Ada support enabled, see [1]. That's why this
issue isn't noticed in all configurations with GCC.)

Clang does support these options in both C and C++ driver modes.

[1] llvm#90332 (comment)
@mstorsjo mstorsjo requested a review from petrhosek September 12, 2024 10:15
@mstorsjo mstorsjo requested review from a team as code owners September 12, 2024 10:15
@llvmbot llvmbot added cmake Build system in general and CMake in particular libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. libc++abi libc++abi C++ Runtime Library. Not libc++. libunwind labels Sep 12, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 12, 2024

@llvm/pr-subscribers-libcxx

@llvm/pr-subscribers-libunwind

Author: Martin Storsjö (mstorsjo)

Changes

While these flags semantically are relevant only for C++, we do add them to CMAKE_REQUIRED_FLAGS if they are detected. All flags in that variable are used both when testing compilation of C and C++ (and for detecting libraries, which uses the C compiler driver).

Therefore, to be sure we safely can add the flags to CMAKE_REQUIRED_FLAGS, test for the option with the C language.

This should fix compilation with GCC; newer versions of GCC do support the -nostdlib++ option, but it's only supported by the C++ compiler driver, not the C driver. (However, many builds of GCC also do accept the option with the C driver, if GCC was compiled with Ada support enabled, see [1]. That's why this issue isn't noticed in all configurations with GCC.)

Clang does support these options in both C and C++ driver modes.

This should fix #90332.

[1] #90332 (comment)


Full diff: https://github.com/llvm/llvm-project/pull/108357.diff

6 Files Affected:

  • (modified) libcxx/cmake/config-ix.cmake (+8-4)
  • (modified) libcxxabi/cmake/config-ix.cmake (+8-4)
  • (modified) libcxxabi/src/CMakeLists.txt (+2-2)
  • (modified) libunwind/cmake/config-ix.cmake (+8-4)
  • (modified) libunwind/src/CMakeLists.txt (+1-1)
  • (modified) runtimes/CMakeLists.txt (+8-4)
diff --git a/libcxx/cmake/config-ix.cmake b/libcxx/cmake/config-ix.cmake
index 270d80575adcfd..192bad7a7a7fc6 100644
--- a/libcxx/cmake/config-ix.cmake
+++ b/libcxx/cmake/config-ix.cmake
@@ -38,9 +38,13 @@ check_cxx_compiler_flag(-nolibc CXX_SUPPORTS_NOLIBC_FLAG)
 # required during compilation (which has the -nostdlib++ or -nodefaultlibs). libc is
 # required for the link to go through. We remove sanitizers from the
 # configuration checks to avoid spurious link errors.
+#
+# Adding flags to CMAKE_REQUIRED_FLAGS will include the flags both when testing
+# compilation of C and C++. Therefore test to make sure that the flags are
+# supported by the C compiler driver, before deciding to include them.
 
-check_cxx_compiler_flag(-nostdlib++ CXX_SUPPORTS_NOSTDLIBXX_FLAG)
-if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+check_c_compiler_flag(-nostdlib++ C_SUPPORTS_NOSTDLIBXX_FLAG)
+if (C_SUPPORTS_NOSTDLIBXX_FLAG)
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
 else()
   check_c_compiler_flag(-nodefaultlibs C_SUPPORTS_NODEFAULTLIBS_FLAG)
@@ -51,7 +55,7 @@ endif()
 
 # Only link against compiler-rt manually if we use -nodefaultlibs, since
 # otherwise the compiler will do the right thing on its own.
-if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (LIBCXX_USE_COMPILER_RT)
     include(HandleCompilerRT)
     find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY
@@ -81,7 +85,7 @@ if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
   endif()
 endif()
 
-if (CXX_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (C_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
   endif ()
diff --git a/libcxxabi/cmake/config-ix.cmake b/libcxxabi/cmake/config-ix.cmake
index 10f2087c68c5e7..ab74ad79a654af 100644
--- a/libcxxabi/cmake/config-ix.cmake
+++ b/libcxxabi/cmake/config-ix.cmake
@@ -22,9 +22,13 @@ endif ()
 # required during compilation (which has the -nodefaultlibs). libc is
 # required for the link to go through. We remove sanitizers from the
 # configuration checks to avoid spurious link errors.
+#
+# Adding flags to CMAKE_REQUIRED_FLAGS will include the flags both when testing
+# compilation of C and C++. Therefore test to make sure that the flags are
+# supported by the C compiler driver, before deciding to include them.
 
-check_cxx_compiler_flag(-nostdlib++ CXX_SUPPORTS_NOSTDLIBXX_FLAG)
-if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+check_c_compiler_flag(-nostdlib++ C_SUPPORTS_NOSTDLIBXX_FLAG)
+if (C_SUPPORTS_NOSTDLIBXX_FLAG)
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
 else()
   check_c_compiler_flag(-nodefaultlibs C_SUPPORTS_NODEFAULTLIBS_FLAG)
@@ -35,7 +39,7 @@ endif()
 
 # Only link against compiler-rt manually if we use -nodefaultlibs, since
 # otherwise the compiler will do the right thing on its own.
-if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (LIBCXXABI_HAS_C_LIB)
     list(APPEND CMAKE_REQUIRED_LIBRARIES c)
   endif ()
@@ -71,7 +75,7 @@ if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
   endif()
 endif()
 
-if (CXX_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (C_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
   endif ()
diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index c1a7bcb14eb199..485349bdb735e6 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -91,7 +91,7 @@ if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21)
 endif()
 
 # Setup flags.
-if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+if (C_SUPPORTS_NOSTDLIBXX_FLAG)
   add_link_flags_if_supported(-nostdlib++)
 else()
   add_link_flags_if_supported(-nodefaultlibs)
@@ -167,7 +167,7 @@ if (LIBCXXABI_USE_LLVM_UNWINDER)
   endif()
 endif()
 target_link_libraries(cxxabi_shared_objects PRIVATE cxx-headers ${LIBCXXABI_LIBRARIES})
-if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG)
   target_link_libraries(cxxabi_shared_objects PRIVATE ${LIBCXXABI_BUILTINS_LIBRARY})
 endif()
 target_link_libraries(cxxabi_shared_objects PUBLIC cxxabi-headers)
diff --git a/libunwind/cmake/config-ix.cmake b/libunwind/cmake/config-ix.cmake
index 126c872f0d4895..88a13b4ec0e41c 100644
--- a/libunwind/cmake/config-ix.cmake
+++ b/libunwind/cmake/config-ix.cmake
@@ -34,9 +34,13 @@ endif()
 # required during compilation (which has the -nostdlib++ or -nodefaultlibs). libc is
 # required for the link to go through. We remove sanitizers from the
 # configuration checks to avoid spurious link errors.
+#
+# Adding flags to CMAKE_REQUIRED_FLAGS will include the flags both when testing
+# compilation of C and C++. Therefore test to make sure that the flags are
+# supported by the C compiler driver, before deciding to include them.
 
-llvm_check_compiler_linker_flag(CXX "-nostdlib++" CXX_SUPPORTS_NOSTDLIBXX_FLAG)
-if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+llvm_check_compiler_linker_flag(C "-nostdlib++" C_SUPPORTS_NOSTDLIBXX_FLAG)
+if (C_SUPPORTS_NOSTDLIBXX_FLAG)
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
 else()
   llvm_check_compiler_linker_flag(C "-nodefaultlibs" C_SUPPORTS_NODEFAULTLIBS_FLAG)
@@ -47,7 +51,7 @@ endif()
 
 # Only link against compiler-rt manually if we use -nodefaultlibs, since
 # otherwise the compiler will do the right thing on its own.
-if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (LIBUNWIND_HAS_C_LIB)
     list(APPEND CMAKE_REQUIRED_LIBRARIES c)
   endif ()
@@ -82,7 +86,7 @@ if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
   endif()
 endif()
 
-if (CXX_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (C_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
   endif ()
diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 780430ba70ba60..09d23e967493d3 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -66,7 +66,7 @@ set(LIBUNWIND_SOURCES
     ${LIBUNWIND_ASM_SOURCES})
 
 # Generate library list.
-if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+if (C_SUPPORTS_NOSTDLIBXX_FLAG)
   add_link_flags_if_supported(-nostdlib++)
 else()
   if (LIBUNWIND_USE_COMPILER_RT)
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index 830165c799c2ab..8db2b3fb9309b1 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -143,12 +143,16 @@ 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).
-llvm_check_compiler_linker_flag(CXX "-nostdlib++" CXX_SUPPORTS_NOSTDLIBXX_FLAG)
-if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+#
+# Adding flags to CMAKE_REQUIRED_FLAGS will include the flags both when testing
+# compilation of C and C++. Therefore test to make sure that the flags are
+# supported by the C compiler driver, before deciding to include them.
+llvm_check_compiler_linker_flag(C "-nostdlib++" C_SUPPORTS_NOSTDLIBXX_FLAG)
+if (C_SUPPORTS_NOSTDLIBXX_FLAG)
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
 endif()
-check_cxx_compiler_flag(-nostdinc++ CXX_SUPPORTS_NOSTDINCXX_FLAG)
-if (CXX_SUPPORTS_NOSTDINCXX_FLAG)
+check_c_compiler_flag(-nostdinc++ C_SUPPORTS_NOSTDINCXX_FLAG)
+if (C_SUPPORTS_NOSTDINCXX_FLAG)
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdinc++")
 endif()
 

@llvmbot
Copy link
Member

llvmbot commented Sep 12, 2024

@llvm/pr-subscribers-libcxxabi

Author: Martin Storsjö (mstorsjo)

Changes

While these flags semantically are relevant only for C++, we do add them to CMAKE_REQUIRED_FLAGS if they are detected. All flags in that variable are used both when testing compilation of C and C++ (and for detecting libraries, which uses the C compiler driver).

Therefore, to be sure we safely can add the flags to CMAKE_REQUIRED_FLAGS, test for the option with the C language.

This should fix compilation with GCC; newer versions of GCC do support the -nostdlib++ option, but it's only supported by the C++ compiler driver, not the C driver. (However, many builds of GCC also do accept the option with the C driver, if GCC was compiled with Ada support enabled, see [1]. That's why this issue isn't noticed in all configurations with GCC.)

Clang does support these options in both C and C++ driver modes.

This should fix #90332.

[1] #90332 (comment)


Full diff: https://github.com/llvm/llvm-project/pull/108357.diff

6 Files Affected:

  • (modified) libcxx/cmake/config-ix.cmake (+8-4)
  • (modified) libcxxabi/cmake/config-ix.cmake (+8-4)
  • (modified) libcxxabi/src/CMakeLists.txt (+2-2)
  • (modified) libunwind/cmake/config-ix.cmake (+8-4)
  • (modified) libunwind/src/CMakeLists.txt (+1-1)
  • (modified) runtimes/CMakeLists.txt (+8-4)
diff --git a/libcxx/cmake/config-ix.cmake b/libcxx/cmake/config-ix.cmake
index 270d80575adcfd..192bad7a7a7fc6 100644
--- a/libcxx/cmake/config-ix.cmake
+++ b/libcxx/cmake/config-ix.cmake
@@ -38,9 +38,13 @@ check_cxx_compiler_flag(-nolibc CXX_SUPPORTS_NOLIBC_FLAG)
 # required during compilation (which has the -nostdlib++ or -nodefaultlibs). libc is
 # required for the link to go through. We remove sanitizers from the
 # configuration checks to avoid spurious link errors.
+#
+# Adding flags to CMAKE_REQUIRED_FLAGS will include the flags both when testing
+# compilation of C and C++. Therefore test to make sure that the flags are
+# supported by the C compiler driver, before deciding to include them.
 
-check_cxx_compiler_flag(-nostdlib++ CXX_SUPPORTS_NOSTDLIBXX_FLAG)
-if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+check_c_compiler_flag(-nostdlib++ C_SUPPORTS_NOSTDLIBXX_FLAG)
+if (C_SUPPORTS_NOSTDLIBXX_FLAG)
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
 else()
   check_c_compiler_flag(-nodefaultlibs C_SUPPORTS_NODEFAULTLIBS_FLAG)
@@ -51,7 +55,7 @@ endif()
 
 # Only link against compiler-rt manually if we use -nodefaultlibs, since
 # otherwise the compiler will do the right thing on its own.
-if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (LIBCXX_USE_COMPILER_RT)
     include(HandleCompilerRT)
     find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY
@@ -81,7 +85,7 @@ if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
   endif()
 endif()
 
-if (CXX_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (C_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
   endif ()
diff --git a/libcxxabi/cmake/config-ix.cmake b/libcxxabi/cmake/config-ix.cmake
index 10f2087c68c5e7..ab74ad79a654af 100644
--- a/libcxxabi/cmake/config-ix.cmake
+++ b/libcxxabi/cmake/config-ix.cmake
@@ -22,9 +22,13 @@ endif ()
 # required during compilation (which has the -nodefaultlibs). libc is
 # required for the link to go through. We remove sanitizers from the
 # configuration checks to avoid spurious link errors.
+#
+# Adding flags to CMAKE_REQUIRED_FLAGS will include the flags both when testing
+# compilation of C and C++. Therefore test to make sure that the flags are
+# supported by the C compiler driver, before deciding to include them.
 
-check_cxx_compiler_flag(-nostdlib++ CXX_SUPPORTS_NOSTDLIBXX_FLAG)
-if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+check_c_compiler_flag(-nostdlib++ C_SUPPORTS_NOSTDLIBXX_FLAG)
+if (C_SUPPORTS_NOSTDLIBXX_FLAG)
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
 else()
   check_c_compiler_flag(-nodefaultlibs C_SUPPORTS_NODEFAULTLIBS_FLAG)
@@ -35,7 +39,7 @@ endif()
 
 # Only link against compiler-rt manually if we use -nodefaultlibs, since
 # otherwise the compiler will do the right thing on its own.
-if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (LIBCXXABI_HAS_C_LIB)
     list(APPEND CMAKE_REQUIRED_LIBRARIES c)
   endif ()
@@ -71,7 +75,7 @@ if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
   endif()
 endif()
 
-if (CXX_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (C_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
   endif ()
diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index c1a7bcb14eb199..485349bdb735e6 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -91,7 +91,7 @@ if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21)
 endif()
 
 # Setup flags.
-if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+if (C_SUPPORTS_NOSTDLIBXX_FLAG)
   add_link_flags_if_supported(-nostdlib++)
 else()
   add_link_flags_if_supported(-nodefaultlibs)
@@ -167,7 +167,7 @@ if (LIBCXXABI_USE_LLVM_UNWINDER)
   endif()
 endif()
 target_link_libraries(cxxabi_shared_objects PRIVATE cxx-headers ${LIBCXXABI_LIBRARIES})
-if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG)
   target_link_libraries(cxxabi_shared_objects PRIVATE ${LIBCXXABI_BUILTINS_LIBRARY})
 endif()
 target_link_libraries(cxxabi_shared_objects PUBLIC cxxabi-headers)
diff --git a/libunwind/cmake/config-ix.cmake b/libunwind/cmake/config-ix.cmake
index 126c872f0d4895..88a13b4ec0e41c 100644
--- a/libunwind/cmake/config-ix.cmake
+++ b/libunwind/cmake/config-ix.cmake
@@ -34,9 +34,13 @@ endif()
 # required during compilation (which has the -nostdlib++ or -nodefaultlibs). libc is
 # required for the link to go through. We remove sanitizers from the
 # configuration checks to avoid spurious link errors.
+#
+# Adding flags to CMAKE_REQUIRED_FLAGS will include the flags both when testing
+# compilation of C and C++. Therefore test to make sure that the flags are
+# supported by the C compiler driver, before deciding to include them.
 
-llvm_check_compiler_linker_flag(CXX "-nostdlib++" CXX_SUPPORTS_NOSTDLIBXX_FLAG)
-if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+llvm_check_compiler_linker_flag(C "-nostdlib++" C_SUPPORTS_NOSTDLIBXX_FLAG)
+if (C_SUPPORTS_NOSTDLIBXX_FLAG)
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
 else()
   llvm_check_compiler_linker_flag(C "-nodefaultlibs" C_SUPPORTS_NODEFAULTLIBS_FLAG)
@@ -47,7 +51,7 @@ endif()
 
 # Only link against compiler-rt manually if we use -nodefaultlibs, since
 # otherwise the compiler will do the right thing on its own.
-if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (LIBUNWIND_HAS_C_LIB)
     list(APPEND CMAKE_REQUIRED_LIBRARIES c)
   endif ()
@@ -82,7 +86,7 @@ if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
   endif()
 endif()
 
-if (CXX_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (C_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
   endif ()
diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 780430ba70ba60..09d23e967493d3 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -66,7 +66,7 @@ set(LIBUNWIND_SOURCES
     ${LIBUNWIND_ASM_SOURCES})
 
 # Generate library list.
-if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+if (C_SUPPORTS_NOSTDLIBXX_FLAG)
   add_link_flags_if_supported(-nostdlib++)
 else()
   if (LIBUNWIND_USE_COMPILER_RT)
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index 830165c799c2ab..8db2b3fb9309b1 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -143,12 +143,16 @@ 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).
-llvm_check_compiler_linker_flag(CXX "-nostdlib++" CXX_SUPPORTS_NOSTDLIBXX_FLAG)
-if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+#
+# Adding flags to CMAKE_REQUIRED_FLAGS will include the flags both when testing
+# compilation of C and C++. Therefore test to make sure that the flags are
+# supported by the C compiler driver, before deciding to include them.
+llvm_check_compiler_linker_flag(C "-nostdlib++" C_SUPPORTS_NOSTDLIBXX_FLAG)
+if (C_SUPPORTS_NOSTDLIBXX_FLAG)
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
 endif()
-check_cxx_compiler_flag(-nostdinc++ CXX_SUPPORTS_NOSTDINCXX_FLAG)
-if (CXX_SUPPORTS_NOSTDINCXX_FLAG)
+check_c_compiler_flag(-nostdinc++ C_SUPPORTS_NOSTDINCXX_FLAG)
+if (C_SUPPORTS_NOSTDINCXX_FLAG)
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdinc++")
 endif()
 


check_cxx_compiler_flag(-nostdlib++ CXX_SUPPORTS_NOSTDLIBXX_FLAG)
if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
check_c_compiler_flag(-nostdlib++ C_SUPPORTS_NOSTDLIBXX_FLAG)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we compile any C sources in libc++? Why do we care what flags the C compiler supports for libc++ and libc++abi? (I understand why it matters for libunwind where we do have C sources).

The reason I'm asking is that there are some simplifications we can make if we assume that all supported compilers accept -nostdlib++, and this patch makes it impossible to make that assumption.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that even if we don’t use any C sources outright, cmake uses C compilation tests when you do a check for whether a library exists. And these are subtly broken if building with GCC right now. (To make matters worse, not all GCC versions are affected. But that’s a bug - GCC intends to reject these options in the C frontend.) IIRC one of the issues mentioned in the linked bug was about library detection in libcxxabi.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that even if we don’t use any C sources outright, cmake uses C compilation tests when you do a check for whether a library exists.

Do you mean these checks?

check_library_exists(pthread pthread_create "" LIBCXX_HAS_PTHREAD_LIB)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly those; any of those basic compiler tests, check_library_exists (used a couple of times in libcxxabi and libcxx), check_include_file (not used in libcxxabi/libcxx, but used in openmp, and also struck by the same issue, in #90332), are executed as plain C compilation, and they will fail if we have stuck C++-only flags in CMAKE_REQUIRED_FLAGS.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping

@mstorsjo mstorsjo merged commit 75d0281 into llvm:main Oct 24, 2024
65 checks passed
@mstorsjo mstorsjo deleted the runtimes-nostdlibxx branch October 24, 2024 20:46
@mstorsjo
Copy link
Member Author

FWIW, I'd like to backport this to 19.x if possible. But I'll wait for a little while to see whether this turns up any issues, before filing the backport request.

@vitalybuka
Copy link
Collaborator

Actually this PR is the case of https://lab.llvm.org/buildbot/#/builders/164/builds/3908, not #113491

@mstorsjo
Copy link
Member Author

Actually this PR is the case of https://lab.llvm.org/buildbot/#/builders/164/builds/3908, not #113491

Sorry about that.

Are you able to dig up any of the cmake configure logs from these builds, so that we can figure out how this ends up breaking things? Because as in most of these cases, the visible output in the buildbot logs mostly say that some configure checks end up going the wrong way, but we can't really see why.

@mstorsjo
Copy link
Member Author

Actually this PR is the case of https://lab.llvm.org/buildbot/#/builders/164/builds/3908, not #113491

Sorry about that.

Are you able to dig up any of the cmake configure logs from these builds, so that we can figure out how this ends up breaking things? Because as in most of these cases, the visible output in the buildbot logs mostly say that some configure checks end up going the wrong way, but we can't really see why.

@vitalybuka Are you able to pull out some details to help figure out what this really broke here?

NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
…lvm#108357)

While these flags semantically are relevant only for C++, we do add them
to CMAKE_REQUIRED_FLAGS if they are detected. All flags in that variable
are used both when testing compilation of C and C++ (and for detecting
libraries, which uses the C compiler driver).

Therefore, to be sure we safely can add the flags to
CMAKE_REQUIRED_FLAGS, test for the option with the C language.

This should fix compilation with GCC; newer versions of GCC do support
the -nostdlib++ option, but it's only supported by the C++ compiler
driver, not the C driver. (However, many builds of GCC also do accept
the option with the C driver, if GCC was compiled with Ada support
enabled, see [1]. That's why this issue isn't noticed in all
configurations with GCC.)

Clang does support these options in both C and C++ driver modes.

This should fix llvm#90332.

[1]
llvm#90332 (comment)
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
@mstorsjo
Copy link
Member Author

Actually this PR is the case of https://lab.llvm.org/buildbot/#/builders/164/builds/3908, not #113491

Sorry about that.
Are you able to dig up any of the cmake configure logs from these builds, so that we can figure out how this ends up breaking things? Because as in most of these cases, the visible output in the buildbot logs mostly say that some configure checks end up going the wrong way, but we can't really see why.

@vitalybuka Are you able to pull out some details to help figure out what this really broke here?

Ping @vitalybuka - can you help out with retrying this PR and providing some details about what went wrong, so that we can have a path towards merging this again?

@h-vetinari
Copy link
Contributor

Ping @vitalybuka

@vitalybuka
Copy link
Collaborator

Actually this PR is the case of https://lab.llvm.org/buildbot/#/builders/164/builds/3908, not #113491

Sorry about that.
Are you able to dig up any of the cmake configure logs from these builds, so that we can figure out how this ends up breaking things? Because as in most of these cases, the visible output in the buildbot logs mostly say that some configure checks end up going the wrong way, but we can't really see why.

@vitalybuka Are you able to pull out some details to help figure out what this really broke here?

Ping @vitalybuka - can you help out with retrying this PR and providing some details about what went wrong, so that we can have a path towards merging this again?

Sure, I can retry the build locally, but would be more convenient for you to just reproduce according to https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild ?
libcxx step is very early, so no need to wait for entire build.

I guess you can just copy cmake invocation from
https://lab.llvm.org/buildbot/#/builders/sanitizer-x86_64-linux-bootstrap-msan/
you need steps:

  1. stage1 build all
  2. stage2/msan build libcxx

@vitalybuka
Copy link
Collaborator

The problem is that some of check_cxx_source_compiles invocation does:

cat t.cpp 
int main() {
 }

/usr/local/google/home/vitalybuka/tmp/bot/llvm_build0/bin/clang++ -fsanitize=memory  -nostdlib++ -nostdinc++  -fuse-ld=lld t.cpp 

>> referenced by ubsan_type_hash_itanium.cpp:245 (/usr/local/google/home/vitalybuka/tmp/bot/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:245)
>>>               ubsan_type_hash_itanium.cpp.o:(__ubsan::checkDynamicType(void*, void*, unsigned long)) in archive /usr/local/google/home/vitalybuka/tmp/bot/llvm_build0/lib/clang/20/lib/x86_64-unknown-linux-gnu/libclang_rt.msan_cxx.a

ld.lld: error: undefined symbol: typeinfo for __cxxabiv1::__class_type_info
>>> referenced by ubsan_type_hash_itanium.cpp:245 (/usr/local/google/home/vitalybuka/tmp/bot/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:245)
>>>               ubsan_type_hash_itanium.cpp.o:(__ubsan::checkDynamicType(void*, void*, unsigned long)) in archive /usr/local/google/home/vitalybuka/tmp/bot/llvm_build0/lib/clang/20/lib/x86_64-unknown-linux-gnu/libclang_rt.msan_cxx.a
>>> referenced by ubsan_type_hash_itanium.cpp:0 (/usr/local/google/home/vitalybuka/tmp/bot/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:0)
>>>               ubsan_type_hash_itanium.cpp.o:(isDerivedFromAtOffset(__cxxabiv1::__class_type_info const*, __cxxabiv1::__class_type_info const*, long)) in archive /usr/local/google/home/vitalybuka/tmp/bot/llvm_build0/lib/clang/20/lib/x86_64-unknown-linux-gnu/libclang_rt.msan_cxx.a
>>> referenced by ubsan_type_hash_itanium.cpp:141 (/usr/local/google/home/vitalybuka/tmp/bot/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:141)
>>>               ubsan_type_hash_itanium.cpp.o:(isDerivedFromAtOffset(__cxxabiv1::__class_type_info const*, __cxxabiv1::__class_type_info const*, long)) in archive /usr/local/google/home/vitalybuka/tmp/bot/llvm_build0/lib/clang/20/lib/x86_64-unknown-linux-gnu/libclang_rt.msan_cxx.a
>>> referenced 2 more times

and so on

So -nostdlib++ removes libc++ but does not remove msan_cxx.a.

My guess we need to fix the driver to do so.

@vitalybuka
Copy link
Collaborator

diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp
index 89f1215afd0c..234c28bfd2c3 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -1083,10 +1083,11 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
                    options::OPT_fno_sanitize_link_runtime, LinkRuntimes);
 
   // Parse -link-cxx-sanitizer flag.
-  LinkCXXRuntimes = Args.hasArg(options::OPT_fsanitize_link_cxx_runtime,
-                                options::OPT_fno_sanitize_link_cxx_runtime,
-                                LinkCXXRuntimes) ||
-                    D.CCCIsCXX();
+  LinkCXXRuntimes =
+      Args.hasFlag(options::OPT_fsanitize_link_cxx_runtime,
+                  options::OPT_fno_sanitize_link_cxx_runtime,
+                  LinkCXXRuntimes) ||
+      (D.CCCIsCXX() && !Args.hasArg(clang::driver::options::OPT_nostdlibxx))  ;
 
   NeedsMemProfRt = Args.hasFlag(options::OPT_fmemory_profile,
                                 options::OPT_fmemory_profile_EQ,

@petrhosek Args.hasArg looks like a typo in https://reviews.llvm.org/D65029 ?

@mstorsjo
Copy link
Member Author

The problem is that some of check_cxx_source_compiles invocation does:

cat t.cpp 
int main() {
 }

/usr/local/google/home/vitalybuka/tmp/bot/llvm_build0/bin/clang++ -fsanitize=memory  -nostdlib++ -nostdinc++  -fuse-ld=lld t.cpp 

>> referenced by ubsan_type_hash_itanium.cpp:245 (/usr/local/google/home/vitalybuka/tmp/bot/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:245)
>>>               ubsan_type_hash_itanium.cpp.o:(__ubsan::checkDynamicType(void*, void*, unsigned long)) in archive /usr/local/google/home/vitalybuka/tmp/bot/llvm_build0/lib/clang/20/lib/x86_64-unknown-linux-gnu/libclang_rt.msan_cxx.a

ld.lld: error: undefined symbol: typeinfo for __cxxabiv1::__class_type_info
>>> referenced by ubsan_type_hash_itanium.cpp:245 (/usr/local/google/home/vitalybuka/tmp/bot/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:245)
>>>               ubsan_type_hash_itanium.cpp.o:(__ubsan::checkDynamicType(void*, void*, unsigned long)) in archive /usr/local/google/home/vitalybuka/tmp/bot/llvm_build0/lib/clang/20/lib/x86_64-unknown-linux-gnu/libclang_rt.msan_cxx.a
>>> referenced by ubsan_type_hash_itanium.cpp:0 (/usr/local/google/home/vitalybuka/tmp/bot/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:0)
>>>               ubsan_type_hash_itanium.cpp.o:(isDerivedFromAtOffset(__cxxabiv1::__class_type_info const*, __cxxabiv1::__class_type_info const*, long)) in archive /usr/local/google/home/vitalybuka/tmp/bot/llvm_build0/lib/clang/20/lib/x86_64-unknown-linux-gnu/libclang_rt.msan_cxx.a
>>> referenced by ubsan_type_hash_itanium.cpp:141 (/usr/local/google/home/vitalybuka/tmp/bot/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:141)
>>>               ubsan_type_hash_itanium.cpp.o:(isDerivedFromAtOffset(__cxxabiv1::__class_type_info const*, __cxxabiv1::__class_type_info const*, long)) in archive /usr/local/google/home/vitalybuka/tmp/bot/llvm_build0/lib/clang/20/lib/x86_64-unknown-linux-gnu/libclang_rt.msan_cxx.a
>>> referenced 2 more times

and so on

So -nostdlib++ removes libc++ but does not remove msan_cxx.a.

My guess we need to fix the driver to do so.

Thanks! So this means, with this patch, we conclude that -nostdlib++ doesn't work, and this causes the build to fail later for other reasons? (The buildbot logs seems to be expired at this point.)

But I find this a bit confusing still, because this patch should make the probing to be done with $CC, not $CXX, so then the test case in your example should be using clang, not clang++? Or is there some longer series of changed conclusions here?

@vitalybuka
Copy link
Collaborator

vitalybuka commented Dec 18, 2024

But I find this a bit confusing still, because this patch should make the probing to be done with $CC, not $CXX, so then the test case in your example should be using clang, not clang++? Or is there some longer series of changed conclusions here?

Error is from this check:

check_cxx_source_compiles("int main() { return 0; }" CXX_SUPPORTS_CUSTOM_LINKER)

Yes, if intention was to affect C compiler, than the patch may need some improvement other than #120370

@mstorsjo
Copy link
Member Author

Ok, now I tried this myself (and indeed, it wasn't very hard to set up - sorry for not trying it earlier).

Here's the effect on the configure run, caused by this patch:

--- log-good-truncated  2024-12-18 13:59:16.334711800 +0200
+++ log-bad     2024-12-18 13:58:07.287917504 +0200
@@ -29,10 +29,19 @@
 -- Could NOT find Clang (missing: Clang_DIR)
 -- Performing Test CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG
 -- Performing Test CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG - Failed
--- Performing Test CXX_SUPPORTS_NOSTDLIBXX_FLAG
--- Performing Test CXX_SUPPORTS_NOSTDLIBXX_FLAG - Failed
--- Performing Test CXX_SUPPORTS_NOSTDINCXX_FLAG
--- Performing Test CXX_SUPPORTS_NOSTDINCXX_FLAG - Success
+-- Performing Test C_SUPPORTS_NOSTDLIBXX_FLAG
+-- Performing Test C_SUPPORTS_NOSTDLIBXX_FLAG - Success
+-- Performing Test C_SUPPORTS_NOSTDINCXX_FLAG
+-- Performing Test C_SUPPORTS_NOSTDINCXX_FLAG - Success
 -- Linker detection: LLD
 -- Performing Test CXX_SUPPORTS_CUSTOM_LINKER
--- Performing Test CXX_SUPPORTS_CUSTOM_LINKER - Success
+-- Performing Test CXX_SUPPORTS_CUSTOM_LINKER - Failed
+CMake Error at /home/martin/code/llvm-project/llvm/cmake/modules/HandleLLVMOpti
ons.cmake:412 (message):
+  Host compiler does not support '-fuse-ld=lld'.  Please make sure that 'lld'
+  is installed and that your host compiler can compile a simple program when
+  given the option '-fuse-ld=lld'.
+Call Stack (most recent call first):
+  CMakeLists.txt:179 (include)
+
+
+-- Configuring incomplete, errors occurred!

So previously, CXX_SUPPORTS_NOSTDLIBXX_FLAG failed, so we didn't add -nostdlib++. It failed due to the issue that does get fixed by #120370. By applying this change, we happen to go around that issue, so we end up adding -nostdlib++, even when it fails to link in C++ mode.

So, indeed, #120370 seems like a proper fix for this. Thanks!

(Ideally, we probably should probe for support for these flags separately for C and C++ mode, but it would require CMake to have something like CMAKE_REQUIRED_FLAGS separately for C and C++, which it doesn't - that's the whole root cause for this mess.)

vitalybuka added a commit that referenced this pull request Dec 18, 2024
1. -f[no-]sanitize-link-c++-runtime suppose to
   override defauld behavior implied from `CCCIsCXX`
2. Take into account -nostdlib++ (unblocks #108357)
3. Fix typo hasFlag vs hasArg.
@mstorsjo
Copy link
Member Author

Ok, so with #120370 landed, I guess we could consider trying to reland this.

By doing that, we would however break doing msan+libcxx builds unless using the very latest Clang (while libcxx in general supports building with the last two stable releases of Clang). Do you think this is an issue, or are we ok with implicitly requiring the very latest for this particular configuration?

@h-vetinari
Copy link
Contributor

We could backport #120370 so that at least clang 19.1.x still becomes compatible again (post-reland)?

@vitalybuka
Copy link
Collaborator

#120370 was reverted, because libc++ tests expose major problem:
Tests and likely many users can have -nostdlib++ -lc++.
The if we remove c++ sanitizer runtimes from linking it will break them and force to add -fsanitize-link-c++-runtime

I will reland unrelated parts of #120370, and think for other solutions.

@mstorsjo
Copy link
Member Author

#120370 was reverted, because libc++ tests expose major problem:
Tests and likely many users can have -nostdlib++ -lc++.
The if we remove c++ sanitizer runtimes from linking it will break them and force to add -fsanitize-link-c++-runtime

That's indeed a problem... However the libc++ test failure, as far as I can see, seems to be that there was a libc++ test that used to fail when built with sanitizers, but that test now no longer fail in that configuration. (I'm not entirely sure why it did use to fail though - but I guess that discussion belongs in #120370 - I'll comment more on it there.)

@vitalybuka
Copy link
Collaborator

#120370 was reverted, because libc++ tests expose major problem:
Tests and likely many users can have -nostdlib++ -lc++.
The if we remove c++ sanitizer runtimes from linking it will break them and force to add -fsanitize-link-c++-runtime

That's indeed a problem... However the libc++ test failure, as far as I can see, seems to be that there was a libc++ test that used to fail when built with sanitizers, but that test now no longer fail in that configuration. (I'm not entirely sure why it did use to fail though - but I guess that discussion belongs in #120370 - I'll comment more on it there.)

That's apply to asan,msan

-nostdlib++ -lc++ is relevant for many ubsan tests https://lab.llvm.org/buildbot/#/builders/25/builds/5017

@mstorsjo
Copy link
Member Author

#120370 was reverted, because libc++ tests expose major problem:
Tests and likely many users can have -nostdlib++ -lc++.
The if we remove c++ sanitizer runtimes from linking it will break them and force to add -fsanitize-link-c++-runtime

That's indeed a problem... However the libc++ test failure, as far as I can see, seems to be that there was a libc++ test that used to fail when built with sanitizers, but that test now no longer fail in that configuration. (I'm not entirely sure why it did use to fail though - but I guess that discussion belongs in #120370 - I'll comment more on it there.)

That's apply to asan,msan

-nostdlib++ -lc++ is relevant for many ubsan tests https://lab.llvm.org/buildbot/#/builders/25/builds/5017

Ah, I see, yeah, there's clearly not just one single test failing there. I mirrored part of this conversation into #120370 where it may be more on topic regarding the fallout of that change.

h-vetinari pushed a commit to h-vetinari/llvm-project that referenced this pull request Dec 24, 2024
…lvm#108357)

While these flags semantically are relevant only for C++, we do add them
to CMAKE_REQUIRED_FLAGS if they are detected. All flags in that variable
are used both when testing compilation of C and C++ (and for detecting
libraries, which uses the C compiler driver).

Therefore, to be sure we safely can add the flags to
CMAKE_REQUIRED_FLAGS, test for the option with the C language.

This should fix compilation with GCC; newer versions of GCC do support
the -nostdlib++ option, but it's only supported by the C++ compiler
driver, not the C driver. (However, many builds of GCC also do accept
the option with the C driver, if GCC was compiled with Ada support
enabled, see [1]. That's why this issue isn't noticed in all
configurations with GCC.)

Clang does support these options in both C and C++ driver modes.

This should fix llvm#90332.

[1]
llvm#90332 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Build system in general and CMake in particular libc++abi libc++abi C++ Runtime Library. Not libc++. libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. libunwind
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[runtimes] [openmp] -nostdlib++ added to CMAKE_REQUIRED_FLAGS breaks hwloc detection for OMPT
5 participants