Merge "Add directives to force stop unwinding."
diff --git a/libc/Android.bp b/libc/Android.bp
index 3391a6c..cd01efd 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -1826,7 +1826,6 @@
"bionic/dl_iterate_phdr_static.cpp",
"bionic/icu_static.cpp",
"bionic/malloc_common.cpp",
- "bionic/libc_init_static.cpp",
],
cflags: ["-DLIBC_STATIC"],
whole_static_libs: ["libc_init_static"],
diff --git a/libc/bionic/clone.cpp b/libc/bionic/clone.cpp
index d7ce37f..66ec503 100644
--- a/libc/bionic/clone.cpp
+++ b/libc/bionic/clone.cpp
@@ -34,11 +34,15 @@
#include "pthread_internal.h"
+#include "private/bionic_macros.h"
+
extern "C" pid_t __bionic_clone(uint32_t flags, void* child_stack, int* parent_tid, void* tls, int* child_tid, int (*fn)(void*), void* arg);
extern "C" __noreturn void __exit(int status);
// Called from the __bionic_clone assembler to call the thread function then exit.
extern "C" __LIBC_HIDDEN__ void __start_thread(int (*fn)(void*), void* arg) {
+ BIONIC_STOP_UNWIND;
+
pthread_internal_t* self = __get_thread();
if (self && self->tid == -1) {
self->tid = syscall(__NR_gettid);
diff --git a/libc/bionic/libc_init_dynamic.cpp b/libc/bionic/libc_init_dynamic.cpp
index 7c73950..349d488 100644
--- a/libc/bionic/libc_init_dynamic.cpp
+++ b/libc/bionic/libc_init_dynamic.cpp
@@ -52,6 +52,7 @@
#include "libc_init_common.h"
#include "private/bionic_globals.h"
+#include "private/bionic_macros.h"
#include "private/bionic_ssp.h"
#include "private/bionic_tls.h"
#include "private/KernelArgumentBlock.h"
@@ -108,6 +109,7 @@
void (*onexit)(void) __unused,
int (*slingshot)(int, char**, char**),
structors_array_t const * const structors) {
+ BIONIC_STOP_UNWIND;
KernelArgumentBlock args(raw_args);
diff --git a/libc/bionic/libc_init_static.cpp b/libc/bionic/libc_init_static.cpp
index 5e06d39..93a63b5 100644
--- a/libc/bionic/libc_init_static.cpp
+++ b/libc/bionic/libc_init_static.cpp
@@ -40,6 +40,7 @@
#include "pthread_internal.h"
#include "private/bionic_globals.h"
+#include "private/bionic_macros.h"
#include "private/bionic_page.h"
#include "private/bionic_tls.h"
#include "private/KernelArgumentBlock.h"
@@ -82,6 +83,8 @@
void (*onexit)(void) __unused,
int (*slingshot)(int, char**, char**),
structors_array_t const * const structors) {
+ BIONIC_STOP_UNWIND;
+
KernelArgumentBlock args(raw_args);
__libc_init_main_thread(args);
diff --git a/libc/private/bionic_macros.h b/libc/private/bionic_macros.h
index 303218e..b1dfc7f 100644
--- a/libc/private/bionic_macros.h
+++ b/libc/private/bionic_macros.h
@@ -66,4 +66,17 @@
return reinterpret_cast<T*>(align_up(reinterpret_cast<uintptr_t>(p), align));
}
+#if defined(__arm__)
+// Do not emit anything for arm, clang does not allow emiting an arm unwind
+// directive.
+// #define BIONIC_STOP_UNWIND asm volatile(".cantunwind")
+#define BIONIC_STOP_UNWIND
+#elif defined(__aarch64__)
+#define BIONIC_STOP_UNWIND asm volatile(".cfi_undefined x30")
+#elif defined(__i386__)
+#define BIONIC_STOP_UNWIND asm volatile(".cfi_undefined \%eip")
+#elif defined(__x86_64__)
+#define BIONIC_STOP_UNWIND asm volatile(".cfi_undefined \%rip")
+#endif
+
#endif // _BIONIC_MACROS_H_