[LLVMdev] Counting pointers to functions
guyadini
guyadini at gmail.com
Wed Mar 30 08:12:39 PDT 2011
Hi all,
I'm trying to write an LLVM pass which would determine whether there is any
pointer which ever points to a function. I couldn't figure out if there is
any existing pass which does something of the kind (maybe some analysis pass
which I'm not aware of?).
Of course, I could just iterate over all values, and check whether they
point to functions (as in a similar recent post). However, this will not
always be sufficient - for example, consider the following C code:
#include "stdio.h"
int foo(){
printf ("Reached function foo\n");
return 0;
}
int bar(){
printf("Reached function bar\n");
return 1;
}
int main(){
int (*f_ptr)() = &foo;
(*f_ptr)();
int diff = (int)&bar- (int)&foo;
f_ptr = (int (*)()) ( (int)f_ptr + diff);
(*f_ptr)();
return 0;
}
This code changes f_ptr from pointing at the function foo to pointing at the
function bar, by explicitly advancing the pointer by the difference in
memory addresses between them.
What can I do to catch that kind of behavior?
Thanks for the help (as usual),
Guy
--
View this message in context: http://old.nabble.com/Counting-pointers-to-functions-tp31278058p31278058.html
Sent from the LLVM - Dev mailing list archive at Nabble.com.
More information about the llvm-dev
mailing list