diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-12-10 12:34:54 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-12-21 10:47:39 -0800 |
commit | 34b153227d5343128cb36931b4dbb27e378372a5 (patch) | |
tree | c6f84632bd072e594f38d56a773f1b4496323dbc | |
parent | e9fe31fb2f629a2b94809c7f9a91577425728b1e (diff) |
update libcxxabi
-rw-r--r-- | system/lib/libcxxabi/CREDITS.TXT | 16 | ||||
-rw-r--r-- | system/lib/libcxxabi/include/cxxabi.h | 2 | ||||
-rwxr-xr-x | system/lib/libcxxabi/lib/buildit | 11 | ||||
-rw-r--r-- | system/lib/libcxxabi/readme.txt | 2 | ||||
-rw-r--r-- | system/lib/libcxxabi/src/abort_message.cpp | 10 | ||||
-rw-r--r-- | system/lib/libcxxabi/src/cxa_demangle.cpp | 768 | ||||
-rw-r--r-- | system/lib/libcxxabi/src/cxa_exception.cpp | 4 | ||||
-rw-r--r-- | system/lib/libcxxabi/src/cxa_exception.hpp | 5 | ||||
-rw-r--r-- | system/lib/libcxxabi/src/cxa_guard.cpp | 12 | ||||
-rw-r--r-- | system/lib/libcxxabi/src/cxa_handlers.cpp | 109 | ||||
-rw-r--r-- | system/lib/libcxxabi/src/cxa_handlers.hpp | 28 | ||||
-rw-r--r-- | system/lib/libcxxabi/src/cxa_personality.cpp | 156 | ||||
-rw-r--r-- | system/lib/libcxxabi/src/fallback_malloc.ipp | 4 | ||||
-rw-r--r-- | system/lib/libcxxabi/src/private_typeinfo.cpp | 202 | ||||
-rw-r--r-- | system/lib/libcxxabi/src/private_typeinfo.h | 34 | ||||
-rw-r--r-- | system/lib/libcxxabi/src/stdexcept.cpp | 77 | ||||
-rw-r--r-- | system/lib/libcxxabi/src/temporary.cpp | 41 |
17 files changed, 939 insertions, 542 deletions
diff --git a/system/lib/libcxxabi/CREDITS.TXT b/system/lib/libcxxabi/CREDITS.TXT index a99245f7..231dfd33 100644 --- a/system/lib/libcxxabi/CREDITS.TXT +++ b/system/lib/libcxxabi/CREDITS.TXT @@ -13,10 +13,22 @@ E: hhinnant@apple.com D: Architect and primary coauthor of libc++abi N: Marshall Clow -E: marshall@idio.com E: mclow.lists@gmail.com -E: mclow@qualcomm.com +E: marshall@idio.com D: Architect and primary coauthor of libc++abi N: Nick Kledzik E: kledzik@apple.com + +N: Andrew Morrow +E: andrew.c.morrow@gmail.com +D: Minor patches and fixes + +N: Erik Olofsson +E: erik.olofsson@hansoft.se +E: erik@olofsson.info +D: Minor patches and fixes + +N: Nowar Gu +E: wenhan.gu@gmail.com +D: Minor patches and fixes diff --git a/system/lib/libcxxabi/include/cxxabi.h b/system/lib/libcxxabi/include/cxxabi.h index b08fba0e..66ef6d46 100644 --- a/system/lib/libcxxabi/include/cxxabi.h +++ b/system/lib/libcxxabi/include/cxxabi.h @@ -64,7 +64,7 @@ extern LIBCXXABI_NORETURN void __cxa_pure_virtual(void); extern LIBCXXABI_NORETURN void __cxa_deleted_virtual(void); // 3.3.2 One-time Construction API -#ifdef LIBCXXABI_ARMEABI +#if __arm__ extern int __cxa_guard_acquire(uint32_t*); extern void __cxa_guard_release(uint32_t*); extern void __cxa_guard_abort(uint32_t*); diff --git a/system/lib/libcxxabi/lib/buildit b/system/lib/libcxxabi/lib/buildit index d1d2acda..75a7028a 100755 --- a/system/lib/libcxxabi/lib/buildit +++ b/system/lib/libcxxabi/lib/buildit @@ -27,7 +27,12 @@ then RC_ProjectSourceVersion=1 fi -EXTRA_FLAGS="-std=c++0x -stdlib=libc++ -fstrict-aliasing -Wstrict-aliasing=2 -Wnewline-eof" +EXTRA_FLAGS="-std=c++0x -stdlib=libc++ -fstrict-aliasing -Wstrict-aliasing=2 \ + -Wsign-conversion -Wshadow -Wconversion -Wunused-variable \ + -Wmissing-field-initializers -Wchar-subscripts -Wmismatched-tags \ + -Wmissing-braces -Wshorten-64-to-32 -Wsign-compare \ + -Wstrict-aliasing=2 -Wstrict-overflow=4 -Wunused-parameter \ + -Wnewline-eof" case $TRIPLE in *-apple-*) @@ -48,6 +53,10 @@ case $TRIPLE in -compatibility_version 1 \ -install_name /usr/lib/libc++abi.dylib \ -lSystem" + if [ -f "${SDKROOT}/usr/local/lib/libCrashReporterClient.a" ] + then + LDSHARED_FLAGS+=" -lCrashReporterClient" + fi ;; *-*-mingw*) # FIXME: removing libgcc and libsupc++ dependencies means porting libcxxrt and LLVM/compiler-rt diff --git a/system/lib/libcxxabi/readme.txt b/system/lib/libcxxabi/readme.txt index 0be9a318..fde423c0 100644 --- a/system/lib/libcxxabi/readme.txt +++ b/system/lib/libcxxabi/readme.txt @@ -1 +1 @@ -These files are from libcxxabi, svn revision 151132, Feb 22 2012 +These files are from libcxxabi, svn revision 169402, Dec 10 2012 diff --git a/system/lib/libcxxabi/src/abort_message.cpp b/system/lib/libcxxabi/src/abort_message.cpp index 7beb86b5..3da4ef67 100644 --- a/system/lib/libcxxabi/src/abort_message.cpp +++ b/system/lib/libcxxabi/src/abort_message.cpp @@ -18,16 +18,6 @@ # if defined(__has_include) && __has_include(<CrashReporterClient.h>) # define HAVE_CRASHREPORTERCLIENT_H 1 # include <CrashReporterClient.h> - - // If any clients of llvm try to link to libCrashReporterClient.a themselves, - // only one crash info struct will be used. - extern "C" { - CRASH_REPORTER_CLIENT_HIDDEN - struct crashreporter_annotations_t gCRAnnotations - __attribute__((section("__DATA," CRASHREPORTER_ANNOTATIONS_SECTION))) - = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0 }; - } - # endif #endif diff --git a/system/lib/libcxxabi/src/cxa_demangle.cpp b/system/lib/libcxxabi/src/cxa_demangle.cpp index 1135c99b..c1e12603 100644 --- a/system/lib/libcxxabi/src/cxa_demangle.cpp +++ b/system/lib/libcxxabi/src/cxa_demangle.cpp @@ -17,7 +17,6 @@ #include <algorithm> #include <assert.h> - #ifdef DEBUGGING #include <string> @@ -42,8 +41,8 @@ public: size_t __size_; __node* __left_; __node* __right_; - long double __value_; long __cached_size_; + long double __value_; public: __node() : __name_(0), __size_(0), __left_(0), __right_(0), __cached_size_(-1) @@ -64,8 +63,8 @@ public: virtual size_t size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = first_size() + second_size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(first_size() + second_size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const {return buf;} virtual char* second_demangled_name(char* buf) const {return buf;} @@ -79,7 +78,7 @@ public: return get_demangled_name(buf); } - virtual bool ends_with_template(bool parsing = false) const + virtual bool ends_with_template(bool /*parsing*/ = false) const { return false; } @@ -134,9 +133,15 @@ void display(__node* x, int indent = 0) { for (int i = 0; i < 2*indent; ++i) printf(" "); - std::string buf(x->size(), '\0'); - x->get_demangled_name(&buf.front()); - printf("%s %s, %p\n", typeid(*x).name(), buf.c_str(), x); + size_t sz = x->size(); + char* buf = (char*)calloc(sz+10, 1); + x->get_demangled_name(buf); + printf("%s [%ld] %s, %p\n", typeid(*x).name(), sz, buf, x); + if (strlen(buf) != sz) + { + printf("strlen(buf) = %ld and size = %ld\n", strlen(buf), sz); + } + free(buf); display(x->__left_, indent+1); display(x->__right_, indent+1); } @@ -157,8 +162,8 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = n + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = n + static_cast<long>(__right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -188,8 +193,8 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = n + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = n + static_cast<long>(__right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -220,9 +225,9 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = n + __left_->size() - + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = n + static_cast<long>(__left_->size() + + __right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -260,8 +265,8 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = n + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = n + static_cast<long>(__right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -291,8 +296,8 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = n + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = n + static_cast<long>(__right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -322,8 +327,8 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = n + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = n + static_cast<long>(__right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -353,8 +358,8 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = n + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(n + __right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -384,8 +389,8 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = n + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(n + __right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -415,8 +420,8 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = n + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(n + __right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -442,8 +447,8 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = n + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(n + __right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -460,7 +465,7 @@ class __source_name : public __node { public: - __source_name(const char* __name, unsigned __size) + __source_name(const char* __name, size_t __size) { __name_ = __name; __size_ = __size; @@ -473,9 +478,9 @@ public: if (__size_ >= 10 && strncmp(__name_, "_GLOBAL__N", 10) == 0) const_cast<long&>(__cached_size_) = 21; else - const_cast<long&>(__cached_size_) = __size_; + const_cast<long&>(__cached_size_) = static_cast<long>(__size_); } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -553,11 +558,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 8 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator&&") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -603,11 +610,11 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = 3+__left_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>(3 + __left_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator&") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -649,11 +656,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 7 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator&") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -700,11 +709,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 8 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator&=") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -751,11 +762,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 7 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator=") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -801,11 +814,11 @@ public: if (__cached_size_ == -1) { if (__right_) - const_cast<long&>(__cached_size_) = __right_->size() + 10; + const_cast<long&>(__cached_size_) = static_cast<long>(__right_->size() + 10); else const_cast<long&>(__cached_size_) = sizeof("operator alignof") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -846,11 +859,11 @@ public: if (__cached_size_ == -1) { if (__right_) - const_cast<long&>(__cached_size_) = __right_->size() + 10; + const_cast<long&>(__cached_size_) = static_cast<long>(__right_->size() + 10); else const_cast<long&>(__cached_size_) = sizeof("operator alignof") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -905,11 +918,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 7 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator,") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -955,11 +970,11 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = 3+__left_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>(3 + __left_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator~") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1015,9 +1030,9 @@ public: } else off = n + __right_->size();; - const_cast<long&>(__cached_size_) = off; + const_cast<long&>(__cached_size_) = static_cast<long>(off); } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1061,13 +1076,14 @@ public: { __left_ = type; __name_ = f; - __size_ = l - f; + __size_ = static_cast<size_t>(l - f); } virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = 2 + __left_->size() + __size_; - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(2 + + __left_->size() + __size_); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1098,11 +1114,11 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = 3+__left_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>(3 + __left_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator*") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1144,11 +1160,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 7 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator/") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1195,11 +1213,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 8 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator/=") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1246,11 +1266,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 7 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator^") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1297,11 +1319,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 8 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator^=") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1348,11 +1372,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 8 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator==") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1399,11 +1425,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 8 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator>=") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1450,11 +1478,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 9 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 9 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator>") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1516,11 +1546,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 8 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator<=") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1567,11 +1599,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 7 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator<") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1618,11 +1652,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 8 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator<<") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1669,11 +1705,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 9 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 9 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator<<=") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1720,11 +1758,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 7 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator-") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1771,11 +1811,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 8 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator-=") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1822,11 +1864,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 7 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator*") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1873,11 +1917,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 8 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator*=") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1924,11 +1970,11 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = 4+__left_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>(4 + __left_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator--") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -1983,11 +2029,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 8 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator!=") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2033,11 +2081,11 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = 3+__left_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>(3 + __left_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator-") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2078,11 +2126,11 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = 3+__left_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>(3 + __left_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator!") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2124,11 +2172,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 8 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator||") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2175,11 +2225,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 7 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator|") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2226,11 +2278,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 8 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator|=") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2277,11 +2331,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 9 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 9 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator->*") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2328,11 +2384,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 7 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator+") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2379,11 +2437,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 8 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator+=") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2430,11 +2490,11 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = 4+__left_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>(4 + __left_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator++") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2488,11 +2548,11 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = 3+__left_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>(3 + __left_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator+") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2534,11 +2594,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 8 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator->") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2588,12 +2650,15 @@ public: if (__left_) { __node* op1 = (__node*)__name_; - const_cast<long&>(__cached_size_) = op1->size() + __left_->size() + 12 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + op1->size() + + __left_->size() + 12 + + __right_->size()); } else const_cast<long&>(__cached_size_) = sizeof("operator?") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2646,11 +2711,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 7 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 7 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator%") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2697,11 +2764,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 8 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator%=") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2748,11 +2817,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 8 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 8 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator>>") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2799,11 +2870,13 @@ public: if (__cached_size_ == -1) { if (__left_) - const_cast<long&>(__cached_size_) = __left_->size() + 9 + __right_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>( + __left_->size() + 9 + + __right_->size()); else const_cast<long&>(__cached_size_) = sizeof("operator>>=") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2849,11 +2922,11 @@ public: if (__cached_size_ == -1) { if (__right_) - const_cast<long&>(__cached_size_) = __right_->size() + 9; + const_cast<long&>(__cached_size_) = static_cast<long>(__right_->size() + 9); else const_cast<long&>(__cached_size_) = sizeof("operator sizeof") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2894,11 +2967,11 @@ public: if (__cached_size_ == -1) { if (__right_) - const_cast<long&>(__cached_size_) = __right_->size() + 9; + const_cast<long&>(__cached_size_) = static_cast<long>(__right_->size() + 9); else const_cast<long&>(__cached_size_) = sizeof("operator sizeof") - 1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2936,8 +3009,8 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = __right_->size() + 8; - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(__right_->size() + 8); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -2965,8 +3038,8 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = __right_->size() + 6; - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(__right_->size() + 6); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -3005,8 +3078,8 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = __right_->size() + 11; - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(__right_->size() + 11); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -3035,8 +3108,9 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = __left_->size() + 14 + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(__left_->size() + + 14 + __right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -3069,8 +3143,9 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = __left_->size() + 16 + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(__left_->size() + + 16 + __right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -3103,8 +3178,9 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = __left_->size() + 20 + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(__left_->size() + + 20 + __right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -3137,8 +3213,9 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = __left_->size() + 15 + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(__left_->size() + + 15 + __right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -3175,9 +3252,9 @@ public: size_t off = __left_->size() + 2; if (__right_) off += __right_->size(); - const_cast<long&>(__cached_size_) = off; + const_cast<long&>(__cached_size_) = static_cast<long>(off); } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -3210,8 +3287,9 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = (__size_ ? 2 : 0) + 9 + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>((__size_ ? 2 : 0) + + 9 + __right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -3242,8 +3320,9 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = (__size_ ? 2 : 0) + 7 + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>((__size_ ? 2 : 0) + + 7 + __right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -3298,9 +3377,9 @@ public: if (__right_) off += __right_->size(); } - const_cast<long&>(__cached_size_) = off; + const_cast<long&>(__cached_size_) = static_cast<long>(off); } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -3360,8 +3439,9 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = __left_->size() + 2 + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(__left_->size() + + 2 + __right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -3390,8 +3470,9 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = __left_->size() + 1 + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(__left_->size() + + 1 + __right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -3419,8 +3500,9 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = __left_->size() + 2 + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(__left_->size() + + 2 + __right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -3623,6 +3705,8 @@ public: } virtual bool is_function() const { + if (__left_ == 0) + return false; return __left_->is_function(); } virtual bool is_cv_qualifer() const @@ -3641,7 +3725,7 @@ public: { if (__left_ == 0) { - if (__size_ < t_end - t_begin) + if (__size_ < static_cast<size_t>(t_end - t_begin)) { __left_ = t_begin[__size_]; __size_ = 0; @@ -3671,8 +3755,9 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = __left_->size() + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(__left_->size() + + __right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -3711,16 +3796,16 @@ public: if (__left_ == NULL) const_cast<long&>(__cached_size_) = 0; else if (__right_ == NULL) - const_cast<long&>(__cached_size_) = __left_->size(); + const_cast<long&>(__cached_size_) = static_cast<long>(__left_->size()); else { size_t off = __right_->size(); if (off > 0) off += 2; - const_cast<long&>(__cached_size_) = __left_->size() + off; + const_cast<long&>(__cached_size_) = static_cast<long>(__left_->size() + off); } } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -3742,10 +3827,14 @@ public: } virtual bool ends_with_template(bool parsing = false) const { - if (__right_ != NULL) + if (__right_ && __right_->size() > 0) + { return __right_->ends_with_template(parsing); - if (__left_ != NULL) + } + else if (__left_ && __left_->size() > 0) + { return __left_->ends_with_template(parsing); + } return false; } virtual bool fix_forward_references(__node** t_begin, __node** t_end) @@ -3788,9 +3877,9 @@ public: ++off; off += __right_->size(); } - const_cast<long&>(__cached_size_) = __left_->size() + off; + const_cast<long&>(__cached_size_) = static_cast<long>(__left_->size() + off); } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -3805,7 +3894,7 @@ public: *buf++ = '>'; return buf; } - virtual bool ends_with_template(bool parsing = false) const + virtual bool ends_with_template(bool /*parsing*/ = false) const { return true; } @@ -3836,8 +3925,8 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = 2 + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(2 + __right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -3852,6 +3941,91 @@ public: } }; +class ___lambda_node + : public __node +{ +public: + ___lambda_node(__node* params, const char *number, size_t number_size) + { + __right_ = params; + __name_ = number; + __size_ = number_size; + } + + virtual size_t first_size() const + { + if (__cached_size_ == -1) + { + size_t r = 2; + r += sizeof("'lambda'")-1; + if (__right_) + r += __right_->size(); + r += __size_; + const_cast<long&>(__cached_size_) = static_cast<long>(r); + } + return static_cast<size_t>(__cached_size_); + } + virtual char* first_demangled_name(char* buf) const + { + size_t n = sizeof("'lambda") - 1; + strncpy(buf, "'lambda", n); + buf += n; + if (__size_) + { + strncpy(buf, __name_, __size_); + buf += __size_; + } + *buf++ = '\''; + *buf++ = '('; + if (__right_) + buf = __right_->get_demangled_name(buf); + *buf++ = ')'; + return buf; + } + virtual bool fix_forward_references(__node** t_begin, __node** t_end) + { + if (__right_) + return __right_->fix_forward_references(t_begin, t_end); + return true; + } +}; + +class __unnamed + : public __node +{ +public: + __unnamed(const char *number, size_t number_size) + { + __name_ = number; + __size_ = number_size; + } + + virtual size_t first_size() const + { + if (__cached_size_ == -1) + { + size_t r = 0; + r += sizeof("'unnamed'")-1; + r += __size_; + const_cast<long&>(__cached_size_) = static_cast<long>(r); + } + return static_cast<size_t>(__cached_size_); + } + virtual char* first_demangled_name(char* buf) const + { + size_t n = sizeof("'unnamed") - 1; + strncpy(buf, "'unnamed", n); + buf += n; + if (__size_) + { + strncpy(buf, __name_, __size_); + buf += __size_; + } + *buf++ = '\''; + return buf; + } +}; + class __cv_qualifiers : public __node { @@ -4229,9 +4403,9 @@ public: off += 2; off += __right_->first_size(); } - const_cast<long&>(__cached_size_) = off; + const_cast<long&>(__cached_size_) = static_cast<long>(off); } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual bool is_function() const @@ -4478,8 +4652,8 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = n + __left_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(n + __left_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -4506,8 +4680,8 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = n + __left_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(n + __left_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -4563,9 +4737,9 @@ public: bottom->__left_ = sub; } } - const_cast<long&>(__cached_size_) = off; + const_cast<long&>(__cached_size_) = static_cast<long>(off); } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -4643,7 +4817,7 @@ public: explicit __wchar_t_literal(const char* __first, const char* __last) { __name_ = __first; - __size_ = __last - __first; + __size_ = static_cast<size_t>(__last - __first); } virtual size_t first_size() const @@ -4715,7 +4889,7 @@ public: explicit __char_literal(const char* __first, const char* __last) { __name_ = __first; - __size_ = __last - __first; + __size_ = static_cast<size_t>(__last - __first); } virtual size_t first_size() const @@ -4762,7 +4936,7 @@ public: explicit __signed_char_literal(const char* __first, const char* __last) { __name_ = __first; - __size_ = __last - __first; + __size_ = static_cast<size_t>(__last - __first); } virtual size_t first_size() const @@ -4809,7 +4983,7 @@ public: explicit __unsigned_char_literal(const char* __first, const char* __last) { __name_ = __first; - __size_ = __last - __first; + __size_ = static_cast<size_t>(__last - __first); } virtual size_t first_size() const @@ -4846,7 +5020,7 @@ public: explicit __short_literal(const char* __first, const char* __last) { __name_ = __first; - __size_ = __last - __first; + __size_ = static_cast<size_t>(__last - __first); } virtual size_t first_size() const @@ -4893,7 +5067,7 @@ public: explicit __unsigned_short_literal(const char* __first, const char* __last) { __name_ = __first; - __size_ = __last - __first; + __size_ = static_cast<size_t>(__last - __first); } virtual size_t first_size() const @@ -4932,7 +5106,7 @@ public: explicit __int_literal(const char* __first, const char* __last) { __name_ = __first; - __size_ = __last - __first; + __size_ = static_cast<size_t>(__last - __first); } virtual size_t first_size() const @@ -4977,7 +5151,7 @@ public: explicit __unsigned_int_literal(const char* __first, const char* __last) { __name_ = __first; - __size_ = __last - __first; + __size_ = static_cast<size_t>(__last - __first); } virtual size_t first_size() const @@ -5014,7 +5188,7 @@ public: explicit __long_literal(const char* __first, const char* __last) { __name_ = __first; - __size_ = __last - __first; + __size_ = static_cast<size_t>(__last - __first); } virtual size_t first_size() const @@ -5060,7 +5234,7 @@ public: explicit __unsigned_long_literal(const char* __first, const char* __last) { __name_ = __first; - __size_ = __last - __first; + __size_ = static_cast<size_t>(__last - __first); } virtual size_t first_size() const @@ -5098,7 +5272,7 @@ public: explicit __long_long_literal(const char* __first, const char* __last) { __name_ = __first; - __size_ = __last - __first; + __size_ = static_cast<size_t>(__last - __first); } virtual size_t first_size() const @@ -5145,7 +5319,7 @@ public: explicit __unsigned_long_long_literal(const char* __first, const char* __last) { __name_ = __first; - __size_ = __last - __first; + __size_ = static_cast<size_t>(__last - __first); } virtual size_t first_size() const @@ -5163,7 +5337,7 @@ public: } }; -class __int128 +class __signed_int128 : public __node { static const size_t n = sizeof("__int128") - 1; @@ -5184,7 +5358,7 @@ public: explicit __int128_literal(const char* __first, const char* __last) { __name_ = __first; - __size_ = __last - __first; + __size_ = static_cast<size_t>(__last - __first); } virtual size_t first_size() const @@ -5231,7 +5405,7 @@ public: explicit __unsigned_int128_literal(const char* __first, const char* __last) { __name_ = __first; - __size_ = __last - __first; + __size_ = static_cast<size_t>(__last - __first); } virtual size_t first_size() const @@ -5264,14 +5438,14 @@ public: float v = static_cast<float>(__value_); const_cast<long&>(__cached_size_) = sprintf(num, "%a", v)+1; } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { char num[20] = {0}; float v = static_cast<float>(__value_); int n = sprintf(num, "%a", v); - strncpy(buf, num, n); + strncpy(buf, num, static_cast<size_t>(n)); buf += n; *buf++ = 'f'; return buf; @@ -5309,14 +5483,14 @@ public: double v = static_cast<double>(__value_); const_cast<long&>(__cached_size_) = sprintf(num, "%a", v); } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { char num[30] = {0}; double v = static_cast<double>(__value_); int n = sprintf(num, "%a", v); - strncpy(buf, num, n); + strncpy(buf, num, static_cast<size_t>(n)); return buf + n; } }; @@ -5521,10 +5695,10 @@ public: if (__right_ != 0) r += __right_->size(); else if (__size_ != 0) - r += snprintf(0, 0, "%ld", __size_); - const_cast<long&>(__cached_size_) = r; + r += static_cast<size_t>(snprintf(0, 0, "%ld", __size_)); + const_cast<long&>(__cached_size_) = static_cast<long>(r); } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* get_demangled_name(char* buf) const @@ -5536,7 +5710,7 @@ public: buf = __right_->get_demangled_name(buf); else if (__size_ != 0) { - size_t rs = sprintf(buf, "%ld", __size_); + int rs = sprintf(buf, "%ld", __size_); buf += rs; } *buf++ = ']'; @@ -5561,7 +5735,7 @@ public: if (__right_ != 0) r += __right_->size(); else if (__size_ != 0) - r += snprintf(0, 0, "%ld", __size_); + r += static_cast<size_t>(snprintf(0, 0, "%ld", __size_)); return r; } @@ -5573,7 +5747,7 @@ public: buf = __right_->get_demangled_name(buf); else if (__size_ != 0) { - size_t off = sprintf(buf, "%ld", __size_); + int off = sprintf(buf, "%ld", __size_); buf += off; } char* t = buf; @@ -5610,10 +5784,10 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = __left_->size() + 3 - + __right_->first_size() - + __right_->second_size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(__left_->size() + 3 + + __right_->first_size() + + __right_->second_size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -5652,8 +5826,8 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = 10 + __right_->size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(10 + __right_->size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const @@ -5684,8 +5858,9 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = __left_->size() + __right_->size() + 2; - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(__left_->size() + + __right_->size() + 2); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const @@ -5713,7 +5888,7 @@ public: return __left_->fix_forward_references(t_begin, t_end) && __right_->fix_forward_references(t_begin, t_end); } - virtual __node* extract_cv(__node*& rt) const + virtual __node* extract_cv(__node*&) const { return __right_->extract_cv(const_cast<__node*&>(__right_)); } @@ -5740,9 +5915,10 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = (__left_ ? __left_->size() + 2 : 0) + - __right_->size() + __size_ * 2; - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>((__left_ ? + __left_->size() + 2 : 0) + + __right_->size() + __size_ * 2); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const @@ -5780,7 +5956,7 @@ public: r = __left_->fix_forward_references(t_begin, t_end); return r && __right_->fix_forward_references(t_begin, t_end); } - virtual __node* extract_cv(__node*& rt) const + virtual __node* extract_cv(__node*&) const { return __right_->extract_cv(const_cast<__node*&>(__right_)); } @@ -5816,8 +5992,8 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = __right_->base_size(); - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(__right_->base_size()); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const @@ -5855,8 +6031,8 @@ public: virtual size_t first_size() const { if (__cached_size_ == -1) - const_cast<long&>(__cached_size_) = __right_->base_size() + 1; - return __cached_size_; + const_cast<long&>(__cached_size_) = static_cast<long>(__right_->base_size() + 1); + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const @@ -5882,7 +6058,7 @@ class __dot_suffix : public __node { public: - __dot_suffix(__node* name, const char* suffix, unsigned sz) + __dot_suffix(__node* name, const char* suffix, size_t sz) { __left_ = name; __name_ = suffix; @@ -5895,9 +6071,9 @@ public: { size_t off = __left_->size(); off += __size_ + 3; - const_cast<long&>(__cached_size_) = off; + const_cast<long&>(__cached_size_) = static_cast<long>(off); } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -5948,9 +6124,9 @@ public: off += __right_->size(); else if (__size_ > 0) off += __size_; - const_cast<long&>(__cached_size_) = off; + const_cast<long&>(__cached_size_) = static_cast<long>(off); } - return __cached_size_; + return static_cast<size_t>(__cached_size_); } virtual char* first_demangled_name(char* buf) const { @@ -6364,7 +6540,7 @@ __demangle_tree::__parse_builtin_type(const char* first, const char* last) ++first; break; case 'n': - if (__make<__int128>()) + if (__make<__signed_int128>()) ++first; break; case 'o': @@ -6444,6 +6620,7 @@ __demangle_tree::__parse_bare_function_type(const char* first, const char* last) { if (first != last) { + bool prev_tag_templates = __tag_templates_; __tag_templates_ = false; const char* t = __parse_type(first, last); if (t != first && __make<__list>(__root_)) @@ -6474,7 +6651,7 @@ __demangle_tree::__parse_bare_function_type(const char* first, const char* last) } } } - __tag_templates_ = true; + __tag_templates_ = prev_tag_templates; } return first; } @@ -6527,11 +6704,11 @@ __demangle_tree::__parse_hex_number(const char* first, const char* last, unsigne if (t == first) n = 0; if (isdigit(*t)) - n = n * 16 + *t - '0'; + n = n * 16 + static_cast<unsigned long long>(*t - '0'); else if (isupper(*t)) - n = n * 16 + *t - 'A' + 10; + n = n * 16 + static_cast<unsigned long long>(*t - 'A') + 10; else - n = n * 16 + *t - 'a' + 10; + n = n * 16 + static_cast<unsigned long long>(*t - 'a') + 10; } first = t; return first; @@ -6567,11 +6744,11 @@ __demangle_tree::__parse_expr_primary(const char* first, const char* last) switch (first[2]) { case '0': - if (__make<__bool_literal>("false", 5)) + if (__make<__bool_literal>("false", 5u)) first += 4; break; case '1': - if (__make<__bool_literal>("true", 4)) + if (__make<__bool_literal>("true", 4u)) first += 4; break; } @@ -6746,6 +6923,10 @@ __demangle_tree::__parse_expr_primary(const char* first, const char* last) first = t+1; } break; + case 'T': + // Invalid mangled name per + // http://sourcerytools.com/pipermail/cxx-abi-dev/2011-August/002422.html + break; default: { // might be named type @@ -6792,12 +6973,67 @@ __demangle_tree::__parse_unnamed_type_name(const char* first, const char* last) { if (last - first > 2 && first[0] == 'U') { - switch (first[1]) + char type = first[1]; + switch (type) { case 't': case 'l': - first += 2; - __status_ = not_yet_implemented; + { + const char* t = first + 2; + __node* params = 0; + if (type == 'l') + { + if (*t == 'v') + { + // void lambda + ++t; + if (t != last && *t == 'E') + ++t; + else + return first; + } + else + { + const char* t1 = __parse_type(t, last); + if (t1 == t || !__make<__list>(__root_)) + return first; + params = __root_; + __node* prev = params; + t = t1; + while (true) + { + t1 = __parse_type(t, last); + if (t1 == t) + break; + if (!__make<__list>(__root_)) + return first; + t = t1; + prev->__right_ = __root_; + __root_->__size_ = prev->__size_ + 1; + prev = __root_; + } + if (t == last || *t != 'E') + return first; + ++t; + } + } + const char* number_start = t; + const char* number_end = __parse_number(t, last); + if (number_end == last || *number_end != '_') + return first; + t = number_end + 1; + if (type == 'l') + { + if (!__make<___lambda_node>(params, number_start, static_cast<size_t>(number_end - number_start))) + return first; + } + else + { + if (!__make<__unnamed>(number_start, static_cast<size_t>(number_end - number_start))) + return first; + } + first = t; + } break; } } @@ -6814,7 +7050,7 @@ __demangle_tree::__parse_unnamed_type_name(const char* first, const char* last) const char* __demangle_tree::__parse_ctor_dtor_name(const char* first, const char* last) { - if (last-first >= 2) + if (last-first >= 2 && __root_) { switch (first[0]) { @@ -6846,7 +7082,7 @@ __demangle_tree::__parse_ctor_dtor_name(const char* first, const char* last) } const char* -__demangle_tree::__parse_unscoped_template_name(const char* first, const char* last) +__demangle_tree::__parse_unscoped_template_name(const char* first, const char*) { // assert(!"__parse_unscoped_template_name not implemented"); __status_ = not_yet_implemented; @@ -7943,10 +8179,10 @@ __demangle_tree::__parse_array_type(const char* first, const char* last) } else if ('1' <= first[1] && first[1] <= '9') { - size_t dim = first[1] - '0'; + size_t dim = static_cast<size_t>(first[1] - '0'); const char* t = first+2; for (; t != last && isdigit(*t); ++t) - dim = dim * 10 + *t - '0'; + dim = dim * 10 + static_cast<size_t>(*t - '0'); if (t != last && *t == '_') { const char* t2 = __parse_type(t+1, last); @@ -8060,16 +8296,16 @@ __demangle_tree::__parse_template_param(const char* first, const char* last) else if (isdigit(first[1])) { const char* t = first+1; - size_t sub = *t - '0'; + size_t sub = static_cast<size_t>(*t - '0'); for (++t; t != last && isdigit(*t); ++t) { sub *= 10; - sub += *t - '0'; + sub += static_cast<size_t>(*t - '0'); } if (t == last || *t != '_') return first; ++sub; - if (sub < __t_end_ - __t_begin_) + if (sub < static_cast<size_t>(__t_end_ - __t_begin_)) { if (__make<__sub>(__t_begin_[sub])) first = t+1; @@ -8109,7 +8345,7 @@ __demangle_tree::__parse_vector_type(const char* first, const char* last) return first; } const char* num = first + 2; - size_t sz = t - num; + size_t sz = static_cast<size_t>(t - num); if (++t != last) { if (*t != 'p') @@ -8986,7 +9222,7 @@ __demangle_tree::__parse_operator_name(const char* first, const char* last, int* case 'v': // cast <type> { - const char* t = __parse_type(first+2, last, false); + const char* t = __parse_type(first+2, last, false, true); if (t != first+2) { __node* cast_type = __root_; @@ -9991,14 +10227,14 @@ __demangle_tree::__parse_source_name(const char* first, const char* last) if ('1' <= c && c <= '9' && first+1 != last) { const char* t = first+1; - size_t n = c - '0'; + size_t n = static_cast<size_t>(c - '0'); for (c = *t; '0' <= c && c <= '9'; c = *t) { - n = n * 10 + c - '0'; + n = n * 10 + static_cast<size_t>(c - '0'); if (++t == last) return first; } - if (last - t >= n && __make<__source_name>(t, n)) + if (static_cast<size_t>(last - t) >= n && __make<__source_name>(t, n)) first = t + n; } } @@ -10103,7 +10339,7 @@ __demangle_tree::__parse_nested_name(const char* first, const char* last) { bool can_sub = true; bool make_nested = true; - const char* t1; + const char* t1 = NULL; switch (*t0) { case '1': @@ -10179,8 +10415,9 @@ __demangle_tree::__parse_nested_name(const char* first, const char* last) } break; case 'U': - assert(!"__parse_nested_name U"); - // could have following <template-args> + t1 = __parse_unnamed_type_name(t0, last); + if (t1 == t0 || t1 == last) + return first; break; case 'T': t1 = __parse_template_param(t0, last); @@ -10482,21 +10719,21 @@ __demangle_tree::__parse_substitution(const char* first, const char* last) size_t sub = 0; const char* t = first+1; if (isdigit(*t)) - sub = *t - '0'; + sub = static_cast<size_t>(*t - '0'); else - sub = *t - 'A' + 10; + sub = static_cast<size_t>(*t - 'A') + 10; for (++t; t != last && (isdigit(*t) || isupper(*t)); ++t) { sub *= 36; if (isdigit(*t)) - sub += *t - '0'; + sub += static_cast<size_t>(*t - '0'); else - sub += *t - 'A' + 10; + sub += static_cast<size_t>(*t - 'A') + 10; } if (t == last || *t != '_') return first; ++sub; - if (sub < __sub_end_ - __sub_begin_) + if (sub < static_cast<size_t>(__sub_end_ - __sub_begin_)) { if (__make<__sub>(__sub_begin_[sub])) first = t+1; @@ -10593,7 +10830,7 @@ __demangle_tree::__parse_dot_suffix(const char* first, const char* last) { if (first != last && *first == '.') { - if (__make<__dot_suffix>(__root_, first, last-first)) + if (__make<__dot_suffix>(__root_, first, static_cast<size_t>(last-first))) first = last; } return first; @@ -10616,6 +10853,7 @@ __demangle_tree::__parse_encoding(const char* first, const char* last) !name->is_ctor_dtor_conv(); __node* ret = NULL; const char* t2; + bool prev_tag_templates = __tag_templates_; __tag_templates_ = false; if (has_return) { @@ -10648,7 +10886,7 @@ __demangle_tree::__parse_encoding(const char* first, const char* last) } } } - __tag_templates_ = true; + __tag_templates_ = prev_tag_templates; } else first = t; @@ -10729,23 +10967,23 @@ printf("\n"); const unsigned N = 4096; char tmp[N]; ptrdiff_t s; - if (est <= bs) + if (static_cast<size_t>(est) <= bs) { char* e = dmg_tree.__get_demangled_name(buf); *e++ = '\0'; s = e - buf; } - else if (est <= N) + else if (static_cast<size_t>(est) <= N) { char* e = dmg_tree.__get_demangled_name(tmp); *e++ = '\0'; s = e - tmp; } else - s = dmg_tree.size() + 1; - if (s > bs) + s = static_cast<ptrdiff_t>(dmg_tree.size() + 1); + if (static_cast<size_t>(s) > bs) { - buf = static_cast<char*>(realloc(buf, s)); + buf = static_cast<char*>(realloc(buf, static_cast<size_t>(s))); if (buf == NULL) { if (status) @@ -10753,12 +10991,12 @@ printf("\n"); return NULL; } if (n) - *n = s; + *n = static_cast<size_t>(s); } - if (est > bs) + if (static_cast<size_t>(est) > bs) { - if (est <= N) - strncpy(buf, tmp, s); + if (static_cast<size_t>(est) <= N) + strncpy(buf, tmp, static_cast<size_t>(s)); else *dmg_tree.__get_demangled_name(buf) = '\0'; } @@ -10784,7 +11022,7 @@ __cxa_demangle(const char* mangled_name, char* buf, size_t* n, int* status) *status = __libcxxabi::invalid_args; return NULL; } - const size_t bs = 64 * 1024; + const size_t bs = 4 * 1024; __attribute((aligned(16))) char static_buf[bs]; buf = __libcxxabi::__demangle(__libcxxabi::__demangle(mangled_name, diff --git a/system/lib/libcxxabi/src/cxa_exception.cpp b/system/lib/libcxxabi/src/cxa_exception.cpp index b866f9e4..1c362993 100644 --- a/system/lib/libcxxabi/src/cxa_exception.cpp +++ b/system/lib/libcxxabi/src/cxa_exception.cpp @@ -466,9 +466,9 @@ __cxa_rethrow() globals->caughtExceptions = 0; } #if __arm__ - (void) _Unwind_SjLj_Resume_or_Rethrow(&exception_header->unwindHeader); + _Unwind_SjLj_RaiseException(&exception_header->unwindHeader); #else - (void)_Unwind_RaiseException(&exception_header->unwindHeader); + _Unwind_RaiseException(&exception_header->unwindHeader); #endif // If we get here, some kind of unwinding error has occurred. diff --git a/system/lib/libcxxabi/src/cxa_exception.hpp b/system/lib/libcxxabi/src/cxa_exception.hpp index cf019d4c..66f05c45 100644 --- a/system/lib/libcxxabi/src/cxa_exception.hpp +++ b/system/lib/libcxxabi/src/cxa_exception.hpp @@ -11,6 +11,9 @@ // //===----------------------------------------------------------------------===// +#ifndef _CXA_EXCEPTION_H +#define _CXA_EXCEPTION_H + #include <exception> // for std::unexpected_handler and std::terminate_handler #include <cxxabi.h> #include "unwind.h" @@ -116,3 +119,5 @@ static const uint64_t get_vendor_and_language = 0xFFFFFFFFFFFFFF00; // mask #pragma GCC visibility pop } + +#endif // _CXA_EXCEPTION_H diff --git a/system/lib/libcxxabi/src/cxa_guard.cpp b/system/lib/libcxxabi/src/cxa_guard.cpp index 814aaeb1..e403b64a 100644 --- a/system/lib/libcxxabi/src/cxa_guard.cpp +++ b/system/lib/libcxxabi/src/cxa_guard.cpp @@ -28,7 +28,7 @@ namespace __cxxabiv1 namespace { -#if LIBCXXABI_ARMEABI +#if __arm__ // A 32-bit, 4-byte-aligned static data value. The least significant 2 bits must // be statically initialized to 0. @@ -62,7 +62,7 @@ void set_initialized(guard_type* guard_object) { pthread_mutex_t guard_mut = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t guard_cv = PTHREAD_COND_INITIALIZER; -#if __APPLE__ +#if defined(__APPLE__) && !defined(__arm__) typedef uint32_t lock_type; @@ -100,7 +100,7 @@ set_lock(uint64_t& x, lock_type y) #endif // __LITTLE_ENDIAN__ -#else // __APPLE__ +#else // !__APPLE__ || __arm__ typedef bool lock_type; @@ -169,7 +169,7 @@ int __cxa_guard_acquire(guard_type* guard_object) int result = *initialized == 0; if (result) { -#if __APPLE__ +#if defined(__APPLE__) && !defined(__arm__) const lock_type id = pthread_mach_thread_np(pthread_self()); lock_type lock = get_lock(*guard_object); if (lock) @@ -189,14 +189,14 @@ int __cxa_guard_acquire(guard_type* guard_object) } else set_lock(*guard_object, id); -#else // __APPLE__ +#else // !__APPLE__ || __arm__ while (get_lock(*guard_object)) if (pthread_cond_wait(&guard_cv, &guard_mut)) abort_message("__cxa_guard_acquire condition variable wait failed"); result = *initialized == 0; if (result) set_lock(*guard_object, true); -#endif // __APPLE__ +#endif // !__APPLE__ || __arm__ } if (pthread_mutex_unlock(&guard_mut)) abort_message("__cxa_guard_acquire failed to release mutex"); diff --git a/system/lib/libcxxabi/src/cxa_handlers.cpp b/system/lib/libcxxabi/src/cxa_handlers.cpp index be43181c..6c13fcd2 100644 --- a/system/lib/libcxxabi/src/cxa_handlers.cpp +++ b/system/lib/libcxxabi/src/cxa_handlers.cpp @@ -22,85 +22,13 @@ namespace std { -static const char* cause = "uncaught"; - -static void default_terminate_handler() -{ - // If there might be an uncaught exception - using namespace __cxxabiv1; - __cxa_eh_globals* globals = __cxa_get_globals_fast(); - if (globals) - { - __cxa_exception* exception_header = globals->caughtExceptions; - // If there is an uncaught exception - if (exception_header) - { - _Unwind_Exception* unwind_exception = - reinterpret_cast<_Unwind_Exception*>(exception_header + 1) - 1; - bool native_exception = - (unwind_exception->exception_class & get_vendor_and_language) == - (kOurExceptionClass & get_vendor_and_language); - if (native_exception) - { - void* thrown_object = - unwind_exception->exception_class == kOurDependentExceptionClass ? - ((__cxa_dependent_exception*)exception_header)->primaryException : - exception_header + 1; - const __shim_type_info* thrown_type = - static_cast<const __shim_type_info*>(exception_header->exceptionType); - // Try to get demangled name of thrown_type - int status; - char buf[1024]; - size_t len = sizeof(buf); - const char* name = __cxa_demangle(thrown_type->name(), buf, &len, &status); - if (status != 0) - name = thrown_type->name(); - // If the uncaught exception can be caught with std::exception& - const __shim_type_info* catch_type = - static_cast<const __shim_type_info*>(&typeid(exception)); - if (catch_type->can_catch(thrown_type, thrown_object)) - { - // Include the what() message from the exception - const exception* e = static_cast<const exception*>(thrown_object); - abort_message("terminating with %s exception of type %s: %s", - cause, name, e->what()); - } - else - // Else just note that we're terminating with an exception - abort_message("terminating with %s exception of type %s", - cause, name); - } - else - // Else we're terminating with a foreign exception - abort_message("terminating with %s foreign exception", cause); - } - } - // Else just note that we're terminating - abort_message("terminating"); -} - -static void default_unexpected_handler() -{ - cause = "unexpected"; - terminate(); -} - -static terminate_handler __terminate_handler = default_terminate_handler; -static unexpected_handler __unexpected_handler = default_unexpected_handler; -static new_handler __new_handler = 0; - -unexpected_handler -set_unexpected(unexpected_handler func) _NOEXCEPT -{ - if (func == 0) - func = default_unexpected_handler; - return __sync_lock_test_and_set(&__unexpected_handler, func); -} - unexpected_handler get_unexpected() _NOEXCEPT { - return __sync_fetch_and_add(&__unexpected_handler, (unexpected_handler)0); + return __sync_fetch_and_add(&__cxa_unexpected_handler, (unexpected_handler)0); +// The above is safe but overkill on x86 +// Using of C++11 atomics this should be rewritten +// return __cxa_unexpected_handler.load(memory_order_acq); } __attribute__((visibility("hidden"), noreturn)) @@ -120,17 +48,12 @@ unexpected() } terminate_handler -set_terminate(terminate_handler func) _NOEXCEPT -{ - if (func == 0) - func = default_terminate_handler; - return __sync_lock_test_and_set(&__terminate_handler, func); -} - -terminate_handler get_terminate() _NOEXCEPT { - return __sync_fetch_and_add(&__terminate_handler, (terminate_handler)0); + return __sync_fetch_and_add(&__cxa_terminate_handler, (terminate_handler)0); +// The above is safe but overkill on x86 +// Using of C++11 atomics this should be rewritten +// return __cxa_terminate_handler.load(memory_order_acq); } __attribute__((visibility("hidden"), noreturn)) @@ -172,25 +95,31 @@ terminate() _NOEXCEPT (unwind_exception->exception_class & get_vendor_and_language) == (kOurExceptionClass & get_vendor_and_language); if (native_exception) - { - __cxa_exception* exception_header = (__cxa_exception*)(unwind_exception+1) - 1; __terminate(exception_header->terminateHandler); - } } } __terminate(get_terminate()); } +extern "C" new_handler __cxa_new_handler = 0; +// In the future these will become: +// std::atomic<std::new_handler> __cxa_new_handler(0); + new_handler set_new_handler(new_handler handler) _NOEXCEPT { - return __sync_lock_test_and_set(&__new_handler, handler); + return __sync_swap(&__cxa_new_handler, handler); +// Using of C++11 atomics this should be rewritten +// return __cxa_new_handler.exchange(handler, memory_order_acq_rel); } new_handler get_new_handler() _NOEXCEPT { - return __sync_fetch_and_add(&__new_handler, (new_handler)0); + return __sync_fetch_and_add(&__cxa_new_handler, (new_handler)0); +// The above is safe but overkill on x86 +// Using of C++11 atomics this should be rewritten +// return __cxa_new_handler.load(memory_order_acq); } } // std diff --git a/system/lib/libcxxabi/src/cxa_handlers.hpp b/system/lib/libcxxabi/src/cxa_handlers.hpp index a7f582c0..64994ac7 100644 --- a/system/lib/libcxxabi/src/cxa_handlers.hpp +++ b/system/lib/libcxxabi/src/cxa_handlers.hpp @@ -10,6 +10,9 @@ // unexpected_handler, and new_handler. //===----------------------------------------------------------------------===// +#ifndef _CXA_HANDLERS_H +#define _CXA_HANDLERS_H + #include <exception> namespace std @@ -24,3 +27,28 @@ void __terminate(terminate_handler func) _NOEXCEPT; } // std + +extern "C" +{ + +extern void (*__cxa_terminate_handler)(); +extern void (*__cxa_unexpected_handler)(); +extern void (*__cxa_new_handler)(); + +/* + + At some point in the future these three symbols will become + C++11 atomic variables: + + extern std::atomic<std::terminate_handler> __cxa_terminate_handler; + extern std::atomic<std::unexpected_handler> __cxa_unexpected_handler; + extern std::atomic<std::new_handler> __cxa_new_handler; + + This change will not impact their ABI. But it will allow for a + portible performance optimization. + +*/ + +} // extern "C" + +#endif // _CXA_HANDLERS_H diff --git a/system/lib/libcxxabi/src/cxa_personality.cpp b/system/lib/libcxxabi/src/cxa_personality.cpp index e49278c0..b2efe2aa 100644 --- a/system/lib/libcxxabi/src/cxa_personality.cpp +++ b/system/lib/libcxxabi/src/cxa_personality.cpp @@ -48,19 +48,36 @@ | callSiteEncoding | (char) | Encoding for Call Site Table | +------------------+--+-----+-----+------------------------+--------------------------+ | callSiteTableLength | (ULEB128) | Call Site Table length, used to find Action table | -+---------------------+-----------+------------------------------------------------+--+ -| Beginning of Call Site Table If the current ip lies within the | ++---------------------+-----------+---------------------------------------------------+ +#if !__arm__ ++---------------------+-----------+------------------------------------------------+ +| Beginning of Call Site Table The current ip lies within the | | ... (start, length) range of one of these | -| call sites, there may be action needed. | +| call sites. There may be action needed. | | +-------------+---------------------------------+------------------------------+ | | | start | (encoded with callSiteEncoding) | offset relative to funcStart | | -| | length | (encoded with callSiteEncoding) | lenght of code fragment | | +| | length | (encoded with callSiteEncoding) | length of code fragment | | | | landingPad | (encoded with callSiteEncoding) | offset relative to lpStart | | | | actionEntry | (ULEB128) | Action Table Index 1-based | | | | | | actionEntry == 0 -> cleanup | | | +-------------+---------------------------------+------------------------------+ | | ... | -+---------------------------------------------------------------------+------------+ ++----------------------------------------------------------------------------------+ +#else // __arm_ ++---------------------+-----------+------------------------------------------------+ +| Beginning of Call Site Table The current ip is a 1-based index into | +| ... this table. Or it is -1 meaning no | +| action is needed. Or it is 0 meaning | +| terminate. | +| +-------------+---------------------------------+------------------------------+ | +| | landingPad | (ULEB128) | offset relative to lpStart | | +| | actionEntry | (ULEB128) | Action Table Index 1-based | | +| | | | actionEntry == 0 -> cleanup | | +| +-------------+---------------------------------+------------------------------+ | +| ... | ++----------------------------------------------------------------------------------+ +#endif // __arm_ ++---------------------------------------------------------------------+ | Beginning of Action Table ttypeIndex == 0 : cleanup | | ... ttypeIndex > 0 : catch | | ttypeIndex < 0 : exception spec | @@ -175,7 +192,7 @@ readULEB128(const uint8_t** data) /// @param data reference variable holding memory pointer to decode from /// @returns decoded value static -uintptr_t +intptr_t readSLEB128(const uint8_t** data) { uintptr_t result = 0; @@ -191,7 +208,7 @@ readSLEB128(const uint8_t** data) *data = p; if ((byte & 0x40) && (shift < (sizeof(result) << 3))) result |= static_cast<uintptr_t>(~0) << shift; - return result; + return static_cast<intptr_t>(result); } /// Read a pointer encoded value and advance pointer @@ -219,7 +236,7 @@ readEncodedPointer(const uint8_t** data, uint8_t encoding) result = readULEB128(&p); break; case DW_EH_PE_sleb128: - result = readSLEB128(&p); + result = static_cast<uintptr_t>(readSLEB128(&p)); break; case DW_EH_PE_udata2: result = *((uint16_t*)p); @@ -230,19 +247,19 @@ readEncodedPointer(const uint8_t** data, uint8_t encoding) p += sizeof(uint32_t); break; case DW_EH_PE_udata8: - result = *((uint64_t*)p); + result = static_cast<uintptr_t>(*((uint64_t*)p)); p += sizeof(uint64_t); break; case DW_EH_PE_sdata2: - result = *((int16_t*)p); + result = static_cast<uintptr_t>(*((int16_t*)p)); p += sizeof(int16_t); break; case DW_EH_PE_sdata4: - result = *((int32_t*)p); + result = static_cast<uintptr_t>(*((int32_t*)p)); p += sizeof(int32_t); break; case DW_EH_PE_sdata8: - result = *((int64_t*)p); + result = static_cast<uintptr_t>(*((int64_t*)p)); p += sizeof(int64_t); break; default: @@ -292,7 +309,7 @@ call_terminate(bool native_exception, _Unwind_Exception* unwind_exception) static const __shim_type_info* -get_shim_type_info(int64_t ttypeIndex, const uint8_t* classInfo, +get_shim_type_info(uint64_t ttypeIndex, const uint8_t* classInfo, uint8_t ttypeEncoding, bool native_exception, _Unwind_Exception* unwind_exception) { @@ -381,6 +398,41 @@ get_thrown_object_ptr(_Unwind_Exception* unwind_exception) return adjustedPtr; } +namespace +{ + +struct scan_results +{ + int64_t ttypeIndex; // > 0 catch handler, < 0 exception spec handler, == 0 a cleanup + const uint8_t* actionRecord; // Currently unused. Retained to ease future maintenance. + const uint8_t* languageSpecificData; // Needed only for __cxa_call_unexpected + uintptr_t landingPad; // null -> nothing found, else something found + void* adjustedPtr; // Used in cxa_exception.cpp + _Unwind_Reason_Code reason; // One of _URC_FATAL_PHASE1_ERROR, + // _URC_FATAL_PHASE2_ERROR, + // _URC_CONTINUE_UNWIND, + // _URC_HANDLER_FOUND +}; + +} // unnamed namespace + +static +void +set_registers(_Unwind_Exception* unwind_exception, _Unwind_Context* context, + const scan_results& results) +{ +#if __arm__ + _Unwind_SetGR(context, 0, reinterpret_cast<uintptr_t>(unwind_exception)); + _Unwind_SetGR(context, 1, static_cast<uintptr_t>(results.ttypeIndex)); +#else + _Unwind_SetGR(context, __builtin_eh_return_data_regno(0), + reinterpret_cast<uintptr_t>(unwind_exception)); + _Unwind_SetGR(context, __builtin_eh_return_data_regno(1), + static_cast<uintptr_t>(results.ttypeIndex)); +#endif + _Unwind_SetIP(context, results.landingPad); +} + /* There are 3 types of scans needed: @@ -402,24 +454,6 @@ get_thrown_object_ptr(_Unwind_Exception* unwind_exception) _UA_CLEANUP_PHASE && !_UA_HANDLER_FRAME */ -namespace -{ - -struct scan_results -{ - int64_t ttypeIndex; // > 0 catch handler, < 0 exception spec handler, == 0 a cleanup - const uint8_t* actionRecord; // Currently unused. Retained to ease future maintenance. - const uint8_t* languageSpecificData; // Needed only for __cxa_call_unexpected - uintptr_t landingPad; // null -> nothing found, else something found - void* adjustedPtr; // Used in cxa_exception.cpp - _Unwind_Reason_Code reason; // One of _URC_FATAL_PHASE1_ERROR, - // _URC_FATAL_PHASE2_ERROR, - // _URC_CONTINUE_UNWIND, - // _URC_HANDLER_FOUND -}; - -} // unnamed namespace - static void scan_eh_tab(scan_results& results, _Unwind_Action actions, bool native_exception, @@ -477,7 +511,19 @@ scan_eh_tab(scan_results& results, _Unwind_Action actions, bool native_exception // Get beginning current frame's code (as defined by the // emitted dwarf code) uintptr_t funcStart = _Unwind_GetRegionStart(context); +#if __arm__ + if (ip == uintptr_t(-1)) + { + // no action + results.reason = _URC_CONTINUE_UNWIND; + return; + } + else if (ip == 0) + call_terminate(native_exception, unwind_exception); + // ip is 1-based index into call site table +#else // __arm__ uintptr_t ipOffset = ip - funcStart; +#endif // __arm__ const uint8_t* classInfo = NULL; // Note: See JITDwarfEmitter::EmitExceptionTable(...) for corresponding // dwarf emission @@ -498,14 +544,18 @@ scan_eh_tab(scan_results& results, _Unwind_Action actions, bool native_exception // Walk call-site table looking for range that // includes current PC. uint8_t callSiteEncoding = *lsda++; - uint32_t callSiteTableLength = readULEB128(&lsda); +#if __arm__ + (void)callSiteEncoding; // On arm callSiteEncoding is never used +#endif + uint32_t callSiteTableLength = static_cast<uint32_t>(readULEB128(&lsda)); const uint8_t* callSiteTableStart = lsda; const uint8_t* callSiteTableEnd = callSiteTableStart + callSiteTableLength; const uint8_t* actionTableStart = callSiteTableEnd; const uint8_t* callSitePtr = callSiteTableStart; - while (true) + while (callSitePtr < callSiteTableEnd) { // There is one entry per call site. +#if !__arm__ // The call sites are non-overlapping in [start, start+length) // The call sites are ordered in increasing value of start uintptr_t start = readEncodedPointer(&callSitePtr, callSiteEncoding); @@ -513,8 +563,15 @@ scan_eh_tab(scan_results& results, _Unwind_Action actions, bool native_exception uintptr_t landingPad = readEncodedPointer(&callSitePtr, callSiteEncoding); uintptr_t actionEntry = readULEB128(&callSitePtr); if ((start <= ipOffset) && (ipOffset < (start + length))) +#else // __arm__ + // ip is 1-based index into this table + uintptr_t landingPad = readULEB128(&callSitePtr); + uintptr_t actionEntry = readULEB128(&callSitePtr); + if (--ip == 0) +#endif // __arm__ { // Found the call site containing ip. +#if !__arm__ if (landingPad == 0) { // No handler here @@ -522,6 +579,9 @@ scan_eh_tab(scan_results& results, _Unwind_Action actions, bool native_exception return; } landingPad = (uintptr_t)lpStart + landingPad; +#else // __arm__ + ++landingPad; +#endif // __arm__ if (actionEntry == 0) { // Found a cleanup @@ -550,9 +610,9 @@ scan_eh_tab(scan_results& results, _Unwind_Action actions, bool native_exception // Found a catch, does it actually catch? // First check for catch (...) const __shim_type_info* catchType = - get_shim_type_info(ttypeIndex, classInfo, - ttypeEncoding, native_exception, - unwind_exception); + get_shim_type_info(static_cast<uint64_t>(ttypeIndex), + classInfo, ttypeEncoding, + native_exception, unwind_exception); if (catchType == 0) { // Found catch (...) catches everything, including foreign exceptions @@ -713,6 +773,7 @@ scan_eh_tab(scan_results& results, _Unwind_Action actions, bool native_exception action += actionOffset; } // there is no break out of this loop, only return } +#if !__arm__ else if (ipOffset < start) { // There is no call site for this ip @@ -720,7 +781,12 @@ scan_eh_tab(scan_results& results, _Unwind_Action actions, bool native_exception // Possible stack corruption. call_terminate(native_exception, unwind_exception); } - } // there is no break out of this loop, only return +#endif // !__arm__ + } // there might be some tricky cases which break out of this loop + + // It is possible that no eh table entry specify how to handle + // this exception. By spec, terminate it immediately. + call_terminate(native_exception, unwind_exception); } // public API @@ -772,7 +838,12 @@ _UA_CLEANUP_PHASE */ _Unwind_Reason_Code -__gxx_personality_v0(int version, _Unwind_Action actions, uint64_t exceptionClass, +#if __arm__ +__gxx_personality_sj0 +#else +__gxx_personality_v0 +#endif + (int version, _Unwind_Action actions, uint64_t exceptionClass, _Unwind_Exception* unwind_exception, _Unwind_Context* context) { if (version != 1 || unwind_exception == 0 || context == 0) @@ -832,9 +903,7 @@ __gxx_personality_v0(int version, _Unwind_Action actions, uint64_t exceptionClas call_terminate(native_exception, unwind_exception); } // Jump to the handler - _Unwind_SetGR(context, __builtin_eh_return_data_regno(0), (uintptr_t)unwind_exception); - _Unwind_SetGR(context, __builtin_eh_return_data_regno(1), results.ttypeIndex); - _Unwind_SetIP(context, results.landingPad); + set_registers(unwind_exception, context, results); return _URC_INSTALL_CONTEXT; } // Either we didn't do a phase 1 search (due to forced unwinding), or @@ -844,9 +913,7 @@ __gxx_personality_v0(int version, _Unwind_Action actions, uint64_t exceptionClas if (results.reason == _URC_HANDLER_FOUND) { // Found a non-catching handler. Jump to it: - _Unwind_SetGR(context, __builtin_eh_return_data_regno(0), (uintptr_t)unwind_exception); - _Unwind_SetGR(context, __builtin_eh_return_data_regno(1), results.ttypeIndex); - _Unwind_SetIP(context, results.landingPad); + set_registers(unwind_exception, context, results); return _URC_INSTALL_CONTEXT; } // Did not find a cleanup. Return the results of the scan @@ -910,6 +977,7 @@ __cxa_call_unexpected(void* arg) // uint8_t ttypeEncoding uint8_t lpStartEncoding = *lsda++; const uint8_t* lpStart = (const uint8_t*)readEncodedPointer(&lsda, lpStartEncoding); + (void)lpStart; // purposefully unused. Just needed to increment lsda. uint8_t ttypeEncoding = *lsda++; if (ttypeEncoding == DW_EH_PE_omit) std::__terminate(t_handler); diff --git a/system/lib/libcxxabi/src/fallback_malloc.ipp b/system/lib/libcxxabi/src/fallback_malloc.ipp index 979f0bbd..e04fb158 100644 --- a/system/lib/libcxxabi/src/fallback_malloc.ipp +++ b/system/lib/libcxxabi/src/fallback_malloc.ipp @@ -54,7 +54,7 @@ heap_node *node_from_offset ( const heap_offset offset ) { return (heap_node *) ( heap + ( offset * sizeof (heap_node))); } heap_offset offset_from_node ( const heap_node *ptr ) - { return (((char *) ptr ) - heap) / sizeof (heap_node); } + { return static_cast<heap_offset>(static_cast<size_t>(((char *) ptr ) - heap) / sizeof (heap_node)); } void init_heap () { freelist = (heap_node *) heap; @@ -87,7 +87,7 @@ void *fallback_malloc(size_t len) { p->len -= nelems; q = p + p->len; q->next_node = 0; - q->len = nelems; + q->len = static_cast<heap_size>(nelems); return (void *) (q + 1); } diff --git a/system/lib/libcxxabi/src/private_typeinfo.cpp b/system/lib/libcxxabi/src/private_typeinfo.cpp index 269116b6..44b084ae 100644 --- a/system/lib/libcxxabi/src/private_typeinfo.cpp +++ b/system/lib/libcxxabi/src/private_typeinfo.cpp @@ -9,17 +9,73 @@ #include "private_typeinfo.h" +// The flag _LIBCXX_DYNAMIC_FALLBACK is used to make dynamic_cast more +// forgiving when type_info's mistakenly have hidden visibility and thus +// multiple type_infos can exist for a single type. +// +// When _LIBCXX_DYNAMIC_FALLBACK is defined, and only in the case where +// there is a detected inconsistency in the type_info hierarchy during a +// dynamic_cast, then the equality operation will fall back to using strcmp +// on type_info names to determin type_info equality. +// +// This change happens *only* under dynamic_cast, and only when +// dynamic_cast is faced with the choice: abort, or possibly give back the +// wrong answer. If when the dynamic_cast is done with this fallback +// algorithm and an inconsistency is still detected, dynamic_cast will call +// abort with an approriate message. +// +// The current implementation of _LIBCXX_DYNAMIC_FALLBACK requires a +// printf-like function called syslog: +// +// void syslog(const char* format, ...); +// +// If you want this functionality but your platform doesn't have syslog, +// just implement it in terms of fprintf(stderr, ...). +// +// _LIBCXX_DYNAMIC_FALLBACK is currently off by default. + +#if _LIBCXX_DYNAMIC_FALLBACK +#include "abort_message.h" +#include <string.h> +#include <sys/syslog.h> +#endif + namespace __cxxabiv1 { #pragma GCC visibility push(hidden) +#if _LIBCXX_DYNAMIC_FALLBACK + +inline +bool +is_equal(const std::type_info* x, const std::type_info* y, bool use_strcmp) +{ + if (!use_strcmp) + return x == y; + return strcmp(x->name(), y->name()) == 0; +} + +#else // !_LIBCXX_DYNAMIC_FALLBACK + +inline +bool +is_equal(const std::type_info* x, const std::type_info* y, bool) +{ + return x == y; +} + +#endif // _LIBCXX_DYNAMIC_FALLBACK + // __shim_type_info __shim_type_info::~__shim_type_info() { } +void __shim_type_info::noop1() const {} +void __shim_type_info::noop2() const {} + // __fundamental_type_info // This miraculously (compiler magic) emits the type_info's for: @@ -116,12 +172,11 @@ bool __fundamental_type_info::can_catch(const __shim_type_info* thrown_type, void*&) const { - return this == thrown_type; + return is_equal(this, thrown_type, false); } bool -__array_type_info::can_catch(const __shim_type_info* thrown_type, - void*&) const +__array_type_info::can_catch(const __shim_type_info*, void*&) const { // We can get here if someone tries to catch an array by reference. // However if someone tries to throw an array, it immediately gets @@ -131,8 +186,7 @@ __array_type_info::can_catch(const __shim_type_info* thrown_type, } bool -__function_type_info::can_catch(const __shim_type_info* thrown_type, - void*&) const +__function_type_info::can_catch(const __shim_type_info*, void*&) const { // We can get here if someone tries to catch a function by reference. // However if someone tries to throw a function, it immediately gets @@ -146,16 +200,19 @@ bool __enum_type_info::can_catch(const __shim_type_info* thrown_type, void*&) const { - return this == thrown_type; + return is_equal(this, thrown_type, false); } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wmissing-field-initializers" + // Handles bullets 1 and 2 bool __class_type_info::can_catch(const __shim_type_info* thrown_type, void*& adjustedPtr) const { // bullet 1 - if (this == thrown_type) + if (is_equal(this, thrown_type, false)) return true; const __class_type_info* thrown_class_type = dynamic_cast<const __class_type_info*>(thrown_type); @@ -173,6 +230,8 @@ __class_type_info::can_catch(const __shim_type_info* thrown_type, return false; } +#pragma clang diagnostic pop + void __class_type_info::process_found_base_class(__dynamic_cast_info* info, void* adjustedPtr, @@ -206,7 +265,7 @@ __class_type_info::has_unambiguous_public_base(__dynamic_cast_info* info, void* adjustedPtr, int path_below) const { - if (this == info->static_type) + if (is_equal(this, info->static_type, false)) process_found_base_class(info, adjustedPtr, path_below); } @@ -215,7 +274,7 @@ __si_class_type_info::has_unambiguous_public_base(__dynamic_cast_info* info, void* adjustedPtr, int path_below) const { - if (this == info->static_type) + if (is_equal(this, info->static_type, false)) process_found_base_class(info, adjustedPtr, path_below); else __base_type->has_unambiguous_public_base(info, adjustedPtr, path_below); @@ -244,7 +303,7 @@ __vmi_class_type_info::has_unambiguous_public_base(__dynamic_cast_info* info, void* adjustedPtr, int path_below) const { - if (this == info->static_type) + if (is_equal(this, info->static_type, false)) process_found_base_class(info, adjustedPtr, path_below); else { @@ -269,11 +328,14 @@ bool __pbase_type_info::can_catch(const __shim_type_info* thrown_type, void*&) const { - if (this == thrown_type) + if (is_equal(this, thrown_type, false)) return true; - return thrown_type == &typeid(std::nullptr_t); + return is_equal(thrown_type, &typeid(std::nullptr_t), false); } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wmissing-field-initializers" + // Handles bullets 1, 3 and 4 bool __pointer_type_info::can_catch(const __shim_type_info* thrown_type, @@ -292,10 +354,10 @@ __pointer_type_info::can_catch(const __shim_type_info* thrown_type, // bullet 3B if (thrown_pointer_type->__flags & ~__flags) return false; - if (__pointee == thrown_pointer_type->__pointee) + if (is_equal(__pointee, thrown_pointer_type->__pointee, false)) return true; // bullet 3A - if (__pointee == &typeid(void)) + if (is_equal(__pointee, &typeid(void), false)) return true; const __class_type_info* catch_class_type = dynamic_cast<const __class_type_info*>(__pointee); @@ -316,9 +378,14 @@ __pointer_type_info::can_catch(const __shim_type_info* thrown_type, return false; } +#pragma clang diagnostic pop + #pragma GCC visibility pop #pragma GCC visibility push(default) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wmissing-field-initializers" + // __dynamic_cast // static_ptr: pointer to an object of type static_type; nonnull, and since the @@ -417,12 +484,28 @@ __dynamic_cast(const void* static_ptr, __dynamic_cast_info info = {dst_type, static_ptr, static_type, src2dst_offset, 0}; // Find out if we can use a giant short cut in the search - if (dynamic_type == dst_type) + if (is_equal(dynamic_type, dst_type, false)) { // Using giant short cut. Add that information to info. info.number_of_dst_type = 1; // Do the search - dynamic_type->search_above_dst(&info, dynamic_ptr, dynamic_ptr, public_path); + dynamic_type->search_above_dst(&info, dynamic_ptr, dynamic_ptr, public_path, false); +#if _LIBCXX_DYNAMIC_FALLBACK + // The following if should always be false because we should definitely + // find (static_ptr, static_type), either on a public or private path + if (info.path_dst_ptr_to_static_ptr == unknown) + { + // We get here only if there is some kind of visibility problem + // in client code. + syslog(LOG_ERR, "dynamic_cast error 1: Both of the following type_info's " + "should have public visibility. At least of of them is hidden. %s" + ", %s.\n", static_type->name(), dynamic_type->name()); + // Redo the search comparing type_info's using strcmp + info = {dst_type, static_ptr, static_type, src2dst_offset, 0}; + info.number_of_dst_type = 1; + dynamic_type->search_above_dst(&info, dynamic_ptr, dynamic_ptr, public_path, true); + } +#endif // _LIBCXX_DYNAMIC_FALLBACK // Query the search. if (info.path_dst_ptr_to_static_ptr == public_path) dst_ptr = dynamic_ptr; @@ -430,7 +513,22 @@ __dynamic_cast(const void* static_ptr, else { // Not using giant short cut. Do the search - dynamic_type->search_below_dst(&info, dynamic_ptr, public_path); + dynamic_type->search_below_dst(&info, dynamic_ptr, public_path, false); + #if _LIBCXX_DYNAMIC_FALLBACK + // The following if should always be false because we should definitely + // find (static_ptr, static_type), either on a public or private path + if (info.path_dst_ptr_to_static_ptr == unknown && + info.path_dynamic_ptr_to_static_ptr == unknown) + { + syslog(LOG_ERR, "dynamic_cast error 2: One or more of the following type_info's " + " has hidden visibility. They should all have public visibility. " + " %s, %s, %s.\n", static_type->name(), dynamic_type->name(), + dst_type->name()); + // Redo the search comparing type_info's using strcmp + info = {dst_type, static_ptr, static_type, src2dst_offset, 0}; + dynamic_type->search_below_dst(&info, dynamic_ptr, public_path, true); + } +#endif // _LIBCXX_DYNAMIC_FALLBACK // Query the search. switch (info.number_to_static_ptr) { @@ -455,6 +553,8 @@ __dynamic_cast(const void* static_ptr, return const_cast<void*>(dst_ptr); } +#pragma clang diagnostic pop + #pragma GCC visibility pop #pragma GCC visibility push(hidden) @@ -584,12 +684,13 @@ __class_type_info::process_static_type_below_dst(__dynamic_cast_info* info, void __vmi_class_type_info::search_below_dst(__dynamic_cast_info* info, const void* current_ptr, - int path_below) const + int path_below, + bool use_strcmp) const { typedef const __base_class_type_info* Iter; - if (this == info->static_type) + if (is_equal(this, info->static_type, use_strcmp)) process_static_type_below_dst(info, current_ptr, path_below); - else if (this == info->dst_type) + else if (is_equal(this, info->dst_type, use_strcmp)) { // We've been here before if we've recorded current_ptr in one of these // two places: @@ -629,7 +730,7 @@ __vmi_class_type_info::search_below_dst(__dynamic_cast_info* info, // Zero out found flags info->found_our_static_ptr = false; info->found_any_static_type = false; - p->search_above_dst(info, current_ptr, current_ptr, public_path); + p->search_above_dst(info, current_ptr, current_ptr, public_path, use_strcmp); if (info->search_done) break; if (info->found_any_static_type) @@ -688,7 +789,7 @@ __vmi_class_type_info::search_below_dst(__dynamic_cast_info* info, // This is not a static_type and not a dst_type. const Iter e = __base_info + __base_count; Iter p = __base_info; - p->search_below_dst(info, current_ptr, path_below); + p->search_below_dst(info, current_ptr, path_below, use_strcmp); if (++p < e) { if ((__flags & __diamond_shaped_mask) || info->number_to_static_ptr == 1) @@ -701,7 +802,7 @@ __vmi_class_type_info::search_below_dst(__dynamic_cast_info* info, { if (info->search_done) break; - p->search_below_dst(info, current_ptr, path_below); + p->search_below_dst(info, current_ptr, path_below, use_strcmp); } while (++p < e); } else if (__flags & __non_diamond_repeat_mask) @@ -720,7 +821,7 @@ __vmi_class_type_info::search_below_dst(__dynamic_cast_info* info, if (info->number_to_static_ptr == 1 && info->path_dst_ptr_to_static_ptr == public_path) break; - p->search_below_dst(info, current_ptr, path_below); + p->search_below_dst(info, current_ptr, path_below, use_strcmp); } while (++p < e); } else @@ -743,7 +844,7 @@ __vmi_class_type_info::search_below_dst(__dynamic_cast_info* info, // and not a dst_type under here. if (info->number_to_static_ptr == 1) break; - p->search_below_dst(info, current_ptr, path_below); + p->search_below_dst(info, current_ptr, path_below, use_strcmp); } while (++p < e); } } @@ -755,11 +856,12 @@ __vmi_class_type_info::search_below_dst(__dynamic_cast_info* info, void __si_class_type_info::search_below_dst(__dynamic_cast_info* info, const void* current_ptr, - int path_below) const + int path_below, + bool use_strcmp) const { - if (this == info->static_type) + if (is_equal(this, info->static_type, use_strcmp)) process_static_type_below_dst(info, current_ptr, path_below); - else if (this == info->dst_type) + else if (is_equal(this, info->dst_type, use_strcmp)) { // We've been here before if we've recorded current_ptr in one of these // two places: @@ -787,7 +889,7 @@ __si_class_type_info::search_below_dst(__dynamic_cast_info* info, // Zero out found flags info->found_our_static_ptr = false; info->found_any_static_type = false; - __base_type->search_above_dst(info, current_ptr, current_ptr, public_path); + __base_type->search_above_dst(info, current_ptr, current_ptr, public_path, use_strcmp); if (info->found_any_static_type) { is_dst_type_derived_from_static_type = true; @@ -822,7 +924,7 @@ __si_class_type_info::search_below_dst(__dynamic_cast_info* info, else { // This is not a static_type and not a dst_type - __base_type->search_below_dst(info, current_ptr, path_below); + __base_type->search_below_dst(info, current_ptr, path_below, use_strcmp); } } @@ -831,12 +933,13 @@ __si_class_type_info::search_below_dst(__dynamic_cast_info* info, void __class_type_info::search_below_dst(__dynamic_cast_info* info, const void* current_ptr, - int path_below) const + int path_below, + bool use_strcmp) const { typedef const __base_class_type_info* Iter; - if (this == info->static_type) + if (is_equal(this, info->static_type, use_strcmp)) process_static_type_below_dst(info, current_ptr, path_below); - else if (this == info->dst_type) + else if (is_equal(this, info->dst_type, use_strcmp)) { // We've been here before if we've recorded current_ptr in one of these // two places: @@ -901,9 +1004,10 @@ void __vmi_class_type_info::search_above_dst(__dynamic_cast_info* info, const void* dst_ptr, const void* current_ptr, - int path_below) const + int path_below, + bool use_strcmp) const { - if (this == info->static_type) + if (is_equal(this, info->static_type, use_strcmp)) process_static_type_above_dst(info, dst_ptr, current_ptr, path_below); else { @@ -926,7 +1030,7 @@ __vmi_class_type_info::search_above_dst(__dynamic_cast_info* info, // Zero out found flags info->found_our_static_ptr = false; info->found_any_static_type = false; - p->search_above_dst(info, dst_ptr, current_ptr, path_below); + p->search_above_dst(info, dst_ptr, current_ptr, path_below, use_strcmp); if (++p < e) { do @@ -955,7 +1059,7 @@ __vmi_class_type_info::search_above_dst(__dynamic_cast_info* info, // Zero out found flags info->found_our_static_ptr = false; info->found_any_static_type = false; - p->search_above_dst(info, dst_ptr, current_ptr, path_below); + p->search_above_dst(info, dst_ptr, current_ptr, path_below, use_strcmp); } while (++p < e); } // Restore flags @@ -970,12 +1074,13 @@ void __si_class_type_info::search_above_dst(__dynamic_cast_info* info, const void* dst_ptr, const void* current_ptr, - int path_below) const + int path_below, + bool use_strcmp) const { - if (this == info->static_type) + if (is_equal(this, info->static_type, use_strcmp)) process_static_type_above_dst(info, dst_ptr, current_ptr, path_below); else - __base_type->search_above_dst(info, dst_ptr, current_ptr, path_below); + __base_type->search_above_dst(info, dst_ptr, current_ptr, path_below, use_strcmp); } // This is the same algorithm as __vmi_class_type_info::search_above_dst but @@ -984,9 +1089,10 @@ void __class_type_info::search_above_dst(__dynamic_cast_info* info, const void* dst_ptr, const void* current_ptr, - int path_below) const + int path_below, + bool use_strcmp) const { - if (this == info->static_type) + if (is_equal(this, info->static_type, use_strcmp)) process_static_type_above_dst(info, dst_ptr, current_ptr, path_below); } @@ -998,7 +1104,8 @@ void __base_class_type_info::search_above_dst(__dynamic_cast_info* info, const void* dst_ptr, const void* current_ptr, - int path_below) const + int path_below, + bool use_strcmp) const { ptrdiff_t offset_to_base = __offset_flags >> __offset_shift; if (__offset_flags & __virtual_mask) @@ -1010,13 +1117,15 @@ __base_class_type_info::search_above_dst(__dynamic_cast_info* info, static_cast<const char*>(current_ptr) + offset_to_base, (__offset_flags & __public_mask) ? path_below : - not_public_path); + not_public_path, + use_strcmp); } void __base_class_type_info::search_below_dst(__dynamic_cast_info* info, const void* current_ptr, - int path_below) const + int path_below, + bool use_strcmp) const { ptrdiff_t offset_to_base = __offset_flags >> __offset_shift; if (__offset_flags & __virtual_mask) @@ -1028,7 +1137,8 @@ __base_class_type_info::search_below_dst(__dynamic_cast_info* info, static_cast<const char*>(current_ptr) + offset_to_base, (__offset_flags & __public_mask) ? path_below : - not_public_path); + not_public_path, + use_strcmp); } #pragma GCC visibility pop diff --git a/system/lib/libcxxabi/src/private_typeinfo.h b/system/lib/libcxxabi/src/private_typeinfo.h index fec081ab..07e8ddea 100644 --- a/system/lib/libcxxabi/src/private_typeinfo.h +++ b/system/lib/libcxxabi/src/private_typeinfo.h @@ -18,13 +18,15 @@ namespace __cxxabiv1 #pragma GCC visibility push(hidden) -class __attribute__ ((__visibility__("hidden"))) __shim_type_info +class __attribute__ ((__visibility__("default"))) __shim_type_info : public std::type_info { public: - virtual ~__shim_type_info(); + __attribute__ ((__visibility__("hidden"))) virtual ~__shim_type_info(); - virtual bool can_catch(const __shim_type_info* thrown_type, void*& adjustedPtr) const = 0; + __attribute__ ((__visibility__("hidden"))) virtual void noop1() const; + __attribute__ ((__visibility__("hidden"))) virtual void noop2() const; + __attribute__ ((__visibility__("hidden"))) virtual bool can_catch(const __shim_type_info* thrown_type, void*& adjustedPtr) const = 0; }; class __attribute__ ((__visibility__("default"))) __fundamental_type_info @@ -68,16 +70,16 @@ enum no }; -class __class_type_info; +class __attribute__ ((__visibility__("default"))) __class_type_info; struct __dynamic_cast_info { // const data supplied to the search: - const __class_type_info* const dst_type; - const void* const static_ptr; - const __class_type_info* const static_type; - const std::ptrdiff_t src2dst_offset; + const __class_type_info* dst_type; + const void* static_ptr; + const __class_type_info* static_type; + std::ptrdiff_t src2dst_offset; // Data that represents the answer: @@ -131,9 +133,9 @@ public: __attribute__ ((__visibility__("hidden"))) void process_found_base_class(__dynamic_cast_info*, void*, int) const; __attribute__ ((__visibility__("hidden"))) - virtual void search_above_dst(__dynamic_cast_info*, const void*, const void*, int) const; + virtual void search_above_dst(__dynamic_cast_info*, const void*, const void*, int, bool) const; __attribute__ ((__visibility__("hidden"))) - virtual void search_below_dst(__dynamic_cast_info*, const void*, int) const; + virtual void search_below_dst(__dynamic_cast_info*, const void*, int, bool) const; __attribute__ ((__visibility__("hidden"))) virtual bool can_catch(const __shim_type_info*, void*&) const; __attribute__ ((__visibility__("hidden"))) @@ -150,9 +152,9 @@ public: __attribute__ ((__visibility__("hidden"))) virtual ~__si_class_type_info(); __attribute__ ((__visibility__("hidden"))) - virtual void search_above_dst(__dynamic_cast_info*, const void*, const void*, int) const; + virtual void search_above_dst(__dynamic_cast_info*, const void*, const void*, int, bool) const; __attribute__ ((__visibility__("hidden"))) - virtual void search_below_dst(__dynamic_cast_info*, const void*, int) const; + virtual void search_below_dst(__dynamic_cast_info*, const void*, int, bool) const; __attribute__ ((__visibility__("hidden"))) virtual void has_unambiguous_public_base(__dynamic_cast_info*, void*, int) const; }; @@ -170,8 +172,8 @@ public: __offset_shift = 8 }; - void search_above_dst(__dynamic_cast_info*, const void*, const void*, int) const; - void search_below_dst(__dynamic_cast_info*, const void*, int) const; + void search_above_dst(__dynamic_cast_info*, const void*, const void*, int, bool) const; + void search_below_dst(__dynamic_cast_info*, const void*, int, bool) const; void has_unambiguous_public_base(__dynamic_cast_info*, void*, int) const; }; @@ -195,9 +197,9 @@ public: __attribute__ ((__visibility__("hidden"))) virtual ~__vmi_class_type_info(); __attribute__ ((__visibility__("hidden"))) - virtual void search_above_dst(__dynamic_cast_info*, const void*, const void*, int) const; + virtual void search_above_dst(__dynamic_cast_info*, const void*, const void*, int, bool) const; __attribute__ ((__visibility__("hidden"))) - virtual void search_below_dst(__dynamic_cast_info*, const void*, int) const; + virtual void search_below_dst(__dynamic_cast_info*, const void*, int, bool) const; __attribute__ ((__visibility__("hidden"))) virtual void has_unambiguous_public_base(__dynamic_cast_info*, void*, int) const; }; diff --git a/system/lib/libcxxabi/src/stdexcept.cpp b/system/lib/libcxxabi/src/stdexcept.cpp index 4aa962d0..de859db4 100644 --- a/system/lib/libcxxabi/src/stdexcept.cpp +++ b/system/lib/libcxxabi/src/stdexcept.cpp @@ -14,6 +14,11 @@ #include <cstdint> #include <cstddef> +#if __APPLE__ +#include <dlfcn.h> +#include <mach-o/dyld.h> +#endif + // Note: optimize for size #pragma GCC visibility push(hidden) @@ -26,13 +31,39 @@ class __libcpp_nmstr private: const char* str_; - typedef std::size_t unused_t; - typedef std::int32_t count_t; - - static const std::ptrdiff_t offset = static_cast<std::ptrdiff_t>(2*sizeof(unused_t) + - sizeof(count_t)); + typedef int count_t; + + struct _Rep_base + { + std::size_t len; + std::size_t cap; + count_t count; + }; + + static const std::ptrdiff_t offset = static_cast<std::ptrdiff_t>(sizeof(_Rep_base)); + + count_t& count() const _NOEXCEPT {return ((_Rep_base*)(str_ - offset))->count;} + +#if __APPLE__ + static + const void* + compute_gcc_empty_string_storage() _LIBCPP_CANTTHROW + { + void* handle = dlopen("/usr/lib/libstdc++.6.dylib", RTLD_NOLOAD); + if (handle == 0) + return 0; + return (const char*)dlsym(handle, "_ZNSs4_Rep20_S_empty_rep_storageE") + offset; + } + + static + const void* + get_gcc_empty_string_storage() _LIBCPP_CANTTHROW + { + static const void* p = compute_gcc_empty_string_storage(); + return p; + } +#endif - count_t& count() const _NOEXCEPT {return (count_t&)(*(str_ - sizeof(count_t)));} public: explicit __libcpp_nmstr(const char* msg); __libcpp_nmstr(const __libcpp_nmstr& s) _LIBCPP_CANTTHROW; @@ -44,9 +75,9 @@ public: __libcpp_nmstr::__libcpp_nmstr(const char* msg) { std::size_t len = strlen(msg); - str_ = new char[len + 1 + offset]; - unused_t* c = (unused_t*)str_; - c[0] = c[1] = len; + str_ = static_cast<const char*>(::operator new(len + 1 + offset)); + _Rep_base* c = (_Rep_base*)str_; + c->len = c->cap = len; str_ += offset; count() = 0; std::strcpy(const_cast<char*>(c_str()), msg); @@ -56,7 +87,10 @@ inline __libcpp_nmstr::__libcpp_nmstr(const __libcpp_nmstr& s) : str_(s.str_) { - __sync_add_and_fetch(&count(), 1); +#if __APPLE__ + if (str_ != get_gcc_empty_string_storage()) +#endif + __sync_add_and_fetch(&count(), 1); } __libcpp_nmstr& @@ -64,17 +98,30 @@ __libcpp_nmstr::operator=(const __libcpp_nmstr& s) { const char* p = str_; str_ = s.str_; - __sync_add_and_fetch(&count(), 1); - if (__sync_add_and_fetch((count_t*)(p-sizeof(count_t)), -1) < 0) - delete [] (p-offset); +#if __APPLE__ + if (str_ != get_gcc_empty_string_storage()) +#endif + __sync_add_and_fetch(&count(), 1); +#if __APPLE__ + if (p != get_gcc_empty_string_storage()) +#endif + if (__sync_add_and_fetch((count_t*)(p-sizeof(count_t)), count_t(-1)) < 0) + { + ::operator delete(const_cast<char*>(p-offset)); + } return *this; } inline __libcpp_nmstr::~__libcpp_nmstr() { - if (__sync_add_and_fetch(&count(), -1) < 0) - delete [] (str_ - offset); +#if __APPLE__ + if (str_ != get_gcc_empty_string_storage()) +#endif + if (__sync_add_and_fetch(&count(), count_t(-1)) < 0) + { + ::operator delete(const_cast<char*>(str_ - offset)); + } } } diff --git a/system/lib/libcxxabi/src/temporary.cpp b/system/lib/libcxxabi/src/temporary.cpp deleted file mode 100644 index 5facf39d..00000000 --- a/system/lib/libcxxabi/src/temporary.cpp +++ /dev/null @@ -1,41 +0,0 @@ -//===---------------------------- temporary.cpp ---------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "abort_message.h" - -#pragma GCC visibility push(default) - -extern "C" -{ - -static -void f1() -{ - abort_message("__cxa_new_handler shouldn't be called"); -} - -static -void f2() -{ - abort_message("__cxa_terminate_handler shouldn't be called"); -} - -static -void f3() -{ - abort_message("__cxa_unexpected_handler shouldn't be called"); -} - -void (*__cxa_new_handler)() = f1; -void (*__cxa_terminate_handler)() = f2; -void (*__cxa_unexpected_handler)() = f3; - -} - -#pragma GCC visibility pop |