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


The following commit(s) were added to refs/heads/master by this push:
     new db5848cb0ac arch/arm,arm64: skip null entries when calling static 
constructors
db5848cb0ac is described below

commit db5848cb0ac0cdba6ab4e23032ee133e1bb38815
Author: anjiahao <[email protected]>
AuthorDate: Fri Nov 27 04:07:38 2026 +0800

    arch/arm,arm64: skip null entries when calling static constructors
    
    The .ctors/.dtors sections can contain padding entries that the
    toolchain leaves as NULL.  The loops call every entry as a function
    pointer, so a padded section crashes during startup.  Skip null
    entries in both the ARM and the ARM64 crt0.
    
    Signed-off-by: anjiahao <[email protected]>
---
 arch/arm/src/common/crt0.c   | 14 ++++++++++++++
 arch/arm64/src/common/crt0.c | 14 ++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/arch/arm/src/common/crt0.c b/arch/arm/src/common/crt0.c
index 8acc03893d2..850ed8a40f0 100644
--- a/arch/arm/src/common/crt0.c
+++ b/arch/arm/src/common/crt0.c
@@ -115,6 +115,13 @@ static void exec_ctors(void)
 {
   for (initializer_t *ctor = _sctors; ctor != _ectors; ctor++)
     {
+      /* Skip padding entries the toolchain may leave in the section. */
+
+      if (*ctor == NULL)
+        {
+          continue;
+        }
+
       /* Under FDPIC the entry is a code address, not a descriptor */
 
       fdpic_call(0, *ctor, fdpic_base());
@@ -133,6 +140,13 @@ static void exec_dtors(void)
 {
   for (initializer_t *dtor = _sdtors; dtor != _edtors; dtor++)
     {
+      /* Skip padding entries the toolchain may leave in the section. */
+
+      if (*dtor == NULL)
+        {
+          continue;
+        }
+
       /* Under FDPIC the entry is a code address, not a descriptor */
 
       fdpic_call(0, *dtor, fdpic_base());
diff --git a/arch/arm64/src/common/crt0.c b/arch/arm64/src/common/crt0.c
index 67c78223a6a..69e84f41046 100644
--- a/arch/arm64/src/common/crt0.c
+++ b/arch/arm64/src/common/crt0.c
@@ -122,6 +122,13 @@ static void exec_ctors(void)
 {
   for (initializer_t *ctor = _sctors; ctor != _ectors; ctor++)
     {
+      /* Skip padding entries the toolchain may leave in the section. */
+
+      if (*ctor == NULL)
+        {
+          continue;
+        }
+
       (*ctor)();
     }
 }
@@ -138,6 +145,13 @@ static void exec_dtors(void)
 {
   for (initializer_t *dtor = _sdtors; dtor != _edtors; dtor++)
     {
+      /* Skip padding entries the toolchain may leave in the section. */
+
+      if (*dtor == NULL)
+        {
+          continue;
+        }
+
       (*dtor)();
     }
 }

Reply via email to