[libc-commits] [libc] e39233d - [libc] Add baremetal minor archive support. (#203015)
via libc-commits
libc-commits at lists.llvm.org
Thu Oct 8 02:04:33 PDT 2026
Author: Simi Pallipurath
Date: 2026-10-08T10:04:25+01:00
New Revision: e39233d7f36c19c73cf6bd89e62dca8e8632e7b6
URL: https://github.com/llvm/llvm-project/commit/e39233d7f36c19c73cf6bd89e62dca8e8632e7b6
DIFF: https://github.com/llvm/llvm-project/commit/e39233d7f36c19c73cf6bd89e62dca8e8632e7b6.diff
LOG: [libc] Add baremetal minor archive support. (#203015)
This adds support for building a minor LLVM libc archive on baremetal
targets, such as libllvmstring.a, from only the entrypoints under a
requested libc subdirectory.
When ENABLE_LLVM_LIBC_MINOR_VARIANT is enabled, the libc archive build
now:
1. Requires LLVM_LIBC_SUBARCHIVE_NAME to be set.
3. Selects only entrypoints matching that subarchive name, for example
libc.src.<name>.*.
4. Builds and installs an archive using the requested name.
5. Avoids installing startup objects for minor archive builds.
This lets a minor variant provide only one category of libc routines
instead of duplicating a full libc.a.
Assisted-by: codex, reviewed and cross checked, also tested with
ATfE(Arm Toolchain for Embedded), by me.
Added:
Modified:
libc/CMakeLists.txt
libc/lib/CMakeLists.txt
libc/startup/baremetal/CMakeLists.txt
Removed:
################################################################################
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 86ddcd2df264f..a5e3cd20f5a8e 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -270,6 +270,12 @@ 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)
option(LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS
"Enable entrypoints with known-incomplete implementations (off by default)" OFF)
+option(LLVM_LIBC_ENABLE_MINOR_VARIANT
+ "Build LLVM libc minor variant archive" OFF)
+set(LLVM_LIBC_SUBARCHIVE_NAME "" CACHE STRING
+ "Target and archive name for the LLVM libc minor variant")
+set(LLVM_LIBC_SUBARCHIVE_ENTRYPOINTS "" CACHE STRING
+ "Semicolon-separated entrypoint targets for the LLVM libc minor variant")
option(LIBC_CONFIG_PATH "The path to user provided folder that configures the build for the target system." OFF)
diff --git a/libc/lib/CMakeLists.txt b/libc/lib/CMakeLists.txt
index 0d8e7424e6247..b244a8f766756 100644
--- a/libc/lib/CMakeLists.txt
+++ b/libc/lib/CMakeLists.txt
@@ -1,11 +1,33 @@
+set(libc_subarchive_entrypoints "")
+if(LLVM_LIBC_ENABLE_MINOR_VARIANT)
+ if(NOT LLVM_LIBC_SUBARCHIVE_NAME)
+ message(FATAL_ERROR
+ "LLVM_LIBC_ENABLE_MINOR_VARIANT requires LLVM_LIBC_SUBARCHIVE_NAME to be set.")
+ endif()
+ if(NOT LLVM_LIBC_SUBARCHIVE_ENTRYPOINTS)
+ message(FATAL_ERROR
+ "LLVM_LIBC_ENABLE_MINOR_VARIANT requires "
+ "LLVM_LIBC_SUBARCHIVE_ENTRYPOINTS to be set.")
+ endif()
+endif()
+
set(libc_archive_targets "")
set(libc_archive_names "")
set(libc_archive_entrypoint_lists "")
-if(LLVM_LIBC_FULL_BUILD)
+if(LLVM_LIBC_ENABLE_MINOR_VARIANT)
+ foreach(entrypoint IN LISTS LLVM_LIBC_SUBARCHIVE_ENTRYPOINTS)
+ if(NOT entrypoint IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
+ message(FATAL_ERROR
+ "LLVM_LIBC_SUBARCHIVE_ENTRYPOINTS contains '${entrypoint}', which is "
+ "not enabled by the target's entrypoints.txt configuration.")
+ endif()
+ list(APPEND libc_subarchive_entrypoints "${entrypoint}")
+ endforeach()
+elseif(LLVM_LIBC_FULL_BUILD)
list(APPEND libc_archive_names c m mvec)
list(APPEND libc_archive_targets libc libm libmvec)
list(APPEND libc_archive_entrypoint_lists
- TARGET_LIBC_ENTRYPOINTS TARGET_LIBM_ENTRYPOINTS TARGET_LIBMVEC_ENTRYPOINTS)
+ TARGET_LIBC_ENTRYPOINTS TARGET_LIBM_ENTRYPOINTS TARGET_LIBMVEC_ENTRYPOINTS)
else()
list(APPEND libc_archive_names llvmlibc)
list(APPEND libc_archive_targets libc)
@@ -56,6 +78,26 @@ foreach(archive IN ZIP_LISTS
endif()
endforeach()
+if(libc_subarchive_entrypoints)
+ add_entrypoint_library(
+ ${LLVM_LIBC_SUBARCHIVE_NAME}
+ DEPENDS
+ ${libc_subarchive_entrypoints}
+ )
+ set_target_properties(
+ ${LLVM_LIBC_SUBARCHIVE_NAME}
+ PROPERTIES
+ ARCHIVE_OUTPUT_NAME llvm${LLVM_LIBC_SUBARCHIVE_NAME}
+ )
+ if(LLVM_LIBC_FULL_BUILD)
+ target_link_libraries(${LLVM_LIBC_SUBARCHIVE_NAME} PUBLIC libc-headers)
+ if(TARGET libc-startup)
+ add_dependencies(${LLVM_LIBC_SUBARCHIVE_NAME} libc-startup)
+ endif()
+ endif()
+ list(APPEND added_archive_targets ${LLVM_LIBC_SUBARCHIVE_NAME})
+endif()
+
install(
TARGETS ${added_archive_targets}
ARCHIVE DESTINATION ${LIBC_INSTALL_LIBRARY_DIR}
diff --git a/libc/startup/baremetal/CMakeLists.txt b/libc/startup/baremetal/CMakeLists.txt
index 2b46b79054426..d186b65688c80 100644
--- a/libc/startup/baremetal/CMakeLists.txt
+++ b/libc/startup/baremetal/CMakeLists.txt
@@ -69,7 +69,9 @@ add_custom_target(libc-startup)
set(fq_target_name libc.startup.baremetal.${LIBC_TARGET_ARCHITECTURE}.crt1)
add_dependencies(libc-startup ${fq_target_name})
-install(FILES $<TARGET_OBJECTS:${fq_target_name}>
- DESTINATION ${LIBC_INSTALL_LIBRARY_DIR}
- RENAME $<TARGET_PROPERTY:${fq_target_name},OUTPUT_NAME>
- COMPONENT libc)
+if(NOT LLVM_LIBC_ENABLE_MINOR_VARIANT)
+ install(FILES $<TARGET_OBJECTS:${fq_target_name}>
+ DESTINATION ${LIBC_INSTALL_LIBRARY_DIR}
+ RENAME $<TARGET_PROPERTY:${fq_target_name},OUTPUT_NAME>
+ COMPONENT libc)
+endif()
More information about the libc-commits
mailing list