binfmt:use crt0 inside of starthook

test:
1.use mps3-an547 build helloxx as module and run it
2.use qemu-armv7a:knsh test kernel build helloxx and run it

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
anjiahao
2025-02-10 17:53:46 +08:00
committed by Xiang Xiao
parent 297a1cb1fe
commit 422c43949a
59 changed files with 156 additions and 287 deletions

View File

@@ -66,7 +66,7 @@ endif
config BINFMT_CONSTRUCTORS
bool "C++ Static Constructor Support"
default n
depends on HAVE_CXX && SCHED_STARTHOOK && ELF
depends on HAVE_CXX && ELF
---help---
Built-in support for C++ constructors in loaded modules. Currently
only support for ELF binary formats.

View File

@@ -52,55 +52,10 @@
* Pre-processor Definitions
****************************************************************************/
/* If C++ constructors are used, then CONFIG_SCHED_STARTHOOK must also be
* selected be the start hook is used to schedule execution of the
* constructors.
*/
#if defined(CONFIG_BINFMT_CONSTRUCTORS) && !defined(CONFIG_SCHED_STARTHOOK)
# error "CONFIG_SCHED_STARTHOOK must be defined to use constructors"
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: exec_ctors
*
* Description:
* Execute C++ static constructors. This function is registered as a
* start hook and runs on the thread of the newly created task before
* the new task's main function is called.
*
* Input Parameters:
* arg - Argument is instance of load state info structure cast to void *.
*
* Returned Value:
* 0 (OK) is returned on success and a negated errno is returned on
* failure.
*
****************************************************************************/
#ifdef CONFIG_BINFMT_CONSTRUCTORS
static void exec_ctors(FAR void *arg)
{
FAR const struct binary_s *binp = (FAR const struct binary_s *)arg;
binfmt_ctor_t *ctor = (CODE binfmt_ctor_t *)binp->mod.initarr;
int i;
/* Execute each constructor */
for (i = 0; i < binp->mod.ninit; i++)
{
binfo("Calling ctor %d at %p\n", i, ctor);
(*ctor)();
ctor++;
}
}
#endif
/****************************************************************************
* Name: exec_swap
*
@@ -356,18 +311,6 @@ int exec_module(FAR struct binary_s *binp,
}
#endif
#ifdef CONFIG_BINFMT_CONSTRUCTORS
/* Setup a start hook that will execute all of the C++ static constructors
* on the newly created thread. The struct binary_s must persist at least
* until the new task has been started.
*/
if (binp->mod.ninit > 0)
{
nxtask_starthook(tcb, exec_ctors, binp);
}
#endif
#ifdef CONFIG_SCHED_USER_IDENTITY
if (binp->mode & S_ISUID)
{