[LLVMbugs] [Bug 15823] New: Address sanitizer interacts badly with -Wl, --as-needed on linux

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Apr 22 15:39:23 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=15823

            Bug ID: 15823
           Summary: Address sanitizer interacts badly with -Wl,--as-needed
                    on linux
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Driver
          Assignee: unassignedclangbugs at nondot.org
          Reporter: nicolasweber at gmx.de
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

On Ubuntu Lucid:

thakis at 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 at 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 at 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 at 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.

-- 
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/20130422/8cf37fe0/attachment.html>


More information about the llvm-bugs mailing list