From c41cb6ffd03fb492e19dd1d39675cb3b5f957e74 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 21 Nov 2023 14:30:46 -0800 Subject: [PATCH] Let the linker add an implicit --end-group Give up on trying to actually compute all of the libraries that need to be between --start-group and --end-group and just let the linker assume there's a --end-group at the end of the command line. Signed-off-by: Keith Packard --- CMakeLists.txt | 7 ++----- cmake/linker/ld/target.cmake | 40 ------------------------------------ 2 files changed, 2 insertions(+), 45 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 951a009a4812026..a7c83c377fd2f0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -590,11 +590,8 @@ endforeach() set(ZEPHYR_CURRENT_MODULE_DIR) set(ZEPHYR_CURRENT_CMAKE_DIR) -# Check to see if the linker handles LIBC_LINK_LIBRARIES internally -if(NOT "${LIBC_LINK_LIBRARIES_SKIP}") - get_property(LIBC_LINK_LIBRARIES TARGET zephyr_interface PROPERTY LIBC_LINK_LIBRARIES) - zephyr_link_libraries(${LIBC_LINK_LIBRARIES}) -endif() +get_property(LIBC_LINK_LIBRARIES TARGET zephyr_interface PROPERTY LIBC_LINK_LIBRARIES) +zephyr_link_libraries(${LIBC_LINK_LIBRARIES}) set(syscall_list_h ${CMAKE_CURRENT_BINARY_DIR}/include/generated/syscall_list.h) set(syscalls_json ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls.json) diff --git a/cmake/linker/ld/target.cmake b/cmake/linker/ld/target.cmake index dd05683944e279c..3dab4092864ec21 100644 --- a/cmake/linker/ld/target.cmake +++ b/cmake/linker/ld/target.cmake @@ -98,34 +98,6 @@ function(toolchain_ld_force_undefined_symbols) endforeach() endfunction() -function(toolchain_ld_all_targets output dir) - get_property(targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS) - get_property(subdirs DIRECTORY ${dir} PROPERTY SUBDIRECTORIES) - - foreach(subdir ${subdirs}) - toolchain_ld_all_targets(subdir_targets ${subdir}) - list(APPEND targets ${subdir_targets}) - endforeach() - - set(${output} ${targets} PARENT_SCOPE) -endfunction() - -function(toolchain_ld_add_transitive targets output) - set(local_output ${${output}}) - foreach(symbol ${ARGN}) - list(FIND local_output "${symbol}" found_index) - if(${found_index} EQUAL -1) - list(APPEND local_output "${symbol}") - list(FIND ${targets} "${symbol}" target_index) - if(NOT ${target_index} EQUAL -1) - get_property(INTERFACE_LINK_LIBRARIES TARGET "${symbol}" PROPERTY INTERFACE_LINK_LIBRARIES) - toolchain_ld_add_transitive(targets local_output ${INTERFACE_LINK_LIBRARIES}) - endif() - endif() - endforeach() - set(${output} ${local_output} PARENT_SCOPE) -endfunction() - # Link a target to given libraries with toolchain-specific argument order # # Usage: @@ -152,13 +124,6 @@ function(toolchain_ld_link_elf) set(use_linker "-fuse-ld=bfd") endif() - get_property(LIBC_LINK_LIBRARIES TARGET zephyr_interface PROPERTY LIBC_LINK_LIBRARIES) - - toolchain_ld_all_targets(LIBC_LINK_ALL_TARGETS ${CMAKE_CURRENT_LIST_DIR}) - - # Get the whole list of libraries to stick between --start-group and --end-group - toolchain_ld_add_transitive(LIBC_LINK_ALL_TARGETS LIBC_LINK_TRANSITIVE ${ZEPHYR_LIBS_WHOLE} ${ZEPHYR_LIBS_PARTIAL}) - # Force the use of common malloc instead of libc malloc if(CONFIG_COMMON_LIBC_MALLOC) @@ -190,16 +155,11 @@ function(toolchain_ld_link_elf) ${LIB_INCLUDE_DIR} -L${PROJECT_BINARY_DIR} ${TOOLCHAIN_LIBS} - ${LIBC_LINK_LIBRARIES} - ${LIBC_LINK_TRANSITIVE} ${TOOLCHAIN_LD_LINK_ELF_DEPENDENCIES} - ${LINKERFLAGPREFIX},--end-group ) endfunction(toolchain_ld_link_elf) -set(LIBC_LINK_LIBRARIES_SKIP TRUE) - # Load toolchain_ld-family macros include(${ZEPHYR_BASE}/cmake/linker/${LINKER}/target_base.cmake) include(${ZEPHYR_BASE}/cmake/linker/${LINKER}/target_baremetal.cmake)