Generate SHA-1 build ID for host-generated *.oat files (1/2).

For host-generated *.oat files, generate a SHA-1 build ID based on the
file content and write it to .note.gnu.build-id ELF section.  This
should allow various developer tools like profilers correlate the data
captured for files like boot.oat on the device with the corresponding
known version of the file during an offline analysis.

Test: Verified that boot.oat contains the build ID section now (with
      this change and https://android-review.googlesource.com/#/c/275630
      applied)
Test: Added ElfWriterTest::CheckBuildIdPresent test.
Test: make test-art-host
Bug: 31292208
Change-Id: Ie5e89da2ef87e34c27c0237ab34ddc7d2dc0aa3b
diff --git a/compiler/elf_writer_test.cc b/compiler/elf_writer_test.cc
index d5f1663..b580049 100644
--- a/compiler/elf_writer_test.cc
+++ b/compiler/elf_writer_test.cc
@@ -101,6 +101,25 @@
   }
 }
 
+TEST_F(ElfWriterTest, CheckBuildIdPresent) {
+  std::string elf_location = GetCoreOatLocation();
+  std::string elf_filename = GetSystemImageFilename(elf_location.c_str(), kRuntimeISA);
+  LOG(INFO) << "elf_filename=" << elf_filename;
+
+  std::unique_ptr<File> file(OS::OpenFileForReading(elf_filename.c_str()));
+  ASSERT_TRUE(file.get() != nullptr);
+  {
+    std::string error_msg;
+    std::unique_ptr<ElfFile> ef(ElfFile::Open(file.get(),
+                                              false,
+                                              false,
+                                              /*low_4gb*/false,
+                                              &error_msg));
+    CHECK(ef.get() != nullptr) << error_msg;
+    EXPECT_TRUE(ef->HasSection(".note.gnu.build-id"));
+  }
+}
+
 TEST_F(ElfWriterTest, EncodeDecodeOatPatches) {
   const std::vector<std::vector<uintptr_t>> test_data {
       { 0, 4, 8, 15, 128, 200 },