From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id DAF592DC08 for ; Fri, 30 Aug 2024 17:09:06 +0200 (CEST) Received: (qmail 16248 invoked by uid 550); 30 Aug 2024 15:09:03 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 16213 invoked from network); 30 Aug 2024 15:09:02 -0000 Date: Fri, 30 Aug 2024 11:08:53 -0400 From: Rich Felker To: JinCheng Li Cc: musl Message-ID: <20240830150853.GN10433@brightrain.aerifal.cx> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] Question about the exit() On Fri, Aug 30, 2024 at 01:34:58PM +0000, JinCheng Li wrote: > Hi > > I have one question in exit(). > Why is the __libc_exit_fini executed after __funcs_on_exit? If some Because that is the contract. > 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. Then that's a bug in the atexit handler. It should not be freeing anything that could later be needed by a destructor or by any thread that may still be running concurrent with exit. In general, freeing anything from an atexit handler is a bug. See Rust issue 126600 where this is discussed in detail: https://github.com/rust-lang/rust/issues/126600 > 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. I don't follow. What do you mean by "registered last"? After what? And where is this "global variables release" coming from? Rich