This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
problem with -fprofile-arcs and -O3
- To: egcs-patches at cygnus dot com
- Subject: problem with -fprofile-arcs and -O3
- From: Herman ten Brugge <Haj dot Ten dot Brugge at net dot HCC dot nl>
- Date: Tue, 13 Oct 1998 20:48:26 +0100 (WEST)
Hello,
I detected a small problem when compiling programs with -fprofile-arcs and
-O3. When this is done the constructor function is sometimes not generated
for small programs.
The following code demonstrates the problem:
int main() { return 0; }
When compiled with '-fprofile-arcs -O3' the constructor function
'_GLOBAL_.I.mainGCOV' is missing. When compiled with -O2 instead of -O3
the '_GLOBAL_.I.mainGCOV' is present again. I corrected this problem in
toplev.c. The problem was that code generation is delayed when -O3 is used.
Herman.
1998-10-13 Herman A.J. ten Brugge <Haj.Ten.Brugge@net.HCC.nl>
* toplev.c (compile_file): Output constructor for small programs
when compiling with -O3 and -fprofile-arcs.
--- toplev.c.org Tue Oct 13 20:35:05 1998
+++ toplev.c Tue Oct 13 20:35:11 1998
@@ -2796,7 +2796,6 @@ compile_file (name)
poplevel (0, 0, 0);
}
- output_func_start_profiler ();
/* Compilation is now finished except for writing
what's left of the symbol table output. */
@@ -2996,6 +2995,49 @@ compile_file (name)
#endif
}
}
+
+ /* Write start profiler code if enabled. */
+
+ if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
+ {
+ int len;
+ int i;
+ tree decl;
+
+ output_func_start_profiler();
+ len = list_length (globals);
+
+ for (i = 0, decl = getdecls (); i < len; i++, decl = TREE_CHAIN (decl))
+ {
+ DECL_DEFER_OUTPUT (decl) = 0;
+ if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0
+ && incomplete_decl_finalize_hook != 0)
+ (*incomplete_decl_finalize_hook) (decl);
+ if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
+ continue;
+
+ if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
+ && (! TREE_READONLY (decl)
+ || TREE_PUBLIC (decl)
+ || (!optimize && flag_keep_static_consts)
+ || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
+ {
+ rest_of_decl_compilation (decl, NULL_PTR, 1, 1);
+ }
+
+ if (TREE_CODE (decl) == FUNCTION_DECL
+ && DECL_INITIAL (decl) != 0
+ && DECL_SAVED_INSNS (decl) != 0
+ && (flag_keep_inline_functions
+ || TREE_PUBLIC (decl)
+ || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
+ {
+ temporary_allocation ();
+ output_inline_function (decl);
+ permanent_allocation (1);
+ }
+ }
+ }
/* Write out any pending weak symbol declarations. */
--
-------------------------------------------------------------------------
Herman ten Brugge Email: Haj.Ten.Brugge@net.HCC.nl