OSDN Git Service

* targhooks.c (default_hidden_stack_protect_fail): Fall back to
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 27 Jun 2005 08:03:26 +0000 (08:03 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 27 Jun 2005 08:03:26 +0000 (08:03 +0000)
default_external_stack_protect_fail if visibility is not supported
or not flag_pic.
* config/i386/i386.c (ix86_stack_protect_fail): New function.
(TARGET_STACK_PROTECT_FAIL): Define.
* config/i386/i386.md (stack_protect_si): Change CLOBBER into
SET to zero.
(stack_protect_di): Likewise.  Use %k2 instead of %2 to avoid
invalid instruction xorl %rax, %rax.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@101349 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/config/i386/i386.c
gcc/config/i386/i386.md
gcc/targhooks.c

index efa4b6e..dde7e57 100644 (file)
@@ -1,3 +1,15 @@
+2005-06-27  Jakub Jelinek  <jakub@redhat.com>
+
+       * targhooks.c (default_hidden_stack_protect_fail): Fall back to
+       default_external_stack_protect_fail if visibility is not supported
+       or not flag_pic.
+       * config/i386/i386.c (ix86_stack_protect_fail): New function.
+       (TARGET_STACK_PROTECT_FAIL): Define.
+       * config/i386/i386.md (stack_protect_si): Change CLOBBER into
+       SET to zero.
+       (stack_protect_di): Likewise.  Use %k2 instead of %2 to avoid
+       invalid instruction xorl %rax, %rax.
+
 2005-06-27  Richard Henderson  <rth@redhat.com>
 
        * c-cppbuiltin.c (c_cpp_builtins): Add __SSP_ALL__ and __SSP__.
index 0f487c4..620d862 100644 (file)
@@ -906,6 +906,7 @@ static bool ix86_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
 static void ix86_init_builtins (void);
 static rtx ix86_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
 static const char *ix86_mangle_fundamental_type (tree);
+static tree ix86_stack_protect_fail (void);
 
 /* This function is only used on Solaris.  */
 static void i386_solaris_elf_named_section (const char *, unsigned int, tree)
@@ -1082,7 +1083,7 @@ static void init_ext_80387_constants (void);
 #define TARGET_MANGLE_FUNDAMENTAL_TYPE ix86_mangle_fundamental_type
 
 #undef TARGET_STACK_PROTECT_FAIL
-#define TARGET_STACK_PROTECT_FAIL default_hidden_stack_protect_fail
+#define TARGET_STACK_PROTECT_FAIL ix86_stack_protect_fail
 
 struct gcc_target targetm = TARGET_INITIALIZER;
 
@@ -17564,4 +17565,17 @@ ix86_mangle_fundamental_type (tree type)
     }
 }
 
+/* For 32-bit code we can save PIC register setup by using
+   __stack_chk_fail_local hidden function instead of calling
+   __stack_chk_fail directly.  64-bit code doesn't need to setup any PIC
+   register, so it is better to call __stack_chk_fail directly.  */
+
+static tree
+ix86_stack_protect_fail (void)
+{
+  return TARGET_64BIT
+        ? default_external_stack_protect_fail ()
+        : default_hidden_stack_protect_fail ();
+}
+
 #include "gt-i386.h"
index 8aaad7b..e8af640 100644 (file)
 (define_insn "stack_protect_set_si"
   [(set (match_operand:SI 0 "memory_operand" "=m")
        (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
-   (clobber (match_scratch:SI 2 "=r"))
+   (set (match_scratch:SI 2 "=&r") (const_int 0))
    (clobber (reg:CC FLAGS_REG))]
   ""
   "mov{l}\t{%1, %2|%2, %1}\;mov{l}\t{%2, %0|%0, %2}\;xor{l}\t%2, %2"
 (define_insn "stack_protect_set_di"
   [(set (match_operand:DI 0 "memory_operand" "=m")
        (unspec:DI [(match_operand:DI 1 "memory_operand" "m")] UNSPEC_SP_SET))
-   (clobber (match_scratch:DI 2 "=r"))
+   (set (match_scratch:DI 2 "=&r") (const_int 0))
    (clobber (reg:CC FLAGS_REG))]
   "TARGET_64BIT"
-  "mov{q}\t{%1, %2|%2, %1}\;mov{q}\t{%2, %0|%0, %2}\;xor{l}\t%2, %2"
+  "mov{q}\t{%1, %2|%2, %1}\;mov{q}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2"
   [(set_attr "type" "multi")])
 
 (define_expand "stack_protect_test"
index ec374c6..0664f2c 100644 (file)
@@ -380,9 +380,15 @@ default_external_stack_protect_fail (void)
 tree
 default_hidden_stack_protect_fail (void)
 {
+#ifndef HAVE_GAS_HIDDEN
+  return default_external_stack_protect_fail ();
+#else
   tree t = stack_chk_fail_decl;
 
-  if (stack_chk_fail_decl == NULL_TREE)
+  if (!flag_pic)
+    return default_external_stack_protect_fail ();
+
+  if (t == NULL_TREE)
     {
       t = build_function_type_list (void_type_node, NULL_TREE);
       t = build_decl (FUNCTION_DECL,
@@ -402,6 +408,7 @@ default_hidden_stack_protect_fail (void)
     }
 
   return build_function_call_expr (t, NULL_TREE);
+#endif
 }
 
 #include "gt-targhooks.h"