Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/libc++/dist/libcxxrt/src Merge 47661d00cd4d6cd7...
details: https://anonhg.NetBSD.org/src/rev/cf39137e8d17
branches: trunk
changeset: 983579:cf39137e8d17
user: joerg <joerg%NetBSD.org@localhost>
date: Sun May 30 00:12:31 2021 +0000
description:
Merge 47661d00cd4d6cd728ae31b0bb29a49a6c06272a
diffstat:
external/bsd/libc++/dist/libcxxrt/src/exception.cc | 54 +-
external/bsd/libc++/dist/libcxxrt/src/libelftc_dem_gnu3.c | 1243 ++++++++----
external/bsd/libc++/dist/libcxxrt/src/unwind-itanium.h | 1 +
3 files changed, 887 insertions(+), 411 deletions(-)
diffs (truncated from 3002 to 300 lines):
diff -r c7f4a55575ca -r cf39137e8d17 external/bsd/libc++/dist/libcxxrt/src/exception.cc
--- a/external/bsd/libc++/dist/libcxxrt/src/exception.cc Sun May 30 00:08:19 2021 +0000
+++ b/external/bsd/libc++/dist/libcxxrt/src/exception.cc Sun May 30 00:12:31 2021 +0000
@@ -304,13 +304,17 @@
static void exception_cleanup(_Unwind_Reason_Code reason,
struct _Unwind_Exception *ex)
{
- __cxa_free_exception(static_cast<void*>(ex));
+ // Exception layout:
+ // [__cxa_exception [_Unwind_Exception]] [exception object]
+ //
+ // __cxa_free_exception expects a pointer to the exception object
+ __cxa_free_exception(static_cast<void*>(ex + 1));
}
static void dependent_exception_cleanup(_Unwind_Reason_Code reason,
struct _Unwind_Exception *ex)
{
- __cxa_free_dependent_exception(static_cast<void*>(ex));
+ __cxa_free_dependent_exception(static_cast<void*>(ex + 1));
}
/**
@@ -340,7 +344,8 @@
if (info->foreign_exception_state != __cxa_thread_info::none)
{
_Unwind_Exception *e = reinterpret_cast<_Unwind_Exception*>(info->globals.caughtExceptions);
- e->exception_cleanup(_URC_FOREIGN_EXCEPTION_CAUGHT, e);
+ if (e->exception_cleanup)
+ e->exception_cleanup(_URC_FOREIGN_EXCEPTION_CAUGHT, e);
}
else
{
@@ -516,7 +521,7 @@
break;
}
}
- assert(buffer > 0 &&
+ assert(buffer >= 0 &&
"Trying to free something that is not an emergency buffer!");
// emergency_malloc() is expected to return 0-initialized data. We don't
// zero the buffer when allocating it, because the static buffers will
@@ -556,7 +561,7 @@
{
// If this allocation is within the address range of the emergency buffer,
// don't call free() because it was not allocated with malloc()
- if ((e > emergency_buffer) &&
+ if ((e >= emergency_buffer) &&
(e < (emergency_buffer + sizeof(emergency_buffer))))
{
emergency_malloc_free(e);
@@ -854,6 +859,13 @@
assert(ex->handlerCount > 0 && "Rethrowing uncaught exception!");
+ // `globals->uncaughtExceptions` was decremented by `__cxa_begin_catch`.
+ // It's normally incremented by `throw_exception`, but this path invokes
+ // `_Unwind_Resume_or_Rethrow` directly to rethrow the exception.
+ // This path is only reachable if we're rethrowing a C++ exception -
+ // foreign exceptions don't adjust any of this state.
+ globals->uncaughtExceptions++;
+
// ex->handlerCount will be decremented in __cxa_end_catch in enclosing
// catch block
@@ -1199,11 +1211,13 @@
// we see is a foreign exception then we won't have called it yet.
__cxa_thread_info *ti = thread_info();
__cxa_eh_globals *globals = &ti->globals;
- globals->uncaughtExceptions--;
_Unwind_Exception *exceptionObject = static_cast<_Unwind_Exception*>(e);
if (isCXXException(exceptionObject->exception_class))
{
+ // Only exceptions thrown with a C++ exception throwing function will
+ // increment this, so don't decrement it here.
+ globals->uncaughtExceptions--;
__cxa_exception *ex = exceptionFromPointer(exceptionObject);
if (ex->handlerCount == 0)
@@ -1280,12 +1294,13 @@
if (ti->foreign_exception_state != __cxa_thread_info::none)
{
- globals->caughtExceptions = 0;
if (ti->foreign_exception_state != __cxa_thread_info::rethrown)
{
_Unwind_Exception *e = reinterpret_cast<_Unwind_Exception*>(ti->globals.caughtExceptions);
- e->exception_cleanup(_URC_FOREIGN_EXCEPTION_CAUGHT, e);
+ if (e->exception_cleanup)
+ e->exception_cleanup(_URC_FOREIGN_EXCEPTION_CAUGHT, e);
}
+ globals->caughtExceptions = 0;
ti->foreign_exception_state = __cxa_thread_info::none;
return;
}
@@ -1339,6 +1354,14 @@
}
/**
+ * Cleanup, ensures that `__cxa_end_catch` is called to balance an explicit
+ * `__cxa_begin_catch` call.
+ */
+static void end_catch(char *)
+{
+ __cxa_end_catch();
+}
+/**
* ABI function, called when an exception specification is violated.
*
* This function does not return.
@@ -1346,6 +1369,12 @@
extern "C" void __cxa_call_unexpected(void*exception)
{
_Unwind_Exception *exceptionObject = static_cast<_Unwind_Exception*>(exception);
+ // Wrap the call to the unexpected handler in calls to `__cxa_begin_catch`
+ // and `__cxa_end_catch` so that we correctly update exception counts if
+ // the unexpected handler throws an exception.
+ __cxa_begin_catch(exceptionObject);
+ __attribute__((cleanup(end_catch)))
+ char unused;
if (exceptionObject->exception_class == exception_class)
{
__cxa_exception *ex = exceptionFromPointer(exceptionObject);
@@ -1472,6 +1501,15 @@
return info->globals.uncaughtExceptions != 0;
}
/**
+ * Returns the number of exceptions currently being thrown that have not
+ * been caught. This can occur inside a nested catch statement.
+ */
+ int uncaught_exceptions() throw()
+ {
+ __cxa_thread_info *info = thread_info();
+ return info->globals.uncaughtExceptions;
+ }
+ /**
* Returns the current unexpected handler.
*/
unexpected_handler get_unexpected() throw()
diff -r c7f4a55575ca -r cf39137e8d17 external/bsd/libc++/dist/libcxxrt/src/libelftc_dem_gnu3.c
--- a/external/bsd/libc++/dist/libcxxrt/src/libelftc_dem_gnu3.c Sun May 30 00:08:19 2021 +0000
+++ b/external/bsd/libc++/dist/libcxxrt/src/libelftc_dem_gnu3.c Sun May 30 00:12:31 2021 +0000
@@ -1,5 +1,6 @@
/*-
- * Copyright (c) 2007, 2008 Hyogeol Lee <hyogeollee%gmail.com@localhost>
+ * Copyright (c) 2007 Hyogeol Lee <hyogeollee%gmail.com@localhost>
+ * Copyright (c) 2015-2017 Kai Wang <kaiwang27%gmail.com@localhost>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -54,12 +55,17 @@
};
#define BUFFER_GROWFACTOR 1.618
+#define BUFFER_GROW(x) (((x)+0.5)*BUFFER_GROWFACTOR)
+
+#define ELFTC_FAILURE 0
+#define ELFTC_ISDIGIT(C) (isdigit((C) & 0xFF))
+#define ELFTC_SUCCESS 1
+
#define VECTOR_DEF_CAPACITY 8
-#define ELFTC_ISDIGIT(C) (isdigit((C) & 0xFF))
enum type_qualifier {
TYPE_PTR, TYPE_REF, TYPE_CMX, TYPE_IMG, TYPE_EXT, TYPE_RST, TYPE_VAT,
- TYPE_CST, TYPE_VEC
+ TYPE_CST, TYPE_VEC, TYPE_RREF
};
struct vector_type_qualifier {
@@ -73,27 +79,47 @@
READ_TYPE, READ_FUNC, READ_PTRMEM
};
+struct read_cmd_item {
+ enum read_cmd cmd;
+ void *data;
+};
+
struct vector_read_cmd {
size_t size, capacity;
- enum read_cmd *r_container;
+ struct read_cmd_item *r_container;
+};
+
+enum push_qualifier {
+ PUSH_ALL_QUALIFIER,
+ PUSH_CV_QUALIFIER,
+ PUSH_NON_CV_QUALIFIER,
};
struct cpp_demangle_data {
struct vector_str output; /* output string vector */
- struct vector_str output_tmp;
struct vector_str subst; /* substitution string vector */
struct vector_str tmpl;
struct vector_str class_type;
+ struct vector_str *cur_output; /* ptr to current output vec */
struct vector_read_cmd cmd;
- bool paren; /* parenthesis opened */
- bool pfirst; /* first element of parameter */
bool mem_rst; /* restrict member function */
bool mem_vat; /* volatile member function */
bool mem_cst; /* const member function */
+ bool mem_ref; /* lvalue-ref member func */
+ bool mem_rref; /* rvalue-ref member func */
+ bool is_tmpl; /* template args */
+ bool is_functype; /* function type */
+ bool ref_qualifier; /* ref qualifier */
+ enum type_qualifier ref_qualifier_type; /* ref qualifier type */
+ enum push_qualifier push_qualifier; /* which qualifiers to push */
int func_type;
const char *cur; /* current mangled name ptr */
const char *last_sname; /* last source name */
- int push_head;
+};
+
+struct type_delimit {
+ bool paren;
+ bool firstp;
};
#define CPP_DEMANGLE_TRY_LIMIT 128
@@ -102,6 +128,8 @@
#define FLOAT_EXTENED_BYTES 10
#define SIMPLE_HASH(x,y) (64 * x + y)
+#define DEM_PUSH_STR(d,s) cpp_demangle_push_str((d), (s), strlen((s)))
+#define VEC_PUSH_STR(d,s) vector_str_push((d), (s), strlen((s)))
static size_t get_strlen_sum(const struct vector_str *v);
static bool vector_str_grow(struct vector_str *v);
@@ -213,7 +241,7 @@
assert(v->capacity > 0);
- tmp_cap = v->capacity * BUFFER_GROWFACTOR;
+ tmp_cap = BUFFER_GROW(v->capacity);
assert(tmp_cap > v->capacity);
@@ -314,7 +342,7 @@
if (dst == NULL || org == NULL)
return (false);
- tmp_cap = (dst->size + org->size) * BUFFER_GROWFACTOR;
+ tmp_cap = BUFFER_GROW(dst->size + org->size);
if ((tmp_ctn = malloc(sizeof(char *) * tmp_cap)) == NULL)
return (false);
@@ -342,6 +370,47 @@
}
/**
+ * @brief Push org vector to the tail of det vector.
+ * @return false at failed, true at success.
+ */
+static bool
+vector_str_push_vector(struct vector_str *dst, struct vector_str *org)
+{
+ size_t i, j, tmp_cap;
+ char **tmp_ctn;
+
+ if (dst == NULL || org == NULL)
+ return (false);
+
+ tmp_cap = BUFFER_GROW(dst->size + org->size);
+
+ if ((tmp_ctn = malloc(sizeof(char *) * tmp_cap)) == NULL)
+ return (false);
+
+ for (i = 0; i < dst->size; ++i)
+ tmp_ctn[i] = dst->container[i];
+
+ for (i = 0; i < org->size; ++i)
+ if ((tmp_ctn[i + dst->size] = strdup(org->container[i])) ==
+ NULL) {
+ for (j = 0; j < i + dst->size; ++j)
+ free(tmp_ctn[j]);
+
+ free(tmp_ctn);
+
+ return (false);
+ }
+
+ free(dst->container);
+
+ dst->container = tmp_ctn;
+ dst->capacity = tmp_cap;
+ dst->size += org->size;
+
+ return (true);
+}
+
+/**
* @brief Get new allocated flat string from vector between begin and end.
*
* If r_len is not NULL, string length will be returned.
@@ -387,6 +456,7 @@
Home |
Main Index |
Thread Index |
Old Index