From f26b0c166f97f3b6f12fe4f3ef36d6039cecd43b 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. --- build/toolchains/arm-eabi-4.2.1/setup.mk | 15 +++++++++++++-- docs/CHANGES.TXT | 10 +++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/build/toolchains/arm-eabi-4.2.1/setup.mk b/build/toolchains/arm-eabi-4.2.1/setup.mk index 4c10c07..f5ca8b4 100644 --- a/build/toolchains/arm-eabi-4.2.1/setup.mk +++ b/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/docs/CHANGES.TXT b/docs/CHANGES.TXT index faad11d..c03fc60 100644 --- a/docs/CHANGES.TXT +++ b/docs/CHANGES.TXT @@ -1,6 +1,14 @@ 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 IMPORTANT BUG FIXES: @@ -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 -- 2.11.0