<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - gcov / gcda-based profiling crashes when shared libraries are unloaded (dlclose())."
   href="https://llvm.org/bugs/show_bug.cgi?id=27224">27224</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>gcov / gcda-based profiling crashes when shared libraries are unloaded (dlclose()).
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>compiler-rt
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.8
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>compiler-rt
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>benoit.belley@autodesk.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=16173" name="attach_16173" title="Suggested fix">attachment 16173</a> <a href="attachment.cgi?id=16173&action=edit" title="Suggested fix">[details]</a></span>
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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>