From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/1147 Path: news.gmane.org!not-for-mail From: Richard Pennington Newsgroups: gmane.linux.lib.musl.general Subject: Timing of destructors? Date: Thu, 14 Jun 2012 06:01:45 -0500 Message-ID: <5479702.eSrS0Tqozu@main.pennware.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7Bit X-Trace: dough.gmane.org 1339671812 5930 80.91.229.3 (14 Jun 2012 11:03:32 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 14 Jun 2012 11:03:32 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-1148-gllmg-musl=m.gmane.org@lists.openwall.com Thu Jun 14 13:03:31 2012 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Sf7pq-0003Nu-Qr for gllmg-musl@plane.gmane.org; Thu, 14 Jun 2012 13:03:30 +0200 Original-Received: (qmail 15954 invoked by uid 550); 14 Jun 2012 11:03:30 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 15902 invoked from network); 14 Jun 2012 11:03:20 -0000 X-Authority-Analysis: v=2.0 cv=D8PF24tj c=1 sm=0 a=/l7PkcR/UKDnn7Q2wmGJww==:17 a=hdNgKtvFP3AA:10 a=fR_ARpL9IlcA:10 a=msTO8fkKGJEA:10 a=kj9zAlcOel0A:10 a=N4Ps669bAAAA:8 a=pGLkceISAAAA:8 a=SPJcGplBxbfZRz_G2MAA:9 a=CjuIK1q_8ugA:10 a=MSl-tDqOz04A:10 a=/l7PkcR/UKDnn7Q2wmGJww==:117 X-Cloudmark-Score: 0 X-Originating-IP: 65.26.59.215 User-Agent: KMail/4.8.3 (Linux/3.3.2-6.fc16.x86_64; KDE/4.8.3; x86_64; ; ) Xref: news.gmane.org gmane.linux.lib.musl.general:1147 Archived-At: Hi, I have a small test program: #include #include void before(void) __attribute__((constructor)); void before(void) { printf("before\n"); } void after(void) __attribute__((destructor)); void after(void) { printf("after\n"); } int main() { printf("hello world\n"); } which doesn't print "after". This is because stdio is cleaned up before destructors are called in exit.c. Using stdio in destructors can be handy for debugging (if nothing else). Would it be evil to modify exit.c to look like this?: void exit(int code) { static int lock; /* If more than one thread calls exit, hang until _Exit ends it all */ while (a_swap(&lock, 1)) __syscall(SYS_pause); /* Destructor s**t is kept separate from atexit to avoid bloat */ if (libc.fini) libc.fini(); if (libc.ldso_fini) libc.ldso_fini(); /* Only do atexit & stdio flush if they were actually used */ __funcs_on_exit(); __fflush_on_exit(); _Exit(code); for(;;); } The change is to move the *_on_exit() calls to after the destructors have been called. -Rich