1From 1fc21976be58987f036caa1103b821d51449af05 Mon Sep 17 00:00:00 2001 2From: David 'Digit' Turner <digit@google.com> 3Date: Fri, 17 Feb 2012 19:38:08 +0100 4Subject: gcc: prevent crash on Eclair and older platforms. 5 6The point of this patch is to work-around a bug in the Eclair 7dynamic linker, which doesn't support weak symbols. By default, 8libsupc++ and libstdc++ generate static C++ constructors that 9reference weak symbols. 10 11When they are statically linked into shared libraries, the 12corresponding code is referenced in its .init_array section 13and run when the shared library is loaded. 14 15On Eclair and previous release, the weak symbol is not resolved 16before the constructor are launched, resulting in a crash when 17the PLT entry tries to jump to address 0. 18 19By not generating weak symbol references, we avoid the problem 20completely. And we don't need them because the pthread symbols 21are all in the C library on Android, unlike legacy Linux systems 22which put them in libpthread.so (and provide weak stubs in libc.so). 23--- 24 gcc-4.8/libgcc/gthr-posix.h | 13 +++++++++++++ 25 gcc-4.9/libgcc/gthr-posix.h | 13 +++++++++++++ 26 3 files changed, 39 insertions(+) 27 28diff --git a/gcc-4.8/libgcc/gthr-posix.h b/gcc-4.8/libgcc/gthr-posix.h 29index f0d8cd7..1d03af0 100644 30--- a/gcc-4.8/libgcc/gthr-posix.h 31+++ b/gcc-4.8/libgcc/gthr-posix.h 32@@ -32,6 +32,19 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 33 #define __GTHREADS 1 34 #define __GTHREADS_CXX0X 1 35 36+/* The following should normally be in a different header file, 37+ * but I couldn't find the right location. The point of the macro 38+ * definition below is to prevent libsupc++ and libstdc++ to reference 39+ * weak symbols in their static C++ constructors. Such code crashes 40+ * when a shared object linked statically to these libraries is 41+ * loaded on Android 2.1 (Eclair) and older platform releases, due 42+ * to a dynamic linker bug. 43+ */ 44+#ifdef __ANDROID__ 45+#undef GTHREAD_USE_WEAK 46+#define GTHREAD_USE_WEAK 0 47+#endif 48+ 49 #include <pthread.h> 50 51 #if ((defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)) \ 52diff --git a/gcc-4.9/libgcc/gthr-posix.h b/gcc-4.9/libgcc/gthr-posix.h 53index 7003a91..19d7d5f 100644 54--- a/gcc-4.9/libgcc/gthr-posix.h 55+++ b/gcc-4.9/libgcc/gthr-posix.h 56@@ -32,6 +32,19 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 57 #define __GTHREADS 1 58 #define __GTHREADS_CXX0X 1 59 60+/* The following should normally be in a different header file, 61+ * but I couldn't find the right location. The point of the macro 62+ * definition below is to prevent libsupc++ and libstdc++ to reference 63+ * weak symbols in their static C++ constructors. Such code crashes 64+ * when a shared object linked statically to these libraries is 65+ * loaded on Android 2.1 (Eclair) and older platform releases, due 66+ * to a dynamic linker bug. 67+ */ 68+#ifdef __ANDROID__ 69+#undef GTHREAD_USE_WEAK 70+#define GTHREAD_USE_WEAK 0 71+#endif 72+ 73 #include <pthread.h> 74 75 #if ((defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)) \ 76-- 771.9.1.423.g4596e3a 78 79