[libc-commits] [libc] f88e9de - [libc] Generate a stub for libpthread.a (#200908)
via libc-commits
libc-commits at lists.llvm.org
Mon Jun 15 23:35:25 PDT 2026
Author: Alexey Samsonov
Date: 2026-06-15T23:35:20-07:00
New Revision: f88e9de37a52abf9b269a7232bf4d4028bc4ace8
URL: https://github.com/llvm/llvm-project/commit/f88e9de37a52abf9b269a7232bf4d4028bc4ace8
DIFF: https://github.com/llvm/llvm-project/commit/f88e9de37a52abf9b269a7232bf4d4028bc4ace8.diff
LOG: [libc] Generate a stub for libpthread.a (#200908)
Several build systems / existing scripts assume that pthread functions
are exposed through separate library (`libpthread.so` / `libpthread.a`)
and thus use `-lpthread` flag explicitly. Since llvm-libc puts all the
pthread functions into the regular `libc`, teach the CMake build rules
to produce an empty static archive `libpthread.a` for compatibility
purposes.
Added:
Modified:
libc/lib/CMakeLists.txt
Removed:
################################################################################
diff --git a/libc/lib/CMakeLists.txt b/libc/lib/CMakeLists.txt
index 08026e937be94..8ef0329471521 100644
--- a/libc/lib/CMakeLists.txt
+++ b/libc/lib/CMakeLists.txt
@@ -70,6 +70,29 @@ foreach(file ${added_bitcode_targets})
)
endforeach()
+# Add empty archive libraries for compatibility with systems expecting certain
+# bits of libc to be located in separate files (e.g. libpthread).
+set(added_empty_archives "")
+if(LLVM_LIBC_FULL_BUILD AND ${LIBC_TARGET_OS} STREQUAL "linux")
+ list(APPEND libc_empty_archive_names pthread)
+ foreach(archive ${libc_empty_archive_names})
+ set(empty_archive_path ${LIBC_LIBRARY_DIR}/lib${archive}.a)
+ add_custom_command(
+ OUTPUT ${empty_archive_path}
+ COMMAND ${CMAKE_AR} cqs ${empty_archive_path}
+ COMMENT "Creating empty archive ${empty_archive_path}"
+ VERBATIM
+ )
+ install(
+ FILES ${empty_archive_path}
+ DESTINATION ${LIBC_INSTALL_LIBRARY_DIR}
+ COMPONENT libc
+ )
+ add_custom_target(empty-${archive} ALL DEPENDS ${empty_archive_path})
+ list(APPEND added_empty_archives empty-${archive})
+ endforeach()
+endif()
+
set(startup_target "")
if(LLVM_LIBC_FULL_BUILD AND NOT LIBC_TARGET_OS_IS_BAREMETAL)
# For now we will disable libc-startup installation for baremetal. The
@@ -86,6 +109,7 @@ endif()
add_custom_target(install-libc
DEPENDS ${added_archive_targets}
${added_bitcode_targets}
+ ${added_empty_archives}
${startup_target}
${header_install_target}
COMMAND "${CMAKE_COMMAND}"
@@ -94,6 +118,7 @@ add_custom_target(install-libc
add_custom_target(install-libc-stripped
DEPENDS ${added_archive_targets}
${added_bitcode_targets}
+ ${added_empty_archives}
${startup_target}
${header_install_target}
COMMAND "${CMAKE_COMMAND}"
More information about the libc-commits
mailing list