This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

[PATCH] take 2: PR 19985, symbol visibility in libgcov


This is a slightly different version of:

  http://gcc.gnu.org/ml/gcc-patches/2005-03/msg01484.html

which Nathan already approved for mainline.  It hides global symbols
in libgcov.a so that an instrumented shared library doesn't use the
same function instances as an executable that exports globals to the
dynamic symbol table.  It fixes PR 19985, a regression from GCC 3.3
reported by multiple real users.

This version differs from the original in that it hides all __gcov*
symbols, not just a few.  Tested on powerpc64-linux with -m32 and -m64
for mainline, 4.0-branch, and 3.4-branch.  The patch is identical for
mainline and 4.0; the 3.4 patch is the same except for __gcov* symbols
that don't exist in that branch.

OK for mainline, 4.0, and 3.4?

2005-03-30  Janis Johnson  <janis187@us.ibm.com>
                                                                                
	PR 19985
	* gcov-io.h: Declare libgcov external funtions hidden.

Index: gcc/gcov-io.h
===================================================================
RCS file: /opt/gcc-cvs/gcc/gcc/gcov-io.h,v
retrieving revision 1.52
diff -u -p -r1.52 gcov-io.h
--- gcc/gcov-io.h	30 Aug 2004 15:52:08 -0000	1.52
+++ gcc/gcov-io.h	22 Mar 2005 22:01:02 -0000
@@ -229,11 +229,15 @@ typedef HOST_WIDEST_INT gcov_type;
 
 #endif /* !IN_LIBGCOV */
 
-/* In gcov we want function linkage to be static. In libgcov we need
-   these functions to be extern, so prefix them with __gcov.  In the
-   compiler we want it extern, so that they can be accessed from
-   elsewhere.  */
+/* In gcov we want function linkage to be static.  In the compiler we want
+   it extern, so that they can be accessed from elsewhere.  In libgcov we
+   need these functions to be extern, so prefix them with __gcov.  In
+   libgcov they must also be hidden so that the instance in the executable
+   is not also used in a DSO.  */
 #if IN_LIBGCOV
+
+#include "auto-host.h"   /* for HAVE_GAS_HIDDEN */
+
 #define gcov_var __gcov_var
 #define gcov_open __gcov_open
 #define gcov_close __gcov_close
@@ -253,6 +257,16 @@ typedef HOST_WIDEST_INT gcov_type;
 #pragma GCC poison gcov_write_string gcov_write_tag gcov_write_length
 #pragma GCC poison gcov_read_string gcov_sync gcov_time gcov_magic
 
+#ifdef HAVE_GAS_HIDDEN
+#define ATTRIBUTE_HIDDEN  __attribute__ ((__visibility__ ("hidden")))
+#else
+#define ATTRIBUTE_HIDDEN
+#endif
+
+#else
+
+#define ATTRIBUTE_HIDDEN
+
 #endif
 
 #ifndef GCOV_LINKAGE
@@ -432,30 +446,31 @@ struct gcov_info
 };
 
 /* Register a new object file module.  */
-extern void __gcov_init (struct gcov_info *);
+extern void __gcov_init (struct gcov_info *) ATTRIBUTE_HIDDEN;
 
 /* Called before fork, to avoid double counting.  */
-extern void __gcov_flush (void);
+extern void __gcov_flush (void) ATTRIBUTE_HIDDEN;
 
 /* The merge function that just sums the counters.  */
-extern void __gcov_merge_add (gcov_type *, unsigned);
+extern void __gcov_merge_add (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
 
 /* The merge function to choose the most common value.  */
-extern void __gcov_merge_single (gcov_type *, unsigned);
+extern void __gcov_merge_single (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
 
 /* The merge function to choose the most common difference between
    consecutive values.  */
-extern void __gcov_merge_delta (gcov_type *, unsigned);
+extern void __gcov_merge_delta (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
 
 #ifndef inhibit_libc
 /* The wrappers around some library functions..  */
 extern pid_t __gcov_fork (void);
-extern int __gcov_execl (const char *, const char *, ...);
-extern int __gcov_execlp (const char *, const char *, ...);
-extern int __gcov_execle (const char *,  const char *, ...);
-extern int __gcov_execv (const char *, char *const []);
-extern int __gcov_execvp (const char *, char *const []);
-extern int __gcov_execve (const char *, char  *const [], char *const []);
+extern int __gcov_execl (const char *, const char *, ...) ATTRIBUTE_HIDDEN;
+extern int __gcov_execlp (const char *, const char *, ...) ATTRIBUTE_HIDDEN;
+extern int __gcov_execle (const char *,  const char *, ...) ATTRIBUTE_HIDDEN;
+extern int __gcov_execv (const char *, char *const []) ATTRIBUTE_HIDDEN;
+extern int __gcov_execvp (const char *, char *const []) ATTRIBUTE_HIDDEN;
+extern int __gcov_execve (const char *, char  *const [], char *const [])
+  ATTRIBUTE_HIDDEN;
 #endif
 
 #endif /* IN_LIBGCOV */
@@ -487,7 +502,7 @@ GCOV_LINKAGE struct gcov_var
   size_t alloc;
   gcov_unsigned_t *buffer;
 #endif
-} gcov_var;
+} gcov_var ATTRIBUTE_HIDDEN;
 
 /* Functions for reading and writing gcov files. In libgcov you can
    open the file for reading then writing. Elsewhere you can open the
@@ -499,29 +514,31 @@ GCOV_LINKAGE struct gcov_var
    functions for writing.  Your file may become corrupted if you break
    these invariants.  */
 #if IN_LIBGCOV
-GCOV_LINKAGE int gcov_open (const char */*name*/);
+GCOV_LINKAGE int gcov_open (const char */*name*/) ATTRIBUTE_HIDDEN;
 #else
 GCOV_LINKAGE int gcov_open (const char */*name*/, int /*direction*/);
 GCOV_LINKAGE int gcov_magic (gcov_unsigned_t, gcov_unsigned_t);
 #endif
-GCOV_LINKAGE int gcov_close (void);
+GCOV_LINKAGE int gcov_close (void) ATTRIBUTE_HIDDEN;
 
 /* Available everywhere.  */
 static gcov_position_t gcov_position (void);
 static int gcov_is_error (void);
 
-GCOV_LINKAGE gcov_unsigned_t gcov_read_unsigned (void);
-GCOV_LINKAGE gcov_type gcov_read_counter (void);
-GCOV_LINKAGE void gcov_read_summary (struct gcov_summary *);
+GCOV_LINKAGE gcov_unsigned_t gcov_read_unsigned (void) ATTRIBUTE_HIDDEN;
+GCOV_LINKAGE gcov_type gcov_read_counter (void) ATTRIBUTE_HIDDEN;
+GCOV_LINKAGE void gcov_read_summary (struct gcov_summary *) ATTRIBUTE_HIDDEN;
 
 #if IN_LIBGCOV
 /* Available only in libgcov */
-GCOV_LINKAGE void gcov_write_counter (gcov_type);
-GCOV_LINKAGE void gcov_write_tag_length (gcov_unsigned_t, gcov_unsigned_t);
+GCOV_LINKAGE void gcov_write_counter (gcov_type) ATTRIBUTE_HIDDEN;
+GCOV_LINKAGE void gcov_write_tag_length (gcov_unsigned_t, gcov_unsigned_t)
+    ATTRIBUTE_HIDDEN;
 GCOV_LINKAGE void gcov_write_summary (gcov_unsigned_t /*tag*/,
-				      const struct gcov_summary *);
+				      const struct gcov_summary *)
+    ATTRIBUTE_HIDDEN;
 static void gcov_rewrite (void);
-GCOV_LINKAGE void gcov_seek (gcov_position_t /*position*/);
+GCOV_LINKAGE void gcov_seek (gcov_position_t /*position*/) ATTRIBUTE_HIDDEN;
 #else
 /* Available outside libgcov */
 GCOV_LINKAGE const char *gcov_read_string (void);
@@ -531,7 +548,7 @@ GCOV_LINKAGE void gcov_sync (gcov_positi
 
 #if !IN_GCOV
 /* Available outside gcov */
-GCOV_LINKAGE void gcov_write_unsigned (gcov_unsigned_t);
+GCOV_LINKAGE void gcov_write_unsigned (gcov_unsigned_t) ATTRIBUTE_HIDDEN;
 #endif
 
 #if !IN_GCOV && !IN_LIBGCOV


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