This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 5aa48d0989ba3a8c1e8647b4ca02695915628a5c
Author: zhangyuan29 <[email protected]>
AuthorDate: Wed Aug 6 11:31:40 2025 +0800

    arch/tricore: don't delete unreferenced sections in user lib
    
    The -OtxYcL link optimization string was passed globally, so its
    delete-unreferenced-sections, delete-duplicate-code and
    delete-duplicate-data actions also applied to the user library in
    protected builds, dropping sections that were still needed.  Scope
    the optimizations to the nuttx kernel target instead and disable
    optimization for the user library in protected builds.
    
    Signed-off-by: zhangyuan29 <[email protected]>
---
 arch/tricore/src/cmake/tasking.cmake   |  2 +-
 arch/tricore/src/common/CMakeLists.txt | 10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/arch/tricore/src/cmake/tasking.cmake 
b/arch/tricore/src/cmake/tasking.cmake
index a067a4c6493..094440122cc 100644
--- a/arch/tricore/src/cmake/tasking.cmake
+++ b/arch/tricore/src/cmake/tasking.cmake
@@ -172,7 +172,7 @@ add_link_options(-lc_fpu)
 add_link_options(-lfp_fpu)
 
 add_link_options(--core=mpe:vtc)
-add_link_options(--hex-format=s -OtxYcL -mcrfiklsmnoduq)
+add_link_options(--hex-format=s -mcrfiklsmnoduq)
 add_link_options(-lrt)
 
 # cmake-format: off
diff --git a/arch/tricore/src/common/CMakeLists.txt 
b/arch/tricore/src/common/CMakeLists.txt
index 6b135462282..da3761103f5 100644
--- a/arch/tricore/src/common/CMakeLists.txt
+++ b/arch/tricore/src/common/CMakeLists.txt
@@ -74,7 +74,6 @@ target_compile_options(nuttx PRIVATE ${IFXFLAGS})
 target_include_directories(
   nuttx SYSTEM PRIVATE ${NUTTX_DIR}/include ${NUTTX_BINARY_DIR}/include
                        ${NUTTX_BINARY_DIR}/include_arch)
-
 # TASKING toolchain: build a fake libc_fpu.a to override the toolchain's 
default
 # C library and provide stubs for the symbols the linker still references (see
 # tricore_libc.c for details).
@@ -84,4 +83,13 @@ if(CONFIG_TRICORE_TOOLCHAIN_TASKING)
   target_sources(c_fpu PRIVATE tricore_libc.c)
   target_link_options(nuttx PRIVATE
                       --library-directory=${CMAKE_CURRENT_BINARY_DIR})
+
+  # Scope the delete-unreferenced-sections optimization to the kernel image
+  # only: applied globally it also strips sections of the user library that are
+  # still needed.
+
+  target_link_options(nuttx PRIVATE -OtxYcL)
+  if(CONFIG_BUILD_PROTECTED)
+    target_link_options(nuttx_user PRIVATE --optimize=0)
+  endif()
 endif()

Reply via email to