From 1dbeeca5c43cdbf060a11a156a3b6e4ddc45b3f0 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Thu, 24 Sep 2009 15:48:44 -0700 Subject: [PATCH] Fix NDK usage of libgcc.a when building shared libraries The main idea is that libgcc.a should appear after object files and static libraries but before depending shared libraries. This willl force the linker to copy the libgcc.a functions required by the generated library into the target binary, instead of relying on what's available in libc.so and others. This ensures maximum portability, and prevent problems in the future when we change the toolchain, which translates to different libgcc.a functions embedded in libc.so and other exposed native libraries. However, this will make also generated shared libraries bigger, because the compiler insists on generating code that depends on a bunch of C++ support functions (even when building from C sources). An increase of about 8KB per shared library is expected. --- ndk/build/toolchains/arm-eabi-4.2.1/setup.mk | 15 +++++++++++++-- ndk/docs/CHANGES.TXT | 10 +++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ndk/build/toolchains/arm-eabi-4.2.1/setup.mk b/ndk/build/toolchains/arm-eabi-4.2.1/setup.mk index 4c10c07bd..f5ca8b45e 100644 --- a/ndk/build/toolchains/arm-eabi-4.2.1/setup.mk +++ b/ndk/build/toolchains/arm-eabi-4.2.1/setup.mk @@ -74,7 +74,7 @@ TARGET_AR := $(TOOLCHAIN_PREFIX)ar TARGET_ARFLAGS := crs TARGET_LIBGCC := $(shell $(TARGET_CC) -mthumb-interwork -print-libgcc-file-name) -TARGET_LDLIBS := -Wl,-rpath-link=$(SYSROOT)/usr/lib $(TARGET_LIBGCC) +TARGET_LDLIBS := -Wl,-rpath-link=$(SYSROOT)/usr/lib # These flags are used to ensure that a binary doesn't reference undefined # flags. @@ -84,6 +84,15 @@ TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined # this toolchain's generated binaries TARGET_ABI_SUBDIR := armeabi +# NOTE: Ensure that TARGET_LIBGCC is placed after all private objects +# and static libraries, but before any other library in the link +# command line when generating shared libraries and executables. +# +# This ensures that all libgcc.a functions required by the target +# will be included into it, instead of relying on what's available +# on other libraries like libc.so, which may change between system +# releases due to toolchain or library changes. +# define cmd-build-shared-library $(TARGET_CC) \ -nostdlib -Wl,-soname,$(notdir $@) \ @@ -93,6 +102,7 @@ $(TARGET_CC) \ $(PRIVATE_WHOLE_STATIC_LIBRARIES) \ -Wl,--no-whole-archive \ $(PRIVATE_STATIC_LIBRARIES) \ + $(TARGET_LIBGCC) \ $(PRIVATE_SHARED_LIBRARIES) \ $(PRIVATE_LDFLAGS) \ $(PRIVATE_LDLIBS) \ @@ -105,10 +115,11 @@ $(TARGET_CC) \ -Wl,-dynamic-linker,/system/bin/linker \ -Wl,--gc-sections \ -Wl,-z,nocopyreloc \ - $(PRIVATE_SHARED_LIBRARIES) \ $(TARGET_CRTBEGIN_DYNAMIC_O) \ $(PRIVATE_OBJECTS) \ $(PRIVATE_STATIC_LIBRARIES) \ + $(TARGET_LIBGCC) \ + $(PRIVATE_SHARED_LIBRARIES) \ $(PRIVATE_LDFLAGS) \ $(PRIVATE_LDLIBS) \ $(TARGET_CRTEND_O) \ diff --git a/ndk/docs/CHANGES.TXT b/ndk/docs/CHANGES.TXT index faad11db8..c03fc6093 100644 --- a/ndk/docs/CHANGES.TXT +++ b/ndk/docs/CHANGES.TXT @@ -1,5 +1,13 @@ Android NDK ChangeLog: +------------------------------------------------------------------------------- +current version + +IMPORTANT BUG FIXES: + +- Make target shared libraries portable to systems that don't use the exact same + toolchain (GCC 4.2.1) . + ------------------------------------------------------------------------------- android-ndk-1.6_r1 @@ -24,7 +32,7 @@ IMPORTANT BUG FIXES: in $(CLEAR_VARS) script. -IMPORTANT CHANGES +IMPORTANT CHANGES: - The 'sources' directory is gone. The NDK build system now looks for $(APP_PROJECT_PATH)/jni/Android.mk by default. You can override this with