[llvm-branch-commits] [libcxxabi] 29521dc - Patches from emscripten 2.0.33
Sam Clegg via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Nov 4 09:02:59 PDT 2021
Author: Sam Clegg
Date: 2021-11-04T09:02:39-07:00
New Revision: 29521dc528ba3714fe315fbf9a4ca7154368869d
URL: https://github.com/llvm/llvm-project/commit/29521dc528ba3714fe315fbf9a4ca7154368869d
DIFF: https://github.com/llvm/llvm-project/commit/29521dc528ba3714fe315fbf9a4ca7154368869d.diff
LOG: Patches from emscripten 2.0.33
Added:
Modified:
compiler-rt/lib/asan/asan_flags.cpp
compiler-rt/lib/asan/asan_posix.cpp
compiler-rt/lib/lsan/lsan_allocator.cpp
compiler-rt/lib/lsan/lsan_allocator.h
compiler-rt/lib/lsan/lsan_interceptors.cpp
compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
compiler-rt/lib/ubsan/ubsan_flags.cpp
libcxxabi/src/cxa_exception.h
libcxxabi/src/cxa_handlers.cpp
libcxxabi/src/cxa_thread_atexit.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/asan/asan_flags.cpp b/compiler-rt/lib/asan/asan_flags.cpp
index 197dfb23661af..5c47926c07e42 100644
--- a/compiler-rt/lib/asan/asan_flags.cpp
+++ b/compiler-rt/lib/asan/asan_flags.cpp
@@ -128,8 +128,9 @@ void InitializeFlags() {
#if SANITIZER_EMSCRIPTEN
char *options;
// Override from Emscripten Module.
+ // TODO: add EM_ASM_I64 and avoid using a double for a 64-bit pointer.
#define MAKE_OPTION_LOAD(parser, name) \
- options = (char*) EM_ASM_INT({ \
+ options = (char*)(long)EM_ASM_DOUBLE({ \
return withBuiltinMalloc(function () { \
return allocateUTF8(Module[name] || 0); \
}); \
diff --git a/compiler-rt/lib/asan/asan_posix.cpp b/compiler-rt/lib/asan/asan_posix.cpp
index 6e49520498158..b19f28a2484db 100644
--- a/compiler-rt/lib/asan/asan_posix.cpp
+++ b/compiler-rt/lib/asan/asan_posix.cpp
@@ -115,7 +115,7 @@ void PlatformTSDDtor(void *tsd) {
atomic_signal_fence(memory_order_seq_cst);
AsanThread::TSDDtor(tsd);
}
-#elif !SANITIZER_EMSCRIPTEN
+#else
static pthread_key_t tsd_key;
static bool tsd_key_inited = false;
void AsanTSDInit(void (*destructor)(void *tsd)) {
diff --git a/compiler-rt/lib/lsan/lsan_allocator.cpp b/compiler-rt/lib/lsan/lsan_allocator.cpp
index 5dff571e4a059..a682cc1fa8caf 100644
--- a/compiler-rt/lib/lsan/lsan_allocator.cpp
+++ b/compiler-rt/lib/lsan/lsan_allocator.cpp
@@ -28,7 +28,7 @@ extern "C" void *memset(void *ptr, int value, uptr num);
namespace __lsan {
#if defined(__i386__) || defined(__arm__) || defined(__wasm32__)
static const uptr kMaxAllowedMallocSize = 1UL << 30;
-#elif defined(__mips64) || defined(__aarch64__)
+#elif defined(__mips64) || defined(__aarch64__) || defined(__wasm64__)
static const uptr kMaxAllowedMallocSize = 4UL << 30;
#else
static const uptr kMaxAllowedMallocSize = 8UL << 30;
diff --git a/compiler-rt/lib/lsan/lsan_allocator.h b/compiler-rt/lib/lsan/lsan_allocator.h
index 050a9143bc014..a15fb0434e255 100644
--- a/compiler-rt/lib/lsan/lsan_allocator.h
+++ b/compiler-rt/lib/lsan/lsan_allocator.h
@@ -50,7 +50,7 @@ struct ChunkMetadata {
};
#if defined(__mips64) || defined(__aarch64__) || defined(__i386__) || \
- defined(__arm__) || defined(__wasm32__)
+ defined(__arm__) || defined(__wasm__)
static const uptr kRegionSizeLog = 20;
static const uptr kNumRegions = SANITIZER_MMAP_RANGE_SIZE >> kRegionSizeLog;
template <typename AddressSpaceView>
diff --git a/compiler-rt/lib/lsan/lsan_interceptors.cpp b/compiler-rt/lib/lsan/lsan_interceptors.cpp
index e90bcb50d0f3a..e4e1d75b84ba5 100644
--- a/compiler-rt/lib/lsan/lsan_interceptors.cpp
+++ b/compiler-rt/lib/lsan/lsan_interceptors.cpp
@@ -532,7 +532,8 @@ namespace __lsan {
void InitializeInterceptors() {
// Fuchsia doesn't use interceptors that require any setup.
-#if !SANITIZER_FUCHSIA && !SANITIZER_EMSCRIPTEN
+#if !SANITIZER_FUCHSIA
+#if !SANITIZER_EMSCRIPTEN
InitializeSignalInterceptors();
INTERCEPT_FUNCTION(malloc);
@@ -562,6 +563,7 @@ void InitializeInterceptors() {
LSAN_MAYBE_INTERCEPT_PTHREAD_ATFORK;
LSAN_MAYBE_INTERCEPT_STRERROR;
+#endif // !SANITIZER_EMSCRIPTEN
#if !SANITIZER_NETBSD && !SANITIZER_FREEBSD
if (pthread_key_create(&g_thread_finalize_key, &thread_finalize)) {
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index d1738e0c2aecf..4b16ca8930b35 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -261,8 +261,11 @@ uptr internal_write(fd_t fd, const void *buf, uptr count) {
uptr internal_ftruncate(fd_t fd, uptr size) {
sptr res;
#if SANITIZER_EMSCRIPTEN
+ // The __SYSCALL_LL_O macros that musl uses to split 64-bit arguments
+ // doesn't work in C++ code so we have to do it manually.
+ union { long long ll; long l[2]; } split{ .ll = size };
HANDLE_EINTR(res, (sptr)internal_syscall(SYSCALL(ftruncate), fd,
- 0, size, 0));
+ split.l[0], split.l[1]));
#else
HANDLE_EINTR(res, (sptr)internal_syscall(SYSCALL(ftruncate), fd,
(OFF_T)size));
@@ -483,7 +486,9 @@ uptr internal_execve(const char *filename, char *const argv[],
#if !SANITIZER_NETBSD
void internal__exit(int exitcode) {
-#if SANITIZER_FREEBSD || SANITIZER_SOLARIS
+#if SANITIZER_EMSCRIPTEN
+ __wasi_proc_exit(exitcode);
+#elif SANITIZER_FREEBSD || SANITIZER_SOLARIS
internal_syscall(SYSCALL(exit), exitcode);
#else
internal_syscall(SYSCALL(exit_group), exitcode);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index ee08024e06987..00e6dec696880 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -493,7 +493,7 @@
#define SANITIZER_INTERCEPT_MMAP SI_POSIX
#define SANITIZER_INTERCEPT_MMAP64 SI_LINUX_NOT_ANDROID
-#define SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO (SI_GLIBC || SI_ANDROID)
+#define SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO (SI_GLIBC || SI_ANDROID || SI_EMSCRIPTEN)
#define SANITIZER_INTERCEPT_MEMALIGN \
(!SI_FREEBSD && !SI_MAC && !SI_NETBSD && SI_NOT_RTEMS)
#define SANITIZER_INTERCEPT___LIBC_MEMALIGN SI_GLIBC
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
index 769fe36a90f78..27ee8dc70d513 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -427,7 +427,8 @@ struct __sanitizer_file_handle {
};
#endif
-#if SANITIZER_MAC
+// These fields are not actually pointers, and so wasm64 must use unsigned and not uptr for them
+#if SANITIZER_MAC || SANITIZER_EMSCRIPTEN
struct __sanitizer_msghdr {
void *msg_name;
unsigned msg_namelen;
diff --git a/compiler-rt/lib/ubsan/ubsan_flags.cpp b/compiler-rt/lib/ubsan/ubsan_flags.cpp
index 48bb217d45695..d5463b1fc8607 100644
--- a/compiler-rt/lib/ubsan/ubsan_flags.cpp
+++ b/compiler-rt/lib/ubsan/ubsan_flags.cpp
@@ -75,6 +75,10 @@ void InitializeFlags() {
parser.ParseString(__ubsan_default_options());
// Override from environment variable.
#if SANITIZER_EMSCRIPTEN
+#ifdef __wasm64__
+ // FIXME: support UBSAN in wasm64.
+ abort();
+#else
char *options = (char*) EM_ASM_INT({
return withBuiltinMalloc(function () {
return allocateUTF8(Module['UBSAN_OPTIONS'] || 0);
@@ -82,6 +86,7 @@ void InitializeFlags() {
});
parser.ParseString(options);
emscripten_builtin_free(options);
+#endif
#else
parser.ParseStringFromEnv("UBSAN_OPTIONS");
#endif // SANITIZER_EMSCRIPTEN
diff --git a/libcxxabi/src/cxa_exception.h b/libcxxabi/src/cxa_exception.h
index 6adc4c597792d..b6b4dd107b475 100644
--- a/libcxxabi/src/cxa_exception.h
+++ b/libcxxabi/src/cxa_exception.h
@@ -19,6 +19,18 @@
namespace __cxxabiv1 {
+#ifdef __USING_EMSCRIPTEN_EXCEPTIONS__
+
+struct _LIBCXXABI_HIDDEN __cxa_exception {
+ size_t referenceCount;
+ std::type_info *exceptionType;
+ void (*exceptionDestructor)(void *);
+ uint8_t caught;
+ uint8_t rethrown;
+};
+
+#else
+
static const uint64_t kOurExceptionClass = 0x434C4E47432B2B00; // CLNGC++\0
static const uint64_t kOurDependentExceptionClass = 0x434C4E47432B2B01; // CLNGC++\1
static const uint64_t get_vendor_and_language = 0xFFFFFFFFFFFFFF00; // mask for CLNGC++
@@ -164,6 +176,8 @@ extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals_fast ();
extern "C" _LIBCXXABI_FUNC_VIS void * __cxa_allocate_dependent_exception ();
extern "C" _LIBCXXABI_FUNC_VIS void __cxa_free_dependent_exception (void * dependent_exception);
+#endif // !__USING_EMSCRIPTEN_EXCEPTIONS__
+
} // namespace __cxxabiv1
#endif // _CXA_EXCEPTION_H
diff --git a/libcxxabi/src/cxa_handlers.cpp b/libcxxabi/src/cxa_handlers.cpp
index 713f02b3c6597..d67f6d2ce2deb 100644
--- a/libcxxabi/src/cxa_handlers.cpp
+++ b/libcxxabi/src/cxa_handlers.cpp
@@ -19,32 +19,6 @@
#include "private_typeinfo.h"
#include "include/atomic_support.h"
-namespace __cxxabiv1 {
-
-#ifdef __USING_EMSCRIPTEN_EXCEPTIONS__
-// XXX EMSCRIPTEN: Copied from cxa_exception.cpp since we don't compile that
-// file in Emscripten EH mode. Note that in no-exceptions builds we include
-// cxa_noexception.cpp which provides stubs of those anyhow.
-
-// Is it one of ours?
-uint64_t __getExceptionClass(const _Unwind_Exception* unwind_exception) {
-// On x86 and some ARM unwinders, unwind_exception->exception_class is
-// a uint64_t. On other ARM unwinders, it is a char[8]
-// See: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0038b/IHI0038B_ehabi.pdf
-// So we just copy it into a uint64_t to be sure.
- uint64_t exClass;
- ::memcpy(&exClass, &unwind_exception->exception_class, sizeof(exClass));
- return exClass;
-}
-
-bool __isOurExceptionClass(const _Unwind_Exception* unwind_exception) {
- return (__getExceptionClass(unwind_exception) & get_vendor_and_language) ==
- (kOurExceptionClass & get_vendor_and_language);
-}
-#endif
-
-}
-
namespace std
{
@@ -99,7 +73,7 @@ __attribute__((noreturn))
void
terminate() _NOEXCEPT
{
-#ifndef _LIBCXXABI_NO_EXCEPTIONS
+#if !defined(_LIBCXXABI_NO_EXCEPTIONS) && !defined(__USING_EMSCRIPTEN_EXCEPTIONS__)
// If there might be an uncaught exception
using namespace __cxxabiv1;
__cxa_eh_globals* globals = __cxa_get_globals_fast();
diff --git a/libcxxabi/src/cxa_thread_atexit.cpp b/libcxxabi/src/cxa_thread_atexit.cpp
index a940eaf2f9cc3..6510e7debd04b 100644
--- a/libcxxabi/src/cxa_thread_atexit.cpp
+++ b/libcxxabi/src/cxa_thread_atexit.cpp
@@ -112,9 +112,14 @@ extern "C" {
#ifdef HAVE___CXA_THREAD_ATEXIT_IMPL
return __cxa_thread_atexit_impl(dtor, obj, dso_symbol);
#else
+#ifndef __EMSCRIPTEN__
+ // Emscripten doesn't fully support weak undefined symbols yet
+ // https://github.com/emscripten-core/emscripten/issues/12819
if (__cxa_thread_atexit_impl) {
return __cxa_thread_atexit_impl(dtor, obj, dso_symbol);
- } else {
+ } else
+#endif
+ {
// Initialize the dtors std::__libcpp_tls_key (uses __cxa_guard_*() for
// one-time initialization and __cxa_atexit() for destruction)
static DtorsManager manager;
More information about the llvm-branch-commits
mailing list