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

commit bd47daf11d8cf073a4b1d07a4c252d50cfb072ce
Author: Marco Casaroli <[email protected]>
AuthorDate: Wed Oct 21 11:47:59 2026 +0200

    arch/risc-v: Link an LTO program that is not relocatable with its options.
    
    Without CONFIG_BINFMT_ELF_RELOCATABLE (rv-virt:knsh64), a program is
    linked to an executable, and LDELFFLAGS has no compile options.  With
    CONFIG_LTO_FULL, gcc links it, adds the start files of its C library,
    and compiles the LTO objects without the ABI of the program:
    
      multiple definition of `_start'; .../riscv-none-elf/lib/crt0.o:
      first defined here
      streams.h:783:5: internal compiler error: Segmentation fault: 11
    
    The gcc branch now sets LDELFEXEFLAGS to the ELF compile options
    (-nostdlib, -march, -mabi, ...), and LDELFFLAGS has them when the
    program is not relocatable, as it has them with -r.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 arch/risc-v/src/common/Toolchain.defs | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/risc-v/src/common/Toolchain.defs 
b/arch/risc-v/src/common/Toolchain.defs
index 62637b1d26b..dca6c97a0ba 100644
--- a/arch/risc-v/src/common/Toolchain.defs
+++ b/arch/risc-v/src/common/Toolchain.defs
@@ -404,6 +404,11 @@ else
 
       LDMODULELTOFLAGS = -flinker-output=nolto-rel $(CMODULEFLAGS)
       LDELFLTOFLAGS = -flinker-output=nolto-rel $(CELFFLAGS)
+
+      # A program that is not relocatable is linked to an executable, also
+      # with the ELF options (-nostdlib, the ABI)
+
+      LDELFEXEFLAGS = $(CELFFLAGS)
       LDXLINKER = -Xlinker
 
       # The export gives the group options to the program link of a kernel 
build
@@ -479,6 +484,8 @@ LDELFFLAGS = -e _start
 
 ifeq ($(CONFIG_BINFMT_ELF_RELOCATABLE),y)
   LDELFFLAGS += -r $(LDELFLTOFLAGS)
+else
+  LDELFFLAGS += $(LDELFEXEFLAGS)
 endif
 
 ifeq ($(CONFIG_ARCH_RV32),y)

Reply via email to