<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 --- - Address sanitizer interacts badly with -Wl,--as-needed on linux"
   href="http://llvm.org/bugs/show_bug.cgi?id=15823">15823</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Address sanitizer interacts badly with -Wl,--as-needed on linux
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

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

        <tr>
          <th>Hardware</th>
          <td>PC
          </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>Driver
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>nicolasweber@gmx.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>On Ubuntu Lucid:

thakis@yearofthelinuxdesktop:/usr/local/google/chrome/src$ cat test.cc
#include <dlfcn.h>
#include <stdio.h>
#include <time.h>

int main() {
  struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts);

  printf("%p\n", dlsym(RTLD_NEXT, "malloc"));
  printf("%p\n", dlsym(RTLD_NEXT, "clock_gettime"));
}
thakis@yearofthelinuxdesktop:/usr/local/google/chrome/src$
third_party/llvm-build/Release+Asserts/bin/clang -fsanitize=address
-Wl,--as-needed -o foo test.cc -ldl -lrt 
thakis@yearofthelinuxdesktop:/usr/local/google/chrome/src$ ./foo 
ASAN:SIGSEGV
=================================================================
==2748==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc
0x000000000000 sp 0x7fff99327e98 bp 0x7fff99327ed0 T0)
AddressSanitizer can not provide additional info.
==2748==ABORTING


This happens because ld ends up not linking in librt:

thakis@yearofthelinuxdesktop:/usr/local/google/chrome/src$ ldd foo
    linux-vdso.so.1 =>  (0x00007fffc41ba000)
    libdl.so.2 => /lib/libdl.so.2 (0x00007ffa37f07000)
    libpthread.so.0 => /lib/libpthread.so.0 (0x00007ffa37cea000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007ffa37ad2000)
    libc.so.6 => /lib/libc.so.6 (0x00007ffa3774c0


However, asan (and the other sans, I think) rely on dlsym(RTLD_NEXT,
"clock_gettime") to return a valid function so that the intercepting function
can call through to the real function. But since there's no dependency on
librt.1.so, dlsym() just returns NULL.


The only thing I can think of that can be done about this is to have the driver
strip out --as-needed when doing a sanitizer build.</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>