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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@103034
138bc75d-0d04-0410-961f-
82ee72b054a4
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.
#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
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);
/* 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);
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);
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);
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);
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);
'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).
gcc_unreachable ();
return;
+ case 'G':
+ fprintf (file, "%u", GET_MODE_SIZE (GET_MODE (x)));
+ return;
+
case 'O':
{
struct s390_address ad;
(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")])