When a function is inlined, the corresponding calls to
__cyg_profile_func_{enter,exit} are passed the address of caller.

Below is an example. Addresses shown in "Enter"/"Exit" messages 
all point to main().
If you add -fno-inline-functions, then this problem goes away.

----- Makefile ------
CC=gcc-4.0.1
all: blah.o lib.o
        $(CC) -o a.out $^
blah.o: blah.c
        $(CC) -O3 -finstrument-functions -c $^
lib.o: lib.c
        $(CC) -O3 -c $^
------ blah.c -------
#include <stdio.h>
int Foo() { return 900; }
int Bar() { return Foo() + 10; }
int main() { printf("Value is %d\n", Bar()); }
------ lib.c --------
#include <stdio.h>
__cyg_profile_func_enter(void *this_fn, void *call_site) { printf("Enter %p\n",
this_fn); }
__cyg_profile_func_exit(void *this_fn, void *call_site) { printf("Exit %p\n",
this_fn); }

-- 
           Summary: -finstrument-functions + -finline-functions produces
                    incorrect output.
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: yasushi dot saito at gmail dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23629

Reply via email to