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]

Re: PATCH: target/19520: protected function pointer doesn't work right


On Fri, Jan 21, 2005 at 05:25:30PM -0800, H. J. Lu wrote:
> On Thu, Jan 20, 2005 at 07:37:21PM -0800, H. J. Lu wrote:
> > > Then come up with somewhere else to put the test, if you object to
> > > adding it to the LD tests.  I think it is a very bad idea to add this
> > > much code for an unintuitive behavior without testing it anywhere.
> > 
> > I will try to add something to gcc.misc-tests.
> > 
> > 
> 
> 

Here is an updated patch. I modified default_binds_local_p_1 to
ignore protected symbols.


H.J.
----
2005-01-20  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/19520
	* config/i386/i386-protos.h (ix86_binds_local_p): New.

	* config/i386/i386.c (output_pic_addr_const): Don't use PLT if
	a function is protected.
	(ix86_binds_local_p): New.

	* config/i386/linux.h (TARGET_BINDS_LOCAL_P): Defined.
	* config/i386/linux64.h (TARGET_BINDS_LOCAL_P): Likewise.

	* output.h (default_binds_local_p_1): Add "unsigned int".
	(IGNORE_PROTECTED_FUNCTION): New.
	(IGNORE_PROTECTED_NON_FUNCTION): New.

	* rtl.h (SYMBOL_FLAG_PROTECTED): New.
	(SYMBOL_REF_PROTECTED_P): Likewise.

	* varasm.c (default_encode_section_info): Check and set
	SYMBOL_FLAG_PROTECTED.
	(default_binds_local_p): Updated.
	(default_binds_local_p_1): Accept "ignored" to check if
	protected visibility should be ignroed.

--- gcc/config/i386/i386-protos.h.vsb	2005-01-20 11:30:00.000000000 -0800
+++ gcc/config/i386/i386-protos.h	2005-01-21 12:04:18.000000000 -0800
@@ -199,6 +199,7 @@ extern rtx function_arg (CUMULATIVE_ARGS
 extern void function_arg_advance (CUMULATIVE_ARGS *, enum machine_mode,
 				  tree, int);
 extern rtx ix86_function_value (tree);
+extern bool ix86_binds_local_p (tree);
 #endif
 
 #endif
--- gcc/config/i386/i386.c.vsb	2005-01-20 11:30:01.000000000 -0800
+++ gcc/config/i386/i386.c	2005-01-21 12:05:21.000000000 -0800
@@ -5881,7 +5881,9 @@ output_pic_addr_const (FILE *file, rtx x
        mark_decl_referenced (SYMBOL_REF_DECL (x));
 
       assemble_name (file, XSTR (x, 0));
-      if (!TARGET_MACHO && code == 'P' && ! SYMBOL_REF_LOCAL_P (x))
+      if (!TARGET_MACHO && code == 'P'
+	  && ! SYMBOL_REF_LOCAL_P (x)
+	  && ! SYMBOL_REF_PROTECTED_P (x))
 	fputs ("@PLT", file);
       break;
 
@@ -16666,4 +16668,11 @@ i386_solaris_elf_named_section (const ch
   default_elf_asm_named_section (name, flags, decl);
 }
 
+bool
+ix86_binds_local_p (tree exp)
+{
+  return default_binds_local_p_1 (exp, flag_shlib,
+				  IGNORE_PROTECTED_FUNCTION);
+}
+
 #include "gt-i386.h"
--- gcc/config/i386/linux.h.vsb	2004-11-27 08:45:14.000000000 -0800
+++ gcc/config/i386/linux.h	2005-01-21 12:05:44.000000000 -0800
@@ -25,6 +25,8 @@ Boston, MA 02111-1307, USA.  */
 /* The .file command should always begin the output.  */
 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
 
+#define TARGET_BINDS_LOCAL_P ix86_binds_local_p
+
 #define TARGET_VERSION fprintf (stderr, " (i386 Linux/ELF)");
 
 /* The svr4 ABI for the i386 says that records and unions are returned
--- gcc/config/i386/linux64.h.vsb	2004-11-27 14:29:34.000000000 -0800
+++ gcc/config/i386/linux64.h	2005-01-21 12:05:51.000000000 -0800
@@ -19,6 +19,8 @@ along with GCC; see the file COPYING.  I
 the Free Software Foundation, 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
+#define TARGET_BINDS_LOCAL_P ix86_binds_local_p
+
 #define TARGET_VERSION fprintf (stderr, " (x86-64 Linux/ELF)");
 
 #define TARGET_OS_CPP_BUILTINS()				\
--- gcc/output.h.vsb	2005-01-20 11:29:23.000000000 -0800
+++ gcc/output.h	2005-01-21 12:01:42.000000000 -0800
@@ -509,7 +509,7 @@ extern void default_elf_select_rtx_secti
 extern void default_encode_section_info (tree, rtx, int);
 extern const char *default_strip_name_encoding (const char *);
 extern bool default_binds_local_p (tree);
-extern bool default_binds_local_p_1 (tree, int);
+extern bool default_binds_local_p_1 (tree, int, unsigned int);
 extern void default_globalize_label (FILE *, const char *);
 extern void default_emit_unwind_label (FILE *, tree, int, int);
 extern void default_internal_label (FILE *, const char *, unsigned long);
@@ -519,6 +519,10 @@ extern bool default_valid_pointer_mode (
 
 extern int default_address_cost (rtx);
 
+/* Flags controlling how to handle a protected symbol.  */
+#define IGNORE_PROTECTED_FUNCTION	0x0001
+#define IGNORE_PROTECTED_NON_FUNCTION	0x0002
+
 /* dbxout helper functions */
 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
 
--- gcc/rtl.h.vsb	2005-01-20 11:29:24.000000000 -0800
+++ gcc/rtl.h	2005-01-20 13:33:42.000000000 -0800
@@ -1234,6 +1234,11 @@ do {						\
 #define SYMBOL_FLAG_MACH_DEP_SHIFT	7
 #define SYMBOL_FLAG_MACH_DEP		(1 << SYMBOL_FLAG_MACH_DEP_SHIFT)
 
+/* Set if this symbol is protected.  */
+#define SYMBOL_FLAG_PROTECTED	(1 << 8)
+#define SYMBOL_REF_PROTECTED_P(RTX) \
+  ((SYMBOL_REF_FLAGS (RTX) & SYMBOL_FLAG_PROTECTED) != 0)
+
 /* Define a macro to look for REG_INC notes,
    but save time on machines where they never exist.  */
 
--- gcc/varasm.c.vsb	2005-01-20 11:29:29.000000000 -0800
+++ gcc/varasm.c	2005-01-21 17:18:21.000000000 -0800
@@ -5203,6 +5203,8 @@ default_encode_section_info (tree decl, 
   flags = 0;
   if (TREE_CODE (decl) == FUNCTION_DECL)
     flags |= SYMBOL_FLAG_FUNCTION;
+  if (DECL_VISIBILITY (decl) == VISIBILITY_PROTECTED)
+    flags |= SYMBOL_FLAG_PROTECTED;
   if (targetm.binds_local_p (decl))
     flags |= SYMBOL_FLAG_LOCAL;
   if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
@@ -5233,11 +5235,11 @@ default_strip_name_encoding (const char 
 bool
 default_binds_local_p (tree exp)
 {
-  return default_binds_local_p_1 (exp, flag_shlib);
+  return default_binds_local_p_1 (exp, flag_shlib, 0);
 }
 
 bool
-default_binds_local_p_1 (tree exp, int shlib)
+default_binds_local_p_1 (tree exp, int shlib, unsigned int ignore)
 {
   bool local_p;
 
@@ -5247,8 +5249,17 @@ default_binds_local_p_1 (tree exp, int s
   /* Static variables are always local.  */
   else if (! TREE_PUBLIC (exp))
     local_p = true;
-  /* A variable is local if the user explicitly tells us so.  */
-  else if (DECL_VISIBILITY_SPECIFIED (exp) && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
+  /* A symbol is local if the user explicitly tells us so, excluding
+     protected symbol when needed.  */
+  else if (DECL_VISIBILITY_SPECIFIED (exp)
+	   && ((DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT
+		&& DECL_VISIBILITY (exp) != VISIBILITY_PROTECTED)
+	       || ((!shlib
+		    || ((!(ignore & IGNORE_PROTECTED_FUNCTION)
+			 || TREE_CODE (exp) != FUNCTION_DECL)
+			&& (!(ignore & IGNORE_PROTECTED_NON_FUNCTION)
+			    || TREE_CODE (exp) == FUNCTION_DECL)))
+		   && DECL_VISIBILITY (exp) == VISIBILITY_PROTECTED)))
     local_p = true;
   /* Otherwise, variables defined outside this object may not be local.  */
   else if (DECL_EXTERNAL (exp))
@@ -5256,8 +5267,16 @@ default_binds_local_p_1 (tree exp, int s
   /* Linkonce and weak data are never local.  */
   else if (DECL_ONE_ONLY (exp) || DECL_WEAK (exp))
     local_p = false;
-  /* If none of the above and visibility is not default, make local.  */
-  else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
+  /* If none of the above and visibility is not default nor symbol
+     is ignored protected, make local.  */
+  else if ((DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT
+	    && DECL_VISIBILITY (exp) != VISIBILITY_PROTECTED)
+	   || ((!shlib
+		|| ((!(ignore & IGNORE_PROTECTED_FUNCTION)
+		     || TREE_CODE (exp) != FUNCTION_DECL)
+		    && (!(ignore & IGNORE_PROTECTED_NON_FUNCTION)
+			|| TREE_CODE (exp) == FUNCTION_DECL)))
+	       && DECL_VISIBILITY (exp) == VISIBILITY_PROTECTED))
     local_p = true;
   /* If PIC, then assume that any global name can be overridden by
      symbols resolved from other modules.  */


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