Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Feb 2021 12:01:34 GMT
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: d4a0c102a237 - stable/13 - Merge libcxxrt master 8049924686b8414d8e652cbd2a52c763b48e8456
Message-ID:  <202102211201.11LC1Y8H069697@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by dim:

URL: https://cgit.FreeBSD.org/src/commit/?id=d4a0c102a237beb5650a2de4cc80f1aa496601d7

commit d4a0c102a237beb5650a2de4cc80f1aa496601d7
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2021-02-18 21:30:27 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-02-21 11:57:45 +0000

    Merge libcxxrt master 8049924686b8414d8e652cbd2a52c763b48e8456
    
    Interesting fixes:
    b3c73ba libelftc_dem_gnu3: Sync with elftoolchain r3877
    7b2335c Mostly fix __cxa_demangle after #3
    
    Reported by:    arichardson
    PR:             253226
    
    (cherry picked from commit 0ee0dbfb0d26cf4bc37f24f12e76c7f532b0f368)
    
    Revert 3c4fd2463bb2 since upstream libcxxrt fixed it in another way
    
    In 0ee0dbfb0d26cf4bc37f24f12e76c7f532b0f368 I imported a more recent
    libcxxrt snapshot, which includes an upstream fix for the padding of
    struct _Unwind_Exception:
    
    https://github.com/libcxxrt/libcxxrt/commit/e458560b7e22fff59af643dba363544b393bd8db
    
    However, we also had a similar fix in our tree as:
    https://cgit.freebsd.org/src/commit/?id=3c4fd2463bb29f65ef1404011fcb31e508cdf2e2
    
    Since having both fixes makes the struct too large again, it leads to
    SIGBUSes when throwing exceptions on amd64 (or other LP64 arches). This
    is most easily tested by running kyua without any arguments.
    
    It looks like our fix is no longer needed now, so revert it to reduce
    diffs against upstream.
    
    PR:             253226
    Reviewed by:    arichardson, kp
    Differential Revision: https://reviews.freebsd.org/D28799
    
    (cherry picked from commit d2b3fadf2db56131376a71b0597876b591a6aee4)
---
 contrib/libcxxrt/exception.cc        | 30 ++++++------------------------
 contrib/libcxxrt/libelftc_dem_gnu3.c | 14 +++++++++++---
 contrib/libcxxrt/unwind-arm.h        |  3 ++-
 contrib/libcxxrt/unwind-itanium.h    | 10 +++++++---
 4 files changed, 26 insertions(+), 31 deletions(-)

diff --git a/contrib/libcxxrt/exception.cc b/contrib/libcxxrt/exception.cc
index 0de878e9e6db..0fb26ddb4ed2 100644
--- a/contrib/libcxxrt/exception.cc
+++ b/contrib/libcxxrt/exception.cc
@@ -572,19 +572,6 @@ static void free_exception(char *e)
 	}
 }
 
-#ifdef __LP64__
-/**
- * There's an ABI bug in __cxa_exception: unwindHeader requires 16-byte
- * alignment but it was broken by the addition of the referenceCount.
- * The unwindHeader is at offset 0x58 in __cxa_exception.  In order to keep
- * compatibility with consumers of the broken __cxa_exception, explicitly add
- * padding on allocation (and account for it on free).
- */
-static const int exception_alignment_padding = 8;
-#else
-static const int exception_alignment_padding = 0;
-#endif
-
 /**
  * Allocates an exception structure.  Returns a pointer to the space that can
  * be used to store an object of thrown_size bytes.  This function will use an
@@ -593,19 +580,16 @@ static const int exception_alignment_padding = 0;
  */
 extern "C" void *__cxa_allocate_exception(size_t thrown_size)
 {
-	size_t size = exception_alignment_padding + sizeof(__cxa_exception) +
-	    thrown_size;
+	size_t size = thrown_size + sizeof(__cxa_exception);
 	char *buffer = alloc_or_die(size);
-	return buffer + exception_alignment_padding + sizeof(__cxa_exception);
+	return buffer+sizeof(__cxa_exception);
 }
 
 extern "C" void *__cxa_allocate_dependent_exception(void)
 {
-	size_t size = exception_alignment_padding +
-	    sizeof(__cxa_dependent_exception);
+	size_t size = sizeof(__cxa_dependent_exception);
 	char *buffer = alloc_or_die(size);
-	return buffer + exception_alignment_padding +
-	    sizeof(__cxa_dependent_exception);
+	return buffer+sizeof(__cxa_dependent_exception);
 }
 
 /**
@@ -633,8 +617,7 @@ extern "C" void __cxa_free_exception(void *thrown_exception)
 		}
 	}
 
-	free_exception(reinterpret_cast<char*>(ex) -
-	    exception_alignment_padding);
+	free_exception(reinterpret_cast<char*>(ex));
 }
 
 static void releaseException(__cxa_exception *exception)
@@ -661,8 +644,7 @@ void __cxa_free_dependent_exception(void *thrown_exception)
 	{
 		releaseException(realExceptionFromException(reinterpret_cast<__cxa_exception*>(ex)));
 	}
-	free_exception(reinterpret_cast<char*>(ex) -
-	    exception_alignment_padding);
+	free_exception(reinterpret_cast<char*>(ex));
 }
 
 /**
diff --git a/contrib/libcxxrt/libelftc_dem_gnu3.c b/contrib/libcxxrt/libelftc_dem_gnu3.c
index a8d061591826..6e88f7b4bb4c 100644
--- a/contrib/libcxxrt/libelftc_dem_gnu3.c
+++ b/contrib/libcxxrt/libelftc_dem_gnu3.c
@@ -541,9 +541,19 @@ __cxa_demangle_gnu3(const char *org)
 	char *rtn;
 	bool has_ret, more_type;
 
-	if (org == NULL || (org_len = strlen(org)) < 2)
+	if (org == NULL)
 		return (NULL);
 
+	org_len = strlen(org);
+	// Try demangling as a type for short encodings
+	if ((org_len < 2) || (org[0] != '_' || org[1] != 'Z' )) {
+		if (!cpp_demangle_data_init(&ddata, org))
+			return (NULL);
+		if (!cpp_demangle_read_type(&ddata, 0))
+			goto clean;
+		rtn = vector_str_get_flat(&ddata.output, (size_t *) NULL);
+		goto clean;
+	}
 	if (org_len > 11 && !strncmp(org, "_GLOBAL__I_", 11)) {
 		if ((rtn = malloc(org_len + 19)) == NULL)
 			return (NULL);
@@ -552,8 +562,6 @@ __cxa_demangle_gnu3(const char *org)
 		return (rtn);
 	}
 
-	if (org[0] != '_' || org[1] != 'Z')
-		return (NULL);
 
 	if (!cpp_demangle_data_init(&ddata, org + 2))
 		return (NULL);
diff --git a/contrib/libcxxrt/unwind-arm.h b/contrib/libcxxrt/unwind-arm.h
index a4bf1bd058bc..ec81237e573b 100644
--- a/contrib/libcxxrt/unwind-arm.h
+++ b/contrib/libcxxrt/unwind-arm.h
@@ -29,6 +29,7 @@
  */
  typedef enum
 {
+	_URC_NO_REASON = 0,
 	_URC_OK = 0,                /* operation completed successfully */
 	_URC_FOREIGN_EXCEPTION_CAUGHT = 1,
 	_URC_END_OF_STACK = 5,
@@ -96,7 +97,7 @@ struct _Unwind_Exception
 	} pr_cache;
 	/** Force alignment of next item to 8-byte boundary */
 	long long int :0;
-};
+} __attribute__((__aligned__(8)));
 
 /* Unwinding functions */
 _Unwind_Reason_Code _Unwind_RaiseException(struct _Unwind_Exception *ucbp);
diff --git a/contrib/libcxxrt/unwind-itanium.h b/contrib/libcxxrt/unwind-itanium.h
index 0ca9488605aa..199d91de283d 100644
--- a/contrib/libcxxrt/unwind-itanium.h
+++ b/contrib/libcxxrt/unwind-itanium.h
@@ -40,6 +40,7 @@ extern "C" {
 typedef enum
   {
     _URC_NO_REASON = 0,
+    _URC_OK = 0,
     _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
     _URC_FATAL_PHASE2_ERROR = 2,
     _URC_FATAL_PHASE1_ERROR = 3,
@@ -78,9 +79,12 @@ struct _Unwind_Exception
   {
     uint64_t exception_class;
     _Unwind_Exception_Cleanup_Fn exception_cleanup;
-    unsigned long private_1;
-    unsigned long private_2;
-  } ;
+    uintptr_t private_1;
+    uintptr_t private_2;
+#if __SIZEOF_POINTER__ == 4
+    uint32_t reserved[3];
+#endif
+  } __attribute__((__aligned__));
 
 extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
 extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202102211201.11LC1Y8H069697>