ART: Make elf loading not abort
Changes elf_file code to use less CHECKs and instead return error
values (usually nullptr). This avoids aborts.
In oat_file, when loading an oat file fails, try to unlink at. If
this succeeds, on the next run we may compile again.
Bug: 17491333
Change-Id: I50fdd2edacd86f25d4dacf2180ce2a6105eaf4af
diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc
index d5142a7..1ee53b8 100644
--- a/runtime/oat_file.cc
+++ b/runtime/oat_file.cc
@@ -19,6 +19,7 @@
#include <dlfcn.h>
#include <sstream>
#include <string.h>
+#include <unistd.h>
#include "base/bit_vector.h"
#include "base/stl_util.h"
@@ -91,6 +92,14 @@
return nullptr;
}
ret.reset(OpenElfFile(file.get(), location, requested_base, false, executable, error_msg));
+
+ // Opening the file failed. Try to delete it and maybe we have more luck after it gets
+ // regenerated.
+ if (ret.get() == nullptr) {
+ LOG(WARNING) << "Attempting to unlink oat file " << filename << " that could not be opened. "
+ << "Error was: " << error_msg;
+ unlink(file->GetPath().c_str()); // Try to remove the file.
+ }
}
return ret.release();
}