[libc-commits] [libc] [libc][cmake] Suppress -Wpsabi note on GCC and clean up resource-dir check. (PR #227968)
via libc-commits
libc-commits at lists.llvm.org
Wed Sep 30 23:06:35 PDT 2026
https://github.com/lntue created https://github.com/llvm/llvm-project/pull/227968
- Add `-Wno-psabi` to GCC compile options to suppress ABI change notes for 80-bit long double unions.
- Pass `ERROR_QUIET` to clang-specific `--print-resource-dir` query in `libc/CMakeLists.txt` so it does not output errors on GCC and MSVC.
Assisted-by: Gemini
>From e466106a7fa7b5bea29912034fc309564510d508 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue at google.com>
Date: Thu, 1 Oct 2026 01:40:00 -0400
Subject: [PATCH] [libc][cmake] Suppress -Wpsabi note on GCC and clean up
resource-dir check.
- Add `-Wno-psabi` to GCC compile options to suppress ABI change notes
for 80-bit long double unions.
- Pass `ERROR_QUIET` to clang-specific `--print-resource-dir` query in
`libc/CMakeLists.txt` so it does not output errors on GCC and MSVC.
Assisted-by: Gemini
---
libc/CMakeLists.txt | 109 ++++++++++++------
.../modules/LLVMLibCCompileOptionRules.cmake | 1 +
libc/cmake/modules/LLVMLibCTestRules.cmake | 1 +
3 files changed, 77 insertions(+), 34 deletions(-)
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 292e4c90a26a858..ccae01cbc675e22 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -127,44 +127,85 @@ set(LIBC_TEST_HERMETIC_ONLY "" OFF CACHE BOOL "Only enable hermetic tests.")
list(APPEND LIBC_COMPILE_OPTIONS_DEFAULT ${LIBC_COMMON_TUNE_OPTIONS})
-# Check --print-resource-dir to find the compiler resource dir if this flag
-# is supported by the compiler.
-execute_process(
- OUTPUT_STRIP_TRAILING_WHITESPACE
- COMMAND ${CMAKE_CXX_COMPILER} --print-resource-dir
- RESULT_VARIABLE COMMAND_RETURN_CODE
- OUTPUT_VARIABLE COMPILER_RESOURCE_DIR
-)
-# Retrieve the host compiler's resource dir.
-if(COMMAND_RETURN_CODE EQUAL 0)
- set(COMPILER_RESOURCE_DIR
- "${COMPILER_RESOURCE_DIR}" CACHE PATH "path to compiler resource dir"
- )
- message(STATUS "Set COMPILER_RESOURCE_DIR to "
- "${COMPILER_RESOURCE_DIR} using --print-resource-dir")
-else()
- # Try with GCC option: -print-search-dirs, which will output in the form:
- # install: <path>
- # programs: ........
- # So we try to capture the <path> after "install: " in the first line of the
- # output.
- execute_process(
- OUTPUT_STRIP_TRAILING_WHITESPACE
- COMMAND ${CMAKE_CXX_COMPILER} -print-search-dirs
- RESULT_VARIABLE COMMAND_RETURN_CODE
- OUTPUT_VARIABLE COMPILER_RESOURCE_DIR
- )
- if(COMMAND_RETURN_CODE EQUAL 0)
- string(REPLACE " " ";" COMPILER_RESOURCE_DIR ${COMPILER_RESOURCE_DIR})
- string(REPLACE "\n" ";" COMPILER_RESOURCE_DIR "${COMPILER_RESOURCE_DIR}")
- list(GET COMPILER_RESOURCE_DIR 1 COMPILER_RESOURCE_DIR)
- message(STATUS "Set COMPILER_RESOURCE_DIR to "
- "${COMPILER_RESOURCE_DIR} using --print-search-dirs")
+# Find the compiler resource dir for compilers that support it.
+if(NOT DEFINED COMPILER_RESOURCE_DIR OR "${COMPILER_RESOURCE_DIR}" STREQUAL "")
+ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ execute_process(
+ COMMAND ${CMAKE_CXX_COMPILER} --print-resource-dir
+ RESULT_VARIABLE COMMAND_RETURN_CODE
+ OUTPUT_VARIABLE RES_DIR
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if(COMMAND_RETURN_CODE EQUAL 0)
+ set(COMPILER_RESOURCE_DIR
+ "${RES_DIR}" CACHE PATH "path to compiler resource dir"
+ )
+ message(STATUS "Set COMPILER_RESOURCE_DIR to "
+ "${COMPILER_RESOURCE_DIR} using --print-resource-dir")
+ endif()
+ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+ execute_process(
+ COMMAND ${CMAKE_CXX_COMPILER} -print-search-dirs
+ RESULT_VARIABLE COMMAND_RETURN_CODE
+ OUTPUT_VARIABLE RES_DIR
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if(COMMAND_RETURN_CODE EQUAL 0 AND RES_DIR MATCHES "install:[ \t]*([^\r\n]+)")
+ string(STRIP "${CMAKE_MATCH_1}" RES_DIR)
+ set(COMPILER_RESOURCE_DIR
+ "${RES_DIR}" CACHE PATH "path to compiler resource dir"
+ )
+ message(STATUS "Set COMPILER_RESOURCE_DIR to "
+ "${COMPILER_RESOURCE_DIR} using --print-search-dirs")
+ endif()
+ elseif(MSVC)
+ if(LIBC_TARGET_OS_IS_GPU)
+ message(FATAL_ERROR "COMPILER_RESOURCE_DIR must be set for GPU builds")
+ else()
+ set(COMPILER_RESOURCE_DIR OFF CACHE PATH "path to compiler resource dir")
+ message(STATUS "COMPILER_RESOURCE_DIR not set (not supported by MSVC)")
+ endif()
else()
+ # Try generic options for other compilers.
+ execute_process(
+ COMMAND ${CMAKE_CXX_COMPILER} --print-resource-dir
+ RESULT_VARIABLE COMMAND_RETURN_CODE
+ OUTPUT_VARIABLE RES_DIR
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if(COMMAND_RETURN_CODE EQUAL 0)
+ set(COMPILER_RESOURCE_DIR
+ "${RES_DIR}" CACHE PATH "path to compiler resource dir"
+ )
+ message(STATUS "Set COMPILER_RESOURCE_DIR to "
+ "${COMPILER_RESOURCE_DIR} using --print-resource-dir")
+ else()
+ execute_process(
+ COMMAND ${CMAKE_CXX_COMPILER} -print-search-dirs
+ RESULT_VARIABLE COMMAND_RETURN_CODE
+ OUTPUT_VARIABLE RES_DIR
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if(COMMAND_RETURN_CODE EQUAL 0 AND RES_DIR MATCHES "install:[ \t]*([^\r\n]+)")
+ string(STRIP "${CMAKE_MATCH_1}" RES_DIR)
+ set(COMPILER_RESOURCE_DIR
+ "${RES_DIR}" CACHE PATH "path to compiler resource dir"
+ )
+ message(STATUS "Set COMPILER_RESOURCE_DIR to "
+ "${COMPILER_RESOURCE_DIR} using --print-search-dirs")
+ endif()
+ endif()
+ endif()
+
+ if(NOT COMPILER_RESOURCE_DIR AND NOT MSVC)
if(LIBC_TARGET_OS_IS_GPU)
message(FATAL_ERROR "COMPILER_RESOURCE_DIR must be set for GPU builds")
else()
- set(COMPILER_RESOURCE_DIR OFF)
+ set(COMPILER_RESOURCE_DIR OFF CACHE PATH "path to compiler resource dir")
message(STATUS "COMPILER_RESOURCE_DIR not set
--print-resource-dir not supported by host compiler")
endif()
diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 79f2d80bcba7a18..d177e0dbcf1f2da 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -307,6 +307,7 @@ function(_get_common_compile_options output_var flags)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# Silence this warning because _Complex is a part of C99.
list(APPEND compile_options "-fext-numeric-literals")
+ list(APPEND compile_options "-Wno-psabi")
else()
list(APPEND compile_options "-Wno-c99-extensions")
list(APPEND compile_options "-Wno-gnu-imaginary-constant")
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 917e0ce2a9b0524..8c6b078d07f4b6c 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -90,6 +90,7 @@ function(_get_common_test_compile_options output_var c_test flags)
if(NOT c_test)
list(APPEND compile_options "-fext-numeric-literals")
endif()
+ list(APPEND compile_options "-Wno-psabi")
else()
list(APPEND compile_options "-Wno-c99-extensions")
list(APPEND compile_options "-Wno-gnu-imaginary-constant")
More information about the libc-commits
mailing list