thanx i little progress
ltimer.c:5:5: error: unknown type name ‘suseconds_t’
thanx i little progress
ltimer.c:5:5: error: unknown type name ‘suseconds_t’
after including sys/time.h
ltimer.c: In function ‘gettimeofday’:
ltimer.c:10:23: error: ‘CLOCK_REALTIME’ undeclared (first use in this function)
ltimer.c:10:23: note: each undeclared identifier is reported only once for each function it appears in
If the precision of the result isn't that important, then returning the previous answer with the time bumped up would work.
You will need the GNU linker option --wrapCode:#define THROTTLE 1000 int __wrap_gettimeofday(struct timeval *tv, struct timezone *tz) { static struct timeval savetv; static struct timezone savetz; static int count = 0; static int result = 0; if ( count++ == 0 ) { // get a real result result = __real_gettimeofday(&savetv,&savetz); } else { // bump the time (add overflow) savetv.tv_usec++; } if ( count == THROTTLE ) { count = 0; } if ( tv ) *tv = savetv; if ( tz ) *tz = savetz; return result; }
--wrap=symbol
Use a wrapper function for symbol. Any undefined reference to symbol will be resolved to "__wrap_symbol". Any undefined reference to "__real_symbol" will be
resolved to symbol.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Try replacing CLOCK_REALTIME with 0.
EDIT:
Salem's shown the cool way to do it, allowing you to call the real function.
The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss
ok got the salem solution compiled
I also wrote a little test program to see if this library is getting used
it looks like only the original gettime is getting used salem
Last edited by NetworkLearning; 09-19-2012 at 01:20 AM.
guys,
can anyone help ? you will help a lot of people study ..this is a program for studying ..
I have
and program that calls itCode:#include <stdio.h> #include <sys/time.h> #define THROTTLE 10000 int __wrap_gettimeofday(struct timeval *tv, struct timezone *tz) { static struct timeval savetv; static struct timezone savetz; static int count = 0; static int result = 0; if ( count++ == 0 ) { // get a real result result = __real_gettimeofday(&savetv,&savetz); } else { // bump the time (add overflow) savetv.tv_usec++; } if ( count == THROTTLE ) { count = 0; } if ( tv ) *tv = savetv; if ( tz ) *tz = savetz; return result; }
Then i haveCode:#include <stdio.h> #include <sys/time.h> int main () { double frame_count, start_time, last_time; struct timeval tempo; gettimeofday(&tempo, NULL); printf("Running for %f milliseconds\n\n", ((double)tempo.tv_usec - start_time)/1000); }
LD_PRELOAD=/home/myhome
LD_LIBRARY_PATH=/home/myhome
in /etc/ld.so.preload : /home/myhome
then i execute it with
home$ strace ./main
Forgetting the code for a minute, what are you trying to do with this program?
Does your hardware have the high performance timer?
What is your OS? Linux of course, but what's the distro?
ubuntu 12.04
on a core i7 machine
btw i ran boomerang on the binary and have some code that i can share if that will help
You just do
$ gcc foo.c -Wl,--wrap=gettimeofday
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I did
gcc -Wl,--wrap=gettimeofday -c ltimer.c -o ltimer.o
Actually, what I suggested is of no use to you, since it seems you're trying to patch an executable that has already been built.
The first thing you need to find out is if gettimeofday is being statically linked or dynamically linked.
If it's statically linked, then the LD_PRELOAD isn't going to work anyway.
Here's how to tell.
If you have something like "U gettimeofday@@GLIBC_2.2.5", then the preload thing might work.Code:$ gcc foo.c $ nm a.out | grep gettime U gettimeofday@@GLIBC_2.2.5 $ gcc -static foo.c $ nm a.out | grep gettime 000000000040d030 T __gettimeofday 000000000040d030 T __gettimeofday_internal 000000000040d030 W gettimeofday
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Actually i get
nm: i86-image: no symbols
and i was able to make my program use an empty gettime
then it was hanging at different spot
so the preload thing should work
but if we can just figure out this test program first
thanx