]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
linux.h (TARGET_THREAD_SSP_OFFSET): Define.
authorAndreas Krebbel <krebbel1@de.ibm.com>
Fri, 12 Aug 2005 13:49:18 +0000 (13:49 +0000)
committerUlrich Weigand <uweigand@gcc.gnu.org>
Fri, 12 Aug 2005 13:49:18 +0000 (13:49 +0000)
2005-08-12  Andreas Krebbel  <krebbel1@de.ibm.com>
    Jakub Jelinek  <jakub@redhat.com>

* config/s390/linux.h (TARGET_THREAD_SSP_OFFSET): Define.
* config/s390/s390-protos.h (s390_get_thread_pointer): Prototype added.
* config/s390/s390.c (print_operand): New output modifier 'G' added.
(get_thread_pointer): Renamed to s390_get_thread_pointer.
* config/s390/s390.md (stack_protect_set, stack_protect_test): If
TARGET_THREAD_SSP_OFFSET is defined, change operands[1] to
(MEM:P (PLUS:P (tp, TARGET_THREAD_SSP_OFFSET))).
(UNSPEC_SP_SET, UNSPEC_SP_TEST): New constants.
("stack_protect_set", "stack_protect_test"): New expanders.
("stack_protect_setsi", "stack_protect_setdi", "stack_protect_testsi",
"stack_protect_testdi"): New insn definitions.

Co-Authored-By: Jakub Jelinek <jakub@redhat.com>
From-SVN: r103034

gcc/ChangeLog
gcc/config/s390/linux.h
gcc/config/s390/s390-protos.h
gcc/config/s390/s390.c
gcc/config/s390/s390.md

index 844115840fdab03e308d5cdf1ed4ba3bbfd8f858..6c0fae6f6a951085ef6a6141dd553853c38ef927 100644 (file)
@@ -1,3 +1,18 @@
+2005-08-12  Andreas Krebbel  <krebbel1@de.ibm.com>
+           Jakub Jelinek  <jakub@redhat.com>
+
+       * config/s390/linux.h (TARGET_THREAD_SSP_OFFSET): Define.
+       * config/s390/s390-protos.h (s390_get_thread_pointer): Prototype added.
+       * config/s390/s390.c (print_operand): New output modifier 'G' added.
+       (get_thread_pointer): Renamed to s390_get_thread_pointer.
+       * config/s390/s390.md (stack_protect_set, stack_protect_test): If
+       TARGET_THREAD_SSP_OFFSET is defined, change operands[1] to
+       (MEM:P (PLUS:P (tp, TARGET_THREAD_SSP_OFFSET))).
+       (UNSPEC_SP_SET, UNSPEC_SP_TEST): New constants.
+       ("stack_protect_set", "stack_protect_test"): New expanders.
+       ("stack_protect_setsi", "stack_protect_setdi", "stack_protect_testsi",
+       "stack_protect_testdi"): New insn definitions.
+
 2005-08-12  Andreas Krebbel  <krebbel1@de.ibm.com>
 
        * config/s390/s390.md ("*movdf_31"): Changed constraint from P to K.
index 866ed5edd476150bb90de19007c9ab223abea293..4f58c734547e87689c7fb3bb3967a92a3030a767 100644 (file)
@@ -94,4 +94,10 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
 
 #define MD_UNWIND_SUPPORT "config/s390/linux-unwind.h"
 
+#ifdef TARGET_LIBC_PROVIDES_SSP
+/* s390 glibc provides __stack_chk_guard in 0x14(tp),
+   s390x glibc provides it at 0x28(tp).  */
+#define TARGET_THREAD_SSP_OFFSET        (TARGET_64BIT ? 0x28 : 0x14)
+#endif
+
 #endif
index 7d63c7503e332d38081a55376ae538624474e843..c9480591b2301487eaec8b835ded201194a42e61 100644 (file)
@@ -91,6 +91,7 @@ extern void s390_initialize_trampoline (rtx, rtx, rtx);
 extern rtx s390_gen_rtx_const_DI (int, int);
 extern int s390_agen_dep_p (rtx, rtx);
 extern rtx s390_load_got (void);
+extern rtx s390_get_thread_pointer (void);
 extern void s390_emit_tpf_eh_return (rtx);
 extern bool s390_legitimate_address_without_index_p (rtx);
 extern int s390_branch_condition_mask (rtx);
index 277006f6473115b7fbf7334f599c3e32f4413985..b5e1bf7f6fd92a935cd24ceb7682eb0543ce2448 100644 (file)
@@ -2832,8 +2832,8 @@ legitimize_pic_address (rtx orig, rtx reg)
 
 /* Load the thread pointer into a register.  */
 
-static rtx
-get_thread_pointer (void)
+rtx
+s390_get_thread_pointer (void)
 {
   rtx tp = gen_reg_rtx (Pmode);
 
@@ -2893,7 +2893,7 @@ legitimize_tls_address (rtx addr, rtx reg)
        temp = gen_reg_rtx (Pmode);
        emit_libcall_block (insn, temp, r2, new);
 
-       new = gen_rtx_PLUS (Pmode, get_thread_pointer (), temp);
+       new = gen_rtx_PLUS (Pmode, s390_get_thread_pointer (), temp);
        if (reg != 0)
          {
            s390_load_address (reg, new);
@@ -2916,7 +2916,7 @@ legitimize_tls_address (rtx addr, rtx reg)
        temp = gen_reg_rtx (Pmode);
        emit_libcall_block (insn, temp, r2, new);
 
-       new = gen_rtx_PLUS (Pmode, get_thread_pointer (), temp);
+       new = gen_rtx_PLUS (Pmode, s390_get_thread_pointer (), temp);
        base = gen_reg_rtx (Pmode);
        s390_load_address (base, new);
 
@@ -3003,7 +3003,7 @@ legitimize_tls_address (rtx addr, rtx reg)
            emit_insn (gen_rtx_SET (Pmode, temp, new));
          }
 
-       new = gen_rtx_PLUS (Pmode, get_thread_pointer (), temp);
+       new = gen_rtx_PLUS (Pmode, s390_get_thread_pointer (), temp);
        if (reg != 0)
          {
            s390_load_address (reg, new);
@@ -3018,7 +3018,7 @@ legitimize_tls_address (rtx addr, rtx reg)
         temp = gen_reg_rtx (Pmode);
        emit_move_insn (temp, new);
 
-       new = gen_rtx_PLUS (Pmode, get_thread_pointer (), temp);
+       new = gen_rtx_PLUS (Pmode, s390_get_thread_pointer (), temp);
        if (reg != 0)
          {
            s390_load_address (reg, new);
@@ -3931,6 +3931,7 @@ print_operand_address (FILE *file, rtx addr)
     'C': print opcode suffix for branch condition.
     'D': print opcode suffix for inverse branch condition.
     'J': print tls_load/tls_gdcall/tls_ldcall suffix
+    'G': print the size of the operand in bytes.
     'O': print only the displacement of a memory reference.
     'R': print only the base register of a memory reference.
     'S': print S-type memory reference (base+displacement).
@@ -3977,6 +3978,10 @@ print_operand (FILE *file, rtx x, int code)
        gcc_unreachable ();
       return;
 
+    case 'G':
+      fprintf (file, "%u", GET_MODE_SIZE (GET_MODE (x)));
+      return;
+
     case 'O':
       {
         struct s390_address ad;
index 26e0e792918fa8efbc6dbf793af47448f6936cf4..85e0b60b30de4caec5d887dd015a6969daf12c42 100644 (file)
    (UNSPEC_TLS_LOAD            512)
 
    ; String Functions
-   (UNSPEC_SRST                600)
+   (UNSPEC_SRST                        600)
+   
+   ; Stack Smashing Protector
+   (UNSPEC_SP_SET              700)
+   (UNSPEC_SP_TEST             701)
  ])
 
 ;;
   DONE;
 })
 
+;
+; Stack Protector Patterns
+;
+
+(define_expand "stack_protect_set"
+  [(set (match_operand 0 "memory_operand" "")
+       (match_operand 1 "memory_operand" ""))]
+  ""
+{
+#ifdef TARGET_THREAD_SSP_OFFSET
+  operands[1]
+    = gen_rtx_MEM (Pmode, gen_rtx_PLUS (Pmode, s390_get_thread_pointer (),
+                                        GEN_INT (TARGET_THREAD_SSP_OFFSET)));
+#endif
+  if (TARGET_64BIT)
+    emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
+  else
+    emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
+
+  DONE;
+})
+
+(define_insn "stack_protect_set<mode>"
+  [(set (match_operand:DSI 0 "memory_operand" "=Q")
+        (unspec:DSI [(match_operand:DSI 1 "memory_operand" "Q")] UNSPEC_SP_SET))]
+  ""
+  "mvc\t%O0(%G0,%R0),%S1"
+  [(set_attr "op_type" "SS")])
+
+(define_expand "stack_protect_test"
+  [(set (reg:CC CC_REGNUM)
+       (compare (match_operand 0 "memory_operand" "")
+                (match_operand 1 "memory_operand" "")))
+   (match_operand 2 "" "")]
+  ""
+{
+#ifdef TARGET_THREAD_SSP_OFFSET
+  operands[1]
+    = gen_rtx_MEM (Pmode, gen_rtx_PLUS (Pmode, s390_get_thread_pointer (),
+                                        GEN_INT (TARGET_THREAD_SSP_OFFSET)));
+#endif
+  s390_compare_op0 = operands[0];
+  s390_compare_op1 = operands[1];
+  s390_compare_emitted = gen_rtx_REG (CCZmode, CC_REGNUM);
+
+  if (TARGET_64BIT)
+    emit_insn (gen_stack_protect_testdi (operands[0], operands[1]));
+  else
+    emit_insn (gen_stack_protect_testsi (operands[0], operands[1]));
+
+  emit_jump_insn (gen_beq (operands[2]));
+
+  DONE;
+})
+
+(define_insn "stack_protect_test<mode>"
+  [(set (reg:CCZ CC_REGNUM)
+        (unspec:CCZ [(match_operand:DSI 0 "memory_operand" "Q")
+                    (match_operand:DSI 1 "memory_operand" "Q")] UNSPEC_SP_TEST))]
+  ""
+  "clc\t%O0(%G0,%R0),%S1"
+  [(set_attr "op_type" "SS")])