• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From 124e9aace7bdf6f39054d6cef341108d0523b08b Mon Sep 17 00:00:00 2001
2From: David 'Digit' Turner <digit@android.com>
3Date: Tue, 24 May 2011 23:34:22 +0200
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
24Change-Id: I289db08a9ea567f0574bb2058516bfeb01c68a2c
25---
26 gcc-4.4.3/gcc/gthr-posix.h |   13 +++++++++++++
27 1 files changed, 13 insertions(+), 0 deletions(-)
28
29diff --git a/gcc-4.4.3/gcc/gthr-posix.h b/gcc-4.4.3/gcc/gthr-posix.h
30index 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--
541.7.6.rc0
55
56