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.6/gcc/gthr-posix.h | 13 +++++++++++++ 25 2 files changed, 26 insertions(+), 0 deletions(-) 26 27diff --git a/gcc-4.6/gcc/gthr-posix.h b/gcc-4.6/gcc/gthr-posix.h 28index ecb06e2..8372c64 100644 29--- a/gcc-4.6/gcc/gthr-posix.h 30+++ b/gcc-4.6/gcc/gthr-posix.h 31@@ -38,6 +38,19 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 32 #define _REENTRANT 1 33 #endif 34 35+/* The following should normally be in a different header file, 36+ * but I couldn't find the right location. The point of the macro 37+ * definition below is to prevent libsupc++ and libstdc++ to reference 38+ * weak symbols in their static C++ constructors. Such code crashes 39+ * when a shared object linked statically to these libraries is 40+ * loaded on Android 2.1 (Eclair) and older platform releases, due 41+ * to a dynamic linker bug. 42+ */ 43+#ifdef __ANDROID__ 44+#undef GTHREAD_USE_WEAK 45+#define GTHREAD_USE_WEAK 0 46+#endif 47+ 48 #include <pthread.h> 49 #include <unistd.h> 50 51diff --git a/gcc-4.7/libgcc/gthr-posix.h b/gcc-4.7/libgcc/gthr-posix.h 52index a935e92..08281b7 100644 53--- a/gcc-4.7/libgcc/gthr-posix.h 54+++ b/gcc-4.7/libgcc/gthr-posix.h 55@@ -38,6 +38,19 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 56 #define _REENTRANT 1 57 #endif 58 59+/* The following should normally be in a different header file, 60+ * but I couldn't find the right location. The point of the macro 61+ * definition below is to prevent libsupc++ and libstdc++ to reference 62+ * weak symbols in their static C++ constructors. Such code crashes 63+ * when a shared object linked statically to these libraries is 64+ * loaded on Android 2.1 (Eclair) and older platform releases, due 65+ * to a dynamic linker bug. 66+ */ 67+#ifdef __ANDROID__ 68+#undef GTHREAD_USE_WEAK 69+#define GTHREAD_USE_WEAK 0 70+#endif 71+ 72 #include <pthread.h> 73 74 #if ((defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)) \ 75diff --git a/gcc-4.8/libgcc/gthr-posix.h b/gcc-4.8/libgcc/gthr-posix.h 76index f0d8cd7..1d03af0 100644 77--- a/gcc-4.8/libgcc/gthr-posix.h 78+++ b/gcc-4.8/libgcc/gthr-posix.h 79@@ -32,6 +32,19 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 80 #define __GTHREADS 1 81 #define __GTHREADS_CXX0X 1 82 83+/* The following should normally be in a different header file, 84+ * but I couldn't find the right location. The point of the macro 85+ * definition below is to prevent libsupc++ and libstdc++ to reference 86+ * weak symbols in their static C++ constructors. Such code crashes 87+ * when a shared object linked statically to these libraries is 88+ * loaded on Android 2.1 (Eclair) and older platform releases, due 89+ * to a dynamic linker bug. 90+ */ 91+#ifdef __ANDROID__ 92+#undef GTHREAD_USE_WEAK 93+#define GTHREAD_USE_WEAK 0 94+#endif 95+ 96 #include <pthread.h> 97 98 #if ((defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)) \ 99-- 1001.7.6.rc0 101 102