Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Thu, 14 Jun 2012 06:01:45 -0500
From: Richard Pennington <>
Subject: Timing of destructors?


I have a small test program:
#include <stdio.h>
#include <stdlib.h>

void before(void) __attribute__((constructor));
void before(void)

void after(void) __attribute__((destructor));
void after(void)

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 

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 */


The change is to move the *_on_exit() calls to after the destructors have been 


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.