[llvm-bugs] [Bug 27224] New: gcov / gcda-based profiling crashes when shared libraries are unloaded (dlclose()).

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Apr 5 12:45:23 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=27224

            Bug ID: 27224
           Summary: gcov / gcda-based profiling crashes when shared
                    libraries are unloaded (dlclose()).
           Product: compiler-rt
           Version: 3.8
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: compiler-rt
          Assignee: unassignedbugs at nondot.org
          Reporter: benoit.belley at autodesk.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 16173
  --> https://llvm.org/bugs/attachment.cgi?id=16173&action=edit
Suggested fix

I believe that GCDA profiling functions should be declared as hidden, i.e.
symbols that are not exported by shared libraries. This would allow the GCDA
based profiling to work correctly with code using dlopen/dlclose to load and
unload shared libraries. 

Each shared library must have its own copy of the following GCDA functions:

     - __gcov_flush
     - llvm_delete_flush_function_list
     - llvm_delete_writeout_function_list
     - llvm_gcda_emit_arcs
     - llvm_gcda_emit_function
     - llvm_gcda_end_file
     - llvm_gcda_increment_indirect_counter
     - llvm_gcda_start_file
     - llvm_gcda_summary_info
     - llvm_gcov_init
     - llvm_register_flush_function
     - llvm_register_writeout_function
     - llvm_writeout_files

Defining these function as "hidden" prevents a shared library from  exporting
them in its interface. The end-result is that each profiled shared library will
be guaranteed to get its own set of the GCDA functions extracted from
libclang_rt.profile.a.

These GCDA functions are referencing the static writeout_fn and flush_fn lists.
These lists are traversed when a shared library is unloaded or the program
exits through an atexit() function. It is important that each shared library
gets its own set of these lists so that the proper .gcda files are updated when
a library is unloaded.

Furthermore, if a shared library doesn't get its own set of GCDA  functions and
associated lists, it will leave dangling pointers to its own "writeout" and
"flush" functions in the static writeout_fn and flush_fn lists of another
shared library. These 
dangling pointers lead to crashes when the other shared library is unloaded or
when the program exits.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160405/3596515a/attachment.html>


More information about the llvm-bugs mailing list