Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZtHgOaH19Hmd23uh@voyager>
Date: Fri, 30 Aug 2024 17:07:37 +0200
From: Markus Wichmann <nullplan@....net>
To: musl@...ts.openwall.com
Cc: JinCheng Li <naiveli233@...look.com>
Subject: Re: Question about the exit()

Am Fri, Aug 30, 2024 at 01:34:58PM +0000 schrieb JinCheng Li:
> 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.
>

POSIX does not require an ordering between atexit handlers and
destructors. Since the order is unspecified, an application requiring a
specific order is broken and must be fixed. Notice that atexit() is the
better mechanism here, since with it you can even select the order in
which the destructors run (they run in reverse order of registration).
With normal destructors, the order is again unspecified.

> 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.
>

You probably missed the part where __cxa_finalize() calls all handlers
in reverse order. The first handler registered is the last handler
executed. Thus, in bionic as well, the application's atexit handlers run
first, followed by the destructors.

Also, according to enh, android rarely has applications exit. They
typically run until killed. So it is also likely that that code is not
well tested.

Ciao,
Markus

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.