[compiler-rt] [compiler-rt][CMake] Fix build when specifying --stdlib= (with 2 dashes) (PR #136111)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 17 01:52:17 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-pgo
Author: Reagan (xbjfk)
<details>
<summary>Changes</summary>
You can pass the stdlib argument either as -stdlib and --stdlib - the previous regex did not accoutn 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.
---
Full diff: https://github.com/llvm/llvm-project/pull/136111.diff
5 Files Affected:
- (modified) compiler-rt/CMakeLists.txt (+2-2)
- (modified) compiler-rt/lib/gwp_asan/CMakeLists.txt (+1-1)
- (modified) compiler-rt/lib/msan/tests/CMakeLists.txt (+1-1)
- (modified) compiler-rt/lib/profile/CMakeLists.txt (+1-1)
- (modified) compiler-rt/lib/scudo/standalone/CMakeLists.txt (+1-1)
``````````diff
diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 9f8e8334d75ba..4297a5d02b6ca 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -596,8 +596,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 fdb6a95fe1404..f638adda3abe1 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 a8500225337e6..83dc61f4214b2 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 ac1451c8ceed1..42f9da4be2e6d 100644
--- a/compiler-rt/lib/profile/CMakeLists.txt
+++ b/compiler-rt/lib/profile/CMakeLists.txt
@@ -144,7 +144,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 3f9ae866a7553..5ee648b692f6a 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)
``````````
</details>
https://github.com/llvm/llvm-project/pull/136111
More information about the llvm-commits
mailing list