robert song wrote: > Andrew, thank you for your reply. > Well, the source file can be modified to solve the problem, but I want > to use one tool to record every address of the running applications > built with -finstrument-sections option, without modifying the > application source code itself. Try this: void __cyg_profile_func_enter (void *this_fn, void *call_site) { Dl_info info; dladdr(__builtin_return_address(0), &info); printf ("addr:%lx %p:%s\n", this_fn, info.dli_saddr, info.dli_sname); } Link with -ldl. > But now the address sometimes may be the PLT address of the application, > and I don't have a good idea to deal with the problem. > > If the real address can be got in the __cyg_profile_func_enter() > function in some way, it will be helpful to analyse. > > 2009/2/26 Andrew Haley <aph@xxxxxxxxxx>: >> The shared library loader is trying to make the code as efficient as possible. >> When you take the address of a symbol in main, the loader is forced to fix up >> the reloc with a pointer into the PLT. This happens because at the time the >> fixup is made, the symbol foo has not been resolved: it'll only be resolved >> later when the first call to foo happens. So, we have to use the PLT address >> because we don't yet know where foo is. >> >> Because of C's rule that the address of a function must be unique, every subsequent >> reference to that symbol will return the PLT address, including the one used >> in the call to __cyg_profile_func_enter(). >> >> You can get around this by compiling main with -fpic and not globally initializing >> ptr. >> >> void *ptr; >> >> int >> main (int argc, char *argv[]) >> { >> ptr = foo; >> >> cc -fpic -finstrument-functions -g -o main main.c tracer.c foo.so -Wl,-rpath `pwd` >> >> $ ./main >> addr:40073c >> addr:110634 >> addr:110634 >> addr:11066b >> addr:11066b >> addr:40073c >> >> Andrew. >> >>