mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] Question about the exit()
@ 2024-08-30 13:34 JinCheng Li
  2024-08-30 15:07 ` Markus Wichmann
  2024-08-30 15:08 ` Rich Felker
  0 siblings, 2 replies; 3+ messages in thread
From: JinCheng Li @ 2024-08-30 13:34 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 1221 bytes --]

Hi

I have one question in exit().
Why is the __libc_exit_fini executed after __funcs_on_exit?  If some finalized functions in .fini_array access global variables which is registered by __cxa_atexit and will be release in __funcs_on_exit, we may run into some crash during __libc_exit_fini executaion.

_Noreturn void exit(int code)
{
    __funcs_on_exit();
    __libc_exit_fini();
    __stdio_exit();
    _Exit(code);
}


In bionic, I found the fini_array functions may be registered at the last before we execute main function and called firstly in exit(before global variables release) . Its order looks like completely opposite to musl.

__noreturn void __libc_init(void* raw_args,
                           void (*onexit)(void) __unused,
                           int (*slingshot)(int, char**, char**),
                           structors_array_t const * const structors) {
......
 if (structors->fini_array) {
   __cxa_atexit(__libc_fini,structors->fini_array,nullptr);
 }
......
 exit(slingshot(args.argc - __libc_shared_globals()->initial_linker_arg_count,
                args.argv + __libc_shared_globals()->initial_linker_arg_count,
                args.envp));
}

Best
Li


[-- Attachment #2: Type: text/html, Size: 8363 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-30 15:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-30 13:34 [musl] Question about the exit() JinCheng Li
2024-08-30 15:07 ` Markus Wichmann
2024-08-30 15:08 ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).