diff options
author | Petr Hosek <phosek@google.com> | 2024-07-02 12:34:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-02 12:34:06 -0700 |
commit | b8bbc57b68454fda9811fd956a1d2caa61d4d323 (patch) | |
tree | 66f2965a29664223a0852958ee5c9c3f97a5fa92 /libc | |
parent | 139508eb87bda18c8adbfb87bba6acac8ce29a36 (diff) | |
download | llvm-b8bbc57b68454fda9811fd956a1d2caa61d4d323.zip llvm-b8bbc57b68454fda9811fd956a1d2caa61d4d323.tar.gz llvm-b8bbc57b68454fda9811fd956a1d2caa61d4d323.tar.bz2 |
[libc] Use -nostdlibinc in the full build mode (#97461)
This avoids accidentally including system headers.
Diffstat (limited to 'libc')
-rw-r--r-- | libc/cmake/modules/CheckCompilerFeatures.cmake | 3 | ||||
-rw-r--r-- | libc/cmake/modules/LLVMLibCCompileOptionRules.cmake | 13 |
2 files changed, 11 insertions, 5 deletions
diff --git a/libc/cmake/modules/CheckCompilerFeatures.cmake b/libc/cmake/modules/CheckCompilerFeatures.cmake index 17806588..d84c07b 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 3bf4293..d283e96 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() |