From 1fc21976be58987f036caa1103b821d51449af05 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Fri, 17 Feb 2012 19:38:08 +0100 Subject: gcc: prevent crash on Eclair and older platforms. The point of this patch is to work-around a bug in the Eclair dynamic linker, which doesn't support weak symbols. By default, libsupc++ and libstdc++ generate static C++ constructors that reference weak symbols. When they are statically linked into shared libraries, the corresponding code is referenced in its .init_array section and run when the shared library is loaded. On Eclair and previous release, the weak symbol is not resolved before the constructor are launched, resulting in a crash when the PLT entry tries to jump to address 0. By not generating weak symbol references, we avoid the problem completely. And we don't need them because the pthread symbols are all in the C library on Android, unlike legacy Linux systems which put them in libpthread.so (and provide weak stubs in libc.so). --- gcc-4.6/gcc/gthr-posix.h | 13 +++++++++++++ gcc-4.8/libgcc/gthr-posix.h | 13 +++++++++++++ gcc-4.9/libgcc/gthr-posix.h | 13 +++++++++++++ 3 files changed, 39 insertions(+) diff --git a/gcc-4.6/gcc/gthr-posix.h b/gcc-4.6/gcc/gthr-posix.h index ecb06e2..8372c64 100644 --- a/gcc-4.6/gcc/gthr-posix.h +++ b/gcc-4.6/gcc/gthr-posix.h @@ -38,6 +38,19 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define _REENTRANT 1 #endif +/* The following should normally be in a different header file, + * but I couldn't find the right location. The point of the macro + * definition below is to prevent libsupc++ and libstdc++ to reference + * weak symbols in their static C++ constructors. Such code crashes + * when a shared object linked statically to these libraries is + * loaded on Android 2.1 (Eclair) and older platform releases, due + * to a dynamic linker bug. + */ +#ifdef __ANDROID__ +#undef GTHREAD_USE_WEAK +#define GTHREAD_USE_WEAK 0 +#endif + #include #include diff --git a/gcc-4.8/libgcc/gthr-posix.h b/gcc-4.8/libgcc/gthr-posix.h index f0d8cd7..1d03af0 100644 --- a/gcc-4.8/libgcc/gthr-posix.h +++ b/gcc-4.8/libgcc/gthr-posix.h @@ -32,6 +32,19 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define __GTHREADS 1 #define __GTHREADS_CXX0X 1 +/* The following should normally be in a different header file, + * but I couldn't find the right location. The point of the macro + * definition below is to prevent libsupc++ and libstdc++ to reference + * weak symbols in their static C++ constructors. Such code crashes + * when a shared object linked statically to these libraries is + * loaded on Android 2.1 (Eclair) and older platform releases, due + * to a dynamic linker bug. + */ +#ifdef __ANDROID__ +#undef GTHREAD_USE_WEAK +#define GTHREAD_USE_WEAK 0 +#endif + #include #if ((defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)) \ diff --git a/gcc-4.9/libgcc/gthr-posix.h b/gcc-4.9/libgcc/gthr-posix.h index 7003a91..19d7d5f 100644 --- a/gcc-4.9/libgcc/gthr-posix.h +++ b/gcc-4.9/libgcc/gthr-posix.h @@ -32,6 +32,19 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define __GTHREADS 1 #define __GTHREADS_CXX0X 1 +/* The following should normally be in a different header file, + * but I couldn't find the right location. The point of the macro + * definition below is to prevent libsupc++ and libstdc++ to reference + * weak symbols in their static C++ constructors. Such code crashes + * when a shared object linked statically to these libraries is + * loaded on Android 2.1 (Eclair) and older platform releases, due + * to a dynamic linker bug. + */ +#ifdef __ANDROID__ +#undef GTHREAD_USE_WEAK +#define GTHREAD_USE_WEAK 0 +#endif + #include #if ((defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)) \ -- 1.9.1.423.g4596e3a