llvm.org GIT mirror llvm / 6e3d3bc
crtend is only for llvm-gcc3, remove it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34529 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 12 years ago
11 changed file(s) with 1 addition(s) and 485 deletion(s). Raw diff Collapse all Expand all
77 ##===----------------------------------------------------------------------===##
88
99 LEVEL := ../..
10 PARALLEL_DIRS := crtend libc libgcc libm
10 PARALLEL_DIRS := libc libgcc libm
1111 include $(LEVEL)/Makefile.common
+0
-54
runtime/GCCLibraries/crtend/Exception.cpp less more
None //===- Exception.cpp - Generic language-independent exceptions ------------===//
1 //
2 // This file defines the the shared data structures used by all language
3 // specific exception handling runtime libraries.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #include "Exception.h"
8
9 // Thread local state for exception handling. FIXME: This should really be made
10 // thread-local!
11
12 // UncaughtExceptionStack - The stack of exceptions currently being thrown.
13 static llvm_exception *UncaughtExceptionStack = 0;
14
15 // __llvm_eh_has_uncaught_exception - This is used to implement
16 // std::uncaught_exception.
17 //
18 bool __llvm_eh_has_uncaught_exception() throw() {
19 return UncaughtExceptionStack != 0;
20 }
21
22 // __llvm_eh_current_uncaught_exception - This function checks to see if the
23 // current uncaught exception is of the specified language type. If so, it
24 // returns a pointer to the exception area data.
25 //
26 void *__llvm_eh_current_uncaught_exception_type(unsigned HandlerType) throw() {
27 if (UncaughtExceptionStack->ExceptionType == HandlerType)
28 return UncaughtExceptionStack+1;
29 return 0;
30 }
31
32 // __llvm_eh_add_uncaught_exception - This adds the specified exception to the
33 // top of the uncaught exception stack. The exception should not already be on
34 // the stack!
35 void __llvm_eh_add_uncaught_exception(llvm_exception *E) throw() {
36 E->Next = UncaughtExceptionStack;
37 UncaughtExceptionStack = E;
38 }
39
40
41 // __llvm_eh_get_uncaught_exception - Returns the current uncaught exception.
42 // There must be an uncaught exception for this to work!
43 llvm_exception *__llvm_eh_get_uncaught_exception() throw() {
44 return UncaughtExceptionStack;
45 }
46
47 // __llvm_eh_pop_from_uncaught_stack - Remove the current uncaught exception
48 // from the top of the stack.
49 llvm_exception *__llvm_eh_pop_from_uncaught_stack() throw() {
50 llvm_exception *E = __llvm_eh_get_uncaught_exception();
51 UncaughtExceptionStack = E->Next;
52 return E;
53 }
+0
-71
runtime/GCCLibraries/crtend/Exception.h less more
None //===- Exception.h - Generic language-independent exceptions ----*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the the shared data structures used by all language
10 // specific exception handling runtime libraries.
11 //
12 // NOTE NOTE NOTE: A copy of this file lives in llvmgcc/libstdc++-v3/libsupc++/
13 // Any modifications to this file must keep it in sync!
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef EXCEPTION_H
18 #define EXCEPTION_H
19
20 struct llvm_exception {
21 // ExceptionDestructor - This call-back function is used to destroy the
22 // current exception, without requiring the caller to know what the concrete
23 // exception type is.
24 //
25 void (*ExceptionDestructor)(llvm_exception *);
26
27 // ExceptionType - This field identifies what runtime library this exception
28 // came from. Currently defined values are:
29 // 0 - Error
30 // 1 - longjmp exception (see longjmp-exception.c)
31 // 2 - C++ exception (see c++-exception.c)
32 //
33 unsigned ExceptionType;
34
35 // Next - This points to the next exception in the current stack.
36 llvm_exception *Next;
37
38 // HandlerCount - This is a count of the number of handlers which have
39 // currently caught this exception. If the handler is caught and this number
40 // falls to zero, the exception is destroyed.
41 //
42 unsigned HandlerCount;
43
44 // isRethrown - This field is set on an exception if it has been 'throw;'n.
45 // This is needed because the exception might exit through a number of the
46 // end_catch statements matching the number of begin_catch statements that
47 // have been processed. When this happens, the exception should become
48 // uncaught, not dead.
49 //
50 int isRethrown;
51 };
52
53 enum {
54 ErrorException = 0,
55 SJLJException = 1,
56 CXXException = 2
57 };
58
59 // Language independent exception handling API...
60 //
61 extern "C" {
62 bool __llvm_eh_has_uncaught_exception() throw();
63 void *__llvm_eh_current_uncaught_exception_type(unsigned HandlerType) throw();
64 void __llvm_eh_add_uncaught_exception(llvm_exception *E) throw();
65
66 llvm_exception *__llvm_eh_get_uncaught_exception() throw();
67 llvm_exception *__llvm_eh_pop_from_uncaught_stack() throw();
68 }
69
70 #endif
+0
-83
runtime/GCCLibraries/crtend/Makefile less more
None ##===- runtime/GCCLibraries/crtend/Makefile ----------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file was developed by the LLVM research group and is distributed under
5 # the University of Illinois Open Source License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8 #
9 # This directory contains the C and C++ runtime libraries for the LLVM GCC
10 # front-ends. See the README.txt file for more details.
11 #
12 # Since this archive has strange requirements, we use some custom rules for
13 # building it.
14 #
15 ##===----------------------------------------------------------------------===##
16
17 LEVEL = ../../..
18 DONT_BUILD_RELINKED = 1
19 LIBRARYNAME = crtend
20 BYTECODE_DESTINATION = $(CFERuntimeLibDir)
21
22 MainSrc := crtend.c
23 GenericEHSrc := Exception.cpp
24 SJLJEHSrc := SJLJ-Exception.cpp
25
26 EXTRA_DIST := $(MainSrc) $(GenericEHSrc) $(SJLJEHSrc) \
27 comp_main.lst comp_genericeh.lst comp_sjljeh.lst
28
29 include $(LEVEL)/Makefile.common
30
31 MainObj := $(ObjDir)/crtend.bc
32 GenericEHObj := $(ObjDir)/Exception.bc
33 SJLJEHObj := $(ObjDir)/SJLJ-Exception.bc
34
35 # __main and ctor/dtor support component
36 $(ObjDir)/comp_main.bc: $(MainObj)
37 $(Echo) Linking $(notdir $@) component...
38 $(Verb) $(GCCLD) -link-as-library \
39 -internalize-public-api-file=$(PROJ_SRC_DIR)/comp_main.lst \
40 $(MainObj) -o $@
41
42 # Generic exception handling support runtime.
43 $(ObjDir)/comp_genericeh.bc: $(GenericEHObj)
44 $(Echo) Linking $(notdir $@) component...
45 $(Verb) $(GCCLD) -link-as-library \
46 -internalize-public-api-file=$(PROJ_SRC_DIR)/comp_genericeh.lst \
47 $(GenericEHObj) -o $@
48
49 # setjmp/longjmp exception handling support runtime.
50 $(ObjDir)/comp_sjljeh.bc: $(SJLJEHObj)
51 $(Echo) Linking $(notdir $@) component...
52 $(Verb) $(GCCLD) -link-as-library \
53 -internalize-public-api-file=$(PROJ_SRC_DIR)/comp_sjljeh.lst \
54 $(SJLJEHObj) -o $@
55
56 SYMBOLHACKEDOBJS := $(ObjDir)/comp_main.bc $(ObjDir)/comp_genericeh.bc \
57 $(ObjDir)/comp_sjljeh.bc
58
59 all-local:: $(LibName.BCA)
60
61 ifdef BYTECODE_DESTINATION
62 BytecodeDestDir := $(BYTECODE_DESTINATION)
63 else
64 BytecodeDestDir := $(PROJ_libdir)
65 endif
66
67 DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
68 install-bytecode-local:: $(DestBytecodeLib)
69 install-local:: $(DestBytecodeLib)
70
71 $(LibName.BCA): $(SYMBOLHACKEDOBJS) $(LibDir)/.dir $(LLVMToolDir)/llvm-ar
72 $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
73 $(Verb) $(RM) -f $@
74 $(Verb) $(LArchive) $@ $(SYMBOLHACKEDOBJS)
75
76 $(DestBytecodeLib): $(BytecodeDestDir) $(LibName.BCA)
77 $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
78 $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
79
80 uninstall-local::
81 $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
82 -$(Verb) $(RM) -f $(DestBytecodeLib)
+0
-15
runtime/GCCLibraries/crtend/README.txt less more
None This directory contains the C and C++ runtime libraries for the LLVM GCC
1 front-ends. It is composed of four distinct pieces:
2
3 1. __main: now dead, but provided for compatibility.
4
5 2. Generic EH support routines. This is used by C/C++ programs that use
6 setjmp/longjmp, and by C++ programs that make use of exceptions.
7
8 3. setjmp/longjmp EH support. This is used by C/C++ programs that call SJLJ.
9
10 4. C++ exception handling runtime support.
11
12 These four components are compiled together into an archive file, so that
13 applications using a subset of the four do not pull in unnecessary code and
14 dependencies.
+0
-146
runtime/GCCLibraries/crtend/SJLJ-Exception.cpp less more
None //===- SJLJ-Exception.cpp - SetJmp/LongJmp Exception Handling -------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the API used by the Setjmp/Longjmp exception handling
10 // runtime library.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "SJLJ-Exception.h"
15 #include
16 #include
17
18 // Assert should only be used for debugging the runtime library. Enabling it in
19 // CVS will break some platforms!
20 #undef assert
21 #define assert(X)
22
23 // get_sjlj_exception - Adjust the llvm_exception pointer to be an appropriate
24 // llvm_sjlj_exception pointer.
25 inline llvm_sjlj_exception *get_sjlj_exception(llvm_exception *E) {
26 assert(E->ExceptionType == SJLJException);
27 return (llvm_sjlj_exception*)(E+1) - 1;
28 }
29
30 // SetJmpMapEntry - One entry in a linked list of setjmps for the current
31 // function.
32 struct SetJmpMapEntry {
33 void *JmpBuf;
34 unsigned SetJmpID;
35 SetJmpMapEntry *Next;
36 };
37
38 // SJLJDestructor - This function is used to free the exception when
39 // language-indent code needs to destroy the exception without knowing exactly
40 // what type it is.
41 static void SJLJDestructor(llvm_exception *E) {
42 free(get_sjlj_exception(E));
43 }
44
45
46 // __llvm_sjljeh_throw_longjmp - This function creates the longjmp exception and
47 // returns. It takes care of mapping the longjmp value from 0 -> 1 as
48 // appropriate. The caller should immediately call llvm.unwind after this
49 // function call.
50 void __llvm_sjljeh_throw_longjmp(void *JmpBuffer, int Val) throw() {
51 llvm_sjlj_exception *E =
52 (llvm_sjlj_exception *)malloc(sizeof(llvm_sjlj_exception));
53 E->BaseException.ExceptionDestructor = SJLJDestructor;
54 E->BaseException.ExceptionType = SJLJException;
55 E->BaseException.HandlerCount = 0;
56 E->BaseException.isRethrown = 0;
57 E->JmpBuffer = JmpBuffer;
58 E->LongJmpValue = Val ? Val : 1;
59
60 __llvm_eh_add_uncaught_exception(&E->BaseException);
61 }
62
63 // __llvm_sjljeh_init_setjmpmap - This funciton initializes the pointer provided
64 // to an empty setjmp map, and should be called on entry to a function which
65 // calls setjmp.
66 void __llvm_sjljeh_init_setjmpmap(void **SetJmpMap) throw() {
67 *SetJmpMap = 0;
68 }
69
70 // __llvm_sjljeh_destroy_setjmpmap - This function frees all memory associated
71 // with the specified setjmpmap structure. It should be called on all exits
72 // (returns or unwinds) from the function which calls ...init_setjmpmap.
73 void __llvm_sjljeh_destroy_setjmpmap(void **SetJmpMap) throw() {
74 SetJmpMapEntry *Next;
75 for (SetJmpMapEntry *SJE = *(SetJmpMapEntry**)SetJmpMap; SJE; SJE = Next) {
76 Next = SJE->Next;
77 free(SJE);
78 }
79 }
80
81 // __llvm_sjljeh_add_setjmp_to_map - This function adds or updates an entry to
82 // the map, to indicate which setjmp should be returned to if a longjmp happens.
83 void __llvm_sjljeh_add_setjmp_to_map(void **SetJmpMap, void *JmpBuf,
84 unsigned SetJmpID) throw() {
85 SetJmpMapEntry **SJE = (SetJmpMapEntry**)SetJmpMap;
86
87 // Scan for a pre-existing entry...
88 for (; *SJE; SJE = &(*SJE)->Next)
89 if ((*SJE)->JmpBuf == JmpBuf) {
90 (*SJE)->SetJmpID = SetJmpID;
91 return;
92 }
93
94 // No prexisting entry found, append to the end of the list...
95 SetJmpMapEntry *New = (SetJmpMapEntry *)malloc(sizeof(SetJmpMapEntry));
96 *SJE = New;
97 New->JmpBuf = JmpBuf;
98 New->SetJmpID = SetJmpID;
99 New->Next = 0;
100 }
101
102 // __llvm_sjljeh_is_longjmp_exception - This function returns true if the
103 // current uncaught exception is a longjmp exception. This is the first step of
104 // catching a sjlj exception.
105 bool __llvm_sjljeh_is_longjmp_exception() throw() {
106 return __llvm_eh_current_uncaught_exception_type(SJLJException) != 0;
107 }
108
109 // __llvm_sjljeh_get_longjmp_value - This function returns the value that the
110 // setjmp call should "return". This requires that the current uncaught
111 // exception be a sjlj exception, though it does not require the exception to be
112 // caught by this function.
113 int __llvm_sjljeh_get_longjmp_value() throw() {
114 llvm_sjlj_exception *E =
115 get_sjlj_exception(__llvm_eh_get_uncaught_exception());
116 return E->LongJmpValue;
117 }
118
119 // __llvm_sjljeh_try_catching_longjmp_exception - This function checks to see if
120 // the current uncaught longjmp exception matches any of the setjmps collected
121 // in the setjmpmap structure. If so, it catches and destroys the exception,
122 // returning the index of the setjmp which caught the exception. If not, it
123 // leaves the exception uncaught and returns a value of ~0.
124 unsigned __llvm_sjljeh_try_catching_longjmp_exception(void **SetJmpMap) throw(){
125 llvm_sjlj_exception *E =
126 get_sjlj_exception(__llvm_eh_get_uncaught_exception());
127
128 // Scan for a matching entry in the SetJmpMap...
129 SetJmpMapEntry *SJE = *(SetJmpMapEntry**)SetJmpMap;
130 for (; SJE; SJE = SJE->Next)
131 if (SJE->JmpBuf == E->JmpBuffer) {
132 // "Catch" and destroy the exception...
133 __llvm_eh_pop_from_uncaught_stack();
134
135 // We know it's a longjmp exception, so we can just free it instead of
136 // calling the destructor.
137 free(E);
138
139 // Return the setjmp ID which we should branch to...
140 return SJE->SetJmpID;
141 }
142
143 // No setjmp in this function catches the exception!
144 return ~0;
145 }
+0
-80
runtime/GCCLibraries/crtend/SJLJ-Exception.h less more
None //===- SJLJ-Exception.h - SetJmp/LongJmp Exception Handling -----*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the data structures and API used by the Setjmp/Longjmp
10 // exception handling runtime library.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef SJLJ_EXCEPTION_H
15 #define SJLJ_EXCEPTION_H
16
17 #include "Exception.h"
18
19 struct llvm_sjlj_exception {
20 // JmpBuffer - This is the buffer which was longjmp'd with.
21 //
22 void *JmpBuffer;
23
24 // LongJmpValue - The value passed into longjmp, which the corresponding
25 // setjmp should return. Note that this value will never be equal to 0.
26 //
27 int LongJmpValue;
28
29 // BaseException - The language independent portion of the exception state.
30 // This is at the end of the record so that we can add additional members to
31 // this structure without breaking binary compatibility.
32 //
33 llvm_exception BaseException;
34 };
35
36 extern "C" {
37 // __llvm_sjljeh_throw_longjmp - This function creates the longjmp exception
38 // and returns. It takes care of mapping the longjmp value from 0 -> 1 as
39 // appropriate. The caller should immediately call llvm.unwind after this
40 // function call.
41 void __llvm_sjljeh_throw_longjmp(void *JmpBuffer, int Val) throw();
42
43 // __llvm_sjljeh_init_setjmpmap - This funciton initializes the pointer
44 // provided to an empty setjmp map, and should be called on entry to a
45 // function which calls setjmp.
46 void __llvm_sjljeh_init_setjmpmap(void **SetJmpMap) throw();
47
48 // __llvm_sjljeh_destroy_setjmpmap - This function frees all memory associated
49 // with the specified setjmpmap structure. It should be called on all exits
50 // (returns or unwinds) from the function which calls ...init_setjmpmap.
51 void __llvm_sjljeh_destroy_setjmpmap(void **SetJmpMap) throw();
52
53 // __llvm_sjljeh_add_setjmp_to_map - This function adds or updates an entry to
54 // the map, to indicate which setjmp should be returned to if a longjmp
55 // happens.
56 void __llvm_sjljeh_add_setjmp_to_map(void **SetJmpMap, void *JmpBuf,
57 unsigned SetJmpID) throw();
58
59 // __llvm_sjljeh_is_longjmp_exception - This function returns true if the
60 // current uncaught exception is a longjmp exception. This is the first step
61 // of catching a sjlj exception.
62 bool __llvm_sjljeh_is_longjmp_exception() throw();
63
64 // __llvm_sjljeh_get_longjmp_value - This function returns the value that the
65 // setjmp call should "return". This requires that the current uncaught
66 // exception be a sjlj exception, though it does not require the exception to
67 // be caught by this function.
68 int __llvm_sjljeh_get_longjmp_value() throw();
69
70 // __llvm_sjljeh_try_catching_longjmp_exception - This function checks to see
71 // if the current uncaught longjmp exception matches any of the setjmps
72 // collected in the setjmpmap structure. If so, it catches and destroys the
73 // exception, returning the index of the setjmp which caught the exception.
74 // If not, it leaves the exception uncaught and returns a value of ~0.
75 unsigned __llvm_sjljeh_try_catching_longjmp_exception(void **SetJmpMap)
76 throw();
77 }
78
79 #endif
+0
-9
runtime/GCCLibraries/crtend/comp_genericeh.lst less more
None __main
1 llvm.global_ctors
2 llvm.global_dtors
3
4 __llvm_eh_has_uncaught_exception
5 __llvm_eh_current_uncaught_exception_type
6 __llvm_eh_add_uncaught_exception
7 __llvm_eh_get_uncaught_exception
8 __llvm_eh_pop_from_uncaught_stack
+0
-3
runtime/GCCLibraries/crtend/comp_main.lst less more
None __main
1 llvm.global_ctors
2 llvm.global_dtors
+0
-7
runtime/GCCLibraries/crtend/comp_sjljeh.lst less more
None __llvm_sjljeh_throw_longjmp
1 __llvm_sjljeh_init_setjmpmap
2 __llvm_sjljeh_destroy_setjmpmap
3 __llvm_sjljeh_add_setjmp_to_map
4 __llvm_sjljeh_is_longjmp_exception
5 __llvm_sjljeh_get_longjmp_value
6 __llvm_sjljeh_try_catching_longjmp_exception
+0
-16
runtime/GCCLibraries/crtend/crtend.c less more
None /*===- crtend.c - Initialization code for programs ------------------------===*\
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file was developed by the LLVM research group and is distributed under
5 * the University of Illinois Open Source License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===*
8 *
9 * This file defines the __main function, which we preserve for backwards
10 * compatibility.
11 *
12 \*===----------------------------------------------------------------------===*/
13
14 void __main(void) {
15 }