Disable LLVM & Subzero stack traces and crash handling

LLVM has custom crash handling and stack trace printing code which may
interfere with the application's error handling. Specifically,
AddressSanitizer makes calls to SymInitialize() and SymSetOptions().

This change disables the config options, and adds a missing preprocessor
conditional for ENABLE_BACKTRACES on Windows to match the Unix behavior.

Bug: chromium:1033484
Change-Id: I3aa35d418212448c15eba4b0c3cc5b55c2da006e
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/39888
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/third_party/llvm-7.0/configs/android/include/llvm/Config/config.h b/third_party/llvm-7.0/configs/android/include/llvm/Config/config.h
index 6f648b2..04e89df 100644
--- a/third_party/llvm-7.0/configs/android/include/llvm/Config/config.h
+++ b/third_party/llvm-7.0/configs/android/include/llvm/Config/config.h
@@ -8,10 +8,10 @@
 #define BUG_REPORT_URL "https://bugs.llvm.org/"
 
 /* Define to 1 to enable backtraces, and to 0 otherwise. */
-/* #undef ENABLE_BACKTRACES */
+#define ENABLE_BACKTRACES 0
 
 /* Define to 1 to enable crash overrides, and to 0 otherwise. */
-/* #undef ENABLE_CRASH_OVERRIDES */
+#define ENABLE_CRASH_OVERRIDES 0
 
 /* Define to 1 if you have the `backtrace' function. */
 /* #undef HAVE_BACKTRACE */
diff --git a/third_party/llvm-7.0/configs/darwin/include/llvm/Config/config.h b/third_party/llvm-7.0/configs/darwin/include/llvm/Config/config.h
index 2e88669..28c9098 100644
--- a/third_party/llvm-7.0/configs/darwin/include/llvm/Config/config.h
+++ b/third_party/llvm-7.0/configs/darwin/include/llvm/Config/config.h
@@ -8,10 +8,10 @@
 #define BUG_REPORT_URL "https://bugs.llvm.org/"
 
 /* Define to 1 to enable backtraces, and to 0 otherwise. */
-/* #undef ENABLE_BACKTRACES */
+#define ENABLE_BACKTRACES 0
 
 /* Define to 1 to enable crash overrides, and to 0 otherwise. */
-/* #undef ENABLE_CRASH_OVERRIDES */
+#define ENABLE_CRASH_OVERRIDES 0
 
 /* Define to 1 if you have the `backtrace' function. */
 /* #undef HAVE_BACKTRACE */
@@ -70,7 +70,7 @@
 /* Define to 1 if you have the <ffi.h> header file. */
 /* #undef HAVE_FFI_H */
 
-/* Define to 1 if you have the `futimens' function. */

+/* Define to 1 if you have the `futimens' function. */
 /* #undef HAVE_FUTIMENS */
 
 /* Define to 1 if you have the `futimes' function. */
diff --git a/third_party/llvm-7.0/configs/fuchsia/include/llvm/Config/config.h b/third_party/llvm-7.0/configs/fuchsia/include/llvm/Config/config.h
index ebc7207..2161c8b 100644
--- a/third_party/llvm-7.0/configs/fuchsia/include/llvm/Config/config.h
+++ b/third_party/llvm-7.0/configs/fuchsia/include/llvm/Config/config.h
@@ -8,10 +8,10 @@
 #define BUG_REPORT_URL "https://bugs.llvm.org/"
 
 /* Define to 1 to enable backtraces, and to 0 otherwise. */
-/* #undef ENABLE_BACKTRACES */
+#define ENABLE_BACKTRACES 0
 
 /* Define to 1 to enable crash overrides, and to 0 otherwise. */
-/* #undef ENABLE_CRASH_OVERRIDES */
+#define ENABLE_CRASH_OVERRIDES 0
 
 /* Define to 1 if you have the `backtrace' function. */
 /* #undef HAVE_BACKTRACE */
diff --git a/third_party/llvm-7.0/configs/linux/include/llvm/Config/config.h b/third_party/llvm-7.0/configs/linux/include/llvm/Config/config.h
index 6e17020..0ce6620 100644
--- a/third_party/llvm-7.0/configs/linux/include/llvm/Config/config.h
+++ b/third_party/llvm-7.0/configs/linux/include/llvm/Config/config.h
@@ -8,10 +8,10 @@
 #define BUG_REPORT_URL "https://bugs.llvm.org/"
 
 /* Define to 1 to enable backtraces, and to 0 otherwise. */
-/* #undef ENABLE_BACKTRACES */
+#define ENABLE_BACKTRACES 0
 
 /* Define to 1 to enable crash overrides, and to 0 otherwise. */
-/* #undef ENABLE_CRASH_OVERRIDES */
+#define ENABLE_CRASH_OVERRIDES 0
 
 /* Define to 1 if you have the `backtrace' function. */
 /* #undef HAVE_BACKTRACE */
diff --git a/third_party/llvm-7.0/configs/windows/include/llvm/Config/config.h b/third_party/llvm-7.0/configs/windows/include/llvm/Config/config.h
index f7466bf..8a1fa6b 100644
--- a/third_party/llvm-7.0/configs/windows/include/llvm/Config/config.h
+++ b/third_party/llvm-7.0/configs/windows/include/llvm/Config/config.h
@@ -8,10 +8,10 @@
 #define BUG_REPORT_URL "https://bugs.llvm.org/"

 

 /* Define to 1 to enable backtraces, and to 0 otherwise. */

-/* #undef ENABLE_BACKTRACES */

+#define ENABLE_BACKTRACES 0

 

 /* Define to 1 to enable crash overrides, and to 0 otherwise. */

-/* #undef ENABLE_CRASH_OVERRIDES */

+#define ENABLE_CRASH_OVERRIDES 0

 

 /* Define to 1 if you have the `backtrace' function. */

 /* #undef HAVE_BACKTRACE */

diff --git a/third_party/llvm-7.0/llvm/lib/Support/Windows/Signals.inc b/third_party/llvm-7.0/llvm/lib/Support/Windows/Signals.inc
index 41eb5e5..1e087bc 100644
--- a/third_party/llvm-7.0/llvm/lib/Support/Windows/Signals.inc
+++ b/third_party/llvm-7.0/llvm/lib/Support/Windows/Signals.inc
@@ -297,6 +297,7 @@
 static void PrintStackTraceForThread(llvm::raw_ostream &OS, HANDLE hProcess,
                                      HANDLE hThread, STACKFRAME64 &StackFrame,
                                      CONTEXT *Context) {
+#if ENABLE_BACKTRACES
   // Initialize the symbol handler.
   fSymSetOptions(SYMOPT_DEFERRED_LOADS | SYMOPT_LOAD_LINES);
   fSymInitialize(hProcess, NULL, TRUE);
@@ -378,6 +379,7 @@
 
     OS << '\n';
   }
+#endif
 }
 
 namespace llvm {
diff --git a/third_party/llvm-subzero/build/Android/include/llvm/Config/config.h b/third_party/llvm-subzero/build/Android/include/llvm/Config/config.h
index 1b5d976..e8c1ecd 100644
--- a/third_party/llvm-subzero/build/Android/include/llvm/Config/config.h
+++ b/third_party/llvm-subzero/build/Android/include/llvm/Config/config.h
@@ -8,10 +8,10 @@
 #define BUG_REPORT_URL "http://llvm.org/bugs/"
 
 /* Define to 1 to enable backtraces, and to 0 otherwise. */
-#define ENABLE_BACKTRACES 1
+#define ENABLE_BACKTRACES 0
 
 /* Define to 1 to enable crash overrides, and to 0 otherwise. */
-#define ENABLE_CRASH_OVERRIDES 1
+#define ENABLE_CRASH_OVERRIDES 0
 
 /* Define to 1 if you have the `backtrace' function. */
 /* #undef HAVE_BACKTRACE */
diff --git a/third_party/llvm-subzero/build/Fuchsia/include/llvm/Config/config.h b/third_party/llvm-subzero/build/Fuchsia/include/llvm/Config/config.h
index 9180f54..c69142e 100644
--- a/third_party/llvm-subzero/build/Fuchsia/include/llvm/Config/config.h
+++ b/third_party/llvm-subzero/build/Fuchsia/include/llvm/Config/config.h
@@ -11,7 +11,7 @@
 #define ENABLE_BACKTRACES 0
 
 /* Define to 1 to enable crash overrides, and to 0 otherwise. */
-#define ENABLE_CRASH_OVERRIDES 1
+#define ENABLE_CRASH_OVERRIDES 0
 
 /* Define to 1 if you have the `backtrace' function. */
 #define HAVE_BACKTRACE 1
diff --git a/third_party/llvm-subzero/build/Linux/include/llvm/Config/config.h b/third_party/llvm-subzero/build/Linux/include/llvm/Config/config.h
index f60b2fa..2f860e1 100644
--- a/third_party/llvm-subzero/build/Linux/include/llvm/Config/config.h
+++ b/third_party/llvm-subzero/build/Linux/include/llvm/Config/config.h
@@ -8,10 +8,10 @@
 #define BUG_REPORT_URL "http://llvm.org/bugs/"
 
 /* Define to 1 to enable backtraces, and to 0 otherwise. */
-#define ENABLE_BACKTRACES 1
+#define ENABLE_BACKTRACES 0
 
 /* Define to 1 to enable crash overrides, and to 0 otherwise. */
-#define ENABLE_CRASH_OVERRIDES 1
+#define ENABLE_CRASH_OVERRIDES 0
 
 /* Define to 1 if you have the `backtrace' function. */
 #define HAVE_BACKTRACE 1
diff --git a/third_party/llvm-subzero/build/MacOS/include/llvm/Config/config.h b/third_party/llvm-subzero/build/MacOS/include/llvm/Config/config.h
index 0542613..f5298f9 100644
--- a/third_party/llvm-subzero/build/MacOS/include/llvm/Config/config.h
+++ b/third_party/llvm-subzero/build/MacOS/include/llvm/Config/config.h
@@ -8,10 +8,10 @@
 #define BUG_REPORT_URL "http://llvm.org/bugs/"
 
 /* Define to 1 to enable backtraces, and to 0 otherwise. */
-#define ENABLE_BACKTRACES 1
+#define ENABLE_BACKTRACES 0
 
 /* Define to 1 to enable crash overrides, and to 0 otherwise. */
-#define ENABLE_CRASH_OVERRIDES 1
+#define ENABLE_CRASH_OVERRIDES 0
 
 /* Define to 1 if you have the `backtrace' function. */
 #define HAVE_BACKTRACE 1
diff --git a/third_party/llvm-subzero/build/Windows/include/llvm/Config/config.h b/third_party/llvm-subzero/build/Windows/include/llvm/Config/config.h
index 7e54490..7139257 100644
--- a/third_party/llvm-subzero/build/Windows/include/llvm/Config/config.h
+++ b/third_party/llvm-subzero/build/Windows/include/llvm/Config/config.h
@@ -8,10 +8,10 @@
 #define BUG_REPORT_URL "http://llvm.org/bugs/"

 

 /* Define to 1 to enable backtraces, and to 0 otherwise. */

-#define ENABLE_BACKTRACES 1

+#define ENABLE_BACKTRACES 0

 

 /* Define to 1 to enable crash overrides, and to 0 otherwise. */

-#define ENABLE_CRASH_OVERRIDES 1

+#define ENABLE_CRASH_OVERRIDES 0

 

 /* Define to 1 if you have the `backtrace' function. */

 /* #undef HAVE_BACKTRACE */

diff --git a/third_party/llvm-subzero/lib/Support/Windows/Signals.inc b/third_party/llvm-subzero/lib/Support/Windows/Signals.inc
index f739421..38cc566 100644
--- a/third_party/llvm-subzero/lib/Support/Windows/Signals.inc
+++ b/third_party/llvm-subzero/lib/Support/Windows/Signals.inc
@@ -293,6 +293,7 @@
 static void PrintStackTraceForThread(llvm::raw_ostream &OS, HANDLE hProcess,
                                      HANDLE hThread, STACKFRAME64 &StackFrame,
                                      CONTEXT *Context) {
+#if ENABLE_BACKTRACES
   // Initialize the symbol handler.
   fSymSetOptions(SYMOPT_DEFERRED_LOADS | SYMOPT_LOAD_LINES);
   fSymInitialize(hProcess, NULL, TRUE);
@@ -374,6 +375,7 @@
 
     OS << '\n';
   }
+#endif
 }
 
 namespace llvm {