Check libbcc build time instead of sha1sum.
Since libbcc.so is larger than 3+Mb, it takes a lot of time
to calculate its sha1 checksum. In order to shorten the startup
time, we introduce the build time check. There will be a string
called libbcc_build_time in libbcc.so and the cached file,
which will store the build time of libbcc.so.
In case that you have to upate libbcc.so frequently, and you
want to enable the sha1 checksum of libbcc, then you may change
USE_LIBBCC_SHA1SUM to true.
diff --git a/lib/bcc/CacheReader.cpp b/lib/bcc/CacheReader.cpp
index 8700eb9..b82eab5 100644
--- a/lib/bcc/CacheReader.cpp
+++ b/lib/bcc/CacheReader.cpp
@@ -144,8 +144,16 @@
}
if (memcmp(mpHeader->version, OBCC_VERSION, 4) != 0) {
- LOGE("Bad oBCC version 0x%08x\n",
- *reinterpret_cast<uint32_t *>(mpHeader->version));
+ mpHeader->version[4 - 1] = '\0'; // ensure c-style string terminated
+ LOGE("Cache file format version mismatch: lib %s cached %s\n",
+ OBCC_VERSION, mpHeader->version);
+ return false;
+ }
+
+ if (memcmp(mpHeader->libbcc_build_time, libbcc_build_time, 24) != 0) {
+ mpHeader->libbcc_build_time[24 - 1] = '\0'; // ensure terminated
+ LOGE("Build time mismatch: lib %s cached %s\n", libbcc_build_time,
+ mpHeader->libbcc_build_time);
return false;
}
diff --git a/lib/bcc/CacheWriter.cpp b/lib/bcc/CacheWriter.cpp
index c274d90..2eaa8ce 100644
--- a/lib/bcc/CacheWriter.cpp
+++ b/lib/bcc/CacheWriter.cpp
@@ -93,6 +93,7 @@
// Magic word and version
memcpy(header->magic, OBCC_MAGIC, 4);
memcpy(header->version, OBCC_VERSION, 4);
+ memcpy(header->libbcc_build_time, libbcc_build_time, 24);
// Machine Integer Type
uint32_t number = 0x00000001;
diff --git a/lib/bcc/Compiler.cpp b/lib/bcc/Compiler.cpp
index 3791f08..77bb690 100644
--- a/lib/bcc/Compiler.cpp
+++ b/lib/bcc/Compiler.cpp
@@ -149,7 +149,7 @@
if (GlobalInitialized)
return;
- LOGI("LIBBCC BUILD: %s %s\n", __DATE__, __TIME__);
+ LOGI("LIBBCC BUILD: %s\n", libbcc_build_time);
// if (!llvm::llvm_is_multithreaded())
// llvm::llvm_start_multithreaded();
@@ -238,7 +238,9 @@
llvm::createLinearScanRegisterAllocator);
// Calculate the SHA1 checksum of libbcc and libRS.
+#if defined(USE_LIBBCC_SHA1SUM)
calcFileSHA1(sha1LibBCC, pathLibBCC);
+#endif
calcFileSHA1(sha1LibRS, pathLibRS);
GlobalInitialized = true;
diff --git a/lib/bcc/Script.cpp b/lib/bcc/Script.cpp
index 588906a..8fb8fd0 100644
--- a/lib/bcc/Script.cpp
+++ b/lib/bcc/Script.cpp
@@ -204,7 +204,10 @@
CacheReader reader;
// Dependencies
+#if defined(USE_LIBBCC_SHA1SUM)
reader.addDependency(BCC_FILE_RESOURCE, pathLibBCC, sha1LibBCC);
+#endif
+
reader.addDependency(BCC_FILE_RESOURCE, pathLibRS, sha1LibRS);
if (sourceBC) {
@@ -288,7 +291,9 @@
CacheWriter writer;
// Dependencies
+#if defined(USE_LIBBCC_SHA1SUM)
writer.addDependency(BCC_FILE_RESOURCE, pathLibBCC, sha1LibBCC);
+#endif
writer.addDependency(BCC_FILE_RESOURCE, pathLibRS, sha1LibRS);
if (sourceBC) {
diff --git a/lib/bcc/Sha1Helper.cpp b/lib/bcc/Sha1Helper.cpp
index 170cb0f..da1565d 100644
--- a/lib/bcc/Sha1Helper.cpp
+++ b/lib/bcc/Sha1Helper.cpp
@@ -23,16 +23,18 @@
#include <string.h>
+#include <utils/StopWatch.h>
+
#include <sha1.h>
namespace bcc {
-
+#if defined(USE_LIBBCC_SHA1SUM)
unsigned char sha1LibBCC[20];
-unsigned char sha1LibRS[20];
-
-
char const *pathLibBCC = "/system/lib/libbcc.so";
+#endif
+
+unsigned char sha1LibRS[20];
char const *pathLibRS = "/system/lib/libRS.so";
@@ -49,6 +51,10 @@
void calcFileSHA1(unsigned char *result, char const *filename) {
+#if defined(__arm__)
+ android::StopWatch calcFileSHA1Timer("calcFileSHA1 time");
+#endif
+
FileHandle file;
if (file.open(filename, OpenMode::Read) < 0) {
diff --git a/lib/bcc/Sha1Helper.h b/lib/bcc/Sha1Helper.h
index 6ebf967..b78c3c4 100644
--- a/lib/bcc/Sha1Helper.h
+++ b/lib/bcc/Sha1Helper.h
@@ -20,10 +20,12 @@
#include <stdint.h>
namespace bcc {
+#if defined(USE_LIBBCC_SHA1SUM)
extern unsigned char sha1LibBCC[20];
- extern unsigned char sha1LibRS[20];
-
extern char const *pathLibBCC;
+#endif
+
+ extern unsigned char sha1LibRS[20];
extern char const *pathLibRS;
void calcSHA1(unsigned char *result, char const *data, size_t size);
diff --git a/lib/bcc/bcc.cpp b/lib/bcc/bcc.cpp
index f88c1e0..9efa020 100644
--- a/lib/bcc/bcc.cpp
+++ b/lib/bcc/bcc.cpp
@@ -27,6 +27,8 @@
#include <utils/StopWatch.h>
+char const libbcc_build_time[24] = __DATE__ " " __TIME__;
+
namespace bcc {
class FuncLogger {
private: