aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-11-17 03:32:33 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-11-17 03:32:33 +0000
commit8b2e1419cf24a33df5a87c99e367528b44dc28cf (patch)
treedfa50da1818a1e9c1d0588c060051c65583821a3 /runtime
parentb2b9c20b6121a54a41ee1c583a4bff4389622da2 (diff)
Undo removal of the runtime libraries. While this may have been a bit
premature, these libraries will be going away for the 2.0 release. Other arrangements for profiling, gc, etc. should be made in the next few months. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31807 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'runtime')
-rw-r--r--runtime/GC/GCInterface.h48
-rw-r--r--runtime/GC/Makefile19
-rw-r--r--runtime/GC/SemiSpace/Makefile19
-rw-r--r--runtime/GC/SemiSpace/semispace.c122
-rw-r--r--runtime/GC/gc_exported_symbols.lst7
-rw-r--r--runtime/GCCLibraries/Makefile12
-rw-r--r--runtime/GCCLibraries/README.txt7
-rw-r--r--runtime/GCCLibraries/crtend/Exception.cpp54
-rw-r--r--runtime/GCCLibraries/crtend/Exception.h71
-rw-r--r--runtime/GCCLibraries/crtend/Makefile83
-rw-r--r--runtime/GCCLibraries/crtend/README.txt15
-rw-r--r--runtime/GCCLibraries/crtend/SJLJ-Exception.cpp146
-rw-r--r--runtime/GCCLibraries/crtend/SJLJ-Exception.h80
-rw-r--r--runtime/GCCLibraries/crtend/comp_genericeh.lst9
-rw-r--r--runtime/GCCLibraries/crtend/comp_main.lst3
-rw-r--r--runtime/GCCLibraries/crtend/comp_sjljeh.lst7
-rw-r--r--runtime/GCCLibraries/crtend/crtend.c16
-rw-r--r--runtime/GCCLibraries/libc/COPYING.LIB510
-rw-r--r--runtime/GCCLibraries/libc/LICENSE.TXT17
-rw-r--r--runtime/GCCLibraries/libc/LICENSES219
-rw-r--r--runtime/GCCLibraries/libc/Makefile19
-rw-r--r--runtime/GCCLibraries/libc/README.txt4
-rw-r--r--runtime/GCCLibraries/libc/atox.c118
-rw-r--r--runtime/GCCLibraries/libc/io.c18
-rw-r--r--runtime/GCCLibraries/libc/qsort.c261
-rw-r--r--runtime/GCCLibraries/libc/remove.c51
-rw-r--r--runtime/GCCLibraries/libc/string.c172
-rw-r--r--runtime/GCCLibraries/libgcc/Makefile16
-rw-r--r--runtime/GCCLibraries/libgcc/eprintf.c13
-rw-r--r--runtime/GCCLibraries/libm/Makefile16
-rw-r--r--runtime/GCCLibraries/libm/temp.c1
-rw-r--r--runtime/Makefile43
-rw-r--r--runtime/README.txt4
-rw-r--r--runtime/libdummy/Makefile19
-rw-r--r--runtime/libdummy/README.txt2
-rw-r--r--runtime/libdummy/dummylib.c144
-rw-r--r--runtime/libprofile/BasicBlockTracing.c67
-rw-r--r--runtime/libprofile/BlockProfiling.c45
-rw-r--r--runtime/libprofile/CommonProfiling.c117
-rw-r--r--runtime/libprofile/EdgeProfiling.c45
-rw-r--r--runtime/libprofile/FunctionProfiling.c42
-rw-r--r--runtime/libprofile/Makefile19
-rw-r--r--runtime/libprofile/Profiling.h31
-rw-r--r--runtime/libprofile/exported_symbols.lst5
-rw-r--r--runtime/libtrace/Makefile18
-rw-r--r--runtime/libtrace/README.txt2
-rw-r--r--runtime/libtrace/tracelib.c392
-rw-r--r--runtime/libtrace/tracelib.h40
48 files changed, 3188 insertions, 0 deletions
diff --git a/runtime/GC/GCInterface.h b/runtime/GC/GCInterface.h
new file mode 100644
index 0000000000..4eb48183bc
--- /dev/null
+++ b/runtime/GC/GCInterface.h
@@ -0,0 +1,48 @@
+/*===-- GCInterface.h - Public interface exposed by garbage collectors ----===*\
+|*
+|* The LLVM Compiler Infrastructure
+|*
+|* This file was developed by the LLVM research group and is distributed under
+|* the University of Illinois Open Source License. See LICENSE.TXT for details.
+|*
+|*===----------------------------------------------------------------------===*|
+|*
+|* This file defines the common public interface that must be exposed by all
+|* LLVM garbage collectors.
+|*
+\*===----------------------------------------------------------------------===*/
+
+#ifndef GCINTERFACE_H
+#define GCINTERFACE_H
+
+/* llvm_cg_walk_gcroots - This function is exposed by the LLVM code generator,
+ * and allows us to traverse the roots on the stack.
+ */
+void llvm_cg_walk_gcroots(void (*FP)(void **Root, void *Meta));
+
+
+/* llvm_gc_initialize - This function is called to initalize the garbage
+ * collector.
+ */
+void llvm_gc_initialize(unsigned InitialHeapSize);
+
+/* llvm_gc_allocate - This function allocates Size bytes from the heap and
+ * returns a pointer to it.
+ */
+void *llvm_gc_allocate(unsigned Size);
+
+/* llvm_gc_collect - This function forces a garbage collection cycle.
+ */
+void llvm_gc_collect();
+
+/* llvm_gc_read - This function should be implemented to include any read
+ * barrier code that is needed by the garbage collector.
+ */
+void *llvm_gc_read(void *ObjPtr, void **FieldPtr);
+
+/* llvm_gc_write - This function should be implemented to include any write
+ * barrier code that is needed by the garbage collector.
+ */
+void llvm_gc_write(void *V, void *ObjPtr, void **FieldPtr);
+
+#endif
diff --git a/runtime/GC/Makefile b/runtime/GC/Makefile
new file mode 100644
index 0000000000..b57dc85907
--- /dev/null
+++ b/runtime/GC/Makefile
@@ -0,0 +1,19 @@
+##===- runtime/GC/Makefile ---------------------------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file was developed by the LLVM research group and is distributed under
+# the University of Illinois Open Source License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../..
+PARALLEL_DIRS := SemiSpace
+EXTRA_DIST := gc_exported_symbols.lst
+include $(LEVEL)/Makefile.common
+
+# Install target for libraries: Copy into $LLVMGCCDIR/bytecode-libs
+#
+install::
+
+clean::
diff --git a/runtime/GC/SemiSpace/Makefile b/runtime/GC/SemiSpace/Makefile
new file mode 100644
index 0000000000..6f8e54ce27
--- /dev/null
+++ b/runtime/GC/SemiSpace/Makefile
@@ -0,0 +1,19 @@
+##===- runtime/GC/SemiSpace/Makefile -----------------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file was developed by the LLVM research group and is distributed under
+# the University of Illinois Open Source License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../../..
+BYTECODE_LIBRARY = 1
+LIBRARYNAME = gcsemispace
+BYTECODE_DESTINATION = $(CFERuntimeLibDir)
+EXPORTED_SYMBOL_FILE = $(PROJ_SRC_DIR)/../gc_exported_symbols.lst
+
+include $(LEVEL)/Makefile.common
+
+CompileCommonOpts := $(filter-out -pedantic,$(CompileCommonOpts))
+CompileCommonOpts := $(filter-out -Wno-long-long,$(CompileCommonOpts))
diff --git a/runtime/GC/SemiSpace/semispace.c b/runtime/GC/SemiSpace/semispace.c
new file mode 100644
index 0000000000..cb5864b0bd
--- /dev/null
+++ b/runtime/GC/SemiSpace/semispace.c
@@ -0,0 +1,122 @@
+/*===-- semispace.c - Simple semi-space copying garbage collector ---------===*\
+|*
+|* The LLVM Compiler Infrastructure
+|*
+|* This file was developed by the LLVM research group and is distributed under
+|* the University of Illinois Open Source License. See LICENSE.TXT for details.
+|*
+|*===----------------------------------------------------------------------===*|
+|*
+|* This garbage collector is an extremely simple copying collector. It splits
+|* the managed region of memory into two pieces: the current space to allocate
+|* from, and the copying space. When the portion being allocated from fills up,
+|* a garbage collection cycle happens, which copies all live blocks to the other
+|* half of the managed space.
+|*
+\*===----------------------------------------------------------------------===*/
+
+#include "../GCInterface.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* AllocPtr - This points to the next byte that is available for allocation.
+ */
+static char *AllocPtr;
+
+/* AllocEnd - This points to the first byte not available for allocation. When
+ * AllocPtr passes this, we have run out of space.
+ */
+static char *AllocEnd;
+
+/* CurSpace/OtherSpace - These pointers point to the two regions of memory that
+ * we switch between. The unallocated portion of the CurSpace is known to be
+ * zero'd out, but the OtherSpace contains junk.
+ */
+static void *CurSpace, *OtherSpace;
+
+/* SpaceSize - The size of each space. */
+static unsigned SpaceSize;
+
+/* llvm_gc_initialize - Allocate the two spaces that we plan to switch between.
+ */
+void llvm_gc_initialize(unsigned InitialHeapSize) {
+ SpaceSize = InitialHeapSize/2;
+ CurSpace = AllocPtr = calloc(1, SpaceSize);
+ OtherSpace = malloc(SpaceSize);
+ AllocEnd = AllocPtr + SpaceSize;
+}
+
+/* We always want to inline the fast path, but never want to inline the slow
+ * path.
+ */
+void *llvm_gc_allocate(unsigned Size) __attribute__((always_inline));
+static void* llvm_gc_alloc_slow(unsigned Size) __attribute__((noinline));
+
+void *llvm_gc_allocate(unsigned Size) {
+ char *OldAP = AllocPtr;
+ char *NewEnd = OldAP+Size;
+ if (NewEnd > AllocEnd)
+ return llvm_gc_alloc_slow(Size);
+ AllocPtr = NewEnd;
+ return OldAP;
+}
+
+static void* llvm_gc_alloc_slow(unsigned Size) {
+ llvm_gc_collect();
+ if (AllocPtr+Size > AllocEnd) {
+ fprintf(stderr, "Garbage collector ran out of memory "
+ "allocating object of size: %d\n", Size);
+ exit(1);
+ }
+
+ return llvm_gc_allocate(Size);
+}
+
+
+static void process_pointer(void **Root, void *Meta) {
+ printf("process_root[0x%p] = 0x%p\n", (void*) Root, (void*) *Root);
+}
+
+void llvm_gc_collect() {
+ // Clear out the space we will be copying into.
+ // FIXME: This should do the copy, then clear out whatever space is left.
+ memset(OtherSpace, 0, SpaceSize);
+
+ printf("Garbage collecting!!\n");
+ llvm_cg_walk_gcroots(process_pointer);
+ abort();
+}
+
+/* We use no read/write barriers */
+void *llvm_gc_read(void *ObjPtr, void **FieldPtr) { return *FieldPtr; }
+void llvm_gc_write(void *V, void *ObjPtr, void **FieldPtr) { *FieldPtr = V; }
+
+
+/*===----------------------------------------------------------------------===**
+ * FIXME: This should be in a code-generator specific library, but for now this
+ * will work for all code generators.
+ */
+typedef struct GCRoot {
+ void **RootPtr;
+ void *Meta;
+} GCRoot;
+
+typedef struct GCRoots {
+ struct GCRoots *Next;
+ unsigned NumRoots;
+ GCRoot RootRecords[];
+} GCRoots;
+GCRoots *llvm_gc_root_chain;
+
+void llvm_cg_walk_gcroots(void (*FP)(void **Root, void *Meta)) {
+ GCRoots *R = llvm_gc_root_chain;
+ for (; R; R = R->Next) {
+ unsigned i, e;
+ for (i = 0, e = R->NumRoots; i != e; ++i)
+ FP(R->RootRecords[i].RootPtr, R->RootRecords[i].Meta);
+ }
+}
+/* END FIXME! */
+
+
diff --git a/runtime/GC/gc_exported_symbols.lst b/runtime/GC/gc_exported_symbols.lst
new file mode 100644
index 0000000000..0ed60f57ee
--- /dev/null
+++ b/runtime/GC/gc_exported_symbols.lst
@@ -0,0 +1,7 @@
+llvm_gc_initialize
+llvm_gc_allocate
+llvm_gc_collect
+llvm_gc_write
+llvm_gc_read
+
+llvm_gc_root_chain \ No newline at end of file
diff --git a/runtime/GCCLibraries/Makefile b/runtime/GCCLibraries/Makefile
new file mode 100644
index 0000000000..b976f1248e
--- /dev/null
+++ b/runtime/GCCLibraries/Makefile
@@ -0,0 +1,12 @@
+##===- runtime/GCCLibraries/Makefile -----------------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file was developed by the LLVM research group and is distributed under
+# the University of Illinois Open Source License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL := ../..
+PARALLEL_DIRS := crtend libc libgcc libm
+include $(LEVEL)/Makefile.common
diff --git a/runtime/GCCLibraries/README.txt b/runtime/GCCLibraries/README.txt
new file mode 100644
index 0000000000..24890d2ef1
--- /dev/null
+++ b/runtime/GCCLibraries/README.txt
@@ -0,0 +1,7 @@
+This directory contains libraries which are used when building the GCC
+front-end. For the most part, these are just stub libraries, but some
+of them contain actual code.
+
+In particular, the crtend library contains the runtime code to handle
+static constructors and destructors for C and C++ programs.
+
diff --git a/runtime/GCCLibraries/crtend/Exception.cpp b/runtime/GCCLibraries/crtend/Exception.cpp
new file mode 100644
index 0000000000..d4ac290122
--- /dev/null
+++ b/runtime/GCCLibraries/crtend/Exception.cpp
@@ -0,0 +1,54 @@
+//===- Exception.cpp - Generic language-independent exceptions ------------===//
+//
+// This file defines the the shared data structures used by all language
+// specific exception handling runtime libraries.
+//
+//===----------------------------------------------------------------------===//
+
+#include "Exception.h"
+
+// Thread local state for exception handling. FIXME: This should really be made
+// thread-local!
+
+// UncaughtExceptionStack - The stack of exceptions currently being thrown.
+static llvm_exception *UncaughtExceptionStack = 0;
+
+// __llvm_eh_has_uncaught_exception - This is used to implement
+// std::uncaught_exception.
+//
+bool __llvm_eh_has_uncaught_exception() throw() {
+ return UncaughtExceptionStack != 0;
+}
+
+// __llvm_eh_current_uncaught_exception - This function checks to see if the
+// current uncaught exception is of the specified language type. If so, it
+// returns a pointer to the exception area data.
+//
+void *__llvm_eh_current_uncaught_exception_type(unsigned HandlerType) throw() {
+ if (UncaughtExceptionStack->ExceptionType == HandlerType)
+ return UncaughtExceptionStack+1;
+ return 0;
+}
+
+// __llvm_eh_add_uncaught_exception - This adds the specified exception to the
+// top of the uncaught exception stack. The exception should not already be on
+// the stack!
+void __llvm_eh_add_uncaught_exception(llvm_exception *E) throw() {
+ E->Next = UncaughtExceptionStack;
+ UncaughtExceptionStack = E;
+}
+
+
+// __llvm_eh_get_uncaught_exception - Returns the current uncaught exception.
+// There must be an uncaught exception for this to work!
+llvm_exception *__llvm_eh_get_uncaught_exception() throw() {
+ return UncaughtExceptionStack;
+}
+
+// __llvm_eh_pop_from_uncaught_stack - Remove the current uncaught exception
+// from the top of the stack.
+llvm_exception *__llvm_eh_pop_from_uncaught_stack() throw() {
+ llvm_exception *E = __llvm_eh_get_uncaught_exception();
+ UncaughtExceptionStack = E->Next;
+ return E;
+}
diff --git a/runtime/GCCLibraries/crtend/Exception.h b/runtime/GCCLibraries/crtend/Exception.h
new file mode 100644
index 0000000000..dc4d3a5f2c
--- /dev/null
+++ b/runtime/GCCLibraries/crtend/Exception.h
@@ -0,0 +1,71 @@
+//===- Exception.h - Generic language-independent exceptions ----*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the the shared data structures used by all language
+// specific exception handling runtime libraries.
+//
+// NOTE NOTE NOTE: A copy of this file lives in llvmgcc/libstdc++-v3/libsupc++/
+// Any modifications to this file must keep it in sync!
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef EXCEPTION_H
+#define EXCEPTION_H
+
+struct llvm_exception {
+ // ExceptionDestructor - This call-back function is used to destroy the
+ // current exception, without requiring the caller to know what the concrete
+ // exception type is.
+ //
+ void (*ExceptionDestructor)(llvm_exception *);
+
+ // ExceptionType - This field identifies what runtime library this exception
+ // came from. Currently defined values are:
+ // 0 - Error
+ // 1 - longjmp exception (see longjmp-exception.c)
+ // 2 - C++ exception (see c++-exception.c)
+ //
+ unsigned ExceptionType;
+
+ // Next - This points to the next exception in the current stack.
+ llvm_exception *Next;
+
+ // HandlerCount - This is a count of the number of handlers which have
+ // currently caught this exception. If the handler is caught and this number
+ // falls to zero, the exception is destroyed.
+ //
+ unsigned HandlerCount;
+
+ // isRethrown - This field is set on an exception if it has been 'throw;'n.
+ // This is needed because the exception might exit through a number of the
+ // end_catch statements matching the number of begin_catch statements that
+ // have been processed. When this happens, the exception should become
+ // uncaught, not dead.
+ //
+ int isRethrown;
+};
+
+enum {
+ ErrorException = 0,
+ SJLJException = 1,
+ CXXException = 2
+};
+
+// Language independent exception handling API...
+//
+extern "C" {
+ bool __llvm_eh_has_uncaught_exception() throw();
+ void *__llvm_eh_current_uncaught_exception_type(unsigned HandlerType) throw();
+ void __llvm_eh_add_uncaught_exception(llvm_exception *E) throw();
+
+ llvm_exception *__llvm_eh_get_uncaught_exception() throw();
+ llvm_exception *__llvm_eh_pop_from_uncaught_stack() throw();
+}
+
+#endif
diff --git a/runtime/GCCLibraries/crtend/Makefile b/runtime/GCCLibraries/crtend/Makefile
new file mode 100644
index 0000000000..1fd3167246
--- /dev/null
+++ b/runtime/GCCLibraries/crtend/Makefile
@@ -0,0 +1,83 @@
+##===- runtime/GCCLibraries/crtend/Makefile ----------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file was developed by the LLVM research group and is distributed under
+# the University of Illinois Open Source License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+#
+# This directory contains the C and C++ runtime libraries for the LLVM GCC
+# front-ends. See the README.txt file for more details.
+#
+# Since this archive has strange requirements, we use some custom rules for
+# building it.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../../..
+DONT_BUILD_RELINKED = 1
+LIBRARYNAME = crtend
+BYTECODE_DESTINATION = $(CFERuntimeLibDir)
+
+MainSrc := crtend.c
+GenericEHSrc := Exception.cpp
+SJLJEHSrc := SJLJ-Exception.cpp
+
+EXTRA_DIST := $(MainSrc) $(GenericEHSrc) $(SJLJEHSrc) \
+ comp_main.lst comp_genericeh.lst comp_sjljeh.lst
+
+include $(LEVEL)/Makefile.common
+
+MainObj := $(ObjDir)/crtend.bc
+GenericEHObj := $(ObjDir)/Exception.bc
+SJLJEHObj := $(ObjDir)/SJLJ-Exception.bc
+
+# __main and ctor/dtor support component
+$(ObjDir)/comp_main.bc: $(MainObj)
+ $(Echo) Linking $(notdir $@) component...
+ $(Verb) $(GCCLD) -link-as-library \
+ -internalize-public-api-file=$(PROJ_SRC_DIR)/comp_main.lst \
+ $(MainObj) -o $@
+
+# Generic exception handling support runtime.
+$(ObjDir)/comp_genericeh.bc: $(GenericEHObj)
+ $(Echo) Linking $(notdir $@) component...
+ $(Verb) $(GCCLD) -link-as-library \
+ -internalize-public-api-file=$(PROJ_SRC_DIR)/comp_genericeh.lst \
+ $(GenericEHObj) -o $@
+
+# setjmp/longjmp exception handling support runtime.
+$(ObjDir)/comp_sjljeh.bc: $(SJLJEHObj)
+ $(Echo) Linking $(notdir $@) component...
+ $(Verb) $(GCCLD) -link-as-library \
+ -internalize-public-api-file=$(PROJ_SRC_DIR)/comp_sjljeh.lst \
+ $(SJLJEHObj) -o $@
+
+SYMBOLHACKEDOBJS := $(ObjDir)/comp_main.bc $(ObjDir)/comp_genericeh.bc \
+ $(ObjDir)/comp_sjljeh.bc
+
+all-local:: $(LibName.BCA)
+
+ifdef BYTECODE_DESTINATION
+BytecodeDestDir := $(BYTECODE_DESTINATION)
+else
+BytecodeDestDir := $(PROJ_libdir)
+endif
+
+DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
+install-bytecode-local:: $(DestBytecodeLib)
+install-local:: $(DestBytecodeLib)
+
+$(LibName.BCA): $(SYMBOLHACKEDOBJS) $(LibDir)/.dir $(LLVMToolDir)/llvm-ar
+ $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
+ $(Verb) $(RM) -f $@
+ $(Verb) $(LArchive) $@ $(SYMBOLHACKEDOBJS)
+
+$(DestBytecodeLib): $(BytecodeDestDir) $(LibName.BCA)
+ $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
+ $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
+
+uninstall-local::
+ $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
+ -$(Verb) $(RM) -f $(DestBytecodeLib)
diff --git a/runtime/GCCLibraries/crtend/README.txt b/runtime/GCCLibraries/crtend/README.txt
new file mode 100644
index 0000000000..a763cb26dd
--- /dev/null
+++ b/runtime/GCCLibraries/crtend/README.txt
@@ -0,0 +1,15 @@
+This directory contains the C and C++ runtime libraries for the LLVM GCC
+front-ends. It is composed of four distinct pieces:
+
+1. __main: now dead, but provided for compatibility.
+
+2. Generic EH support routines. This is used by C/C++ programs that use
+ setjmp/longjmp, and by C++ programs that make use of exceptions.
+
+3. setjmp/longjmp EH support. This is used by C/C++ programs that call SJLJ.
+
+4. C++ exception handling runtime support.
+
+These four components are compiled together into an archive file, so that
+applications using a subset of the four do not pull in unnecessary code and
+dependencies.
diff --git a/runtime/GCCLibraries/crtend/SJLJ-Exception.cpp b/runtime/GCCLibraries/crtend/SJLJ-Exception.cpp
new file mode 100644
index 0000000000..6a3e4724ae
--- /dev/null
+++ b/runtime/GCCLibraries/crtend/SJLJ-Exception.cpp
@@ -0,0 +1,146 @@
+//===- SJLJ-Exception.cpp - SetJmp/LongJmp Exception Handling -------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the API used by the Setjmp/Longjmp exception handling
+// runtime library.
+//
+//===----------------------------------------------------------------------===//
+
+#include "SJLJ-Exception.h"
+#include <cstdlib>
+#include <cassert>
+
+// Assert should only be used for debugging the runtime library. Enabling it in
+// CVS will break some platforms!
+#undef assert
+#define assert(X)
+
+// get_sjlj_exception - Adjust the llvm_exception pointer to be an appropriate
+// llvm_sjlj_exception pointer.
+inline llvm_sjlj_exception *get_sjlj_exception(llvm_exception *E) {
+ assert(E->ExceptionType == SJLJException);
+ return (llvm_sjlj_exception*)(E+1) - 1;
+}
+
+// SetJmpMapEntry - One entry in a linked list of setjmps for the current
+// function.
+struct SetJmpMapEntry {
+ void *JmpBuf;
+ unsigned SetJmpID;
+ SetJmpMapEntry *Next;
+};
+
+// SJLJDestructor - This function is used to free the exception when
+// language-indent code needs to destroy the exception without knowing exactly
+// what type it is.
+static void SJLJDestructor(llvm_exception *E) {
+ free(get_sjlj_exception(E));
+}
+
+
+// __llvm_sjljeh_throw_longjmp - This function creates the longjmp exception and
+// returns. It takes care of mapping the longjmp value from 0 -> 1 as
+// appropriate. The caller should immediately call llvm.unwind after this
+// function call.
+void __llvm_sjljeh_throw_longjmp(void *JmpBuffer, int Val) throw() {
+ llvm_sjlj_exception *E =
+ (llvm_sjlj_exception *)malloc(sizeof(llvm_sjlj_exception));
+ E->BaseException.ExceptionDestructor = SJLJDestructor;
+ E->BaseException.ExceptionType = SJLJException;
+ E->BaseException.HandlerCount = 0;
+ E->BaseException.isRethrown = 0;
+ E->JmpBuffer = JmpBuffer;
+ E->LongJmpValue = Val ? Val : 1;
+
+ __llvm_eh_add_uncaught_exception(&E->BaseException);
+}
+
+// __llvm_sjljeh_init_setjmpmap - This funciton initializes the pointer provided
+// to an empty setjmp map, and should be called on entry to a function which
+// calls setjmp.
+void __llvm_sjljeh_init_setjmpmap(void **SetJmpMap) throw() {
+ *SetJmpMap = 0;
+}
+
+// __llvm_sjljeh_destroy_setjmpmap - This function frees all memory associated
+// with the specified setjmpmap structure. It should be called on all exits
+// (returns or unwinds) from the function which calls ...init_setjmpmap.
+void __llvm_sjljeh_destroy_setjmpmap(void **SetJmpMap) throw() {
+ SetJmpMapEntry *Next;
+ for (SetJmpMapEntry *SJE = *(SetJmpMapEntry**)SetJmpMap; SJE; SJE = Next) {
+ Next = SJE->Next;
+ free(SJE);
+ }
+}
+
+// __llvm_sjljeh_add_setjmp_to_map - This function adds or updates an entry to
+// the map, to indicate which setjmp should be returned to if a longjmp happens.
+void __llvm_sjljeh_add_setjmp_to_map(void **SetJmpMap, void *JmpBuf,
+ unsigned SetJmpID) throw() {
+ SetJmpMapEntry **SJE = (SetJmpMapEntry**)SetJmpMap;
+
+ // Scan for a pre-existing entry...
+ for (; *SJE; SJE = &(*SJE)->Next)
+ if ((*SJE)->JmpBuf == JmpBuf) {
+ (*SJE)->SetJmpID = SetJmpID;
+ return;
+ }
+
+ // No prexisting entry found, append to the end of the list...
+ SetJmpMapEntry *New = (SetJmpMapEntry *)malloc(sizeof(SetJmpMapEntry));
+ *SJE = New;
+ New->JmpBuf = JmpBuf;
+ New->SetJmpID = SetJmpID;
+ New->Next = 0;
+}
+
+// __llvm_sjljeh_is_longjmp_exception - This function returns true if the
+// current uncaught exception is a longjmp exception. This is the first step of
+// catching a sjlj exception.
+bool __llvm_sjljeh_is_longjmp_exception() throw() {
+ return __llvm_eh_current_uncaught_exception_type(SJLJException) != 0;
+}
+
+// __llvm_sjljeh_get_longjmp_value - This function returns the value that the
+// setjmp call should "return". This requires that the current uncaught
+// exception be a sjlj exception, though it does not require the exception to be
+// caught by this function.
+int __llvm_sjljeh_get_longjmp_value() throw() {
+ llvm_sjlj_exception *E =
+ get_sjlj_exception(__llvm_eh_get_uncaught_exception());
+ return E->LongJmpValue;
+}
+
+// __llvm_sjljeh_try_catching_longjmp_exception - This function checks to see if
+// the current uncaught longjmp exception matches any of the setjmps collected
+// in the setjmpmap structure. If so, it catches and destroys the exception,
+// returning the index of the setjmp which caught the exception. If not, it
+// leaves the exception uncaught and returns a value of ~0.
+unsigned __llvm_sjljeh_try_catching_longjmp_exception(void **SetJmpMap) throw(){
+ llvm_sjlj_exception *E =
+