From 56ec06f3441c10dbb6678790322f92144163c753 Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Tue, 20 Dec 2022 10:36:34 -0800 Subject: [PATCH] kconfig: linker: Add --no-relax build option In some architectures the linker performs global optimization relaxing address modes and changing intructions in the output object file. This is a problem when userspace is enabled since it assumes that addresses won't change after certain build stage. In no supported architectures this option is ignored. Signed-off-by: Flavio Ceolin --- Kconfig.zephyr | 17 +++++++++++++++++ cmake/linker/ld/target_base.cmake | 6 ++++++ cmake/linker/lld/target_base.cmake | 6 ++++++ 3 files changed, 29 insertions(+) diff --git a/Kconfig.zephyr b/Kconfig.zephyr index a6560d8f863..2dd8492f750 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -292,6 +292,23 @@ config LINKER_LAST_SECTION_ID_PATTERN be used. The size of the pattern must not exceed 4 bytes. +config LINKER_USE_NO_RELAX + bool + help + Hidden symbol to allow features to force the use of no relax. + +config LINKER_USE_RELAX + bool "Linker optimization of call addressing" + depends on !LINKER_USE_NO_RELAX + default y + help + This option performs global optimizations that become possible when the linker resolves + addressing in the program, such as relaxing address modes and synthesizing new + instructions in the output object file. For ld and lld, this enables `--relax`. + On platforms where this is not supported, `--relax' is accepted, but ignored. + Disabling it can reduce performance, as the linker is no longer able to substiture long / + in-effective jump calls to shorter / more effective instructions. + endmenu # "Linker Sections" endmenu diff --git a/cmake/linker/ld/target_base.cmake b/cmake/linker/ld/target_base.cmake index 1fec5ca96f3..ac8054abbf6 100644 --- a/cmake/linker/ld/target_base.cmake +++ b/cmake/linker/ld/target_base.cmake @@ -28,4 +28,10 @@ macro(toolchain_ld_base) ${LINKERFLAGPREFIX},--sort-section=alignment ) + if (NOT CONFIG_LINKER_USE_RELAX) + zephyr_ld_options( + ${LINKERFLAGPREFIX},--no-relax + ) + endif() + endmacro() diff --git a/cmake/linker/lld/target_base.cmake b/cmake/linker/lld/target_base.cmake index a23f1c1da3b..d504dfaa8cf 100644 --- a/cmake/linker/lld/target_base.cmake +++ b/cmake/linker/lld/target_base.cmake @@ -26,4 +26,10 @@ macro(toolchain_ld_base) ${LINKERFLAGPREFIX},--sort-section=alignment ) + if (NOT CONFIG_LINKER_USE_RELAX) + zephyr_ld_options( + ${LINKERFLAGPREFIX},--no-relax + ) + endif() + endmacro()