Call asan_init from .preinit_array.

Protected by an #ifdef, disabled by default.


git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@147932 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/asan/asan_rtl.cc b/lib/asan/asan_rtl.cc
index 57dfa2e..8944246 100644
--- a/lib/asan/asan_rtl.cc
+++ b/lib/asan/asan_rtl.cc
@@ -494,3 +494,11 @@
     Report("AddressSanitizer Init done\n");
   }
 }
+
+#if defined(ASAN_USE_PREINIT_ARRAY)
+// On Linux, we force __asan_init to be called before anyone else
+// by placing it into .preinit_array section.
+// FIXME: do we have anything like this on Mac?
+__attribute__((section(".preinit_array")))
+  typeof(__asan_init) *__asan_preinit =__asan_init;
+#endif