<html>
    <head>
      <base href="http://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 --- - Allow using ASan and UBSan together on OSX"
   href="http://llvm.org/bugs/show_bug.cgi?id=21112">21112</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Allow using ASan and UBSan together on OSX
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </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>glider@google.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>glider@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu, samsonov@google.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Copying my own letter here:

I think the UBSan+ASan hybrid is fundamentally broken on OSX for at
least the two following reasons:

1. Parts of sanitizer_common from libclang_rt.ubsan_osx.a are linked
into the main executable, which also depends on
libclang_rt.asan_osx_dynamic.dylib. The latter contains its own copy
of sanitizer_common bits, so the two tools cannot share data (e.g.
common_flags()) like they do on Linux.

2. UBSan may be initialized too late on OSX. Because there's no
.preinit_array, we can only rely on static constructors. Because the
ASan runtime library must be preloaded into the executable, when
ASan's static constructor is called for the first time, it sets the
appropriate env and calls exec() on the binary. After that ASan
runtime library is initialized before other libraries that the program
loads.
UBSan is initialized way later, when the main executable's
constructors are invoked. Not sure if that's a big issue, but it could
be in the case other libraries are also built with UBSan.

Looks like we need to put the necessary UBSan parts into the dynamic
library (something like libclang_rt.asan_ubsan_osx_dynamic.dylib) and
link that library in the case both -fsanitize=address and
-fsanitize=integer are passed to the driver. It's a good question how
to initialize UBSan in this case.</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>