From fa7ab41c1b60d656e2674a8d432eefffb53a849e Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Wed, 20 Sep 2023 12:35:15 +0200 Subject: [PATCH] native_simulator: Be sure the symbol_to_keep section is kept The native simulator final link can garbage collect unused symbols. So let's ensure the symbol to keep ones are indeed kept even if not used. Signed-off-by: Alberto Escolar Piedras --- boards/posix/common/natsim_config.cmake | 3 +++ boards/posix/common/natsim_linker_script.ld | 22 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 boards/posix/common/natsim_linker_script.ld diff --git a/boards/posix/common/natsim_config.cmake b/boards/posix/common/natsim_config.cmake index 54f26aef3ef..30da901f535 100644 --- a/boards/posix/common/natsim_config.cmake +++ b/boards/posix/common/natsim_config.cmake @@ -4,6 +4,9 @@ set(zephyr_build_path ${CMAKE_BINARY_DIR}/zephyr) get_property(CCACHE GLOBAL PROPERTY RULE_LAUNCH_COMPILE) +target_link_options(native_simulator INTERFACE + "-T ${ZEPHYR_BASE}/boards/posix/common/natsim_linker_script.ld") + set(nsi_config_content ${nsi_config_content} "NSI_BUILD_OPTIONS:=$,\ >" diff --git a/boards/posix/common/natsim_linker_script.ld b/boards/posix/common/natsim_linker_script.ld new file mode 100644 index 00000000000..add80b86c75 --- /dev/null +++ b/boards/posix/common/natsim_linker_script.ld @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief Extra linker command/script file for the native simulator runner + */ + +SECTIONS + { + symbol_to_keep : + { + KEEP(*(symbol_to_keep*)); + } + } INSERT AFTER .data; + +/* + * Note this script augments the default native simulator linker script + */