-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[libc][cmake][linux] require new LLVM_LIBC_USE_HOST_KERNEL_HEADERS or LIBC_KERNEL_HEADERS #123820
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
Changes from all commits
456a4f5
d918f85
e2c259d
76e422c
d4c49a6
db5b2f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,6 +216,27 @@ if (LIBC_TARGET_OS_IS_WINDOWS AND LLVM_LIBC_FULL_BUILD) | |
message(FATAL_ERROR "Windows does not support full mode build.") | ||
endif () | ||
|
||
if (LIBC_TARGET_OS_IS_LINUX) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to automatically set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's worthwhile to consider this. Let me jot down my thoughts. Doing so would effectively change the implicit default value of Two invariants I'd like to maintain:
Thinking through the case of wanting to do an overlay build, is there ever a case where we'd want to use newer kernel headers (or perhaps older kernel headers) than what was available on the host? A hypothetical use case for newer headers: you want to build on one host (that has old headers) but support newer syscalls. The result can only run on other machines with newer kernels (when newer syscalls are made at runtime). A hypothetical use case for older headers: you want to build on one host (that has newer headers), but run the libc on another target that is running an older kernel. Both of those hypotheticals seem to be a stretch in my mind. Perhaps overlay mode should (or does) imply "literally the result will only run on my host machine+kernel?" An inspiration for In the same vein, I don't want to outright prevent people from looking at By adding So I guess, yes, it would make sense to automatically set it. But that betrays an intent in this PR to add one more hoop for folks who refuse to just build the kernel headers from source to sign on the X that they are potentially including more than just kernel headers when they add /usr/include to the compiler's header search path. Is that being too malicious? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My main concern is around default configurations. Currently, Currently, if you run
The other issue is that for overlay mode we do actually need to look at the other libc's headers. All of our type/macro headers in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
D'oh, you're right!
This is something I hadn't even considered. I can get behind wanting an optionless configure to build out of the box. Let me think more about this over lunch.
I agree. Filed #124973. |
||
if (NOT LIBC_USE_HOST_KERNEL_HEADERS AND "${LIBC_KERNEL_HEADERS}" STREQUAL "") | ||
message(FATAL_ERROR "MUST specify either LIBC_KERNEL_HEADERS or LIBC_USE_HOST_KERNEL_HEADERS") | ||
endif() | ||
if (LIBC_USE_HOST_KERNEL_HEADERS AND NOT "${LIBC_KERNEL_HEADERS}" STREQUAL "") | ||
message(FATAL_ERROR "LIBC_USE_HOST_KERNEL_HEADERS and LIBC_USE_HOST_KERNEL_HEADERS are mutually exclusive") | ||
endif() | ||
if(LIBC_TARGET_TRIPLE AND LIBC_USE_HOST_KERNEL_HEADERS) | ||
# This is because the syscall numbers are frequently different between | ||
# different target architectures. Code may compile, but you'll get spooky | ||
# runtime failures. | ||
message(FATAL_ERROR "LIBC_USE_HOST_KERNEL_HEADERS should not be set when using LIBC_TARGET_TRIPLE, set LIBC_KERNEL_HEADERS instead") | ||
endif() | ||
if (NOT "${LIBC_KERNEL_HEADERS}" STREQUAL "" AND NOT IS_DIRECTORY "${LIBC_KERNEL_HEADERS}") | ||
message(FATAL_ERROR "LIBC_KERNEL_HEADERS should be a path to an existing directory") | ||
endif() | ||
if (LIBC_USE_HOST_KERNEL_HEADERS) | ||
set(LIBC_KERNEL_HEADERS "/usr/include" CACHE STRING "Path to Linux kernel headers" FORCE) | ||
endif() | ||
endif() | ||
|
||
|
||
message(STATUS | ||
"Building libc for ${LIBC_TARGET_ARCHITECTURE} on ${LIBC_TARGET_OS} with | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,10 @@ development. In this we've set the Ninja generator, set the build type to | |
"Debug", and enabled the Scudo allocator. This build also enables generating the | ||
documentation and verbose cmake logging, which are useful development features. | ||
|
||
If targeting Linux, see :ref:`linux_headers` for how to build the Linux kernel | ||
headers from source, which llvm-libc will depend on. If not targeting Linux, | ||
the below cmake variable ``LIBC_KERNEL_HEADERS`` should be omitted. | ||
|
||
.. note:: | ||
if your build fails with an error saying the compiler can't find | ||
``<asm/unistd.h>`` or similar then you're probably missing the symlink from | ||
|
@@ -44,11 +48,12 @@ documentation and verbose cmake logging, which are useful development features. | |
$> cd build | ||
$> cmake ../runtimes \ | ||
-G Ninja \ | ||
-DCMAKE_C_COMPILER=clang \ | ||
-DCMAKE_BUILD_TYPE=Debug \ | ||
-DCMAKE_CXX_COMPILER=clang++ \ | ||
-DCMAKE_C_COMPILER=clang \ | ||
-DLLVM_ENABLE_RUNTIMES="libc;compiler-rt" \ | ||
-DLIBC_KERNEL_HEADERS=/path/to/sysroot/ \ | ||
-DLLVM_LIBC_FULL_BUILD=ON \ | ||
-DCMAKE_BUILD_TYPE=Debug \ | ||
-DLLVM_LIBC_INCLUDE_SCUDO=ON \ | ||
-DCOMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC=ON \ | ||
-DCOMPILER_RT_BUILD_GWP_ASAN=OFF \ | ||
|
@@ -131,6 +136,7 @@ allocator for LLVM-libc. | |
-DCMAKE_BUILD_TYPE=Release \ | ||
-DCMAKE_C_COMPILER=clang \ | ||
-DCMAKE_CXX_COMPILER=clang++ \ | ||
-DLIBC_KERNEL_HEADERS=/path/to/sysroot/ \ | ||
-DLLVM_LIBC_FULL_BUILD=ON \ | ||
-DLLVM_LIBC_INCLUDE_SCUDO=ON \ | ||
-DCOMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC=ON \ | ||
|
@@ -171,6 +177,8 @@ toolchain with which you can build practical/real-world C applications. See | |
`<https://github.com/llvm/llvm-project/tree/main/libc/examples>`_ for examples | ||
of how to start using this new toolchain. | ||
|
||
.. _linux_headers: | ||
|
||
Linux Headers | ||
============= | ||
|
||
|
@@ -183,7 +191,9 @@ Linux headers in your sysroot. Let's build them from source. | |
$> make LLVM=1 INSTALL_HDR_PATH=/path/to/sysroot -C /tmp/linux headers_install | ||
|
||
The headers can be built to target non-host architectures by adding the | ||
``ARCH={arm|arm64|i386}`` to the above invocation of ``make``. | ||
``ARCH={arm|arm64|i386}`` to the above invocation of ``make``. Then you should | ||
set the cmake variable `-DLIBC_KERNEL_HEADERS=/path/to/sysroot` when | ||
Comment on lines
191
to
+195
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for consistency, would it make sense to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, you're right about the inconsistency. I think I will resolve it the other way, since existing docs talk about setting
above. So I will use Done in db5b2f9. |
||
configuring llvm-libc. | ||
|
||
Using your newly built libc | ||
=========================== | ||
|
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.
oh, I wonder if we should be using
option
instead? I see that used elsewhere in our cmake. I'm not familiar withoption
...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.
There are two ways to define a boolean flag in CMake:
The difference between the two is that the
option
command does not create aCACHE
variable if a normal variable with the same name exists, but usingset
withCACHE
variable namedFOO
whenFOO
exists as a normal variable will yield two copies ofFOO
, a normal variable and aCACHE
one.Which is one more appropriate really depends on your intention. There are places in LLVM build system where we intentionally rely on the
set
semantics (e.g. we would use theCACHE
variable as the default value to initialize the normal variable).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.
Ok, so it sounds like cmake has distinct "namespace-esque" differentiation between "normal variables" and "cache variables."
For cmake variables that we encourage folks to use to configure llvm-libc, I think we may want
option
. That seems very common inlibcxx/CMakeLists.txt
.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.
76e422c