This is the mail archive of the gcc-bugs@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]

Re: -finstrument-functions and inlining problem?




On Sat, 10 Jun 2000, Martin v. Loewis wrote:

> > I have sent this also to the gcc mailing list but I haven't got any
> > answer. Perhaps this is the right list to ask?
> 
> Don't be surprised about getting no answer. I read your original
> question, but your description was quite involved, and I had never
> heard of -finstrument-functions before. If nobody answers, you may
> want to investigate this in more detail, i.e. by studying the compiler
> source.

OK, I know that my English is not good. So, I will try to make my question
more clear.

The -finstrument-functions option tells gcc to insert a call to a function
named __cyg_profile_func_enter() immediately after entering any function
in your program. It also inserts a call to a function named
__cyg_profile_func_exit() before it returns from any function. Gcc
passes to each one of the __cyg_profile functions 2 arguments. The
first one is the address of the function from where it was called, for
example the address of main(). That address is the this_fn argument in my
previous posting. The second argument is the return address of the
function, for example the return address of main() is an address in glibc.
That address is the call_site argument in my previous posting. In
pseudocode :

func1:   Here starts function func1
         Push registers to stack
         call __cyg_profile_func_enter(func1, Label1)

         Code for func1

         call __cyg_profile_func_exit(func1, Label1)
         Pop registers from stack
         ret

Label1 is the address where the program will continue it's execution when
it returns from the func1() function. The __cyg_profile functions must be
present in the program or in a library.

Now I return to my previous posting. The test1() function is called in
main(). This means that the return address of test1() must be an addresses
in main(), because after returning from test1() the execution of the
program continues in main(). This is true if test1() is not inlined.

But it is not true when gcc inlines test1(). In this case there doesn't
exist a return address for test1(), because it is inlined. So, gcc passes
the return address of main() to the __cyg_profile functions.

I believe that the correct and expected behavior would be to pass as the
second argument to the __cyg_profile functions the address of main() which
is exactly after the inlined function :

main:   Code for main

        Start inlining test1                      --+
        call __cyg_profile_func_enter(main, Label2) |
                                                    |
        Code of test1                               | This is test1()
                                                    | inlined in main()
        call __cyg_profile_func_exit(main, Label2)  |
        End inline test1                          --+

Label2: Here continues the execution of main.

This way you emulate a call to test1(). And this is what everyone expects
to see, because in the source code main() calls test1().

I am trying to use this functionality to create a library which will count
the time spent in each function and for each kernel thread that the
program creates. I also wanted to create a call graph this way. But I
had this problem with the inlined functions. I couldn't find from which
function they were called.

I hope this mail was clear. If not, I must take some more English lessons
before I post a mail again ;-) !!!

Ioannis E. Venetis


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