From b875defc55bd4c2f3fc0572c84aead61c2a48d27 Mon Sep 17 00:00:00 2001 From: Siva Chandra Reddy Date: Tue, 31 Jan 2023 05:31:18 +0000 Subject: [PATCH] [libc] Build two different static archives libc.a and libm.a under full build. We currently put everything in one single archive libc.a which breaks in certain situations where the compiler drivers expect libm.a also. With this change, we separate out libc.a and libm.a functions as is done conventionally and put them in two different static archives. One will now have to build two targets, `libc` and `libm` which produce `libc.a` and `libm.a` respectively. Under default build, one still builds only one target named `libc` which produces `libllvmlibc.a`. Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D143005 --- libc/CMakeLists.txt | 9 ------- libc/lib/CMakeLists.txt | 51 ++++++++++++++++++++++++++++++--------- libc/startup/linux/CMakeLists.txt | 2 +- 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index 5c6df6e..e59d04c 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -163,10 +163,7 @@ foreach(entrypoint IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS) list(APPEND TARGET_ENTRYPOINT_NAME_LIST ${entrypoint_name}) endforeach() -set(LIBC_TARGET) -set(LIBC_COMPONENT) set(LIBC_INSTALL_DEPENDS) -set(LIBC_INSTALL_TARGET) if(LLVM_LIBC_FULL_BUILD) set(LIBC_INSTALL_DEPENDS "install-libc-static-archives;install-libc-headers") if(NOT LIBC_TARGET_OS_IS_BAREMETAL) @@ -175,14 +172,8 @@ if(LLVM_LIBC_FULL_BUILD) # and install it as part of the libc installation. list(APPEND LIBC_INSTALL_DEPENDS "libc-startup") endif() - if(LIBC_TARGET_ARCHITECTURE_IS_GPU) - set(LIBC_ARCHIVE_NAME cgpu) - else() - set(LIBC_ARCHIVE_NAME c) - endif() else() set(LIBC_INSTALL_DEPENDS install-libc-static-archives) - set(LIBC_ARCHIVE_NAME llvmlibc) endif() add_subdirectory(include) diff --git a/libc/lib/CMakeLists.txt b/libc/lib/CMakeLists.txt index b76fe41..f257582 100644 --- a/libc/lib/CMakeLists.txt +++ b/libc/lib/CMakeLists.txt @@ -1,13 +1,40 @@ -add_entrypoint_library( - libc - DEPENDS - ${TARGET_LLVMLIBC_ENTRYPOINTS} -) -set_target_properties( - libc - PROPERTIES - ARCHIVE_OUTPUT_NAME ${LIBC_ARCHIVE_NAME} -) +set(libc_archive_targets "") +set(libc_archive_names "") +set(libc_archive_entrypoint_lists "") +if(LLVM_LIBC_FULL_BUILD) + if(LIBC_TARGET_ARCHITECTURE_IS_GPU) + list(APPEND libc_archive_names cgpu mgpu) + else() + list(APPEND libc_archive_names c m) + endif() + list(APPEND libc_archive_targets libc libm) + list(APPEND libc_archive_entrypoint_lists + TARGET_LIBC_ENTRYPOINTS TARGET_LIBM_ENTRYPOINTS) +else() + list(APPEND libc_archive_names llvmlibc) + list(APPEND libc_archive_targets libc) + list(APPEND libc_archive_entrypoint_lists TARGET_LLVMLIBC_ENTRYPOINTS) +endif() + +set(added_archive_targets "") +foreach(archive IN ZIP_LISTS + libc_archive_names libc_archive_targets libc_archive_entrypoint_lists) + if(NOT ${archive_2}) + # If an entrypoint list is missing, then skip adding targets for it. + continue() + endif() + add_entrypoint_library( + ${archive_1} + DEPENDS + ${${archive_2}} + ) + set_target_properties( + ${archive_1} + PROPERTIES + ARCHIVE_OUTPUT_NAME ${archive_0} + ) + list(APPEND added_archive_targets ${archive_1}) +endforeach() if(LIBC_TARGET_TRIPLE) set(LIBC_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LIBC_TARGET_TRIPLE}) @@ -19,13 +46,13 @@ else() endif() install( - TARGETS libc + TARGETS ${added_archive_targets} ARCHIVE DESTINATION ${LIBC_INSTALL_LIBRARY_DIR} COMPONENT libc-static-archives ) add_llvm_install_targets( install-libc-static-archives - DEPENDS libc + DEPENDS ${added_archive_targets} COMPONENT libc-static-archives ) diff --git a/libc/startup/linux/CMakeLists.txt b/libc/startup/linux/CMakeLists.txt index f043ec5..5b044b9 100644 --- a/libc/startup/linux/CMakeLists.txt +++ b/libc/startup/linux/CMakeLists.txt @@ -92,5 +92,5 @@ foreach(target IN LISTS startup_components) get_target_property(startup_object ${fq_target_name} STARTUP_OBJECT) install(FILES ${startup_object} DESTINATION ${CMAKE_INSTALL_LIBDIR} - COMPONENT ${LIBC_COMPONENT}) + COMPONENT libc) endforeach() -- 2.7.4