Index: lib/asan/asan_rtl.cc
===================================================================
--- lib/asan/asan_rtl.cc	(revision 159455)
+++ lib/asan/asan_rtl.cc	(working copy)
@@ -68,6 +68,7 @@
 static s64    FLAG_atexit = 0;
 bool    FLAG_poison_shadow = 1;
 s64 FLAG_report_globals = 1;
+bool    FLAG_initializers = 1;
 bool    FLAG_handle_segv = ASAN_NEEDS_SEGV;
 bool    FLAG_use_sigaltstack = 0;
 bool    FLAG_symbolize = 0;
@@ -257,6 +258,8 @@
     __asan_register_global(0, 0, 0);
     __asan_register_globals(0, 0);
     __asan_unregister_globals(0, 0);
+    __asan_poison_globals(0, 0);
+    __asan_unpoison_globals(0, 0);
     __asan_set_death_callback(0);
     __asan_set_error_report_callback(0);
     __asan_handle_no_return();
@@ -453,6 +456,7 @@
   IntFlagValue(options, "quarantine_size=", (s64*)&FLAG_quarantine_size);
 
   IntFlagValue(options, "atexit=", &FLAG_atexit);
+  BoolFlagValue(options, "initializers=", &FLAG_initializers);
   BoolFlagValue(options, "poison_shadow=", &FLAG_poison_shadow);
   IntFlagValue(options, "report_globals=", &FLAG_report_globals);
   BoolFlagValue(options, "handle_segv=", &FLAG_handle_segv);
Index: lib/asan/asan_interface.h
===================================================================
--- lib/asan/asan_interface.h	(revision 159455)
+++ lib/asan/asan_interface.h	(working copy)
@@ -46,6 +46,13 @@
       SANITIZER_INTERFACE_ATTRIBUTE;
   void __asan_unregister_globals(__asan_global *globals, uptr n)
       SANITIZER_INTERFACE_ATTRIBUTE;
+  // These two functions should be called before and after global initializers
+  // run, respectively.  They should be called with parameters describing all
+  // globals defined in the calling TU
+  void __asan_poison_globals(__asan_global *globals, uptr n)
+      SANITIZER_INTERFACE_ATTRIBUTE;
+  void __asan_unpoison_globals(__asan_global *globals, uptr n)
+      SANITIZER_INTERFACE_ATTRIBUTE;
 
   // These two functions are used by the instrumented code in the
   // use-after-return mode. __asan_stack_malloc allocates size bytes of
Index: lib/asan/asan_internal.h
===================================================================
--- lib/asan/asan_internal.h	(revision 159455)
+++ lib/asan/asan_internal.h	(working copy)
@@ -136,30 +136,31 @@
 # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE true
 #endif  // __APPLE__
 
-extern uptr  FLAG_quarantine_size;
-extern s64 FLAG_demangle;
-extern bool    FLAG_symbolize;
-extern s64 FLAG_v;
-extern uptr  FLAG_redzone;
-extern s64 FLAG_debug;
-extern bool    FLAG_poison_shadow;
-extern s64 FLAG_report_globals;
-extern uptr  FLAG_malloc_context_size;
-extern bool    FLAG_replace_str;
-extern bool    FLAG_replace_intrin;
-extern bool    FLAG_replace_cfallocator;
-extern bool    FLAG_mac_ignore_invalid_free;
-extern bool    FLAG_fast_unwind;
-extern bool    FLAG_use_fake_stack;
-extern uptr  FLAG_max_malloc_fill_size;
-extern s64 FLAG_exitcode;
-extern bool    FLAG_allow_user_poisoning;
-extern s64 FLAG_sleep_before_dying;
-extern bool    FLAG_handle_segv;
-extern bool    FLAG_use_sigaltstack;
-extern bool    FLAG_check_malloc_usable_size;
-extern bool    FLAG_unmap_shadow_on_exit;
-extern bool    FLAG_abort_on_error;
+extern uptr FLAG_quarantine_size;
+extern s64  FLAG_demangle;
+extern bool FLAG_symbolize;
+extern s64  FLAG_v;
+extern uptr FLAG_redzone;
+extern s64  FLAG_debug;
+extern bool FLAG_poison_shadow;
+extern s64  FLAG_report_globals;
+extern bool FLAG_initializers;
+extern uptr FLAG_malloc_context_size;
+extern bool FLAG_replace_str;
+extern bool FLAG_replace_intrin;
+extern bool FLAG_replace_cfallocator;
+extern bool FLAG_mac_ignore_invalid_free;
+extern bool FLAG_fast_unwind;
+extern bool FLAG_use_fake_stack;
+extern uptr FLAG_max_malloc_fill_size;
+extern s64  FLAG_exitcode;
+extern bool FLAG_allow_user_poisoning;
+extern s64  FLAG_sleep_before_dying;
+extern bool FLAG_handle_segv;
+extern bool FLAG_use_sigaltstack;
+extern bool FLAG_check_malloc_usable_size;
+extern bool FLAG_unmap_shadow_on_exit;
+extern bool FLAG_abort_on_error;
 
 extern int asan_inited;
 // Used to avoid infinite recursion in __asan_init().
Index: lib/asan/asan_globals.cc
===================================================================
--- lib/asan/asan_globals.cc	(revision 159455)
+++ lib/asan/asan_globals.cc	(working copy)
@@ -133,6 +133,36 @@
   // implementation. It might not be worth doing anyway.
 }
 
+// Poison all shadow memory for a single global
+static void PoisonGlobal(const Global *g) {
+  CHECK(asan_inited);
+  CHECK(FLAG_initializers);
+  CHECK(AddrIsInMem(g->beg));
+  CHECK(AddrIsAlignedByGranularity(g->beg));
+  CHECK(AddrIsAlignedByGranularity(g->size_with_redzone));
+  PoisonShadow(g->beg, g->size_with_redzone, -1);
+}
+
+static void UnpoisonGlobal(const Global *g) {
+  CHECK(asan_inited);
+  CHECK(FLAG_initializers);
+  CHECK(AddrIsInMem(g->beg));
+  CHECK(AddrIsAlignedByGranularity(g->beg));
+  CHECK(AddrIsAlignedByGranularity(g->size_with_redzone));
+  PoisonShadow(g->beg, g->size_with_redzone, 0);
+  PoisonRedZones(*g);
+}
+
+static bool IsGlobalInList(const Global *ListGlobals, uptr n, const Global *g) {
+  for (uptr i = 0; i < n; i++) {
+    if (ListGlobals[i].beg == g->beg)
+      return true;
+  }
+  return false;
+}
+
+
+
 }  // namespace __asan
 
 // ---------------------- Interface ---------------- {{{1
@@ -169,3 +199,25 @@
     UnregisterGlobal(&globals[i]);
   }
 }
+
+// Register all non TU-defined globals as poisoned
+// This will catch the "static initialization order fiasco"
+void __asan_poison_globals(__asan_global *globals, uptr n) {
+  if (!FLAG_initializers) return;
+  ScopedLock lock(&mu_for_globals);
+  for (ListOfGlobals *l = list_of_globals; l; l = l->next) {
+    //Poison only globals not defined in this TU
+    if (!IsGlobalInList(globals, n, l->g)){
+      PoisonGlobal(l->g);
+    }
+  }
+}
+
+// Clear the poison bits of all globals
+void __asan_unpoison_globals(__asan_global *globals, uptr n) {
+  if (!FLAG_initializers) return;
+  ScopedLock lock(&mu_for_globals);
+  for (ListOfGlobals *l = list_of_globals; l; l = l->next) {
+    UnpoisonGlobal(l->g);
+  }
+}
