https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66830

            Bug ID: 66830
           Summary: Problem with C++ unique symbols in plugins
           Product: gcc
           Version: 4.9.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pleuba at swissonline dot ch
  Target Milestone: ---

I have a problem in an application loading several plugins using the same
library containing a static variable (object of class, not POD) in an inline
function.

The compiler generates STB_GNU_UNIQUE symbols for the the variable and its
guard.

Scenario:
- dlopen plugin1 (dynamic loader detect the unique variables and mark DSO as
not unloadable)
- dlopen plugin2 (dynamic loader will uses the unique variables of plugin1 and
do NOT mark DSO as unloadable, because its unique symbol is not used)
- Invoke some code in plugin2 that call the inline function, so the variable
(of plugin 1) is constructed and its guard marked initialized, but the
destructor of the variable is incorrectly registered with __cxa_atexit to be
called on unload of plugin2.
- dlclose the plugin2, so it is unloaded, __CXA_finalize calls the destructor
of the global variable owned by plugin1 !, keeping the guard marked as
initialised.
- If we reload the plugin2, it will not reconstruct the global variable as it
is still marked as initialised and access it. This results either immediately
or later in crash.

Using compiler flag -fno-gnu-unique prevents the problem.

Is this problem already known ?

Philippe

Reply via email to