1 /*
2 Copyright (c) 2004 Paul Brook <paul@codesourcery.com>
3
4 Common routine to implement atexit-like functionality.
5
6 This is also the key function to be configured as lite exit, a size-reduced
7 implementation of exit that doesn't invoke clean-up functions such as _fini
8 or global destructors.
9
10 Default (without lite exit) call graph is like:
11 start -> atexit -> __register_exitproc
12 start -> __libc_init_array -> __cxa_atexit -> __register_exitproc
13 on_exit -> __register_exitproc
14 start -> exit -> __call_exitprocs
15
16 Here an -> means arrow tail invokes arrow head. All invocations here
17 are non-weak reference in current newlib.
18
19 Lite exit makes some of above calls as weak reference, so that size expansive
20 functions __register_exitproc and __call_exitprocs may not be linked. These
21 calls are:
22 start w-> atexit
23 cxa_atexit w-> __register_exitproc
24 exit w-> __call_exitprocs
25
26 Lite exit also makes sure that __call_exitprocs will be referenced as non-weak
27 whenever __register_exitproc is referenced as non-weak.
28
29 Thus with lite exit libs, a program not explicitly calling atexit or on_exit
30 will escape from the burden of cleaning up code. A program with atexit or on_exit
31 will work consistently to normal libs.
32
33 Lite exit is enabled with --enable-lite-exit, and is controlled with macro
34 LITE_EXIT.
35 */
36 /*
37 * Implementation if __cxa_finalize.
38 */
39
40
41 #include <stdlib.h>
42 #include "atexit.h"
43
44 /*
45 * Call registered exit handlers. If D is null then all handlers are called,
46 * otherwise only the handlers from that DSO are called.
47 */
48
49 void
__cxa_finalize(void * d)50 __cxa_finalize (void * d)
51 {
52 __call_exitprocs (0, d);
53 }
54