Skip to content

Commit f8c8334

Browse files
authored
Arm backend: Fix standalone runner link order (pytorch#20756)
Fix the Arm semihosting executor runner link order used by setup_testing.sh. The previous link line placed backend archives before the objects and dependent archives that reference them, so ld could miss bare-metal symbols when building the standalone runners. Group the runner libraries and keep the backend archives in a whole-archive region after clearing their inherited interface link options. This keeps symbols visible to the linker while preserving the existing runner setup. cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani Signed-off-by: Baris Demir <baris.demir@arm.com>
1 parent cf7dc0e commit f8c8334

1 file changed

Lines changed: 54 additions & 9 deletions

File tree

examples/arm/executor_runner/CMakeLists.txt

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,25 +299,31 @@ execute_process(
299299
)
300300
target_link_options(arm_executor_runner PRIVATE "-T" "${LINK_FILE_OUT}")
301301

302-
# Apply whole-archive helper where available to keep static initializers.
303-
executorch_target_link_options_shared_lib(executorch_delegate_ethos_u)
304-
executorch_target_link_options_shared_lib(quantized_kernels)
305-
executorch_target_link_options_shared_lib(cortex_m_kernels)
306-
executorch_target_link_options_shared_lib(portable_kernels)
307-
308302
set(arm_executor_runner_link)
309303
list(
310304
APPEND
311305
arm_executor_runner_link
306+
-Wl,--start-group
312307
extension_runner_util
313308
ethosu_target_init
309+
-Wl,--whole-archive
314310
executorch
315311
quantized_ops_lib
316312
cortex_m_ops_lib
317313
executorch_delegate_ethos_u
318314
quantized_kernels
319315
cortex_m_kernels
320316
portable_kernels
317+
executorch_core
318+
cmsis-nn
319+
ethosu_core_driver
320+
timing_adapter
321+
ethosu_mhu_dummy
322+
ethosu_mailbox
323+
ethosu_uart_cmsdk_apb
324+
-Wl,--no-whole-archive
325+
kernels_util_all_deps
326+
-Wl,--end-group
321327
-Xlinker
322328
-Map=arm_executor_runner.map
323329
)
@@ -397,7 +403,12 @@ if(NOT ("${EXECUTORCH_SELECT_OPS_LIST}" STREQUAL ""
397403
DTYPE_SELECTIVE_BUILD
398404
"${EXECUTORCH_ENABLE_DTYPE_SELECTIVE_BUILD}"
399405
)
400-
list(APPEND arm_executor_runner_link arm_portable_ops_lib)
406+
list(FIND arm_executor_runner_link -Wl,--no-whole-archive
407+
_arm_runner_no_whole_archive_idx
408+
)
409+
list(INSERT arm_executor_runner_link ${_arm_runner_no_whole_archive_idx}
410+
arm_portable_ops_lib
411+
)
401412
endif()
402413

403414
if(EXECUTORCH_ENABLE_EVENT_TRACER)
@@ -454,8 +465,42 @@ if(ET_BUNDLE_IO)
454465
endif()
455466
endif()
456467

457-
# Need whole-archive to ensure C++ ctor's are called - this may be wasteful for
458-
# bin size as we link in a number of other symbols
468+
# Keep static registration libraries force-loaded, but do it in the executable
469+
# link list rather than through INTERFACE_LINK_OPTIONS. The latter is emitted
470+
# before this target's objects and before the runner's dependency closure, which
471+
# breaks bare-metal archive resolution for the runner.
472+
set(_arm_runner_whole_archive_targets
473+
executorch
474+
quantized_ops_lib
475+
cortex_m_ops_lib
476+
executorch_delegate_ethos_u
477+
quantized_kernels
478+
cortex_m_kernels
479+
portable_kernels
480+
executorch_core
481+
cmsis-nn
482+
ethosu_core_driver
483+
timing_adapter
484+
ethosu_mhu_dummy
485+
ethosu_mailbox
486+
ethosu_uart_cmsdk_apb
487+
)
488+
if(TARGET arm_portable_ops_lib)
489+
list(APPEND _arm_runner_whole_archive_targets arm_portable_ops_lib)
490+
endif()
491+
foreach(_arm_runner_whole_archive_target IN
492+
LISTS _arm_runner_whole_archive_targets
493+
)
494+
if(TARGET ${_arm_runner_whole_archive_target})
495+
set_property(
496+
TARGET ${_arm_runner_whole_archive_target} PROPERTY INTERFACE_LINK_OPTIONS
497+
""
498+
)
499+
endif()
500+
endforeach()
501+
502+
# Need whole-archive to ensure C++ ctors are called. This may be wasteful for
503+
# binary size as we link in a number of other symbols.
459504
target_link_libraries(arm_executor_runner PUBLIC ${arm_executor_runner_link})
460505

461506
# Ensure the ELF lands next to the CMake build tree so run.sh (and downstream

0 commit comments

Comments
 (0)