This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: __cyg_profile_func_enter is not called with correct address ?


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.

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@redhat.com>:
> 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.
>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]