1 From 2761d8d2cb59b5447a9ea1a5b10a1262a84211d6 Mon Sep 17 00:00:00 2001 2 From: David 'Digit' Turner <digit (a] android.com> 3 Date: Tue, 24 May 2011 23:34:22 +0200 4 Subject: [PATCH] gcc: prevent crash on Eclair and older platforms. 5 6 The point of this patch is to work-around a bug in the Eclair 7 dynamic linker, which doesn't support weak symbols. By default, 8 libsupc++ and libstdc++ generate static C++ constructors that 9 reference weak symbols. 10 11 When they are statically linked into shared libraries, the 12 corresponding code is referenced in its .init_array section 13 and run when the shared library is loaded. 14 15 On Eclair and previous release, the weak symbol is not resolved 16 before the constructor are launched, resulting in a crash when 17 the PLT entry tries to jump to address 0. 18 19 By not generating weak symbol references, we avoid the problem 20 completely. And we don't need them because the pthread symbols 21 are all in the C library on Android, unlike legacy Linux systems 22 which put them in libpthread.so (and provide weak stubs in libc.so). 23 24 Change-Id: I289db08a9ea567f0574bb2058516bfeb01c68a2c 25 --- 26 gcc-4.4.3/gcc/gthr-posix.h | 13 +++++++++++++ 27 1 files changed, 13 insertions(+), 0 deletions(-) 28 29 diff --git a/gcc-4.4.3/gcc/gthr-posix.h b/gcc-4.4.3/gcc/gthr-posix.h 30 index 27652f9..a104d91 100644 31 --- a/gcc-4.4.3/gcc/gthr-posix.h 32 +++ b/gcc-4.4.3/gcc/gthr-posix.h 33 @@ -38,6 +38,19 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 34 #define _REENTRANT 1 35 #endif 36 37 +/* The following should normally be in a different header file, 38 + * but I couldn't find the right location. The point of the macro 39 + * definition below is to prevent libsupc++ and libstdc++ to reference 40 + * weak symbols in their static C++ constructors. Such code crashes 41 + * when a shared object linked statically to these libraries is 42 + * loaded on Android 2.1 (Eclair) and older platform releases, due 43 + * to a dynamic linker bug. 44 + */ 45 +#ifdef __ANDROID__ 46 +#undef GTHREAD_USE_WEAK 47 +#define GTHREAD_USE_WEAK 0 48 +#endif 49 + 50 #include <pthread.h> 51 #include <unistd.h> 52 53 -- 54 1.7.3.1 55 56