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: Add -fsystem-header-visibility=


The current visibility scheme doesn't work too well with symbols from
system headers. In most cases, symbols from system headers are defined
in libraries which always have default visibility. But when
-fvisibililty= or "#pragma GCC visibililty push" is used, symbols from
system headers may have non-default visibility. This leads to link-time
or run-time problems. This patch adds -fsystem-header-visibility=. It
can be used to set the symbols from system headers with different
visibility.



H.J.
-----
2005-08-24  H.J. Lu  <hongjiu.lu@intel.com>

	* c-opts.c (c_common_handle_option): Handle
	OPT_fsystem_header_visibility_.

	* c.opt (fsystem-header-visibility=): New.

	* flags.h (system_header_default_visibility_p): New.
	* opts.c (system_header_default_visibility_p): New.

	* tree.c (build_decl_stat): Set DECL_VISIBILITY to
	*system_header_default_visibility_p if it isn't NULL.

--- gcc/c-opts.c.system	2005-07-19 09:49:54.000000000 -0700
+++ gcc/c-opts.c	2005-08-24 13:04:42.000000000 -0700
@@ -787,6 +787,24 @@ c_common_handle_option (size_t scode, co
       flag_zero_link = value;
       break;
 
+    case OPT_fsystem_header_visibility_:
+      {
+	static enum symbol_visibility system_header_default_visibility;
+        if (!strcmp(arg, "default"))
+          system_header_default_visibility = VISIBILITY_DEFAULT;
+        else if (!strcmp(arg, "internal"))
+          system_header_default_visibility = VISIBILITY_INTERNAL;
+        else if (!strcmp(arg, "hidden"))
+          system_header_default_visibility = VISIBILITY_HIDDEN;
+        else if (!strcmp(arg, "protected"))
+          system_header_default_visibility = VISIBILITY_PROTECTED;
+        else
+          error ("unrecognised visibility value \"%s\"", arg);
+	system_header_default_visibility_p
+	  = &system_header_default_visibility;
+      }
+      break;
+
     case OPT_gen_decls:
       flag_gen_declaration = 1;
       break;
--- gcc/c.opt.system	2005-07-20 10:27:53.000000000 -0700
+++ gcc/c.opt	2005-08-24 13:04:42.000000000 -0700
@@ -730,6 +730,10 @@ fzero-link
 ObjC ObjC++
 Generate lazy class lookup (via objc_getClass()) for use in Zero-Link mode
 
+fsystem-header-visibility=
+C ObjC C++ ObjC++ Joined RejectNegative
+-fsystem-header-visibility=[default|internal|hidden|protected]	Set the default system header symbol visibility
+
 gen-decls
 ObjC ObjC++
 Dump declarations to a .decl file
--- gcc/flags.h.system	2005-06-30 15:34:07.000000000 -0700
+++ gcc/flags.h	2005-08-24 13:04:42.000000000 -0700
@@ -73,6 +73,9 @@ enum symbol_visibility
 /* The default visibility for all symbols (unless overridden).  */
 extern enum symbol_visibility default_visibility;
 
+/* The default visibility for symbols in system header files.  */
+extern enum symbol_visibility *system_header_default_visibility_p;
+
 struct visibility_flags
 {
   unsigned inpragma : 1;	/* True when in #pragma GCC visibility.  */
--- gcc/opts.c.system	2005-07-28 21:48:22.000000000 -0700
+++ gcc/opts.c	2005-08-24 13:04:42.000000000 -0700
@@ -80,6 +80,9 @@ bool use_gnu_debug_info_extensions;
 /* The default visibility for all symbols (unless overridden) */
 enum symbol_visibility default_visibility = VISIBILITY_DEFAULT;
 
+/* The default visibility for symbols in system header files.  */
+enum symbol_visibility *system_header_default_visibility_p;
+
 /* Global visibility options.  */
 struct visibility_flags visibility_options;
 
--- gcc/tree.c.system	2005-08-16 09:25:39.000000000 -0700
+++ gcc/tree.c	2005-08-24 13:05:43.000000000 -0700
@@ -3039,7 +3039,11 @@ build_decl_stat (enum tree_code code, tr
     {
       /* Set default visibility to whatever the user supplied with
 	 visibility_specified depending on #pragma GCC visibility.  */
-      DECL_VISIBILITY (t) = default_visibility;
+      if (system_header_default_visibility_p != NULL
+	  && DECL_IN_SYSTEM_HEADER (t))
+	DECL_VISIBILITY (t) = *system_header_default_visibility_p;
+      else
+	DECL_VISIBILITY (t) = default_visibility;
       DECL_VISIBILITY_SPECIFIED (t) = visibility_options.inpragma;
     }
 


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