Skip to content
Snippets Groups Projects
  • Nadav Har'El's avatar
    4bc7f599
    C++ runtime: shared-object static destructors · 4bc7f599
    Nadav Har'El authored
    
    GCC implements static destructors in shared-objects (DSO) by registering a
    single finalization function, __cxa_finalize(), to run when the DSO is
    unloaded, and each constructor calls __cxa_atexit() to register a destructor
    which __cxa_finalize() should call.
    
    This patch implements the missing __cxa_finalize() and __cxa_atexit()
    functions. The do-nothing stubs we had never registered, and never ran,
    destructors. The implementation in this patch is amazingly simple to
    write in C++11 :-)
    
    Before this fix, we had a crash when running tst-tracepoint.so twice:
    The first run ran the tracepoints' constructors, which added to the global
    linked list of tracepoints pointers into the mapped DSO. When the DSO
    was later unmapped but destructors not run, the linked list of tracepoints
    was left with pointers to unmapped memory. When we ran the test again,
    and it wanted to construct more tracepoints, it accessed the broken linked
    list and crashed.
    
    Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
    4bc7f599
    History
    C++ runtime: shared-object static destructors
    Nadav Har'El authored
    
    GCC implements static destructors in shared-objects (DSO) by registering a
    single finalization function, __cxa_finalize(), to run when the DSO is
    unloaded, and each constructor calls __cxa_atexit() to register a destructor
    which __cxa_finalize() should call.
    
    This patch implements the missing __cxa_finalize() and __cxa_atexit()
    functions. The do-nothing stubs we had never registered, and never ran,
    destructors. The implementation in this patch is amazingly simple to
    write in C++11 :-)
    
    Before this fix, we had a crash when running tst-tracepoint.so twice:
    The first run ran the tracepoints' constructors, which added to the global
    linked list of tracepoints pointers into the mapped DSO. When the DSO
    was later unmapped but destructors not run, the linked list of tracepoints
    was left with pointers to unmapped memory. When we ran the test again,
    and it wanted to construct more tracepoints, it accessed the broken linked
    list and crashed.
    
    Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
runtime.cc 8.58 KiB