[PATCH] Fix up -fsanitize=address ctor order (PR sanitizer/77396)

Jakub Jelinek jakub@redhat.com
Thu Sep 1 08:17:00 GMT 2016


On Thu, Sep 01, 2016 at 09:58:44AM +0200, Richard Biener wrote:
> > and thus if no globals have been registered, dynamic_init_globals is NULL,
> > and without the assertion it would crash on dynamic_init_globals->size().
> > The fix would be just to do:
> >    if (!flags()->check_initialization_order ||
> > +      !dynamic_init_globals ||
> >        !CanPoisonMemory())
> >      return;
> >    bool strict_init_order = flags()->strict_init_order;
> > -  CHECK(dynamic_init_globals);
> > or so (and similarly in the other function).
> 
> Ah, so it expects sth _before_ before-dynamic-init?  At least it seems
> that globals are not only registered inbetween before/after-dynamic-init.

Yes, usually __asan_register_globals is called before
__asan_before_dynamic_init, the former in the constructor created during
asan_finish_file very late during compilation.  dynamic_init_globals is
set to non-NULL only when registering the first global with the
__has_dynamic_init flag:
  if (g->has_dynamic_init) {
    if (!dynamic_init_globals) {
      dynamic_init_globals = new(allocator_for_globals)
          VectorOfGlobals(kDynamicInitGlobalsInitialCapacity);
    }
...
That flag corresponds to a varpool node with
vnode->dynamically_initialized

In any case, I'll discuss with upstream.  Perhaps LLVM never removes
local statics or local statics with former dynamic initialization or
something similar.

	Jakub



More information about the Gcc-patches mailing list