[libc-commits] [libc] [libc] Add baremetal minor archive support. (PR #203015)
Simi Pallipurath via libc-commits
libc-commits at lists.llvm.org
Thu Jun 11 02:47:16 PDT 2026
https://github.com/simpal01 updated https://github.com/llvm/llvm-project/pull/203015
>From 3cfc6e639428dc9421d6b33046a02e395b49754b Mon Sep 17 00:00:00 2001
From: Simi Pallipurath <simi.pallipurath at arm.com>
Date: Wed, 10 Jun 2026 13:10:15 +0100
Subject: [PATCH 1/2] [libc] Add baremetal minor archive support.
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 a baremetal target.
2. 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 baremetal 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,
by me.
---
libc/lib/CMakeLists.txt | 62 +++++++++++++++++++++++----
libc/startup/baremetal/CMakeLists.txt | 10 +++--
2 files changed, 60 insertions(+), 12 deletions(-)
diff --git a/libc/lib/CMakeLists.txt b/libc/lib/CMakeLists.txt
index 08026e937be94..fa057c1c50137 100644
--- a/libc/lib/CMakeLists.txt
+++ b/libc/lib/CMakeLists.txt
@@ -1,15 +1,40 @@
+set(libc_subarchive_entrypoints "")
+if(ENABLE_LLVM_LIBC_MINOR_VARIANT)
+ if(NOT LIBC_TARGET_OS_IS_BAREMETAL)
+ message(FATAL_ERROR
+ "ENABLE_LLVM_LIBC_MINOR_VARIANT is only supported on baremetal targets.")
+ endif()
+ if(NOT LLVM_LIBC_SUBARCHIVE_NAME)
+ message(FATAL_ERROR
+ "ENABLE_LLVM_LIBC_MINOR_VARIANT requires LLVM_LIBC_SUBARCHIVE_NAME to be set.")
+ endif()
+endif()
+
set(libc_archive_targets "")
set(libc_archive_names "")
set(libc_archive_entrypoint_lists "")
-if(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)
+if(NOT ENABLE_LLVM_LIBC_MINOR_VARIANT)
+ if(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)
+ else()
+ list(APPEND libc_archive_names llvmlibc)
+ list(APPEND libc_archive_targets libc)
+ list(APPEND libc_archive_entrypoint_lists TARGET_LLVMLIBC_ENTRYPOINTS)
+ endif()
else()
- list(APPEND libc_archive_names llvmlibc)
- list(APPEND libc_archive_targets libc)
- list(APPEND libc_archive_entrypoint_lists TARGET_LLVMLIBC_ENTRYPOINTS)
+ foreach(entrypoint IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS)
+ if(entrypoint MATCHES "^libc\\.src\\.${LLVM_LIBC_SUBARCHIVE_NAME}\\.")
+ list(APPEND libc_subarchive_entrypoints ${entrypoint})
+ endif()
+ endforeach()
+ if(NOT libc_subarchive_entrypoints)
+ message(FATAL_ERROR
+ "ENABLE_LLVM_LIBC_MINOR_VARIANT requires matching entrypoints for "
+ "'${LLVM_LIBC_SUBARCHIVE_NAME}'.")
+ endif()
endif()
set(added_archive_targets "")
@@ -56,6 +81,27 @@ 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
+ PREFIX ""
+ 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 e361000f788ea..0e50126b81bf2 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 ENABLE_LLVM_LIBC_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()
>From e2888b9213693e312706bbdfa46cb84a199e9aba Mon Sep 17 00:00:00 2001
From: Simi Pallipurath <simi.pallipurath at arm.com>
Date: Thu, 11 Jun 2026 10:42:34 +0100
Subject: [PATCH 2/2] fixup! [libc] Add baremetal minor archive support.
1. Renamed ENABLE_LLVM_LIBC_MINOR_VARIANT to LLVM_LIBC_ENABLE_MINOR_VARIANT
2. Ordered the if else condition so that positove case comes first.
3. Removed baremetal targets restriction for this functionality.
4. Added LLVM_LIBC_ENABLE_MINOR_VARIANT as an opton in CMake.
---
libc/CMakeLists.txt | 2 ++
libc/lib/CMakeLists.txt | 32 ++++++++++++---------------
libc/startup/baremetal/CMakeLists.txt | 2 +-
3 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 3b5f3949b286d..3156f0ccbc08e 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -142,6 +142,8 @@ 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)
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 fa057c1c50137..8244ffba349d2 100644
--- a/libc/lib/CMakeLists.txt
+++ b/libc/lib/CMakeLists.txt
@@ -1,19 +1,26 @@
set(libc_subarchive_entrypoints "")
-if(ENABLE_LLVM_LIBC_MINOR_VARIANT)
- if(NOT LIBC_TARGET_OS_IS_BAREMETAL)
- message(FATAL_ERROR
- "ENABLE_LLVM_LIBC_MINOR_VARIANT is only supported on baremetal targets.")
- endif()
+if(LLVM_LIBC_ENABLE_MINOR_VARIANT)
if(NOT LLVM_LIBC_SUBARCHIVE_NAME)
message(FATAL_ERROR
- "ENABLE_LLVM_LIBC_MINOR_VARIANT requires LLVM_LIBC_SUBARCHIVE_NAME to be set.")
+ "LLVM_LIBC_ENABLE_MINOR_VARIANT requires LLVM_LIBC_SUBARCHIVE_NAME to be set.")
endif()
endif()
set(libc_archive_targets "")
set(libc_archive_names "")
set(libc_archive_entrypoint_lists "")
-if(NOT ENABLE_LLVM_LIBC_MINOR_VARIANT)
+if(LLVM_LIBC_ENABLE_MINOR_VARIANT)
+ foreach(entrypoint IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS)
+ if(entrypoint MATCHES "^libc\\.src\\.${LLVM_LIBC_SUBARCHIVE_NAME}\\.")
+ list(APPEND libc_subarchive_entrypoints ${entrypoint})
+ endif()
+ endforeach()
+ if(NOT libc_subarchive_entrypoints)
+ message(FATAL_ERROR
+ "LLVM_LIBC_ENABLE_MINOR_VARIANT requires matching entrypoints for "
+ "'${LLVM_LIBC_SUBARCHIVE_NAME}'.")
+ endif()
+else()
if(LLVM_LIBC_FULL_BUILD)
list(APPEND libc_archive_names c m mvec)
list(APPEND libc_archive_targets libc libm libmvec)
@@ -24,17 +31,6 @@ if(NOT ENABLE_LLVM_LIBC_MINOR_VARIANT)
list(APPEND libc_archive_targets libc)
list(APPEND libc_archive_entrypoint_lists TARGET_LLVMLIBC_ENTRYPOINTS)
endif()
-else()
- foreach(entrypoint IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS)
- if(entrypoint MATCHES "^libc\\.src\\.${LLVM_LIBC_SUBARCHIVE_NAME}\\.")
- list(APPEND libc_subarchive_entrypoints ${entrypoint})
- endif()
- endforeach()
- if(NOT libc_subarchive_entrypoints)
- message(FATAL_ERROR
- "ENABLE_LLVM_LIBC_MINOR_VARIANT requires matching entrypoints for "
- "'${LLVM_LIBC_SUBARCHIVE_NAME}'.")
- endif()
endif()
set(added_archive_targets "")
diff --git a/libc/startup/baremetal/CMakeLists.txt b/libc/startup/baremetal/CMakeLists.txt
index 0e50126b81bf2..0a8d31774f40a 100644
--- a/libc/startup/baremetal/CMakeLists.txt
+++ b/libc/startup/baremetal/CMakeLists.txt
@@ -69,7 +69,7 @@ add_custom_target(libc-startup)
set(fq_target_name libc.startup.baremetal.${LIBC_TARGET_ARCHITECTURE}.crt1)
add_dependencies(libc-startup ${fq_target_name})
-if(NOT ENABLE_LLVM_LIBC_MINOR_VARIANT)
+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>
More information about the libc-commits
mailing list