https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77396
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Created attachment 39517 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=39517&action=edit gcc7-pr77396.patch Untested partial fix for the compiler side. It should fix the common case when this happens, but it is still possible that something from the file scope ctors isn't optimized away, yet no global vars are referenced, like: // PR sanitizer/77396 // { dg-do run } // { dg-additional-options "-O2" } // { dg-set-target-env-var ASAN_OPTIONS "check_initialization_order=true" } struct S { S () { asm volatile ("" : : : "memory"); } }; static S c; int main () { return 0; } and in that case it will still fail. I'm afraid it is too hard to fix this inside of GCC, unless we want to emit too ugly code - the __asan_{before,after}_dynamic_call calls need to be in a different function from the function that invokes the globals registration, and the latter is only emitted at the very end, so either we'd need to for -fsanitize=address disable some optimization (e.g. don't remove unused local statics), or force some useless global if there are no other globals but __asan_{before,after}_dynamic_call has been seen. All in all, IMHO it is better to change __asan_{before,after}_dynamic_call - exit early if the vector is NULL, instead of the assertion.