From b6ba817de4b80ec2430383899b051e86dd2bec27 Mon Sep 17 00:00:00 2001 From: dimitry Date: Wed, 23 Aug 2017 10:25:22 +0200 Subject: [PATCH] Define current ABI string in android-base/macros.h Test: make Change-Id: I8200d7b3232edba43a583c5ff1e1b0f78c768f69 --- base/include/android-base/macros.h | 15 ++++++++++ debuggerd/libdebuggerd/include/utility.h | 19 +------------ libmemunreachable/MemUnreachable.cpp | 17 ----------- libnativebridge/Android.bp | 2 +- libnativebridge/native_bridge.cc | 20 ++----------- libnativebridge/tests/Android.mk | 1 + .../tests/NeedsNativeBridge_test.cpp | 28 +++++-------------- 7 files changed, 27 insertions(+), 75 deletions(-) diff --git a/base/include/android-base/macros.h b/base/include/android-base/macros.h index 88bbe8a73..25f2ff4ed 100644 --- a/base/include/android-base/macros.h +++ b/base/include/android-base/macros.h @@ -179,4 +179,19 @@ void UNUSED(const T&...) { } while (0) #endif +// Current ABI string +#if defined(__arm__) +#define ABI_STRING "arm" +#elif defined(__aarch64__) +#define ABI_STRING "arm64" +#elif defined(__i386__) +#define ABI_STRING "x86" +#elif defined(__x86_64__) +#define ABI_STRING "x86_64" +#elif defined(__mips__) && !defined(__LP64__) +#define ABI_STRING "mips" +#elif defined(__mips__) && defined(__LP64__) +#define ABI_STRING "mips64" +#endif + #endif // ANDROID_BASE_MACROS_H diff --git a/debuggerd/libdebuggerd/include/utility.h b/debuggerd/libdebuggerd/include/utility.h index e5e510634..f481b78b8 100644 --- a/debuggerd/libdebuggerd/include/utility.h +++ b/debuggerd/libdebuggerd/include/utility.h @@ -24,26 +24,9 @@ #include +#include #include -// Figure out the abi based on defined macros. -#if defined(__arm__) -#define ABI_STRING "arm" -#elif defined(__aarch64__) -#define ABI_STRING "arm64" -#elif defined(__mips__) && !defined(__LP64__) -#define ABI_STRING "mips" -#elif defined(__mips__) && defined(__LP64__) -#define ABI_STRING "mips64" -#elif defined(__i386__) -#define ABI_STRING "x86" -#elif defined(__x86_64__) -#define ABI_STRING "x86_64" -#else -#error "Unsupported ABI" -#endif - - struct log_t{ // Tombstone file descriptor. int tfd; diff --git a/libmemunreachable/MemUnreachable.cpp b/libmemunreachable/MemUnreachable.cpp index 5e062fde7..24fdc7f37 100644 --- a/libmemunreachable/MemUnreachable.cpp +++ b/libmemunreachable/MemUnreachable.cpp @@ -479,23 +479,6 @@ std::string Leak::ToString(bool log_contents) const { return oss.str(); } -// Figure out the abi based on defined macros. -#if defined(__arm__) -#define ABI_STRING "arm" -#elif defined(__aarch64__) -#define ABI_STRING "arm64" -#elif defined(__mips__) && !defined(__LP64__) -#define ABI_STRING "mips" -#elif defined(__mips__) && defined(__LP64__) -#define ABI_STRING "mips64" -#elif defined(__i386__) -#define ABI_STRING "x86" -#elif defined(__x86_64__) -#define ABI_STRING "x86_64" -#else -#error "Unsupported ABI" -#endif - std::string UnreachableMemoryInfo::ToString(bool log_contents) const { std::ostringstream oss; oss << " " << leak_bytes << " bytes in "; diff --git a/libnativebridge/Android.bp b/libnativebridge/Android.bp index 8b48a87e9..b3c42f072 100644 --- a/libnativebridge/Android.bp +++ b/libnativebridge/Android.bp @@ -11,7 +11,7 @@ cc_library { host_supported: true, srcs: ["native_bridge.cc"], - shared_libs: ["liblog"], + shared_libs: ["liblog", "libbase"], export_include_dirs=["include"], diff --git a/libnativebridge/native_bridge.cc b/libnativebridge/native_bridge.cc index 02b4fe7ad..e24307af5 100644 --- a/libnativebridge/native_bridge.cc +++ b/libnativebridge/native_bridge.cc @@ -28,6 +28,7 @@ #include +#include #include namespace android { @@ -243,29 +244,12 @@ bool LoadNativeBridge(const char* nb_library_filename, } } -#if defined(__arm__) -static const char* kRuntimeISA = "arm"; -#elif defined(__aarch64__) -static const char* kRuntimeISA = "arm64"; -#elif defined(__mips__) && !defined(__LP64__) -static const char* kRuntimeISA = "mips"; -#elif defined(__mips__) && defined(__LP64__) -static const char* kRuntimeISA = "mips64"; -#elif defined(__i386__) -static const char* kRuntimeISA = "x86"; -#elif defined(__x86_64__) -static const char* kRuntimeISA = "x86_64"; -#else -static const char* kRuntimeISA = "unknown"; -#endif - - bool NeedsNativeBridge(const char* instruction_set) { if (instruction_set == nullptr) { ALOGE("Null instruction set in NeedsNativeBridge."); return false; } - return strncmp(instruction_set, kRuntimeISA, strlen(kRuntimeISA) + 1) != 0; + return strncmp(instruction_set, ABI_STRING, strlen(ABI_STRING) + 1) != 0; } #ifdef __APPLE__ diff --git a/libnativebridge/tests/Android.mk b/libnativebridge/tests/Android.mk index c1e65ff98..b3861e080 100644 --- a/libnativebridge/tests/Android.mk +++ b/libnativebridge/tests/Android.mk @@ -29,6 +29,7 @@ test_src_files := \ shared_libraries := \ liblog \ + libbase \ libnativebridge \ libnativebridge-dummy diff --git a/libnativebridge/tests/NeedsNativeBridge_test.cpp b/libnativebridge/tests/NeedsNativeBridge_test.cpp index 2067ed205..c8ff743b0 100644 --- a/libnativebridge/tests/NeedsNativeBridge_test.cpp +++ b/libnativebridge/tests/NeedsNativeBridge_test.cpp @@ -16,34 +16,20 @@ #include "NativeBridgeTest.h" +#include + namespace android { static const char* kISAs[] = { "arm", "arm64", "mips", "mips64", "x86", "x86_64", "random", "64arm", "64_x86", "64_x86_64", "", "reallylongstringabcd", nullptr }; -#if defined(__arm__) -static const char* kRuntimeISA = "arm"; -#elif defined(__aarch64__) -static const char* kRuntimeISA = "arm64"; -#elif defined(__mips__) && !defined(__LP64__) -static const char* kRuntimeISA = "mips"; -#elif defined(__mips__) && defined(__LP64__) -static const char* kRuntimeISA = "mips64"; -#elif defined(__i386__) -static const char* kRuntimeISA = "x86"; -#elif defined(__x86_64__) -static const char* kRuntimeISA = "x86_64"; -#else -static const char* kRuntimeISA = "unknown"; -#endif - TEST_F(NativeBridgeTest, NeedsNativeBridge) { - EXPECT_EQ(false, NeedsNativeBridge(kRuntimeISA)); + EXPECT_EQ(false, NeedsNativeBridge(ABI_STRING)); - const size_t kISACount = sizeof(kISAs)/sizeof(kISAs[0]); - for (size_t i = 0; i < kISACount; i++) { - EXPECT_EQ(kISAs[i] == nullptr ? false : strcmp(kISAs[i], kRuntimeISA) != 0, - NeedsNativeBridge(kISAs[i])); + const size_t kISACount = sizeof(kISAs) / sizeof(kISAs[0]); + for (size_t i = 0; i < kISACount; i++) { + EXPECT_EQ(kISAs[i] == nullptr ? false : strcmp(kISAs[i], ABI_STRING) != 0, + NeedsNativeBridge(kISAs[i])); } }