Use ElfFile instead of dlopen for Quick

Bug: 10614658
Change-Id: I6a7e2cb0960a5d468a55d220c3fafa80bc239fa9
diff --git a/runtime/elf_file.cc b/runtime/elf_file.cc
index 0be274c..2140334 100644
--- a/runtime/elf_file.cc
+++ b/runtime/elf_file.cc
@@ -70,7 +70,10 @@
     return false;
   }
   if (file_length < sizeof(llvm::ELF::Elf32_Ehdr)) {
-    LOG(WARNING) << "File not large enough to contain ELF header: " << file_->GetPath();
+    if (writable) {
+      LOG(WARNING) << "File size " << file_length
+                   << " not large enough to contain ELF header: " << file_->GetPath();
+    }
     return false;
   }
 
@@ -78,7 +81,6 @@
     // first just map ELF header to get program header size information
     size_t elf_header_size = sizeof(llvm::ELF::Elf32_Ehdr);
     if (!SetMap(MemMap::MapFile(elf_header_size, prot, flags, file_->Fd(), 0))) {
-      LOG(WARNING) << "Failed to map ELF header: " << file_->GetPath();
       return false;
     }
     // then remap to cover program header
diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc
index abd1287..418af0f 100644
--- a/runtime/oat_file.cc
+++ b/runtime/oat_file.cc
@@ -63,10 +63,16 @@
                        bool executable) {
   CHECK(!filename.empty()) << location;
   CheckLocation(filename);
-  // If we are trying to execute, we need to use dlopen.
+#ifdef ART_USE_PORTABLE_COMPILER
+  // If we are using PORTABLE, use dlopen to deal with relocations.
+  //
+  // We use our own ELF loader for Quick to deal with legacy apps that
+  // open a generated dex file by name, remove the file, then open
+  // another generated dex file with the same name. http://b/10614658
   if (executable) {
     return OpenDlopen(filename, location, requested_base);
   }
+#endif
   // If we aren't trying to execute, we just use our own ElfFile loader for a couple reasons:
   //
   // On target, dlopen may fail when compiling due to selinux restrictions on installd.
@@ -160,7 +166,9 @@
 bool OatFile::ElfFileOpen(File* file, byte* requested_base, bool writable, bool executable) {
   elf_file_.reset(ElfFile::Open(file, writable, true));
   if (elf_file_.get() == NULL) {
-    PLOG(WARNING) << "Failed to create ELF file for " << file->GetPath();
+    if (writable) {
+      PLOG(WARNING) << "Failed to open ELF file for " << file->GetPath();
+    }
     return false;
   }
   bool loaded = elf_file_->Load(executable);