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

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

commit 88dc0c461cbc0fd5e004e2e5de7ce1dc7fc77cf2
Author: Brijesh Thakkar <[email protected]>
AuthorDate: Sun Oct 18 03:11:07 2026 +0530

    arch/sim: resolve host symbols eagerly on Linux in CMake.
    
    The Make build got -Wl,-z,now in ad182bcb4b ("sim: resolve host symbols
    eagerly on Linux"), but the CMake build never did. Add it to the sim
    link options under the same condition (a Linux host).
    
    Without it, the first call to a host function through the PLT goes
    through the lazy binder. up_irq_save() is such a call: it runs from
    host_allocheap() at the very start of nx_start(), with simulated
    interrupts masked, and _dl_fixup() faults once the binary is linked
    non-PIE:
    
      #0  _dl_fixup (...) at ./elf/dl-runtime.c:162
      #1  _dl_runtime_resolve_xsavec () at ../sysdeps/x86_64/dl-trampoline.h:98
      #2  up_irq_save () at sim/posix/sim_hostirq.c:98
      #3  host_allocheap (size=67108864, exec=false) at 
sim/posix/sim_hostmemory.c:71
    
    The sim then dies with SIGSEGV before NSH starts. Running the same
    binary with LD_BIND_NOW=1 boots fine, which confirms that lazy binding
    is the trigger.
    
    CMake sim:nsh from current master still boots on gcc 15 (Ubuntu 26.04),
    but the next patch, which passes -no-pie through the gcc driver,
    reproduces the crash there without this change, so this goes first.
    
    The Make build is not affected since it already links with -z now.
    
    Assisted-by: Claude:claude-sonnet-5-5
    Signed-off-by: Brijesh Thakkar <[email protected]>
---
 arch/sim/src/cmake/Toolchain.cmake | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/sim/src/cmake/Toolchain.cmake 
b/arch/sim/src/cmake/Toolchain.cmake
index dcec62d66bd..65b8a2aae35 100644
--- a/arch/sim/src/cmake/Toolchain.cmake
+++ b/arch/sim/src/cmake/Toolchain.cmake
@@ -279,4 +279,7 @@ endif()
 
 if(SIM_HOST_LINUX)
   add_link_options(-Wl,-z,noexecstack)
+  # Resolve PLT entries at load time so early host calls made with simulated
+  # interrupts masked do not fault inside the lazy binder.
+  add_link_options(-Wl,-z,now)
 endif()

Reply via email to