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

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


The following commit(s) were added to refs/heads/master by this push:
     new fcb4df8391a cmake: Keep gcc-ar when LTO is enabled after the first 
configure.
fcb4df8391a is described below

commit fcb4df8391a36e1e9554805071ad8d13bcc6678b
Author: Marco Casaroli <[email protected]>
AuthorDate: Mon Oct 19 15:45:52 2026 +0200

    cmake: Keep gcc-ar when LTO is enabled after the first configure.
    
    CMake saves CMAKE_AR and CMAKE_RANLIB of the first configure in
    CMakeFiles/<version>/CMake<LANG>Compiler.cmake.  On each later
    configure, CMake reads this file after the toolchain file, so the saved
    tools replace the tools that the toolchain file selects.
    
    The arm, arm64 and risc-v GCC toolchain files select gcc-ar only when
    LTO is on.  arm and risc-v also select gcc-ranlib only with LTO.  When
    LTO is enabled in an existing build directory, for example with
    menuconfig or kconfig-tweak, the archive rules keep the plain ar and
    ranlib.  These tools load the LTO plugin only if the toolchain installs
    it in lib/bfd-plugins, and the Arm GNU toolchain does not.  Then the
    archive index has no symbols of the LTO objects, and the linker takes no
    member from the libraries.  An arm link warns "cannot find entry symbol
    __start" and writes an empty nuttx, or stops with undefined references
    from the assembly start-up code.  arm64 always runs gcc-ranlib, which
    writes a correct index.
    
    Put the tools that the toolchain file selects in the archive rules,
    instead of the <CMAKE_AR> and <CMAKE_RANLIB> placeholders.  The
    toolchain file runs on each configure, after .config is read, so the
    rules follow the current LTO options.  A first configure gives the same
    rules as before.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 arch/arm/src/cmake/gcc.cmake          | 8 +++++---
 arch/arm64/src/cmake/gcc.cmake        | 8 +++++---
 arch/risc-v/src/cmake/Toolchain.cmake | 8 +++++---
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/arch/arm/src/cmake/gcc.cmake b/arch/arm/src/cmake/gcc.cmake
index acbdada38f0..081c6b845fd 100644
--- a/arch/arm/src/cmake/gcc.cmake
+++ b/arch/arm/src/cmake/gcc.cmake
@@ -83,10 +83,12 @@ if(CMAKE_GENERATOR MATCHES "Ninja")
   set(CMAKE_ASM_RESPONSE_FILE_FLAG "$DEFINES $INCLUDES $FLAGS @")
 endif()
 
-# override the ARCHIVE command
+# override the ARCHIVE command.  CMake keeps CMAKE_AR and CMAKE_RANLIB of the
+# first configure, so put the tools selected above in the rules: they follow a
+# later change of the LTO options.
 
-set(CMAKE_ARCHIVE_COMMAND "<CMAKE_AR> rcs <TARGET> <LINK_FLAGS> <OBJECTS>")
-set(CMAKE_RANLIB_COMMAND "<CMAKE_RANLIB> <TARGET>")
+set(CMAKE_ARCHIVE_COMMAND "${CMAKE_AR} rcs <TARGET> <LINK_FLAGS> <OBJECTS>")
+set(CMAKE_RANLIB_COMMAND "${CMAKE_RANLIB} <TARGET>")
 set(CMAKE_C_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
 set(CMAKE_CXX_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
 set(CMAKE_ASM_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
diff --git a/arch/arm64/src/cmake/gcc.cmake b/arch/arm64/src/cmake/gcc.cmake
index 3e8a0ad2732..58a90f6fe38 100644
--- a/arch/arm64/src/cmake/gcc.cmake
+++ b/arch/arm64/src/cmake/gcc.cmake
@@ -49,9 +49,11 @@ if(CONFIG_LTO_FULL)
 endif()
 
 add_link_options(--entry=__start)
-# override the ARCHIVE command
-set(CMAKE_ARCHIVE_COMMAND "<CMAKE_AR> rcs <TARGET> <LINK_FLAGS> <OBJECTS>")
-set(CMAKE_RANLIB_COMMAND "<CMAKE_RANLIB> <TARGET>")
+# override the ARCHIVE command.  CMake keeps CMAKE_AR and CMAKE_RANLIB of the
+# first configure, so put the tools selected above in the rules: they follow a
+# later change of the LTO options.
+set(CMAKE_ARCHIVE_COMMAND "${CMAKE_AR} rcs <TARGET> <LINK_FLAGS> <OBJECTS>")
+set(CMAKE_RANLIB_COMMAND "${CMAKE_RANLIB} <TARGET>")
 set(CMAKE_C_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
 set(CMAKE_CXX_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
 set(CMAKE_ASM_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
diff --git a/arch/risc-v/src/cmake/Toolchain.cmake 
b/arch/risc-v/src/cmake/Toolchain.cmake
index 2e0a9614293..89e032a6d4f 100644
--- a/arch/risc-v/src/cmake/Toolchain.cmake
+++ b/arch/risc-v/src/cmake/Toolchain.cmake
@@ -120,9 +120,11 @@ if(CMAKE_GENERATOR MATCHES "Ninja")
   set(CMAKE_ASM_RESPONSE_FILE_FLAG "$DEFINES $INCLUDES $FLAGS @")
 endif()
 
-# override the ARCHIVE command
-set(CMAKE_ARCHIVE_COMMAND "<CMAKE_AR> rcs <TARGET> <LINK_FLAGS> <OBJECTS>")
-set(CMAKE_RANLIB_COMMAND "<CMAKE_RANLIB> <TARGET>")
+# override the ARCHIVE command.  CMake keeps CMAKE_AR and CMAKE_RANLIB of the
+# first configure, so put the tools selected above in the rules: they follow a
+# later change of the LTO options.
+set(CMAKE_ARCHIVE_COMMAND "${CMAKE_AR} rcs <TARGET> <LINK_FLAGS> <OBJECTS>")
+set(CMAKE_RANLIB_COMMAND "${CMAKE_RANLIB} <TARGET>")
 set(CMAKE_C_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
 set(CMAKE_CXX_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
 set(CMAKE_ASM_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})

Reply via email to