patacongo commented on issue #12356:
URL: https://github.com/apache/nuttx/issues/12356#issuecomment-2125637674

   > I have seen places where the ctor/dtor code is executed in binfmt
   
   Constructors and destructors should run in crti and crtN, respectively, for 
general Unix compatibility.  crti should support __init and crtN should 
supporrt __fini.
   
   Lots more detail if you care about this:  
https://gcc.gnu.org/onlinedocs/gccint/Initialization.html
   
   As the OP mentioned, this is currently done with conditional logic in crt0.  
That is technically okay but will likely confuse people who are used to 
thinking about things in the GCC/GLIBC way.
   
   There is a long-open issue #1265 (and related #1263).  Perhaps this is only 
a problem in PROTECTED mode which as a single set of ctors and dtors for the 
whole user-space blob.  KERNEL mode uses only loadable ELF modules, each with 
their own ctors and dtors.
   
   crt0.c exists only for armv7-a, arm64, and riscv-5 all of which can support 
the KERNEL build.
   
   So crt0 with ELF modules should never be used in PROTECTED mode right now or 
else you would get doubly constructed static classes.
   
   >  I have seen places where the ctor/dtor code is executed in binfmt (there 
is a kconfig that controls this I believe, don't remember the name though)
   
   That is CONFIG_BINFMT_CONSTRUCTORS.  I think that should be disabled in 
KERNEL mode to let the ELF module call its own constructors and destructors in 
the correct context.
   
   This seems awkward and prone to errors to me.
   


-- 
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: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to