casaroli opened a new pull request, #19938:
URL: https://github.com/apache/nuttx/pull/19938

   ## Summary
   
   `CONFIG_BINFMT_CONSTRUCTORS` has never had any effect on a module loaded 
through `exec()`. `elf_loadbinary()` records `.preinit_array` and `.init_array` 
in `binp->mod`, and nothing reads them back, so a C++ module's global objects 
stay as `.bss` and its constructors are dropped without a word.
   
   This calls the arrays at the end of the load, which is where 
`libelf_insert()` has always called them for a module that arrives through 
`dlopen()`.
   
   They cannot run on the task that will run the module: `exec_module()` had a 
hook for that, `exec_ctors()` through `nxtask_starthook()`, and it went with 
`CONFIG_SCHED_STARTHOOK`.
   
   This is the first of four independent pieces split out of #19673, so each 
can be reviewed on its own. The others are `[2/4]`, `[3/4]` and `[4/4]`. They 
do not depend on each other and can merge in any order.
   
   ## Impact
   
   A module with a global constructor now gets it run, where before it was 
silently skipped. That is a fix, not a break, but it is worth knowing: a module 
that worked around the gap by initializing from its entry point will find the 
constructor has already run, and should drop the workaround, since left in 
place it initializes twice.
   
   A module that reaches its globals through a PIC base register is left alone. 
The loading task carries its own base, not the module's, so a constructor would 
address the wrong data. Such a module gets what it got before, which is no 
constructors at all. Installing the base for the length of one call is a 
separate problem and comes with the FDPIC work in #19673.
   
   Destructors are unchanged: `elf_unloadbinary()` does not call `.fini_array` 
either.
   
   A module with no constructors is unaffected, as is any configuration with 
`CONFIG_BINFMT_CONSTRUCTORS` disabled.
   
   ## Testing
   
   Built for `mps3-an547:picostest` with `CONFIG_BINFMT_CONSTRUCTORS` enabled, 
which that configuration does not set by default. `tools/checkpatch.sh` passes.
   
   Runtime evidence on real hardware follows tomorrow, on an RP2350. Help is 
welcome from anyone with a board that can load an ELF module: enable 
`CONFIG_BINFMT_CONSTRUCTORS` and run `apps/examples/sotest` or 
`apps/examples/module` with a module that has a global constructor. No FDPIC, 
no special toolchain and no filesystem support are needed.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to