llvm.org GIT mirror llvm / daac729
Make the new and old front-ends more similar: now neither uses __main. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26629 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
4 changed file(s) with 5 addition(s) and 83 deletion(s). Raw diff Collapse all Expand all
1919 LIBRARYNAME = crtend
2020 BYTECODE_DESTINATION = $(CFERuntimeLibDir)
2121
22 MainSrc := crtend.c listend.ll
22 MainSrc := crtend.c
2323 GenericEHSrc := Exception.cpp
2424 SJLJEHSrc := SJLJ-Exception.cpp
2525
2828
2929 include $(LEVEL)/Makefile.common
3030
31 MainObj := $(ObjDir)/crtend.bc $(ObjDir)/listend.bc
31 MainObj := $(ObjDir)/crtend.bc
3232 GenericEHObj := $(ObjDir)/Exception.bc
3333 SJLJEHObj := $(ObjDir)/SJLJ-Exception.bc
3434
0 This directory contains the C and C++ runtime libraries for the LLVM GCC
11 front-ends. It is composed of four distinct pieces:
22
3 1. __main and static ctor/dtor support. This is used by both C and C++ codes.
3 1. __main: now dead, but provided for compatibility.
44
55 2. Generic EH support routines. This is used by C/C++ programs that use
66 setjmp/longjmp, and by C++ programs that make use of exceptions.
66 *
77 *===----------------------------------------------------------------------===*
88 *
9 * This file defines the __main function, which is used to run static
10 * constructors and destructors in C++ programs, or with C programs that use GCC
11 * extensions to accomplish the same effect.
12 *
13 * The main data structures used to implement this functionality is the
14 * llvm.global_ctors and llvm.global_dtors lists, which are null terminated
15 * lists of TorRec (defined below) structures.
9 * This file defines the __main function, which we preserve for backwards
10 * compatibility.
1611 *
1712 \*===----------------------------------------------------------------------===*/
1813
19 #include
20
21 /* TorRec - The record type for each element of the ctor/dtor list */
22 typedef struct TorRec {
23 int Priority;
24 void (*FP)(void);
25 } TorRec;
26
27 /* __llvm_getGlobalCtors, __llvm_getGlobalDtors - Interface to the LLVM
28 * listend.ll file to get access to the start of the ctor and dtor lists...
29 */
30 TorRec *__llvm_getGlobalCtors(void);
31 TorRec *__llvm_getGlobalDtors(void);
32
33 static void run_destructors(void);
34
35 /* __main - A call to this function is automatically inserted into the top of
36 * the "main" function in the program compiled. This function is responsible
37 * for calling static constructors before the program starts executing.
38 */
3914 void __main(void) {
40 /* Loop over all of the constructor records, calling each function pointer. */
41 TorRec *R = __llvm_getGlobalCtors();
42
43 /* Recursively calling main is not legal C, but lots of people do it for
44 * testing stuff. We might as well work for them.
45 */
46 static _Bool Initialized = 0;
47 if (Initialized) return;
48 Initialized = 1;
49
50 /* Only register the global dtor handler if there is at least one global
51 * dtor!
52 */
53 if (__llvm_getGlobalDtors()[0].FP)
54 if (atexit(run_destructors))
55 abort(); /* Should be able to install ONE atexit handler! */
56
57 /* FIXME: This should sort the list by priority! */
58 if (R->FP)
59 for (; R->FP; ++R)
60 R->FP();
6115 }
62
63 static void run_destructors(void) {
64 /* Loop over all of the destructor records, calling each function pointer. */
65 TorRec *R = __llvm_getGlobalDtors();
66
67 /* FIXME: This should sort the list by priority! */
68 for (; R->FP; ++R)
69 R->FP();
70 }
+0
-23
runtime/GCCLibraries/crtend/listend.ll less more
None ; global_ctors/global_dtors terminator: this is used to add a terminating null
1 ; value to the initialization list.
2
3 %struct..TorRec = type { int, void ()* }
4
5 %llvm.global_ctors = appending global [1 x %struct..TorRec] [
6 %struct..TorRec { int 2147483647, void ()* null }
7 ]
8
9 %llvm.global_dtors = appending global [1 x %struct..TorRec] [
10 %struct..TorRec { int 2147483647, void ()* null }
11 ]
12
13 implementation
14
15 %struct..TorRec* %__llvm_getGlobalCtors() {
16 ret %struct..TorRec* getelementptr ([1 x %struct..TorRec]* %llvm.global_ctors,
17 long 0, long 0)
18 }
19 %struct..TorRec* %__llvm_getGlobalDtors() {
20 ret %struct..TorRec* getelementptr ([1 x %struct..TorRec]* %llvm.global_dtors,
21 long 0, long 0)
22 }