problem with -fprofile-arcs and -O3

Jeffrey A Law
Fri Jan 8 00:46:00 GMT 1999

  In message <>you write:
  > > If that's all you need to do, then you do not need two passes, you would 
  > > only need to mvoe the call output_func_start_profiler after the loop
  > > over the deferred functions.
  > > 
  > > If you are claiming that output_func_start_profiler can cause us to need
  > > to output more deferred functions, then that indicates that
  > > output_func_start_profiler belongs *inside* the existing loop.  Note that
  > > you would probably need to call it each iteration through the loop and
  > > set "reconsider" if output_func_start_profiler actually emitted any code.
  > > That would mean output_func_start_profiler would have to return a value,
  > > but that's easily done :-)
  > This does not work because we first have to call 'getdecls()' and
  > 'list_length (globals)' to get the function emitted by 
  > output_func_start_profiler. We also have to setup the 'vec' array and
  > do a 'DECL_DEFER_OUTPUT (decl) = 0' for all global decls.
  > The easiest way to do this is in the patch I send.
I still do not see why you need multiple passes.  But that may be because you
did not answer one critical question.

Does the call to output_func_start_profiler cause us to need any additional
functions other than the block profiler?

I believe the answer is no from looking at output_func_start_profiler.

output_func_start_profiler will generate a trivial function which calls
__bb_init_func (which is defined in libgcc.a).  The address of a profiling
label is passed as an argument.  That label is emitted unconditionally by
end_final when profiling is enabled.

otuput_func_start_profiler will call rest_of_compilation on this trivial
function, which should cause the function to be compiled and emitted into
the assembler file.

This trivial function references no other named data or functions; therefore,
as far as I can tell output_func_start_profiler not cause any additional
functions or data to need to be output.  Therefore, it can have no effect on
the loop which emits deferred functions and variables.

So, I believe this is the right patch for your problem.  I have installed
it into the egcs sources:

        * toplev.c (compile_file): Move call to output_func_start_profiler
        to after the loop to emit deferred functions.

Index: toplev.c
RCS file: /egcs/carton/cvsfiles/egcs/gcc/toplev.c,v
retrieving revision 1.141
diff -c -3 -p -r1.141 toplev.c
*** toplev.c	1998/12/22 23:13:39	1.141
--- toplev.c	1999/01/08 08:42:31
*************** compile_file (name)
*** 2907,2914 ****
  	poplevel (0, 0, 0);
-   output_func_start_profiler ();
    /* Compilation is now finished except for writing
       what's left of the symbol table output.  */
--- 2907,2912 ----
*************** compile_file (name)
*** 3014,3019 ****
--- 3012,3026 ----
+     /* This must occur after the loop to output deferred functions.  Else
+        the profiler initializer would not be emitted if all the functions
+        in this compilation unit were deferred.
+        output_func_start_profiler can not cause any additional functions or
+        data to need to be output, so it need not be in the deferred function
+        loop above.  */
+     output_func_start_profiler ();
      /* Now that all possible functions have been output, we can dump
         the exception table.  */

More information about the Gcc-patches mailing list