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 e7c636753364f9120be28584494abca04cb5b15f
Author: Marco Casaroli <[email protected]>
AuthorDate: Mon Sep 28 20:35:28 2026 +0200

    arch/arm: Call FDPIC constructors with the module's own data base.
    
    Under FDPIC an .init_array or .fini_array entry is a code address, but a
    C function pointer is a function descriptor.  crt0 called each entry
    through a function pointer, so it read the constructor's first
    instructions as a descriptor and jumped to garbage.
    
    Call each entry with fdpic_call() and the data base from fdpic_base(),
    which is the module's own.  Without CONFIG_FDPIC both are a direct call,
    as before.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 arch/arm/src/common/crt0.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/arm/src/common/crt0.c b/arch/arm/src/common/crt0.c
index d552161b50b..b2a24e8276b 100644
--- a/arch/arm/src/common/crt0.c
+++ b/arch/arm/src/common/crt0.c
@@ -31,6 +31,7 @@
 
 #include <nuttx/addrenv.h>
 #include <nuttx/arch.h>
+#include <nuttx/fdpic.h>
 
 #include <arch/syscall.h>
 
@@ -114,7 +115,9 @@ static void exec_ctors(void)
 {
   for (initializer_t *ctor = _sctors; ctor != _ectors; ctor++)
     {
-      (*ctor)();
+      /* Under FDPIC the entry is a code address, not a descriptor */
+
+      fdpic_call(0, *ctor, fdpic_base());
     }
 }
 
@@ -130,7 +133,9 @@ static void exec_dtors(void)
 {
   for (initializer_t *dtor = _sdtors; dtor != _edtors; dtor++)
     {
-      (*dtor)();
+      /* Under FDPIC the entry is a code address, not a descriptor */
+
+      fdpic_call(0, *dtor, fdpic_base());
     }
 }
 

Reply via email to