[libcxx] [libcxxabi] [libunwind] [llvm] [runtimes] Probe for -nostdlib++ and -nostdinc++ with the C compiler (PR #108357)

Martin Storsjö via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 2 01:09:33 PDT 2024


================
@@ -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)
----------------
mstorsjo wrote:

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`.

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


More information about the cfe-commits mailing list