Fix x86_64 build, clean up intermediate libraries.
The x86_64 build was failing because clone.S had a call to __thread_entry which
was being added to a different intermediate .a on the way to making libc.so,
and the linker couldn't guarantee statically that such a relocation would be
possible.
ld: error: out/target/product/generic_x86_64/obj/STATIC_LIBRARIES/libc_common_intermediates/libc_common.a(clone.o): requires dynamic R_X86_64_PC32 reloc against '__thread_entry' which may overflow at runtime; recompile with -fPIC
This patch addresses that by ensuring that the caller and callee end up in the
same intermediate .a. While I'm here, I've tried to clean up some of the mess
that led to this situation too. In particular, this removes libc/private/ from
the default include path (except for the DNS code), and splits out the DNS
code into its own library (since it's a weird special case of upstream NetBSD
code that's diverged so heavily it's unlikely ever to get back in sync).
There's more cleanup of the DNS situation possible, but this is definitely a
step in the right direction, and it's more than enough to get x86_64 building
cleanly.
Change-Id: I00425a7245b7a2573df16cc38798187d0729e7c4
diff --git a/libc/Android.mk b/libc/Android.mk
index 72a655c..20f190a 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -151,34 +151,38 @@
bionic/usleep.c \
bionic/utmp.c \
bionic/wcscoll.c \
- netbsd/gethnamaddr.c \
- netbsd/inet/nsap_addr.c \
- netbsd/resolv/__dn_comp.c \
- netbsd/resolv/__res_close.c \
- netbsd/resolv/__res_send.c \
- netbsd/resolv/herror.c \
- netbsd/resolv/res_comp.c \
- netbsd/resolv/res_data.c \
- netbsd/resolv/res_debug.c \
- netbsd/resolv/res_init.c \
- netbsd/resolv/res_mkquery.c \
- netbsd/resolv/res_query.c \
- netbsd/resolv/res_send.c \
- netbsd/resolv/res_state.c \
- netbsd/resolv/res_cache.c \
- netbsd/net/nsdispatch.c \
- netbsd/net/getaddrinfo.c \
- netbsd/net/getnameinfo.c \
- netbsd/net/getservbyname.c \
- netbsd/net/getservent.c \
- netbsd/net/base64.c \
- netbsd/net/getservbyport.c \
- netbsd/nameser/ns_name.c \
- netbsd/nameser/ns_parse.c \
- netbsd/nameser/ns_ttl.c \
- netbsd/nameser/ns_netint.c \
- netbsd/nameser/ns_print.c \
- netbsd/nameser/ns_samedomain.c \
+
+
+libc_dns_src_files += \
+ netbsd/gethnamaddr.c \
+ netbsd/inet/nsap_addr.c \
+ netbsd/nameser/ns_name.c \
+ netbsd/nameser/ns_netint.c \
+ netbsd/nameser/ns_parse.c \
+ netbsd/nameser/ns_print.c \
+ netbsd/nameser/ns_samedomain.c \
+ netbsd/nameser/ns_ttl.c \
+ netbsd/net/base64.c \
+ netbsd/net/getaddrinfo.c \
+ netbsd/net/getnameinfo.c \
+ netbsd/net/getservbyname.c \
+ netbsd/net/getservbyport.c \
+ netbsd/net/getservent.c \
+ netbsd/net/nsdispatch.c \
+ netbsd/resolv/__dn_comp.c \
+ netbsd/resolv/herror.c \
+ netbsd/resolv/res_cache.c \
+ netbsd/resolv/__res_close.c \
+ netbsd/resolv/res_comp.c \
+ netbsd/resolv/res_data.c \
+ netbsd/resolv/res_debug.c \
+ netbsd/resolv/res_init.c \
+ netbsd/resolv/res_mkquery.c \
+ netbsd/resolv/res_query.c \
+ netbsd/resolv/__res_send.c \
+ netbsd/resolv/res_send.c \
+ netbsd/resolv/res_state.c \
+
# These are shared by all the 32-bit targets, but not the 64-bit ones.
ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86))
@@ -254,6 +258,7 @@
bionic/stubs.cpp \
bionic/sysconf.cpp \
bionic/tdestroy.cpp \
+ bionic/__thread_entry.cpp \
bionic/tmpfile.cpp \
bionic/wait.cpp \
bionic/wchar.cpp \
@@ -504,10 +509,10 @@
upstream-freebsd/lib/libc/string/wmemcmp.c \
libc_common_src_files += \
- bionic/pthread-atfork.c \
- bionic/pthread-rwlocks.c \
- bionic/pthread-timers.c \
- bionic/ptrace.c
+ bionic/pthread-atfork.c \
+ bionic/pthread-rwlocks.c \
+ bionic/pthread-timers.c \
+ bionic/ptrace.c \
libc_static_common_src_files += \
bionic/pthread.c \
@@ -549,8 +554,8 @@
$(LOCAL_PATH)/arch-$(TARGET_ARCH)/$(TARGET_ARCH).mk
include $(LOCAL_PATH)/arch-$(TARGET_ARCH)/$(TARGET_ARCH).mk
-libc_common_src_files += $(_LIBC_ARCH_COMMON_SRC_FILES)
-libc_common_src_files += $(_LIBC_ARCH_CPU_VARIANT_SRC_FILES)
+libc_bionic_src_files += $(_LIBC_ARCH_COMMON_SRC_FILES)
+libc_bionic_src_files += $(_LIBC_ARCH_CPU_VARIANT_SRC_FILES)
libc_arch_static_src_files := $(_LIBC_ARCH_STATIC_SRC_FILES)
libc_arch_dynamic_src_files := $(_LIBC_ARCH_DYNAMIC_SRC_FILES)
libc_common_additional_dependencies += $(_LIBC_ARCH_ADDITIONAL_DEPENDENCIES)
@@ -560,9 +565,6 @@
libc_common_cflags := \
-DANDROID_CHANGES \
-D_LIBC=1 \
- -DINET6 \
- -I$(LOCAL_PATH)/private \
- -DPOSIX_MISTAKE \
-Wall -Wextra \
# Try to catch typical 32-bit assumptions that break with 64-bit pointers.
@@ -616,7 +618,8 @@
# crtbrand.c needs <stdint.h> and a #define for the platform SDK version.
libc_crt_target_cflags += \
-I$(LOCAL_PATH)/include \
- -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION)
+ -I$(LOCAL_PATH)/arch-$(TARGET_ARCH)/include \
+ -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION) \
# Define some common conlyflags
libc_common_conlyflags := \
@@ -634,12 +637,6 @@
$(LOCAL_PATH)/stdio \
external/safe-iop/include
-# Needed to access private/__dso_handle.h from
-# crtbegin_xxx.S and crtend_xxx.S
-libc_crt_target_cflags += \
- -I$(LOCAL_PATH)/private \
- -I$(LOCAL_PATH)/arch-$(TARGET_ARCH)/include
-
# Define the libc run-time (crt) support object files that must be built,
# which are needed to build all other objects (shared/static libs and
# executables)
@@ -809,6 +806,29 @@
# ========================================================
+# libc_dns.a - modified NetBSD DNS code
+# ========================================================
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(libc_dns_src_files)
+LOCAL_CFLAGS := \
+ $(libc_common_cflags) \
+ -DINET6 \
+ -I$(LOCAL_PATH)/private \
+ -I$(LOCAL_PATH)/upstream-netbsd/libc/include # for NetBSD private headers
+
+LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
+LOCAL_CPPFLAGS := $(libc_common_cppflags)
+LOCAL_C_INCLUDES := $(libc_common_c_includes)
+LOCAL_MODULE := libc_dns
+LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
+LOCAL_SYSTEM_SHARED_LIBRARIES :=
+
+include $(BUILD_STATIC_LIBRARY)
+
+
+# ========================================================
# libc_freebsd.a - upstream FreeBSD C library code
# ========================================================
#
@@ -845,6 +865,7 @@
LOCAL_SRC_FILES := $(libc_upstream_netbsd_src_files)
LOCAL_CFLAGS := \
$(libc_common_cflags) \
+ -DPOSIX_MISTAKE \
-I$(LOCAL_PATH)/upstream-netbsd \
-I$(LOCAL_PATH)/upstream-netbsd/libc/include \
-include upstream-netbsd/netbsd-compat.h
@@ -883,8 +904,7 @@
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(libc_common_src_files)
-LOCAL_CFLAGS := $(libc_common_cflags) \
- -I$(LOCAL_PATH)/upstream-netbsd/libc/include # for netbsd private headers
+LOCAL_CFLAGS := $(libc_common_cflags)
LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
LOCAL_CPPFLAGS := $(libc_common_cppflags)
LOCAL_C_INCLUDES := $(libc_common_c_includes)
@@ -893,9 +913,11 @@
LOCAL_WHOLE_STATIC_LIBRARIES := \
libbionic_ssp \
libc_bionic \
+ libc_dns \
libc_freebsd \
libc_netbsd \
- libc_tzcode
+ libc_tzcode \
+
LOCAL_SYSTEM_SHARED_LIBRARIES :=
# TODO: split out the asflags.