Make __asan_default_options a weak function that returns a const char*.
Users may define it to override the default ASan options.
This function has to be marked with __attribute__((no_address_safety_analysis)), because it is called before ASan is fully initialized.

Add an output test checking the __asan_default_options functionality.


git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@160712 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/asan/asan_flags.h b/lib/asan/asan_flags.h
index 2d5249a..43aa3a3 100644
--- a/lib/asan/asan_flags.h
+++ b/lib/asan/asan_flags.h
@@ -25,7 +25,7 @@
 extern "C" {
 #if !defined(_WIN32)
   // We do not need to redefine the defaults right now on Windows.
-  char *__asan_default_options SANITIZER_WEAK_ATTRIBUTE;
+  const char *__asan_default_options() SANITIZER_WEAK_ATTRIBUTE;
 #endif
 }
 
@@ -89,6 +89,7 @@
   // to dump 16T+ core.
   bool disable_core;
 };
+
 Flags *flags();
 void InitializeFlags(Flags *f, const char *env);
 
diff --git a/lib/asan/asan_rtl.cc b/lib/asan/asan_rtl.cc
index 70e4b57..2f15445 100644
--- a/lib/asan/asan_rtl.cc
+++ b/lib/asan/asan_rtl.cc
@@ -128,10 +128,10 @@
   // Override from user-specified string.
 #if !defined(_WIN32)
   if (__asan_default_options) {
-    ParseFlagsFromString(f, __asan_default_options);
+    ParseFlagsFromString(f, __asan_default_options());
     if (flags()->verbosity) {
       Report("Using the defaults from __asan_default_options: %s\n",
-             __asan_default_options);
+             __asan_default_options());
     }
   }
 #endif
diff --git a/lib/asan/output_tests/default_options.cc b/lib/asan/output_tests/default_options.cc
new file mode 100644
index 0000000..d6c7029
--- /dev/null
+++ b/lib/asan/output_tests/default_options.cc
@@ -0,0 +1,12 @@
+const char *kAsanDefaultOptions="verbosity=1 foo=bar";
+
+extern "C"
+__attribute__((no_address_safety_analysis))
+const char *__asan_default_options() {
+  return kAsanDefaultOptions;
+}
+
+int main() {
+  // Check-Common: foo=bar
+  return 0;
+}
diff --git a/lib/asan/output_tests/test_output.sh b/lib/asan/output_tests/test_output.sh
index 216760d..6510043 100755
--- a/lib/asan/output_tests/test_output.sh
+++ b/lib/asan/output_tests/test_output.sh
@@ -39,6 +39,8 @@
 export ASAN_OPTIONS=""
 rm ./a.out
 
+# FIXME: some tests do not need to be ran for all the combinations of arch
+# and optimization mode.
 for t in  *.cc; do
   for b in 32 64; do
     for O in 0 1 2 3; do