From b2ce908a48e0ab6b0404742f38e5e5d0ee51cc2f Mon Sep 17 00:00:00 2001 From: Reagan Date: Sat, 28 Feb 2026 22:22:27 -0800 Subject: [PATCH] [compiler-rt][CMake] Fix build when specifying --stdlib= (with 2 dashes) (#136111) You can pass the stdlib argument either as -stdlib and --stdlib - the previous regex did not account for this however - which caused the build to fail, as a --stdlib argument would be replaced with a single dash, causing clang to assume reading from stdin and the build to fail: clang++: error: -E or -x required when input is from standard input clang++: error: cannot specify -o when generating multiple output files The files [libcxxabi/CMakeLists.txt](https://github.com/llvm/llvm-project/blob/bf6986f9f09f79da38006a83c339226c429bb686/libcxxabi/CMakeLists.txt#L261) and [libunwind/CMakeLists.txt](https://github.com/llvm/llvm-project/blob/bf6986f9f09f79da38006a83c339226c429bb686/libunwind/CMakeLists.txt#L257) account for this by removing --stdlib first. Co-authored-by: Vitaly Buka --- compiler-rt/CMakeLists.txt | 4 ++-- compiler-rt/lib/gwp_asan/CMakeLists.txt | 2 +- compiler-rt/lib/msan/tests/CMakeLists.txt | 2 +- compiler-rt/lib/profile/CMakeLists.txt | 2 +- compiler-rt/lib/scudo/standalone/CMakeLists.txt | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt index d82b247bd712..0147aa1a4fd9 100644 --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -607,8 +607,8 @@ append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ SANITIZER_COMMON_CFLA append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ SANITIZER_COMMON_LINK_FLAGS) # Remove -stdlib= which is unused when passing -nostdinc++... -string(REGEX MATCHALL "-stdlib=[a-zA-Z+]*" stdlib_flag "${CMAKE_CXX_FLAGS}") -string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +string(REGEX MATCHALL "-?-stdlib=[a-zA-Z+]*" stdlib_flag "${CMAKE_CXX_FLAGS}") +string(REGEX REPLACE "-?-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # ...we need it to build some runtimes and tests so readd it where appropriate. list(APPEND COMPILER_RT_COMMON_CFLAGS ${stdlib_flag}) diff --git a/compiler-rt/lib/gwp_asan/CMakeLists.txt b/compiler-rt/lib/gwp_asan/CMakeLists.txt index fdb6a95fe140..f638adda3abe 100644 --- a/compiler-rt/lib/gwp_asan/CMakeLists.txt +++ b/compiler-rt/lib/gwp_asan/CMakeLists.txt @@ -39,7 +39,7 @@ append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC GWP_ASAN_CFLAGS) # append_list_if(COMPILER_RT_HAS_SANITIZER_COMMON ${SANITIZER_COMMON_CFLAGS} GWP_ASAN_CFLAGS) # Remove -stdlib= which is unused when passing -nostdinc++. -string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +string(REGEX REPLACE "-?-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # Options parsing support is optional. This is an optional library that can be # used by an allocator to automatically parse GwpAsan options from the diff --git a/compiler-rt/lib/msan/tests/CMakeLists.txt b/compiler-rt/lib/msan/tests/CMakeLists.txt index b4848a8d190d..978e16c290e0 100644 --- a/compiler-rt/lib/msan/tests/CMakeLists.txt +++ b/compiler-rt/lib/msan/tests/CMakeLists.txt @@ -46,7 +46,7 @@ set(MSAN_UNITTEST_COMMON_CFLAGS -fno-sanitize-memory-param-retval # unittests test mostly this mode. ) # Remove -stdlib= which is unused when passing -nostdinc++. -string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) +string(REGEX REPLACE "-?-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) set(MSAN_UNITTEST_INSTRUMENTED_CFLAGS ${MSAN_UNITTEST_COMMON_CFLAGS} diff --git a/compiler-rt/lib/profile/CMakeLists.txt b/compiler-rt/lib/profile/CMakeLists.txt index 7c8473cc5f20..ca2b97a3169a 100644 --- a/compiler-rt/lib/profile/CMakeLists.txt +++ b/compiler-rt/lib/profile/CMakeLists.txt @@ -163,7 +163,7 @@ endif() # We don't use the C++ Standard Library here, so avoid including it by mistake. append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ EXTRA_FLAGS) # XRay uses C++ standard library headers. -string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +string(REGEX REPLACE "-?-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # This appears to be a C-only warning banning the use of locals in aggregate # initializers. All other compilers accept this, though. diff --git a/compiler-rt/lib/scudo/standalone/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/CMakeLists.txt index db494a9a74a3..20c59b460061 100644 --- a/compiler-rt/lib/scudo/standalone/CMakeLists.txt +++ b/compiler-rt/lib/scudo/standalone/CMakeLists.txt @@ -13,7 +13,7 @@ list(APPEND SCUDO_CFLAGS -nostdinc++) # Remove -stdlib= which is unused when passing -nostdinc++. -string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +string(REGEX REPLACE "-?-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") append_list_if(COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG -fvisibility=hidden SCUDO_CFLAGS)