Removed double NAME entry.
[AROS.git] / compiler / autoinit / initexitsets.c
blobaa0b33defafbb037e51edaa4c4efaaa118f1a799
1 /*
2 Copyright © 2009 - 2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: autoinit library - handle init and exit symolsets
6 */
7 #include <aros/startup.h>
8 #include <aros/symbolsets.h>
9 #include <setjmp.h>
11 #define DEBUG 0
12 #include <aros/debug.h>
14 int __noinitexitsets __attribute__((weak)) = 0;
15 extern void *__eh_frame_start;
18 * These two functions could have been overriden by libgcc's Dwarf2 unwinder code.
19 * (used for example for C++ exception handling).
20 * We do this trick in order to avoid linking in the whole unwinder just by referencing
21 * these functions. This helps to keep C executables smaller.
22 * Note that we call them when libraries are already open because __register_frame()
23 * internally uses malloc(). See unwind-dw2-fde.c in gcc source code.
25 * TODO: Calling these functions from here means that only plain executables register their
26 * exception frames. This means that:
27 * a) C++ exceptions won't work inside shared libraries.
28 * This can be easily fixed in libraries startup code. But libraries are separate executables, and
29 * this would mean that they register their own frames in their own copy of libgcc runtime. As a
30 * consequence:
31 * b) C++ exceptions can't be thrown outside of shared libraries using this approach.
32 * (b) is more difficult to fix. When some program opens the library, it should be able to register
33 * its frames and actually process exceptions using program's runtime. This can be implemented
34 * in a number of ways, every of them involving development of some ABI standard.
36 void __attribute__((weak)) __register_frame(void *begin) {}
37 void __attribute__((weak)) __deregister_frame(void *begin) {}
39 THIS_PROGRAM_HANDLES_SYMBOLSET(LIBS)
40 THIS_PROGRAM_HANDLES_SYMBOLSET(CTORS)
41 THIS_PROGRAM_HANDLES_SYMBOLSET(DTORS)
42 THIS_PROGRAM_HANDLES_SYMBOLSET(INIT)
43 THIS_PROGRAM_HANDLES_SYMBOLSET(EXIT)
44 DEFINESET(CTORS);
45 DEFINESET(DTORS);
46 DEFINESET(INIT);
47 DEFINESET(EXIT);
49 static void __startup_initexit(struct ExecBase *SysBase)
51 D(bug("Entering __startup_initexit\n"));
53 if (set_open_libraries())
55 __register_frame(&__eh_frame_start);
57 if (set_call_funcs(SETNAME(INIT), 1, 1))
59 /* ctors/dtors get called in inverse order than init funcs */
60 set_call_funcs(SETNAME(CTORS), -1, 0);
62 __startup_entries_next();
64 set_call_funcs(SETNAME(DTORS), 1, 0);
66 set_call_funcs(SETNAME(EXIT), -1, 0);
68 __deregister_frame(&__eh_frame_start);
70 set_close_libraries();
72 D(bug("Leaving __startup_initexit\n"));
75 ADD2SET(__startup_initexit, PROGRAM_ENTRIES, -20);