summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoranonymous <local@localhost>2010-08-13 14:47:47 +0000
committeranonymous <local@localhost>2010-08-13 14:47:47 +0000
commit0b2ee73455bbfa4c5131c95f8b195d12d19ccb04 (patch)
tree650080e9afe7ce3bbb6af3829ed645495dc08cb4
parent23725157c815e3fccfca988317624d7b0896e932 (diff)
parent44b2f6d2bf4a1c7695651a908b392a5c3faf6190 (diff)
downloadlibcxxrt-0b2ee73455bbfa4c5131c95f8b195d12d19ccb04.tar.gz
libcxxrt-0b2ee73455bbfa4c5131c95f8b195d12d19ccb04.tar.bz2
libcxxrt-0b2ee73455bbfa4c5131c95f8b195d12d19ccb04.tar.xz
Merge branch 'master' of github.com:pathscale/libcxxrt
-rw-r--r--CMakeLists.txt11
-rw-r--r--src/CMakeLists.txt22
-rw-r--r--src/Makefile12
-rw-r--r--src/aux.cc13
-rw-r--r--src/dwarf_eh.h2
-rw-r--r--src/exception.cc13
-rw-r--r--src/memory.cc23
-rw-r--r--src/stdexcept.cc80
-rw-r--r--src/stdexcept.h56
-rw-r--r--test/CMakeLists.txt35
-rw-r--r--test/Makefile6
-rw-r--r--test/expected_output.log21
-rw-r--r--test/new.cc16
-rwxr-xr-xtest/run_test.sh4
14 files changed, 294 insertions, 20 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..403d43f
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 2.8.1)
+
+enable_testing()
+
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
+
+add_subdirectory(src)
+add_subdirectory(test)
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..d30da28
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,22 @@
+
+set(CXXRT_SOURCES
+ dynamic_cast.cc
+ exception.cc
+ guard.cc
+ terminate.cc
+ typeinfo.cc
+ stdexcept.cc
+ memory.cc
+ aux.cc
+ )
+
+
+add_library(cxxrt-static STATIC ${CXXRT_SOURCES})
+add_library(cxxrt-shared SHARED ${CXXRT_SOURCES})
+
+set_target_properties(cxxrt-static cxxrt-shared PROPERTIES
+ OUTPUT_NAME "cxxrt"
+ )
+
+
+
diff --git a/src/Makefile b/src/Makefile
index d8240a7..499a05c 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,4 +1,5 @@
-OBJECTS = typeinfo.o exception.o dynamic_cast.o terminate.o guard.o
+OBJECTS = typeinfo.o exception.o dynamic_cast.o terminate.o guard.o \
+ stdexcept.o memory.o aux.o
# Needed for building the shared library
CXXFLAGS = -fPIC
@@ -20,10 +21,16 @@ LDFLAGS += -L/usr/local/lib -L. -lpthread -fexceptions
PRODUCTS = libcxxabi.so.1
+all: libcxxabi.so.1 libcxxabi.a
+
libcxxabi.so.1: $(OBJECTS)
@echo Linking $@...
@gcc -fexception -shared $(OBJECTS) $(LDFLAGS) -o libcxxabi.so.1 #-lunwind
+libcxxabi.a: $(OBJECTS)
+ @ar cr libcxxabi.a $(OBJECTS)
+
+
.cc.o:
@echo Compiling $<...
@$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
@@ -38,3 +45,6 @@ exception.o: exception.cc typeinfo.h abi_namespace.h typeinfo dwarf_eh.h
guard.o: guard.cc
terminate.o: terminate.cc
typeinfo.o: typeinfo.cc typeinfo.h abi_namespace.h typeinfo
+stdexcept.o: stdexcept.cc stdexcept.h
+memory.o: memory.cc stdexcept.h
+aux.o: aux.cc stdexcept.h
diff --git a/src/aux.cc b/src/aux.cc
new file mode 100644
index 0000000..c1590e5
--- /dev/null
+++ b/src/aux.cc
@@ -0,0 +1,13 @@
+
+#include "stdexcept.h"
+
+extern "C" void __cxa_bad_cast()
+{
+ throw std::bad_cast();
+}
+
+extern "C" void __cxa_bad_typeid()
+{
+ throw std::bad_typeid();
+}
+
diff --git a/src/dwarf_eh.h b/src/dwarf_eh.h
index 1ab25db..02b9db9 100644
--- a/src/dwarf_eh.h
+++ b/src/dwarf_eh.h
@@ -11,6 +11,8 @@
# include <unwind.h>
#endif
+#include <stdint.h>
+
typedef unsigned char *dw_eh_ptr_t;
// Flag indicating a signed quantity
#define DW_EH_PE_signed 0x08
diff --git a/src/exception.cc b/src/exception.cc
index ce06435..5b2c011 100644
--- a/src/exception.cc
+++ b/src/exception.cc
@@ -7,6 +7,11 @@
#include "typeinfo.h"
#include "dwarf_eh.h"
+
+namespace std {
+ void unexpected();
+}
+
/**
* Class of exceptions to distinguish between this and other exception types.
*
@@ -753,7 +758,11 @@ extern "C" _Unwind_Reason_Code __gxx_personality_v0(int version,
* pointer to the caught exception, which is either the adjusted pointer (for
* C++ exceptions) of the unadjusted pointer (for foreign exceptions).
*/
+#if __GNUC_MINOR__ > 2
+extern "C" void *__cxa_begin_catch(void *e) throw()
+#else
extern "C" void *__cxa_begin_catch(void *e)
+#endif
{
// Decrement the uncaught exceptions count
__cxa_eh_globals *globals = __cxa_get_globals();
@@ -877,5 +886,9 @@ namespace std
}
terminate();
}
+ bool uncaught_exception() throw() {
+ __cxa_thread_info *info = thread_info();
+ return info->globals.uncaughtExceptions != 0;
+ }
}
diff --git a/src/memory.cc b/src/memory.cc
new file mode 100644
index 0000000..de4bc0c
--- /dev/null
+++ b/src/memory.cc
@@ -0,0 +1,23 @@
+
+
+// This file contains definition of C++ new/delete operators
+
+
+#include <stddef.h>
+#include <malloc.h>
+#include "stdexcept.h"
+
+void * operator new(size_t size) {
+ void * mem = malloc(size);
+ if(mem == NULL) {
+ throw std::bad_alloc();
+ }
+
+ return mem;
+}
+
+
+void operator delete(void * ptr) {
+ free(ptr);
+}
+
diff --git a/src/stdexcept.cc b/src/stdexcept.cc
new file mode 100644
index 0000000..3d4e086
--- /dev/null
+++ b/src/stdexcept.cc
@@ -0,0 +1,80 @@
+
+#include "stdexcept.h"
+
+namespace std {
+
+
+exception::exception() throw() {
+}
+
+exception::exception(const exception&) throw() {
+}
+
+exception& exception::operator=(const exception&) throw() {
+ return *this;
+}
+
+exception::~exception() {
+}
+
+const char* exception::what() const throw() {
+ return 0;
+}
+
+
+bad_alloc::bad_alloc() throw() {
+}
+
+bad_alloc::bad_alloc(const bad_alloc&) throw() {
+}
+
+bad_alloc& bad_alloc::operator=(const bad_alloc&) throw() {
+ return *this;
+}
+
+bad_alloc::~bad_alloc() {
+}
+
+const char* bad_alloc::what() const throw() {
+ return "cxxrt::bad_alloc";
+}
+
+
+
+bad_cast::bad_cast() throw() {
+}
+
+bad_cast::bad_cast(const bad_cast&) throw() {
+}
+
+bad_cast& bad_cast::operator=(const bad_cast&) throw() {
+ return *this;
+}
+
+bad_cast::~bad_cast() {
+}
+
+const char* bad_cast::what() const throw() {
+ return "std::bad_cast";
+}
+
+
+bad_typeid::bad_typeid() throw() {
+}
+
+bad_typeid::bad_typeid(const bad_typeid &__rhs) throw() {
+}
+
+bad_typeid::~bad_typeid() {
+}
+
+bad_typeid& bad_typeid::operator=(const bad_typeid &__rhs) throw() {
+ return *this;
+}
+
+const char* bad_typeid::what() const throw() {
+ return "std::bad_typeid";
+}
+
+}
+
diff --git a/src/stdexcept.h b/src/stdexcept.h
new file mode 100644
index 0000000..af06bda
--- /dev/null
+++ b/src/stdexcept.h
@@ -0,0 +1,56 @@
+
+
+// This header defines standard exception classes which are needed
+// for implementing new/delete operators
+
+
+#ifndef __LIBCXXSUP_STDEXCEPT_H__
+#define __LIBCXXSUP_STDEXCEPT_H__
+
+namespace std {
+
+class exception {
+public:
+ exception() throw();
+ exception(const exception&) throw();
+ exception& operator=(const exception&) throw();
+ virtual ~exception();
+ virtual const char* what() const throw();
+};
+
+
+class bad_alloc: public exception {
+public:
+ bad_alloc() throw();
+ bad_alloc(const bad_alloc&) throw();
+ bad_alloc& operator=(const bad_alloc&) throw();
+ ~bad_alloc();
+ virtual const char* what() const throw();
+};
+
+
+class bad_cast: public exception {
+public:
+ bad_cast() throw();
+ bad_cast(const bad_cast&) throw();
+ bad_cast& operator=(const bad_cast&) throw();
+ virtual ~bad_cast();
+ virtual const char* what() const throw();
+};
+
+
+class bad_typeid: public exception {
+public:
+ bad_typeid() throw();
+ bad_typeid(const bad_typeid &__rhs) throw();
+ virtual ~bad_typeid();
+ bad_typeid& operator=(const bad_typeid &__rhs) throw();
+ virtual const char* what() const throw();
+};
+
+
+
+} // namespace std
+
+#endif // __LIBCXXSUP_STDEXCEPT_H__
+
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 0000000..6e6ea58
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,35 @@
+
+set(CXXTEST_SOURCES
+ test.cc
+ test_exception.cc
+ test_guard.cc
+ test_typeinfo.cc
+ )
+
+
+add_executable(cxxrt-test-static ${CXXTEST_SOURCES})
+target_link_libraries(cxxrt-test-static cxxrt-static pthread dl)
+
+add_executable(cxxrt-test-shared ${CXXTEST_SOURCES})
+target_link_libraries(cxxrt-test-shared cxxrt-shared pthread dl)
+
+add_executable(system-test ${CXXTEST_SOURCES})
+
+file(READ "${CMAKE_CURRENT_SOURCE_DIR}/expected_output.log" expected_output)
+
+add_test(system-test-test
+ ${CMAKE_CURRENT_SOURCE_DIR}/run_test.sh
+ ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/system-test
+ ${CMAKE_CURRENT_SOURCE_DIR}/expected_output.log)
+
+add_test(cxxrt-test-static-test
+ ${CMAKE_CURRENT_SOURCE_DIR}/run_test.sh
+ ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/cxxrt-test-static
+ ${CMAKE_CURRENT_SOURCE_DIR}/expected_output.log)
+
+add_test(cxxrt-test-shared-test
+ ${CMAKE_CURRENT_SOURCE_DIR}/run_test.sh
+ ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/cxxrt-test-shared
+ ${CMAKE_CURRENT_SOURCE_DIR}/expected_output.log)
+
+
diff --git a/test/Makefile b/test/Makefile
index fdbdc8f..84f573a 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,4 +1,4 @@
-TEST_OBJECTS = test_typeinfo.o test.o test_exception.o new.o test_guard.o
+TEST_OBJECTS = test_typeinfo.o test.o test_exception.o test_guard.o
# This library implements exception handling, so make sure that the compiler
# emits the correct code
@@ -12,12 +12,12 @@ CXXFLAGS += -Wall -pedantic -g
# Find the unwind.h header installed from ports
CPPFLAGS += -I/usr/local/include
-LDFLAGS += -L/usr/local/lib -L. -lpthread -fexceptions -lcxxabi
+LDFLAGS += -L/usr/local/lib -L. -lpthread -fexceptions
PRODUCTS = test libcxxabi.so.1 system_test
test: $(TEST_OBJECTS) libcxxabi.so library
- @gcc $(CPPFLAGS) $(LDFLAGS) -o test $(TEST_OBJECTS)
+ @gcc $(CPPFLAGS) $(LDFLAGS) -o test $(TEST_OBJECTS) -lcxxabi -ldl
library:
@cd ../src && $(MAKE)
diff --git a/test/expected_output.log b/test/expected_output.log
new file mode 100644
index 0000000..6c95ecc
--- /dev/null
+++ b/test/expected_output.log
@@ -0,0 +1,21 @@
+Initialized static
+Initialized static
+Entering try
+Caught int 1!
+cl destroyed: 12
+Entering try
+Caught float 1.000000!
+cl destroyed: 12
+Entering try
+Caught struct {2}!
+cl destroyed: 12
+Entering try
+Caught struct {2}!
+cl destroyed: 12
+cl destroyed: 123
+Caught re-thrown float
+Entering try
+Caught int 0!
+cl destroyed: 12
+
+23 tests, 23 passed, 0 failed
diff --git a/test/new.cc b/test/new.cc
deleted file mode 100644
index 73184ea..0000000
--- a/test/new.cc
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <stdlib.h>
-
-// Stub (incomplete) implementations to allow testing the library without an
-// STL implementation
-//
-// Note: gcc complains on x86 if this takes a size_t, and on x86-64 if it takes
-// an unsigned int. This is just a stub, so it doesn't matter too much.
-void *operator new(unsigned int s)
-{
- return malloc(s);
-}
-
-void operator delete(void *o)
-{
- free(o);
-}
diff --git a/test/run_test.sh b/test/run_test.sh
new file mode 100755
index 0000000..42795a7
--- /dev/null
+++ b/test/run_test.sh
@@ -0,0 +1,4 @@
+test_command=$1
+expected_output=$2
+$test_command > test_log 2>&1
+diff test_log $expected_output