Only do some checks when compiling against the core image.

This will avoid false negatives when running dex2oatd on apks.

bug:21865473

Change-Id: Id8eacaefae0bcf07a2ada8aedd7951854cdb5c4f
diff --git a/compiler/optimizing/optimizing_compiler.cc b/compiler/optimizing/optimizing_compiler.cc
index 1944ba6..1e51530 100644
--- a/compiler/optimizing/optimizing_compiler.cc
+++ b/compiler/optimizing/optimizing_compiler.cc
@@ -614,7 +614,8 @@
   {
     PassScope scope(HGraphBuilder::kBuilderPassName, &pass_observer);
     if (!builder.BuildGraph(*code_item)) {
-      CHECK(!shouldCompile) << "Could not build graph in optimizing compiler";
+      DCHECK(!(IsCompilingWithCoreImage() && shouldCompile))
+          << "Could not build graph in optimizing compiler";
       pass_observer.SetGraphInBadState();
       return nullptr;
     }
@@ -705,4 +706,9 @@
   return new OptimizingCompiler(driver);
 }
 
+bool IsCompilingWithCoreImage() {
+  const std::string& image = Runtime::Current()->GetImageLocation();
+  return EndsWith(image, "core.art") || EndsWith(image, "core-optimizing.art");
+}
+
 }  // namespace art