[libc-commits] [libc] [libc] Use -nostdlibinc in the full build mode (PR #97461)
via libc-commits
libc-commits at lists.llvm.org
Tue Jul 2 12:06:13 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Petr Hosek (petrhosek)
<details>
<summary>Changes</summary>
This avoids accidentally including system headers.
---
Full diff: https://github.com/llvm/llvm-project/pull/97461.diff
2 Files Affected:
- (modified) libc/cmake/modules/CheckCompilerFeatures.cmake (+3)
- (modified) libc/cmake/modules/LLVMLibCCompileOptionRules.cmake (+4)
``````````diff
diff --git a/libc/cmake/modules/CheckCompilerFeatures.cmake b/libc/cmake/modules/CheckCompilerFeatures.cmake
index 17806588550eb..52090d2ab4097 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_c_compiler_flag("-nostdlibinc" LIBC_C_SUPPORTS_NOSTDLIBINC)
diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 3bf429381d4af..441a816176e68 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -46,6 +46,10 @@ 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 all standard include paths.
+ if(LIBC_C_SUPPORTS_NOSTDLIBINC)
+ list(APPEND compile_options "-nostdlibinc")
+ endif()
endif()
if(LIBC_COMPILER_HAS_FIXED_POINT)
``````````
</details>
https://github.com/llvm/llvm-project/pull/97461
More information about the libc-commits
mailing list