Skip to content

Commit

Permalink
Let the linker add an implicit --end-group
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
keith-packard committed Nov 21, 2023
1 parent 9fd68de commit c41cb6f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 45 deletions.
7 changes: 2 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 0 additions & 40 deletions cmake/linker/ld/target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c41cb6f

Please sign in to comment.