Define current ABI string in android-base/macros.h

Test: make
Change-Id: I8200d7b3232edba43a583c5ff1e1b0f78c768f69
This commit is contained in:
dimitry 2017-08-23 10:25:22 +02:00
parent 7f16cad877
commit b6ba817de4
7 changed files with 27 additions and 75 deletions

View File

@ -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

View File

@ -24,26 +24,9 @@
#include <string>
#include <android-base/macros.h>
#include <backtrace/Backtrace.h>
// 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;

View File

@ -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 ";

View File

@ -11,7 +11,7 @@ cc_library {
host_supported: true,
srcs: ["native_bridge.cc"],
shared_libs: ["liblog"],
shared_libs: ["liblog", "libbase"],
export_include_dirs=["include"],

View File

@ -28,6 +28,7 @@
#include <cstring>
#include <android-base/macros.h>
#include <log/log.h>
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__

View File

@ -29,6 +29,7 @@ test_src_files := \
shared_libraries := \
liblog \
libbase \
libnativebridge \
libnativebridge-dummy

View File

@ -16,34 +16,20 @@
#include "NativeBridgeTest.h"
#include <android-base/macros.h>
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]));
}
}