[libc] Add LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS CMake flag#197537
Conversation
Adds a new CMake option, OFF by default, to gate entrypoints with known-incomplete implementations. This lets developers build with partially-implemented functions for testing or development without exposing them to production users. Moved sysconf behind the new flag across x86_64, aarch64, and riscv. The implementation only handles _SC_PAGESIZE, _SC_NPROCESSORS_CONF, and _SC_NPROCESSORS_ONLN; all other _SC_* values return EINVAL. The flag is propagated as -DLIBC_EXPERIMENTAL_ENTRYPOINTS to both production and test compile options, following the same pattern as LIBC_FULL_BUILD. Assisted-by: Automated tooling, human reviewed.
|
@llvm/pr-subscribers-libc @llvm/pr-subscribers-backend-risc-v Author: Jeff Bailey (kaladron) ChangesAdds a new CMake option, OFF by default, to gate entrypoints with known-incomplete implementations. This lets developers build and test partially-implemented functions without exposing them to production users. The motivating case is Changes:
The flag does not require Full diff: https://github.com/llvm/llvm-project/pull/197537.diff 6 Files Affected:
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index e796598e48924..a31fb60e8d958 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -140,6 +140,14 @@ option(LLVM_LIBC_FULL_BUILD "Build and test LLVM libc as if it is the full libc"
option(LLVM_LIBC_IMPLEMENTATION_DEFINED_TEST_BEHAVIOR "Build LLVM libc tests assuming our implementation-defined behavior" ON)
option(LLVM_LIBC_ENABLE_LINTING "Enables linting of libc source files" OFF)
option(LLVM_LIBC_ALL_HEADERS "Outputs all functions in header files, regardless of whether they are enabled on this target" OFF)
+# Enable entrypoints that have known-incomplete implementations but are useful
+# for testing or development purposes. These are NOT suitable for production use
+# and are disabled by default. Examples include functions that only handle a
+# subset of their specified inputs (e.g. sysconf, which only handles a few
+# _SC_* constants). Enable this flag if you need to build with these entrypoints
+# for testing or if you are actively working on their implementation.
+option(LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS
+ "Enable entrypoints with known-incomplete implementations (off by default)" OFF)
option(LIBC_CONFIG_PATH "The path to user provided folder that configures the build for the target system." OFF)
diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 2fae55997cabb..5bb79fc47f60f 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -253,6 +253,10 @@ function(_get_common_compile_options output_var flags)
endif()
endif()
+ if(LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
+ list(APPEND compile_options "-DLIBC_EXPERIMENTAL_ENTRYPOINTS")
+ endif()
+
if(LIBC_COMPILER_HAS_FIXED_POINT)
list(APPEND compile_options "-ffixed-point")
endif()
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 034396cba158c..ce2e8f689873a 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -34,6 +34,10 @@ function(_get_common_test_compile_options output_var c_test flags)
endif()
endif()
+ if(LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
+ list(APPEND compile_options "-DLIBC_EXPERIMENTAL_ENTRYPOINTS")
+ endif()
+
if(LIBC_COMPILER_HAS_FIXED_POINT)
list(APPEND compile_options "-ffixed-point")
endif()
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index e62bc67e2d5ca..743e761c746f6 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -387,7 +387,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.unistd.setsid
libc.src.unistd.symlink
libc.src.unistd.symlinkat
- libc.src.unistd.sysconf
libc.src.unistd.truncate
libc.src.unistd.unlink
libc.src.unistd.unlinkat
@@ -1265,6 +1264,16 @@ if(LLVM_LIBC_FULL_BUILD)
)
endif()
+# Entrypoints with known-incomplete implementations. Only enabled when
+# LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS is ON.
+if(LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
+ list(APPEND TARGET_LIBC_ENTRYPOINTS
+ # unistd.h - incomplete: only handles _SC_PAGESIZE, _SC_NPROCESSORS_CONF,
+ # and _SC_NPROCESSORS_ONLN; returns EINVAL for all other _SC_* values.
+ libc.src.unistd.sysconf
+ )
+endif()
+
set(TARGET_LIBMVEC_ENTRYPOINTS)
if(LIBC_COMPILER_HAS_EXT_VECTOR_TYPE)
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index d1c52dffdb6e7..7645aded27c9a 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -390,7 +390,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.unistd.setsid
libc.src.unistd.symlink
libc.src.unistd.symlinkat
- libc.src.unistd.sysconf
libc.src.unistd.truncate
libc.src.unistd.unlink
libc.src.unistd.unlinkat
@@ -1399,6 +1398,16 @@ if(LLVM_LIBC_FULL_BUILD)
)
endif()
+# Entrypoints with known-incomplete implementations. Only enabled when
+# LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS is ON.
+if(LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
+ list(APPEND TARGET_LIBC_ENTRYPOINTS
+ # unistd.h - incomplete: only handles _SC_PAGESIZE, _SC_NPROCESSORS_CONF,
+ # and _SC_NPROCESSORS_ONLN; returns EINVAL for all other _SC_* values.
+ libc.src.unistd.sysconf
+ )
+endif()
+
set(TARGET_LLVMLIBC_ENTRYPOINTS
${TARGET_LIBC_ENTRYPOINTS}
${TARGET_LIBM_ENTRYPOINTS}
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 73b4b3fcd191f..00210c9064dbe 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -408,7 +408,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.unistd.setsid
libc.src.unistd.symlink
libc.src.unistd.symlinkat
- libc.src.unistd.sysconf
libc.src.unistd.truncate
libc.src.unistd.unlink
libc.src.unistd.unlinkat
@@ -1489,6 +1488,16 @@ if(LLVM_LIBC_FULL_BUILD)
)
endif()
+# Entrypoints with known-incomplete implementations. Only enabled when
+# LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS is ON.
+if(LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
+ list(APPEND TARGET_LIBC_ENTRYPOINTS
+ # unistd.h - incomplete: only handles _SC_PAGESIZE, _SC_NPROCESSORS_CONF,
+ # and _SC_NPROCESSORS_ONLN; returns EINVAL for all other _SC_* values.
+ libc.src.unistd.sysconf
+ )
+endif()
+
set(TARGET_LIBMVEC_ENTRYPOINTS)
if(LIBC_COMPILER_HAS_EXT_VECTOR_TYPE)
|
…ENTRYPOINTS Remove compile-time -DLIBC_EXPERIMENTAL_ENTRYPOINTS define from both LLVMLibCCompileOptionRules.cmake and LLVMLibCTestRules.cmake. The flag is purely a build-system concern; no source-level #ifdef usage exists. Remove verbose comments from the option definition in CMakeLists.txt and the entrypoints.txt blocks. The if() guard is self-documenting, and per-entrypoint inline comments would quickly go stale. Assisted-by: Automated tooling, human reviewed.
|
Hi Michael! You and I had talked about doing something like this for things like sysconf and the regex patches. Can you please take a look and see if it meets what you're thinking? @vonosmas - My apologies. I actually created the PR earlier than planned. |
michaelrj-google
left a comment
There was a problem hiding this comment.
LGTM, we should probably update the build instructions on the website to mention this but that can be a followup.
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/179/builds/46952 Here is the relevant piece of the build log for the reference |
…#197537) Adds a new CMake option, OFF by default, to gate entrypoints with known-incomplete implementations. This lets developers build and test partially-implemented functions without exposing them to production users. The motivating case is `sysconf`, which only handles three of the required `_SC_*` constants (`_SC_PAGESIZE`, `_SC_NPROCESSORS_CONF`, `_SC_NPROCESSORS_ONLN`) and returns `EINVAL` for everything else. Functions like this are useful to have in a build for testing progress, but shouldn't be part of a default full build until the implementation is complete. Changes: - `libc/CMakeLists.txt`: adds `option(LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS ... OFF)` - `libc/cmake/modules/LLVMLibCCompileOptionRules.cmake`: propagates `-DLIBC_EXPERIMENTAL_ENTRYPOINTS` when ON - `libc/cmake/modules/LLVMLibCTestRules.cmake`: same for test compile options - `libc/config/linux/{x86_64,aarch64,riscv}/entrypoints.txt`: moves `sysconf` behind the new flag The flag does not require `LLVM_LIBC_FULL_BUILD` since overlay builds may also have incomplete entrypoints that benefit from this gating.
Adds a new CMake option, OFF by default, to gate entrypoints with known-incomplete implementations. This lets developers build and test partially-implemented functions without exposing them to production users.
The motivating case is
sysconf, which only handles three of the required_SC_*constants (_SC_PAGESIZE,_SC_NPROCESSORS_CONF,_SC_NPROCESSORS_ONLN) and returnsEINVALfor everything else. Functions like this are useful to have in a build for testing progress, but shouldn't be part of a default full build until the implementation is complete.Changes:
libc/CMakeLists.txt: addsoption(LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS ... OFF)libc/cmake/modules/LLVMLibCCompileOptionRules.cmake: propagates-DLIBC_EXPERIMENTAL_ENTRYPOINTSwhen ONlibc/cmake/modules/LLVMLibCTestRules.cmake: same for test compile optionslibc/config/linux/{x86_64,aarch64,riscv}/entrypoints.txt: movessysconfbehind the new flagThe flag does not require
LLVM_LIBC_FULL_BUILDsince overlay builds may also have incomplete entrypoints that benefit from this gating.