[llvm-bugs] [Bug 26989] New: -fsanitize=function doesn't work with dlopen

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Mar 18 10:43:23 PDT 2016


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

            Bug ID: 26989
           Summary: -fsanitize=function doesn't work with dlopen
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: peter at pcc.me.uk
          Reporter: vonosmas at gmail.com
                CC: llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk
    Classification: Unclassified

Reproducer:

$ cat dlopen-test.cc
#include <dlfcn.h>

int main() {
  void *dl_handle = dlopen("dlopen_test.so", RTLD_NOW | RTLD_LOCAL);
  typedef int (*IncFn)(int);
  IncFn inc = reinterpret_cast<IncFn>(dlsym(dl_handle, "my_inc"));
  return (1 != inc(0));
}
$ cat dlopen_so.cc
extern "C" int my_inc(int a) {
    return a + 1;
}
$ ./bin/clang++ -fsanitize=function dlopen_so.cc -shared -o dlopen_test.so -g
$ ./bin/clang++ -fsanitize=function dlopen-test.cc -g
$ ./a.out
dlopen-test.cc:7:16: runtime error: call to function my_inc through pointer to
incorrect function type 'int (*)(int)'
dlopen_so.cc:1: note: my_inc defined here


We have two different versions of RTTI for int (*)(int) (_ZTIFiiE) - one in the
main executable, and one in the shared library. Before the indirect call
to "my_inc" through function pointer, we verify that the prologue of "my_inc"
contains a pointer to _ZTIFiiE in the main executable, but my_inc prologue
instead contains pointer to _ZTIFiiE in shared library, which is not merged.
This leads to a false positive.

-- 
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/20160318/07c32c9c/attachment-0001.html>


More information about the llvm-bugs mailing list