diff --git a/ndk/build/core/build-binary.mk b/ndk/build/core/build-binary.mk index f5ebdcb44..6566fec39 100644 --- a/ndk/build/core/build-binary.mk +++ b/ndk/build/core/build-binary.mk @@ -54,6 +54,14 @@ else endif endif +# +# If LOCAL_ALLOW_UNDEFINED_SYMBOLS, the linker will allow the generation +# of a binary that uses undefined symbols. +# +ifeq ($(strip $(LOCAL_ALLOW_UNDEFINED_SYMBOLS)),) + LOCAL_LDFLAGS := $(LOCAL_LDFLAGS) $($(my)NO_UNDEFINED_LDFLAGS) +endif + # # The original Android build system allows you to use the .arm prefix # to a source file name to indicate that it should be defined in either diff --git a/ndk/build/core/clear-vars.mk b/ndk/build/core/clear-vars.mk index c9461261b..0d2702286 100644 --- a/ndk/build/core/clear-vars.mk +++ b/ndk/build/core/clear-vars.mk @@ -27,6 +27,7 @@ NDK_LOCAL_VARS := \ LOCAL_STATIC_WHOLE_LIBRARIES \ LOCAL_SHARED_LIBRARIES \ LOCAL_MAKEFILE \ + LOCAL_NO_UNDEFINED_SYMBOLS \ $(call clear-vars, $(NDK_LOCAL_VARS)) 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 3f58347c8..4c10c07bd 100644 --- a/ndk/build/toolchains/arm-eabi-4.2.1/setup.mk +++ b/ndk/build/toolchains/arm-eabi-4.2.1/setup.mk @@ -76,6 +76,10 @@ TARGET_ARFLAGS := crs TARGET_LIBGCC := $(shell $(TARGET_CC) -mthumb-interwork -print-libgcc-file-name) TARGET_LDLIBS := -Wl,-rpath-link=$(SYSROOT)/usr/lib $(TARGET_LIBGCC) +# These flags are used to ensure that a binary doesn't reference undefined +# flags. +TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined + # The ABI-specific sub-directory that the SDK tools recognize for # this toolchain's generated binaries TARGET_ABI_SUBDIR := armeabi diff --git a/ndk/docs/ANDROID-MK.TXT b/ndk/docs/ANDROID-MK.TXT index 1778ae44f..fb6bc8e8b 100644 --- a/ndk/docs/ANDROID-MK.TXT +++ b/ndk/docs/ANDROID-MK.TXT @@ -352,3 +352,12 @@ LOCAL_SHARED_LIBRARIES Note that this does not append the listed modules to the build graph, i.e. you should still add them to your application's required modules in your Application.mk + +LOCAL_ALLOW_UNDEFINED_SYMBOLS + By default, any undefined reference encountered when trying to build + a shared library will result in an "undefined symbol" error. This is a + great help to catch bugs in your source code. + + However, if for some reason you need to disable this check, set this + variable to 'true'. Note that the corresponding shared library may fail + to load at runtime.