http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55617
--- Comment #12 from Alexander Potapenko <glider at google dot com> 2013-01-30 14:32:54 UTC --- > The question is why does... > > if (builtin_decl_implicit_p (BUILT_IN_ASAN_INIT)) > return; > > in initialize_sanitizer_builtins() not emit a __asan_init while apparently... I'm guessing initialize_sanitizer_builtins() just warms something up, but doesn't actually emit any code. IANAGCCH though. > tree fn = builtin_decl_implicit (BUILT_IN_ASAN_INIT); > > in asan_finish_file() emits an apparenty unnecessary one in the wrong section. This one is a necessary one. asan_finish_file inserts __asan_init into the array of constructors (aka __mod_init_func section). But for some reason it is inserted at the end of that array, while the constructors are being executed from the start of the array at program startup. That's why the program crashes (because it's trying to execute some instrumented code that accesses the shadow memory, which isn't mapped yet), and the real question is how do we put the new constructor first provided that the ctor priorities do not work well on Darwin.