Register __llvm_profile_write_file with at_quick_exit

Bug: http://b/186576313

This allows programs to call quick_exit() to avoid static destructors
but still be able to write coverage data.

This is a workaround until we add at_quick_exit to libclang_rt.profile.

Test: Change dex2oat to call quick_exit instead of _exit and verify that
      coverage data gets written.
Change-Id: Iaaa438a4c999ca9506b9b2f9dbfd2ef37808aa16
diff --git a/toolchain-extras/profile-clang-extras.cpp b/toolchain-extras/profile-clang-extras.cpp
index 89c18b2..a80fc7d 100644
--- a/toolchain-extras/profile-clang-extras.cpp
+++ b/toolchain-extras/profile-clang-extras.cpp
@@ -36,6 +36,14 @@
   }
 }
 
+static void writeFileWithoutReturn() {
+  __llvm_profile_write_file();
+}
+
+static __attribute__((constructor)) void register_quick_exit_handler(void) {
+  at_quick_exit(writeFileWithoutReturn);
+}
+
 __attribute__((weak)) int init_profile_extras_once = 0;
 
 // Initialize libprofile-extras: