Hi Hemanth,
KLEE doesn't support use of dlsym/dlopen. KLEE works best when you
have a closed program, where all the code is compiled in. If you
don't, then for calls like dlsym/dlopen KLEE will just use the native
versions, but it doesn't understand that the result you get back from
dlsym is something you are allowed to call -- and it still wouldn't be
able to do a good job of checking it since it doesn't have an LLVM IR
version of the function.
I recommend finding a way to compile all your code together so that
you don't need to use dlsym/dlopen if you wish to use KLEE
effectively.
- Daniel
On Tue, Aug 3, 2010 at 7:10 PM, Hemanth Murthy <hm2474 at columbia.edu> wrote:
> Hello All,
> I have a .so file libfoo.so which contains the definition for function int
> foo(const char*);
> My main function looks like this:
> int main {
> ?? ? ?int (*fptr) (const char *) = 0;
> ?? ? ?char *library = "/home/hemanth/Desktop/proj/samples/libfoo.so";
> ?? ? ?printf ("libary name(%s), len(%d) \n", library, strlen (library));
> ?? ? ?void *handle = dlopen (library, RTLD_NOW);
> ?? ? ?if (handle != 0)
> ? ?{
> ?printf ("dlopen worked \n");
> ?*(void **) &fptr = dlsym (handle, "foo");
> ?if (fptr != 0)
> ? ?{
> ? ? ?printf ("dlsym worked too \n");
> ? ? ?(*fptr) ("1st hello from main");
> ? ? ?(*fptr) ("2nd hello from main again");
> ? ?}
> ? ?}
> }
> I use dlopen and dlsym to locate the function foo. However klee flags an
> error saying fptr is an invalid function pointer and halts execution. Can
> klee support such function calls using function pointers?
> The o/p of the program is:
> KLEE: WARNING: calling __user_main with extra arguments.
> libary name(/home/hemanth/Desktop/proj/samples/libfoo.so), len(44)
> dlopen worked
> dlsym worked too
> KLEE: ERROR: /home/hemanth/Desktop/proj/samples/main.c:51: invalid function
> pointer
> KLEE: NOTE: now ignoring this error at this location
> terminateStateOnError Tid 23935, num_threads 0
> KLEE: ctrl-c detected, requesting interpreter to halt.
> KLEE: halting execution, dumping remaining states
> I can get the program to work using --load option, but my project uses of
> dlopen and dlsym extensively and I need to understand how to get klee to
> invoke function pointers.
> --
>
> Thanks,
> Hemanth
>
> _______________________________________________
> klee-dev mailing list
> klee-dev at keeda.stanford.edu
> http://keeda.Stanford.EDU/mailman/listinfo/klee-dev
>
>