Fix __get_tls() in static C library to use kernel helpers.
This is needed to fix gdbserver's handling of threaded programs,
among other things.
Change-Id: I823387c602cef9891532da946a01db14be780ab0
diff --git a/libc/Android.mk b/libc/Android.mk
index 510864f..f700ca0 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -64,7 +64,6 @@
unistd/sleep.c \
unistd/statfs.c \
unistd/strsignal.c \
- unistd/sysconf.c \
unistd/syslog.c \
unistd/system.c \
unistd/tcgetpgrp.c \
@@ -245,7 +244,6 @@
tzcode/localtime.c \
tzcode/strftime.c \
tzcode/strptime.c \
- bionic/__errno.c \
bionic/__set_errno.c \
bionic/_rand48.c \
bionic/cpuacct.c \
@@ -314,6 +312,23 @@
regex/regexec.c \
regex/regfree.c \
+# The following files are common, but must be compiled
+# with different C flags when building a static C library.
+#
+# The reason for this is the implementation of __get_tls()
+# that will differ between the shared and static versions
+# of the library.
+#
+# See comments in private/bionic_tls.h for more details.
+#
+# NOTE: bionic/pthread.c is added later to this list
+# because it needs special handling on ARM, see
+# below.
+#
+libc_static_common_src_files := \
+ unistd/sysconf.c \
+ bionic/__errno.c \
+
# Architecture specific source files go here
# =========================================================
ifeq ($(TARGET_ARCH),arm)
@@ -348,11 +363,13 @@
# can set breakpoints in them without messing
# up any thumb code.
libc_common_src_files += \
- bionic/pthread.c.arm \
bionic/pthread-rwlocks.c.arm \
bionic/pthread-timers.c.arm \
bionic/ptrace.c.arm
+libc_static_common_src_files += \
+ bionic/pthread.c.arm \
+
# these are used by the static and dynamic versions of the libc
# respectively
libc_arch_static_src_files := \
@@ -383,11 +400,13 @@
arch-x86/string/strcmp_wrapper.S \
arch-x86/string/strncmp_wrapper.S \
arch-x86/string/strlen.S \
- bionic/pthread.c \
bionic/pthread-rwlocks.c \
bionic/pthread-timers.c \
bionic/ptrace.c
+libc_static_common_src_files += \
+ bionic/pthread.c \
+
# this is needed for static versions of libc
libc_arch_static_src_files := \
arch-x86/bionic/dl_iterate_phdr_static.c
@@ -420,11 +439,14 @@
string/strncmp.c \
string/memcmp.c \
string/strlen.c \
- bionic/pthread.c \
bionic/pthread-rwlocks.c \
bionic/pthread-timers.c \
bionic/ptrace.c \
unistd/socketcalls.c
+
+libc_static_common_src_files += \
+ bionic/pthread.c \
+
endif # sh
endif # !x86
@@ -584,10 +606,12 @@
LOCAL_SRC_FILES := \
$(libc_arch_static_src_files) \
+ $(libc_static_common_src_files) \
bionic/libc_init_static.c
LOCAL_C_INCLUDES := $(libc_common_c_includes)
-LOCAL_CFLAGS := $(libc_common_cflags)
+LOCAL_CFLAGS := $(libc_common_cflags) \
+ -DLIBC_STATIC
LOCAL_MODULE := libc_nomalloc
LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
@@ -603,6 +627,7 @@
LOCAL_SRC_FILES := \
$(libc_arch_static_src_files) \
+ $(libc_static_common_src_files) \
bionic/dlmalloc.c \
bionic/malloc_debug_common.c \
bionic/libc_init_static.c
@@ -627,6 +652,7 @@
LOCAL_SRC_FILES := \
$(libc_arch_dynamic_src_files) \
+ $(libc_static_common_src_files) \
bionic/dlmalloc.c \
bionic/malloc_debug_common.c \
bionic/libc_init_dynamic.c