-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc] Use -nostdlibinc in the full build mode #97461
Conversation
This avoids accidentally including system headers.
@llvm/pr-subscribers-libc Author: Petr Hosek (petrhosek) ChangesThis avoids accidentally including system headers. Full diff: https://github.com/llvm/llvm-project/pull/97461.diff 2 Files Affected:
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)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know I pass -nostdinc
for the GPU, do you know what the exact difference is? If it does the same job we should probably unify that. (The GPU is always in full build mode).
I was about to reach out to and ask if you want to use this flag for the GPU build as well? AFAIK this flag is exactly what you've done in llvm-project/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake Lines 114 to 115 in 5f1743c
|
# Manually disable standard include paths to prevent system headers from | ||
# being included. | ||
if(LIBC_C_SUPPORTS_NOSTDLIBINC) | ||
list(APPEND compile_options "-nostdlibinc") | ||
else() | ||
list(APPEND compile_options "-isystem${COMPILER_RESOURCE_DIR}/include") | ||
list(APPEND compile_options "-nostdinc") | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to duplicate the logic here, since the GPU libc build should already in full build mode it should hit the condition above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check_c_compiler_flag("-nostdlibinc" LIBC_C_SUPPORTS_NOSTDLIBINC) | |
check_c_compiler_flag("-nostdlibinc" LIBC_C_SUPPORTS_NOSTDLIBINC) |
Isn't this a CXX
project? Wouldn't make sense to require both C and CXX compiler to be set and match if so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, works on my end.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/71/builds/1322 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/171/builds/1283 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/131/builds/1289 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/179/builds/1289 Here is the relevant piece of the build log for the reference:
|
Seems to be all the headers that |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/183/builds/826 Here is the relevant piece of the build log for the reference:
|
When doing a full build for Linux, as of llvm#97461 we no longer include system headers, but we need to include Linux kernel headers.
When doing a full build for Linux, as of #97461 we no longer include system headers, but we need to include Linux kernel headers.
This avoids accidentally including system headers.
When doing a full build for Linux, as of llvm#97461 we no longer include system headers, but we need to include Linux kernel headers.
This avoids accidentally including system headers.
When doing a full build for Linux, as of llvm#97461 we no longer include system headers, but we need to include Linux kernel headers.
This avoids accidentally including system headers.