diff mbox

Fix -fprofile-generate __gcov* var naming (PR gcov-profile/52150)

Message ID 20120208123752.GL18768@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Feb. 8, 2012, 12:37 p.m. UTC
Hi!

build_var in coverage.c doesn't strip_name_encoding, therefore happily
puts in characters like leading * into the __gcov* variable names.
Fixed thusly, additionally I'm changing the last _ to . or $ when possible
to avoid failures if user code e.g. contains variables like __gcov__foo
(yeah, I know, it is implementation reserved namespace, still it doesn't
hurt to avoid it if possible).

Bootstrapped/regtested on x86_64-linux and i686-linux, tested with Firefox
PGO build by the reporter.  Ok for trunk?

2012-02-08  Jakub Jelinek  <jakub@redhat.com>

	PR gcov-profile/52150
	* coverage.c: Include target.h.
	(build_var): Call targetm.strip_name_encoding on the assembler name.
	Change one _ into . or $ if the target allows it.
	* Makefile.in (coverage.o): Depend on $(TARGET_H).

	* gcc.dg/tree-prof/pr52150.c: New test.


	Jakub

Comments

Richard Biener Feb. 8, 2012, 1:22 p.m. UTC | #1
On Wed, Feb 8, 2012 at 1:37 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> build_var in coverage.c doesn't strip_name_encoding, therefore happily
> puts in characters like leading * into the __gcov* variable names.
> Fixed thusly, additionally I'm changing the last _ to . or $ when possible
> to avoid failures if user code e.g. contains variables like __gcov__foo
> (yeah, I know, it is implementation reserved namespace, still it doesn't
> hurt to avoid it if possible).
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, tested with Firefox
> PGO build by the reporter.  Ok for trunk?

Ok.

Thanks,
Richard.

> 2012-02-08  Jakub Jelinek  <jakub@redhat.com>
>
>        PR gcov-profile/52150
>        * coverage.c: Include target.h.
>        (build_var): Call targetm.strip_name_encoding on the assembler name.
>        Change one _ into . or $ if the target allows it.
>        * Makefile.in (coverage.o): Depend on $(TARGET_H).
>
>        * gcc.dg/tree-prof/pr52150.c: New test.
>
> --- gcc/coverage.c.jj   2012-01-01 19:54:46.000000000 +0100
> +++ gcc/coverage.c      2012-02-08 09:24:49.345911957 +0100
> @@ -50,6 +50,7 @@ along with GCC; see the file COPYING3.
>  #include "diagnostic-core.h"
>  #include "intl.h"
>  #include "filenames.h"
> +#include "target.h"
>
>  #include "gcov-io.h"
>  #include "gcov-io.c"
> @@ -656,13 +657,25 @@ static tree
>  build_var (tree fn_decl, tree type, int counter)
>  {
>   tree var = build_decl (BUILTINS_LOCATION, VAR_DECL, NULL_TREE, type);
> -  tree fn_name = DECL_ASSEMBLER_NAME (fn_decl);
> -  char *buf = (char *)alloca (IDENTIFIER_LENGTH (fn_name) + 10);
> +  const char *fn_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fn_decl));
> +  char *buf;
> +  size_t fn_name_len, len;
> +
> +  fn_name = targetm.strip_name_encoding (fn_name);
> +  fn_name_len = strlen (fn_name);
> +  buf = XALLOCAVEC (char, fn_name_len + 8 + sizeof (int) * 3);
>
>   if (counter < 0)
> -    sprintf (buf, "__gcov__%s", IDENTIFIER_POINTER (fn_name));
> +    strcpy (buf, "__gcov__");
>   else
> -    sprintf (buf, "__gcov%u_%s", counter, IDENTIFIER_POINTER (fn_name));
> +    sprintf (buf, "__gcov%u_", counter);
> +  len = strlen (buf);
> +#ifndef NO_DOT_IN_LABEL
> +  buf[len - 1] = '.';
> +#elif !defined NO_DOLLAR_IN_LABEL
> +  buf[len - 1] = '$';
> +#endif
> +  memcpy (buf + len, fn_name, fn_name_len + 1);
>   DECL_NAME (var) = get_identifier (buf);
>   TREE_STATIC (var) = 1;
>   TREE_ADDRESSABLE (var) = 1;
> --- gcc/Makefile.in.jj  2012-01-30 00:10:01.000000000 +0100
> +++ gcc/Makefile.in     2012-02-08 09:20:24.616554891 +0100
> @@ -3002,7 +3002,7 @@ coverage.o : coverage.c $(GCOV_IO_H) $(C
>    $(TM_H) $(RTL_H) $(TREE_H) $(FLAGS_H) output.h $(REGS_H) $(EXPR_H) \
>    $(FUNCTION_H) $(BASIC_BLOCK_H) toplev.h $(DIAGNOSTIC_CORE_H) $(GGC_H) langhooks.h $(COVERAGE_H) \
>    $(HASHTAB_H) tree-iterator.h $(CGRAPH_H) $(TREE_PASS_H) gcov-io.c $(TM_P_H) \
> -   $(DIAGNOSTIC_CORE_H) intl.h gt-coverage.h
> +   $(DIAGNOSTIC_CORE_H) intl.h gt-coverage.h $(TARGET_H)
>  cselib.o : cselib.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \
>    $(REGS_H) hard-reg-set.h $(FLAGS_H) insn-config.h $(RECOG_H) \
>    $(EMIT_RTL_H) $(DIAGNOSTIC_CORE_H) output.h $(FUNCTION_H) $(TREE_PASS_H) \
> --- gcc/testsuite/gcc.dg/tree-prof/pr52150.c.jj 2012-02-08 09:29:41.334297278 +0100
> +++ gcc/testsuite/gcc.dg/tree-prof/pr52150.c    2012-02-08 09:30:22.580068958 +0100
> @@ -0,0 +1,16 @@
> +/* PR gcov-profile/52150 */
> +/* { dg-options "-O0" } */
> +
> +void foo () __asm__ ("bar");
> +
> +void
> +foo ()
> +{
> +}
> +
> +int
> +main ()
> +{
> +  foo ();
> +  return 0;
> +}
>
>        Jakub
diff mbox

Patch

--- gcc/coverage.c.jj	2012-01-01 19:54:46.000000000 +0100
+++ gcc/coverage.c	2012-02-08 09:24:49.345911957 +0100
@@ -50,6 +50,7 @@  along with GCC; see the file COPYING3.
 #include "diagnostic-core.h"
 #include "intl.h"
 #include "filenames.h"
+#include "target.h"
 
 #include "gcov-io.h"
 #include "gcov-io.c"
@@ -656,13 +657,25 @@  static tree
 build_var (tree fn_decl, tree type, int counter)
 {
   tree var = build_decl (BUILTINS_LOCATION, VAR_DECL, NULL_TREE, type);
-  tree fn_name = DECL_ASSEMBLER_NAME (fn_decl);
-  char *buf = (char *)alloca (IDENTIFIER_LENGTH (fn_name) + 10);
+  const char *fn_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fn_decl));
+  char *buf;
+  size_t fn_name_len, len;
+
+  fn_name = targetm.strip_name_encoding (fn_name);
+  fn_name_len = strlen (fn_name);
+  buf = XALLOCAVEC (char, fn_name_len + 8 + sizeof (int) * 3);
 
   if (counter < 0)
-    sprintf (buf, "__gcov__%s", IDENTIFIER_POINTER (fn_name));
+    strcpy (buf, "__gcov__");
   else
-    sprintf (buf, "__gcov%u_%s", counter, IDENTIFIER_POINTER (fn_name));
+    sprintf (buf, "__gcov%u_", counter);
+  len = strlen (buf);
+#ifndef NO_DOT_IN_LABEL
+  buf[len - 1] = '.';
+#elif !defined NO_DOLLAR_IN_LABEL
+  buf[len - 1] = '$';
+#endif
+  memcpy (buf + len, fn_name, fn_name_len + 1);
   DECL_NAME (var) = get_identifier (buf);
   TREE_STATIC (var) = 1;
   TREE_ADDRESSABLE (var) = 1;
--- gcc/Makefile.in.jj	2012-01-30 00:10:01.000000000 +0100
+++ gcc/Makefile.in	2012-02-08 09:20:24.616554891 +0100
@@ -3002,7 +3002,7 @@  coverage.o : coverage.c $(GCOV_IO_H) $(C
    $(TM_H) $(RTL_H) $(TREE_H) $(FLAGS_H) output.h $(REGS_H) $(EXPR_H) \
    $(FUNCTION_H) $(BASIC_BLOCK_H) toplev.h $(DIAGNOSTIC_CORE_H) $(GGC_H) langhooks.h $(COVERAGE_H) \
    $(HASHTAB_H) tree-iterator.h $(CGRAPH_H) $(TREE_PASS_H) gcov-io.c $(TM_P_H) \
-   $(DIAGNOSTIC_CORE_H) intl.h gt-coverage.h
+   $(DIAGNOSTIC_CORE_H) intl.h gt-coverage.h $(TARGET_H)
 cselib.o : cselib.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \
    $(REGS_H) hard-reg-set.h $(FLAGS_H) insn-config.h $(RECOG_H) \
    $(EMIT_RTL_H) $(DIAGNOSTIC_CORE_H) output.h $(FUNCTION_H) $(TREE_PASS_H) \
--- gcc/testsuite/gcc.dg/tree-prof/pr52150.c.jj	2012-02-08 09:29:41.334297278 +0100
+++ gcc/testsuite/gcc.dg/tree-prof/pr52150.c	2012-02-08 09:30:22.580068958 +0100
@@ -0,0 +1,16 @@ 
+/* PR gcov-profile/52150 */
+/* { dg-options "-O0" } */
+
+void foo () __asm__ ("bar");
+
+void
+foo ()
+{
+}
+
+int
+main ()
+{
+  foo ();
+  return 0;
+}