mesa: simplify dependencies in mmakefiles
[AROS.git] / compiler / autoinit / initexitsets.c
blob748f4412ec2214d4272b53544578eac167fb8b08
1 /*
2 Copyright © 2009-2016, 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, all 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_ARRAY)
43 THIS_PROGRAM_HANDLES_SYMBOLSET(FINI_ARRAY)
44 THIS_PROGRAM_HANDLES_SYMBOLSET(INIT)
45 THIS_PROGRAM_HANDLES_SYMBOLSET(EXIT)
46 DEFINESET(CTORS);
47 DEFINESET(DTORS);
48 DEFINESET(INIT_ARRAY);
49 DEFINESET(FINI_ARRAY);
50 DEFINESET(INIT);
51 DEFINESET(EXIT);
53 static void __startup_initexit(struct ExecBase *SysBase)
55 D(bug("Entering __startup_initexit\n"));
57 if (set_open_libraries())
59 __register_frame(&__eh_frame_start);
61 if (set_call_funcs(SETNAME(INIT), 1, 1))
63 /* ctors/dtors get called in inverse order than init funcs */
64 set_call_funcs(SETNAME(CTORS), -1, 0);
66 set_call_funcs(SETNAME(INIT_ARRAY), 1, 0);
68 __startup_entries_next();
70 set_call_funcs(SETNAME(FINI_ARRAY), -1, 0);
72 set_call_funcs(SETNAME(DTORS), 1, 0);
74 set_call_funcs(SETNAME(EXIT), -1, 0);
76 __deregister_frame(&__eh_frame_start);
78 set_close_libraries();
80 D(bug("Leaving __startup_initexit\n"));
83 ADD2SET(__startup_initexit, PROGRAM_ENTRIES, -20);