[x32] PATCH: Remove ix86_promote_function_mode

H.J. Lu hongjiu.lu@intel.com
Mon Jun 20 13:55:00 GMT 2011


Promote pointers to Pmode when passing/returning in registers is
a security concern.  This patch removes ix86_promote_function_mode,
which exposes:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47725

There are 2 different patches for PR 47725:

http://gcc.gnu.org/ml/gcc-patches/2011-02/threads.html#01018

One checks zero/sign extended hard registers in cant_combine_insn_p
and the other changes assign_parm_setup_reg to copy the hard register
first before extending it.  This patch changes cant_combine_insn_p.


H.J.
----
commit 6202f3601f5b2a5a41b60425f1206681823ecaa9
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sun Jun 19 19:24:11 2011 -0700

    Remove ix86_promote_function_mode.
    
    2011-06-19  H.J. Lu  <hongjiu.lu@intel.com>
    
    	PR middle-end/47725
    	PR target/48085
    	* calls.c (precompute_register_parameters): Don't convert
    	pointer to TLS symbol if needed.
    
    	* combine.c (cant_combine_insn_p): Check zero/sign extended
    	hard registers.
    
    	* config/i386/i386.c (ix86_promote_function_mode): Removed.
    	(TARGET_PROMOTE_FUNCTION_MODE): Likewise.

diff --git a/gcc/ChangeLog.x32 b/gcc/ChangeLog.x32
index 564e123..6619f2f 100644
--- a/gcc/ChangeLog.x32
+++ b/gcc/ChangeLog.x32
@@ -1,3 +1,16 @@
+2011-06-19  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR middle-end/47725
+	PR target/48085
+	* calls.c (precompute_register_parameters): Don't convert
+	pointer to TLS symbol if needed.
+
+	* combine.c (cant_combine_insn_p): Check zero/sign extended
+	hard registers.
+
+	* config/i386/i386.c (ix86_promote_function_mode): Removed.
+	(TARGET_PROMOTE_FUNCTION_MODE): Likewise.
+
 2011-06-15  H.J. Lu  <hongjiu.lu@intel.com>
 
 	PR middle-end/48016
diff --git a/gcc/calls.c b/gcc/calls.c
index 5a00d95..3d9a03f 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -706,13 +706,7 @@ precompute_register_parameters (int num_actuals, struct arg_data *args,
 	   pseudo now.  TLS symbols sometimes need a call to resolve.  */
 	if (CONSTANT_P (args[i].value)
 	    && !targetm.legitimate_constant_p (args[i].mode, args[i].value))
-	  {
-	    if (GET_MODE (args[i].value) != args[i].mode)
-	      args[i].value = convert_to_mode (args[i].mode,
-					       args[i].value,
-					       args[i].unsignedp);
-	    args[i].value = force_reg (args[i].mode, args[i].value);
-	  }
+	  args[i].value = force_reg (args[i].mode, args[i].value);
 
 	/* If we are to promote the function arg to a wider mode,
 	   do it now.  */
diff --git a/gcc/combine.c b/gcc/combine.c
index d3574a3..5512649 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -2168,6 +2168,12 @@ cant_combine_insn_p (rtx insn)
     return 0;
   src = SET_SRC (set);
   dest = SET_DEST (set);
+  if (GET_CODE (src) == ZERO_EXTEND
+      || GET_CODE (src) == SIGN_EXTEND)
+    src = XEXP (src, 0);
+  if (GET_CODE (dest) == ZERO_EXTEND
+      || GET_CODE (dest) == SIGN_EXTEND)
+    dest = XEXP (dest, 0);
   if (GET_CODE (src) == SUBREG)
     src = SUBREG_REG (src);
   if (GET_CODE (dest) == SUBREG)
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index fa5ae97..104767b 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -7050,23 +7050,6 @@ ix86_function_value (const_tree valtype, const_tree fntype_or_decl,
   return ix86_function_value_1 (valtype, fntype_or_decl, orig_mode, mode);
 }
 
-/* Pointer function arguments and return values are promoted to
-   Pmode.  */
-
-static enum machine_mode
-ix86_promote_function_mode (const_tree type, enum machine_mode mode,
-			    int *punsignedp, const_tree fntype,
-			    int for_return)
-{
-  if (for_return != 1 && type != NULL_TREE && POINTER_TYPE_P (type))
-    {
-      *punsignedp = POINTERS_EXTEND_UNSIGNED;
-      return Pmode;
-    }
-  return default_promote_function_mode (type, mode, punsignedp, fntype,
-					for_return);
-}
-
 rtx
 ix86_libcall_value (enum machine_mode mode)
 {
@@ -35132,9 +35115,6 @@ ix86_autovectorize_vector_sizes (void)
 #undef TARGET_FUNCTION_VALUE_REGNO_P
 #define TARGET_FUNCTION_VALUE_REGNO_P ix86_function_value_regno_p
 
-#undef TARGET_PROMOTE_FUNCTION_MODE
-#define TARGET_PROMOTE_FUNCTION_MODE ix86_promote_function_mode
-
 #undef TARGET_SECONDARY_RELOAD
 #define TARGET_SECONDARY_RELOAD ix86_secondary_reload
 



More information about the Gcc-patches mailing list