[libc-commits] [libc] b8bbc57 - [libc] Use -nostdlibinc in the full build mode (#97461)
via libc-commits
libc-commits at lists.llvm.org
Tue Jul 2 12:34:10 PDT 2024
Author: Petr Hosek
Date: 2024-07-02T12:34:06-07:00
New Revision: b8bbc57b68454fda9811fd956a1d2caa61d4d323
URL: https://github.com/llvm/llvm-project/commit/b8bbc57b68454fda9811fd956a1d2caa61d4d323
DIFF: https://github.com/llvm/llvm-project/commit/b8bbc57b68454fda9811fd956a1d2caa61d4d323.diff
LOG: [libc] Use -nostdlibinc in the full build mode (#97461)
This avoids accidentally including system headers.
Added:
Modified:
libc/cmake/modules/CheckCompilerFeatures.cmake
libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
Removed:
################################################################################
diff --git a/libc/cmake/modules/CheckCompilerFeatures.cmake b/libc/cmake/modules/CheckCompilerFeatures.cmake
index 17806588550eb..d84c07b35d2d7 100644
--- a/libc/cmake/modules/CheckCompilerFeatures.cmake
+++ b/libc/cmake/modules/CheckCompilerFeatures.cmake
@@ -73,3 +73,6 @@ check_cxx_compiler_flag("-ftrivial-auto-var-init=pattern" LIBC_CC_SUPPORTS_PATTE
# clang-6+, gcc-13+
check_cxx_compiler_flag("-nostdlib++" LIBC_CC_SUPPORTS_NOSTDLIBPP)
+
+# clang-3.0+
+check_cxx_compiler_flag("-nostdlibinc" LIBC_CC_SUPPORTS_NOSTDLIBINC)
diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 3bf429381d4af..d283e966bffcf 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -46,6 +46,14 @@ function(_get_common_compile_options output_var flags)
list(APPEND compile_options "-DLIBC_FULL_BUILD")
# Only add -ffreestanding flag in full build mode.
list(APPEND compile_options "-ffreestanding")
+ # Manually disable standard include paths to prevent system headers from
+ # being included.
+ if(LIBC_CC_SUPPORTS_NOSTDLIBINC)
+ list(APPEND compile_options "-nostdlibinc")
+ else()
+ list(APPEND compile_options "-isystem${COMPILER_RESOURCE_DIR}/include")
+ list(APPEND compile_options "-nostdinc")
+ endif()
endif()
if(LIBC_COMPILER_HAS_FIXED_POINT)
@@ -108,11 +116,6 @@ function(_get_common_compile_options output_var flags)
elseif(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
list(APPEND compile_options "SHELL:-Xclang -mcode-object-version=none")
endif()
-
- # Manually disable all standard include paths and include the resource
- # directory to prevent system headers from being included.
- list(APPEND compile_options "-isystem${COMPILER_RESOURCE_DIR}/include")
- list(APPEND compile_options "-nostdinc")
endif()
set(${output_var} ${compile_options} PARENT_SCOPE)
endfunction()
More information about the libc-commits
mailing list