From 22d294307882c7b2a341e9f5823b7b62ef6ed2d0 Mon Sep 17 00:00:00 2001 From: zijunzhao Date: Thu, 6 Oct 2022 18:17:52 +0000 Subject: [PATCH] Add support to ndk-build in Application.mk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: https://github.com/android/ndk/issues/837 Tests: ./run_tests.py –rebuild –filter weak_symbols_build_support Change-Id: I08b45b667a7480fc6e68d6edffeecdb14700cde0 --- build/core/default-build-commands.mk | 5 +++++ build/core/definitions.mk | 1 + .../weak_symbols_build_support/jni/Android.mk | 10 ++++++++++ .../weak_symbols_build_support/jni/Application.mk | 2 ++ .../jni/weak_symbols.cpp | 14 ++++++++++++++ 5 files changed, 32 insertions(+) create mode 100644 tests/device/weak_symbols_build_support/jni/Android.mk create mode 100644 tests/device/weak_symbols_build_support/jni/Application.mk create mode 100644 tests/device/weak_symbols_build_support/jni/weak_symbols.cpp diff --git a/build/core/default-build-commands.mk b/build/core/default-build-commands.mk index 98ee438f..6a4e00db 100644 --- a/build/core/default-build-commands.mk +++ b/build/core/default-build-commands.mk @@ -119,6 +119,11 @@ GLOBAL_CFLAGS += \ GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=2 + +ifeq ($(APP_WEAK_API_DEFS), true) + GLOBAL_CFLAGS += -D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__ +endif + GLOBAL_LDFLAGS = \ -target $(LLVM_TRIPLE)$(TARGET_PLATFORM_LEVEL) \ -no-canonical-prefixes \ diff --git a/build/core/definitions.mk b/build/core/definitions.mk index 4b5395e2..03d6d299 100644 --- a/build/core/definitions.mk +++ b/build/core/definitions.mk @@ -1192,6 +1192,7 @@ NDK_APP_VARS_OPTIONAL := \ APP_STL \ APP_STRIP_MODE \ APP_THIN_ARCHIVE \ + APP_WEAK_API_DEFS \ APP_WRAP_SH \ # NDK_ALL_ABIS is not configured yet. diff --git a/tests/device/weak_symbols_build_support/jni/Android.mk b/tests/device/weak_symbols_build_support/jni/Android.mk new file mode 100644 index 00000000..7429d9ab --- /dev/null +++ b/tests/device/weak_symbols_build_support/jni/Android.mk @@ -0,0 +1,10 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := weak_symbols +LOCAL_SRC_FILES := weak_symbols.cpp +LOCAL_STATIC_LIBRARIES := googletest_main +LOCAL_LDLIBS := -landroid +include $(BUILD_EXECUTABLE) + +$(call import-module,third_party/googletest) \ No newline at end of file diff --git a/tests/device/weak_symbols_build_support/jni/Application.mk b/tests/device/weak_symbols_build_support/jni/Application.mk new file mode 100644 index 00000000..44e21963 --- /dev/null +++ b/tests/device/weak_symbols_build_support/jni/Application.mk @@ -0,0 +1,2 @@ +APP_STL := c++_static +APP_WEAK_API_DEFS := true \ No newline at end of file diff --git a/tests/device/weak_symbols_build_support/jni/weak_symbols.cpp b/tests/device/weak_symbols_build_support/jni/weak_symbols.cpp new file mode 100644 index 00000000..49ebf71d --- /dev/null +++ b/tests/device/weak_symbols_build_support/jni/weak_symbols.cpp @@ -0,0 +1,14 @@ +#include +#include +#include + +TEST(weak_symbols, weak_symbol_enable) { + bool called = false; + if (__builtin_available(android 29, *)) { + // 0 is an arbitrary cookie. The specific value doesn't matter because + // this will never run concurrently. + ATrace_beginAsyncSection("ndk::asyncBeginEndSection", 0); + called = true; + } + ASSERT_EQ(android_get_device_api_level() >= 29, called); +} \ No newline at end of file