Add patchoat check that input oat file has patch section.

Do this check before opening the output file in case this could be
causing the file to become truncated.

Bug: 27723864

(cherry-picked from commit 99503b9805def2ed7d4fe4bf285c6fdd8ddce6ed)

Change-Id: Icf71016adae5404e4f8588f2f5e23da6405ef2e7
diff --git a/runtime/elf_file.cc b/runtime/elf_file.cc
index 3b4b88d..096f003 100644
--- a/runtime/elf_file.cc
+++ b/runtime/elf_file.cc
@@ -1830,6 +1830,14 @@
   }
 }
 
+bool ElfFile::HasSection(const std::string& name) const {
+  if (elf64_.get() != nullptr) {
+    return elf64_->FindSectionByName(name) != nullptr;
+  } else {
+    return elf32_->FindSectionByName(name) != nullptr;
+  }
+}
+
 uint64_t ElfFile::FindSymbolAddress(unsigned section_type,
                                     const std::string& symbol_name,
                                     bool build_map) {
diff --git a/runtime/elf_file.h b/runtime/elf_file.h
index b5229b5..c3616f7 100644
--- a/runtime/elf_file.h
+++ b/runtime/elf_file.h
@@ -69,6 +69,8 @@
 
   bool GetSectionOffsetAndSize(const char* section_name, uint64_t* offset, uint64_t* size) const;
 
+  bool HasSection(const std::string& name) const;
+
   uint64_t FindSymbolAddress(unsigned section_type,
                              const std::string& symbol_name,
                              bool build_map);