|
|
4dd737 |
commit 27d2a2d27f3e0060ade9a1a82ce2292aad6c6931
|
|
|
4dd737 |
Author: law <law@138bc75d-0d04-0410-961f-82ee72b054a4>
|
|
|
4dd737 |
Date: Mon Sep 25 23:13:55 2017 +0000
|
|
|
4dd737 |
|
|
|
4dd737 |
* config/rs6000/rs6000-protos.h (output_probe_stack_range): Update
|
|
|
4dd737 |
prototype for new argument.
|
|
|
4dd737 |
* config/rs6000/rs6000.c (rs6000_emit_allocate_stack_1): New function,
|
|
|
4dd737 |
mostly extracted from rs6000_emit_allocate_stack.
|
|
|
4dd737 |
(rs6000_emit_probe_stack_range_stack_clash): New function.
|
|
|
4dd737 |
(rs6000_emit_allocate_stack): Call
|
|
|
4dd737 |
rs6000_emit_probe_stack_range_stack_clash as needed.
|
|
|
4dd737 |
(rs6000_emit_probe_stack_range): Add additional argument
|
|
|
4dd737 |
to call to gen_probe_stack_range{si,di}.
|
|
|
4dd737 |
(output_probe_stack_range): New.
|
|
|
4dd737 |
(output_probe_stack_range_1): Renamed from output_probe_stack_range.
|
|
|
4dd737 |
(output_probe_stack_range_stack_clash): New.
|
|
|
4dd737 |
(rs6000_emit_prologue): Emit notes into dump file as requested.
|
|
|
4dd737 |
* rs6000.md (allocate_stack): Handle -fstack-clash-protection.
|
|
|
4dd737 |
(probe_stack_range<P:mode>): Operand 0 is now early-clobbered.
|
|
|
4dd737 |
Add additional operand and pass it to output_probe_stack_range.
|
|
|
4dd737 |
|
|
|
4dd737 |
* lib/target-supports.exp
|
|
|
4dd737 |
(check_effective_target_supports_stack_clash_protection): Enable for
|
|
|
4dd737 |
rs6000 and powerpc targets.
|
|
|
4dd737 |
|
|
|
4dd737 |
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@253179 138bc75d-0d04-0410-961f-82ee72b054a4
|
|
|
4dd737 |
|
|
|
4dd737 |
diff --git a/gcc/config/rs6000/rs6000-protos.h b/gcc/config/rs6000/rs6000-protos.h
|
|
|
4dd737 |
index d4b93d9970d..cfb23ab80cc 100644
|
|
|
4dd737 |
--- a/gcc/config/rs6000/rs6000-protos.h
|
|
|
4dd737 |
+++ b/gcc/config/rs6000/rs6000-protos.h
|
|
|
4dd737 |
@@ -114,7 +114,7 @@ extern void rs6000_emit_sCOND (enum machine_mode, rtx[]);
|
|
|
4dd737 |
extern void rs6000_emit_cbranch (enum machine_mode, rtx[]);
|
|
|
4dd737 |
extern char * output_cbranch (rtx, const char *, int, rtx);
|
|
|
4dd737 |
extern char * output_e500_flip_gt_bit (rtx, rtx);
|
|
|
4dd737 |
-extern const char * output_probe_stack_range (rtx, rtx);
|
|
|
4dd737 |
+extern const char * output_probe_stack_range (rtx, rtx, rtx);
|
|
|
4dd737 |
extern rtx rs6000_emit_set_const (rtx, enum machine_mode, rtx, int);
|
|
|
4dd737 |
extern int rs6000_emit_cmove (rtx, rtx, rtx, rtx);
|
|
|
4dd737 |
extern int rs6000_emit_vector_cond_expr (rtx, rtx, rtx, rtx, rtx, rtx);
|
|
|
4dd737 |
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
|
|
|
4dd737 |
index a9052c6becf..c5d9988c1d9 100644
|
|
|
4dd737 |
--- a/gcc/config/rs6000/rs6000.c
|
|
|
4dd737 |
+++ b/gcc/config/rs6000/rs6000.c
|
|
|
4dd737 |
@@ -22320,6 +22320,220 @@ rs6000_emit_stack_tie (rtx fp, bool hard_frame_needed)
|
|
|
4dd737 |
emit_insn (gen_stack_tie (gen_rtx_PARALLEL (VOIDmode, p)));
|
|
|
4dd737 |
}
|
|
|
4dd737 |
|
|
|
4dd737 |
+/* Allocate SIZE_INT bytes on the stack using a store with update style insn
|
|
|
4dd737 |
+ and set the appropriate attributes for the generated insn. Return the
|
|
|
4dd737 |
+ first insn which adjusts the stack pointer or the last insn before
|
|
|
4dd737 |
+ the stack adjustment loop.
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ SIZE_INT is used to create the CFI note for the allocation.
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ SIZE_RTX is an rtx containing the size of the adjustment. Note that
|
|
|
4dd737 |
+ since stacks grow to lower addresses its runtime value is -SIZE_INT.
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ ORIG_SP contains the backchain value that must be stored at *sp. */
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+static rtx
|
|
|
4dd737 |
+rs6000_emit_allocate_stack_1 (HOST_WIDE_INT size_int, rtx orig_sp)
|
|
|
4dd737 |
+{
|
|
|
4dd737 |
+ rtx insn;
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ rtx size_rtx = GEN_INT (-size_int);
|
|
|
4dd737 |
+ if (size_int > 32767)
|
|
|
4dd737 |
+ {
|
|
|
4dd737 |
+ rtx tmp_reg = gen_rtx_REG (Pmode, 0);
|
|
|
4dd737 |
+ /* Need a note here so that try_split doesn't get confused. */
|
|
|
4dd737 |
+ if (get_last_insn () == NULL_RTX)
|
|
|
4dd737 |
+ emit_note (NOTE_INSN_DELETED);
|
|
|
4dd737 |
+ insn = emit_move_insn (tmp_reg, size_rtx);
|
|
|
4dd737 |
+ try_split (PATTERN (insn), insn, 0);
|
|
|
4dd737 |
+ size_rtx = tmp_reg;
|
|
|
4dd737 |
+ }
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ if (Pmode == SImode)
|
|
|
4dd737 |
+ insn = emit_insn (gen_movsi_update_stack (stack_pointer_rtx,
|
|
|
4dd737 |
+ stack_pointer_rtx,
|
|
|
4dd737 |
+ size_rtx,
|
|
|
4dd737 |
+ orig_sp));
|
|
|
4dd737 |
+ else
|
|
|
4dd737 |
+ insn = emit_insn (gen_movdi_di_update_stack (stack_pointer_rtx,
|
|
|
4dd737 |
+ stack_pointer_rtx,
|
|
|
4dd737 |
+ size_rtx,
|
|
|
4dd737 |
+ orig_sp));
|
|
|
4dd737 |
+ rtx par = PATTERN (insn);
|
|
|
4dd737 |
+ gcc_assert (GET_CODE (par) == PARALLEL);
|
|
|
4dd737 |
+ rtx set = XVECEXP (par, 0, 0);
|
|
|
4dd737 |
+ gcc_assert (GET_CODE (set) == SET);
|
|
|
4dd737 |
+ rtx mem = SET_DEST (set);
|
|
|
4dd737 |
+ gcc_assert (MEM_P (mem));
|
|
|
4dd737 |
+ MEM_NOTRAP_P (mem) = 1;
|
|
|
4dd737 |
+ set_mem_alias_set (mem, get_frame_alias_set ());
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ RTX_FRAME_RELATED_P (insn) = 1;
|
|
|
4dd737 |
+ add_reg_note (insn, REG_FRAME_RELATED_EXPR,
|
|
|
4dd737 |
+ gen_rtx_SET (VOIDmode, stack_pointer_rtx,
|
|
|
4dd737 |
+ gen_rtx_PLUS (Pmode,
|
|
|
4dd737 |
+ stack_pointer_rtx,
|
|
|
4dd737 |
+ GEN_INT (-size_int))));
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ /* Emit a blockage to ensure the allocation/probing insns are
|
|
|
4dd737 |
+ not optimized, combined, removed, etc. Add REG_STACK_CHECK
|
|
|
4dd737 |
+ note for similar reasons. */
|
|
|
4dd737 |
+ if (flag_stack_clash_protection)
|
|
|
4dd737 |
+ {
|
|
|
4dd737 |
+ add_reg_note (insn, REG_STACK_CHECK, const0_rtx);
|
|
|
4dd737 |
+ emit_insn (gen_blockage ());
|
|
|
4dd737 |
+ }
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ return insn;
|
|
|
4dd737 |
+}
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+static HOST_WIDE_INT
|
|
|
4dd737 |
+get_stack_clash_protection_probe_interval (void)
|
|
|
4dd737 |
+{
|
|
|
4dd737 |
+ return (HOST_WIDE_INT_1U
|
|
|
4dd737 |
+ << PARAM_VALUE (PARAM_STACK_CLASH_PROTECTION_PROBE_INTERVAL));
|
|
|
4dd737 |
+}
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+static HOST_WIDE_INT
|
|
|
4dd737 |
+get_stack_clash_protection_guard_size (void)
|
|
|
4dd737 |
+{
|
|
|
4dd737 |
+ return (HOST_WIDE_INT_1U
|
|
|
4dd737 |
+ << PARAM_VALUE (PARAM_STACK_CLASH_PROTECTION_GUARD_SIZE));
|
|
|
4dd737 |
+}
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+/* Allocate ORIG_SIZE bytes on the stack and probe the newly
|
|
|
4dd737 |
+ allocated space every STACK_CLASH_PROTECTION_PROBE_INTERVAL bytes.
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ COPY_REG, if non-null, should contain a copy of the original
|
|
|
4dd737 |
+ stack pointer at exit from this function.
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ This is subtly different than the Ada probing in that it tries hard to
|
|
|
4dd737 |
+ prevent attacks that jump the stack guard. Thus it is never allowed to
|
|
|
4dd737 |
+ allocate more than STACK_CLASH_PROTECTION_PROBE_INTERVAL bytes of stack
|
|
|
4dd737 |
+ space without a suitable probe. */
|
|
|
4dd737 |
+static rtx
|
|
|
4dd737 |
+rs6000_emit_probe_stack_range_stack_clash (HOST_WIDE_INT orig_size,
|
|
|
4dd737 |
+ rtx copy_reg)
|
|
|
4dd737 |
+{
|
|
|
4dd737 |
+ rtx orig_sp = copy_reg;
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ HOST_WIDE_INT probe_interval = get_stack_clash_protection_probe_interval ();
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ /* Round the size down to a multiple of PROBE_INTERVAL. */
|
|
|
4dd737 |
+ HOST_WIDE_INT rounded_size = ROUND_DOWN (orig_size, probe_interval);
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ /* If explicitly requested,
|
|
|
4dd737 |
+ or the rounded size is not the same as the original size
|
|
|
4dd737 |
+ or the the rounded size is greater than a page,
|
|
|
4dd737 |
+ then we will need a copy of the original stack pointer. */
|
|
|
4dd737 |
+ if (rounded_size != orig_size
|
|
|
4dd737 |
+ || rounded_size > probe_interval
|
|
|
4dd737 |
+ || copy_reg)
|
|
|
4dd737 |
+ {
|
|
|
4dd737 |
+ /* If the caller did not request a copy of the incoming stack
|
|
|
4dd737 |
+ pointer, then we use r0 to hold the copy. */
|
|
|
4dd737 |
+ if (!copy_reg)
|
|
|
4dd737 |
+ orig_sp = gen_rtx_REG (Pmode, 0);
|
|
|
4dd737 |
+ emit_move_insn (orig_sp, stack_pointer_rtx);
|
|
|
4dd737 |
+ }
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ /* There's three cases here.
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ One is a single probe which is the most common and most efficiently
|
|
|
4dd737 |
+ implemented as it does not have to have a copy of the original
|
|
|
4dd737 |
+ stack pointer if there are no residuals.
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ Second is unrolled allocation/probes which we use if there's just
|
|
|
4dd737 |
+ a few of them. It needs to save the original stack pointer into a
|
|
|
4dd737 |
+ temporary for use as a source register in the allocation/probe.
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ Last is a loop. This is the most uncommon case and least efficient. */
|
|
|
4dd737 |
+ rtx retval = NULL;
|
|
|
4dd737 |
+ if (rounded_size == probe_interval)
|
|
|
4dd737 |
+ {
|
|
|
4dd737 |
+ retval = rs6000_emit_allocate_stack_1 (probe_interval, stack_pointer_rtx);
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ dump_stack_clash_frame_info (PROBE_INLINE, rounded_size != orig_size);
|
|
|
4dd737 |
+ }
|
|
|
4dd737 |
+ else if (rounded_size <= 8 * probe_interval)
|
|
|
4dd737 |
+ {
|
|
|
4dd737 |
+ /* The ABI requires using the store with update insns to allocate
|
|
|
4dd737 |
+ space and store the backchain into the stack
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ So we save the current stack pointer into a temporary, then
|
|
|
4dd737 |
+ emit the store-with-update insns to store the saved stack pointer
|
|
|
4dd737 |
+ into the right location in each new page. */
|
|
|
4dd737 |
+ for (int i = 0; i < rounded_size; i += probe_interval)
|
|
|
4dd737 |
+ {
|
|
|
4dd737 |
+ rtx insn = rs6000_emit_allocate_stack_1 (probe_interval, orig_sp);
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ /* Save the first stack adjustment in RETVAL. */
|
|
|
4dd737 |
+ if (i == 0)
|
|
|
4dd737 |
+ retval = insn;
|
|
|
4dd737 |
+ }
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ dump_stack_clash_frame_info (PROBE_INLINE, rounded_size != orig_size);
|
|
|
4dd737 |
+ }
|
|
|
4dd737 |
+ else
|
|
|
4dd737 |
+ {
|
|
|
4dd737 |
+ /* Compute the ending address. */
|
|
|
4dd737 |
+ rtx end_addr
|
|
|
4dd737 |
+ = copy_reg ? gen_rtx_REG (Pmode, 0) : gen_rtx_REG (Pmode, 12);
|
|
|
4dd737 |
+ rtx rs = GEN_INT (-rounded_size);
|
|
|
4dd737 |
+ rtx insn;
|
|
|
4dd737 |
+ if (add_operand (rs, Pmode))
|
|
|
4dd737 |
+ insn = emit_insn (gen_add3_insn (end_addr, stack_pointer_rtx, rs));
|
|
|
4dd737 |
+ else
|
|
|
4dd737 |
+ {
|
|
|
4dd737 |
+ emit_move_insn (end_addr, GEN_INT (-rounded_size));
|
|
|
4dd737 |
+ insn = emit_insn (gen_add3_insn (end_addr, end_addr,
|
|
|
4dd737 |
+ stack_pointer_rtx));
|
|
|
4dd737 |
+ /* Describe the effect of INSN to the CFI engine. */
|
|
|
4dd737 |
+ add_reg_note (insn, REG_FRAME_RELATED_EXPR,
|
|
|
4dd737 |
+ gen_rtx_SET (VOIDmode, end_addr,
|
|
|
4dd737 |
+ gen_rtx_PLUS (Pmode, stack_pointer_rtx,
|
|
|
4dd737 |
+ rs)));
|
|
|
4dd737 |
+ }
|
|
|
4dd737 |
+ RTX_FRAME_RELATED_P (insn) = 1;
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ /* Emit the loop. */
|
|
|
4dd737 |
+ if (TARGET_64BIT)
|
|
|
4dd737 |
+ retval = emit_insn (gen_probe_stack_rangedi (stack_pointer_rtx,
|
|
|
4dd737 |
+ stack_pointer_rtx, orig_sp,
|
|
|
4dd737 |
+ end_addr));
|
|
|
4dd737 |
+ else
|
|
|
4dd737 |
+ retval = emit_insn (gen_probe_stack_rangesi (stack_pointer_rtx,
|
|
|
4dd737 |
+ stack_pointer_rtx, orig_sp,
|
|
|
4dd737 |
+ end_addr));
|
|
|
4dd737 |
+ RTX_FRAME_RELATED_P (retval) = 1;
|
|
|
4dd737 |
+ /* Describe the effect of INSN to the CFI engine. */
|
|
|
4dd737 |
+ add_reg_note (retval, REG_FRAME_RELATED_EXPR,
|
|
|
4dd737 |
+ gen_rtx_SET (VOIDmode, stack_pointer_rtx, end_addr));
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ /* Emit a blockage to ensure the allocation/probing insns are
|
|
|
4dd737 |
+ not optimized, combined, removed, etc. Other cases handle this
|
|
|
4dd737 |
+ within their call to rs6000_emit_allocate_stack_1. */
|
|
|
4dd737 |
+ emit_insn (gen_blockage ());
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ dump_stack_clash_frame_info (PROBE_LOOP, rounded_size != orig_size);
|
|
|
4dd737 |
+ }
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ if (orig_size != rounded_size)
|
|
|
4dd737 |
+ {
|
|
|
4dd737 |
+ /* Allocate (and implicitly probe) any residual space. */
|
|
|
4dd737 |
+ HOST_WIDE_INT residual = orig_size - rounded_size;
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ rtx insn = rs6000_emit_allocate_stack_1 (residual, orig_sp);
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ /* If the residual was the only allocation, then we can return the
|
|
|
4dd737 |
+ allocating insn. */
|
|
|
4dd737 |
+ if (!retval)
|
|
|
4dd737 |
+ retval = insn;
|
|
|
4dd737 |
+ }
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ return retval;
|
|
|
4dd737 |
+}
|
|
|
4dd737 |
+
|
|
|
4dd737 |
/* Emit the correct code for allocating stack space, as insns.
|
|
|
4dd737 |
If COPY_REG, make sure a copy of the old frame is left there.
|
|
|
4dd737 |
The generated code may use hard register 0 as a temporary. */
|
|
|
4dd737 |
@@ -22331,7 +22545,6 @@ rs6000_emit_allocate_stack (HOST_WIDE_INT size, rtx copy_reg, int copy_off)
|
|
|
4dd737 |
rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
|
|
|
4dd737 |
rtx tmp_reg = gen_rtx_REG (Pmode, 0);
|
|
|
4dd737 |
rtx todec = gen_int_mode (-size, Pmode);
|
|
|
4dd737 |
- rtx par, set, mem;
|
|
|
4dd737 |
|
|
|
4dd737 |
if (INTVAL (todec) != -size)
|
|
|
4dd737 |
{
|
|
|
4dd737 |
@@ -22368,6 +22581,22 @@ rs6000_emit_allocate_stack (HOST_WIDE_INT size, rtx copy_reg, int copy_off)
|
|
|
4dd737 |
warning (0, "stack limit expression is not supported");
|
|
|
4dd737 |
}
|
|
|
4dd737 |
|
|
|
4dd737 |
+ if (flag_stack_clash_protection)
|
|
|
4dd737 |
+ {
|
|
|
4dd737 |
+ if (size < get_stack_clash_protection_guard_size ())
|
|
|
4dd737 |
+ dump_stack_clash_frame_info (NO_PROBE_SMALL_FRAME, true);
|
|
|
4dd737 |
+ else
|
|
|
4dd737 |
+ {
|
|
|
4dd737 |
+ rtx insn = rs6000_emit_probe_stack_range_stack_clash (size, copy_reg);
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ /* If we asked for a copy with an offset, then we still need add in
|
|
|
4dd737 |
+ the offset. */
|
|
|
4dd737 |
+ if (copy_reg && copy_off)
|
|
|
4dd737 |
+ emit_insn (gen_add3_insn (copy_reg, copy_reg, GEN_INT (copy_off)));
|
|
|
4dd737 |
+ return;
|
|
|
4dd737 |
+ }
|
|
|
4dd737 |
+ }
|
|
|
4dd737 |
+
|
|
|
4dd737 |
if (copy_reg)
|
|
|
4dd737 |
{
|
|
|
4dd737 |
if (copy_off != 0)
|
|
|
4dd737 |
@@ -22376,39 +22605,12 @@ rs6000_emit_allocate_stack (HOST_WIDE_INT size, rtx copy_reg, int copy_off)
|
|
|
4dd737 |
emit_move_insn (copy_reg, stack_reg);
|
|
|
4dd737 |
}
|
|
|
4dd737 |
|
|
|
4dd737 |
- if (size > 32767)
|
|
|
4dd737 |
- {
|
|
|
4dd737 |
- /* Need a note here so that try_split doesn't get confused. */
|
|
|
4dd737 |
- if (get_last_insn () == NULL_RTX)
|
|
|
4dd737 |
- emit_note (NOTE_INSN_DELETED);
|
|
|
4dd737 |
- insn = emit_move_insn (tmp_reg, todec);
|
|
|
4dd737 |
- try_split (PATTERN (insn), insn, 0);
|
|
|
4dd737 |
- todec = tmp_reg;
|
|
|
4dd737 |
- }
|
|
|
4dd737 |
-
|
|
|
4dd737 |
- insn = emit_insn (TARGET_32BIT
|
|
|
4dd737 |
- ? gen_movsi_update_stack (stack_reg, stack_reg,
|
|
|
4dd737 |
- todec, stack_reg)
|
|
|
4dd737 |
- : gen_movdi_di_update_stack (stack_reg, stack_reg,
|
|
|
4dd737 |
- todec, stack_reg));
|
|
|
4dd737 |
/* Since we didn't use gen_frame_mem to generate the MEM, grab
|
|
|
4dd737 |
it now and set the alias set/attributes. The above gen_*_update
|
|
|
4dd737 |
calls will generate a PARALLEL with the MEM set being the first
|
|
|
4dd737 |
operation. */
|
|
|
4dd737 |
- par = PATTERN (insn);
|
|
|
4dd737 |
- gcc_assert (GET_CODE (par) == PARALLEL);
|
|
|
4dd737 |
- set = XVECEXP (par, 0, 0);
|
|
|
4dd737 |
- gcc_assert (GET_CODE (set) == SET);
|
|
|
4dd737 |
- mem = SET_DEST (set);
|
|
|
4dd737 |
- gcc_assert (MEM_P (mem));
|
|
|
4dd737 |
- MEM_NOTRAP_P (mem) = 1;
|
|
|
4dd737 |
- set_mem_alias_set (mem, get_frame_alias_set ());
|
|
|
4dd737 |
-
|
|
|
4dd737 |
- RTX_FRAME_RELATED_P (insn) = 1;
|
|
|
4dd737 |
- add_reg_note (insn, REG_FRAME_RELATED_EXPR,
|
|
|
4dd737 |
- gen_rtx_SET (VOIDmode, stack_reg,
|
|
|
4dd737 |
- gen_rtx_PLUS (Pmode, stack_reg,
|
|
|
4dd737 |
- GEN_INT (-size))));
|
|
|
4dd737 |
+ insn = rs6000_emit_allocate_stack_1 (size, stack_reg);
|
|
|
4dd737 |
+ return;
|
|
|
4dd737 |
}
|
|
|
4dd737 |
|
|
|
4dd737 |
#define PROBE_INTERVAL (1 << STACK_CHECK_PROBE_INTERVAL_EXP)
|
|
|
4dd737 |
@@ -22490,9 +22692,9 @@ rs6000_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size)
|
|
|
4dd737 |
until it is equal to ROUNDED_SIZE. */
|
|
|
4dd737 |
|
|
|
4dd737 |
if (TARGET_64BIT)
|
|
|
4dd737 |
- emit_insn (gen_probe_stack_rangedi (r12, r12, r0));
|
|
|
4dd737 |
+ emit_insn (gen_probe_stack_rangedi (r12, r12, stack_pointer_rtx, r0));
|
|
|
4dd737 |
else
|
|
|
4dd737 |
- emit_insn (gen_probe_stack_rangesi (r12, r12, r0));
|
|
|
4dd737 |
+ emit_insn (gen_probe_stack_rangesi (r12, r12, stack_pointer_rtx, r0));
|
|
|
4dd737 |
|
|
|
4dd737 |
|
|
|
4dd737 |
/* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time
|
|
|
4dd737 |
@@ -22504,10 +22706,10 @@ rs6000_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size)
|
|
|
4dd737 |
}
|
|
|
4dd737 |
|
|
|
4dd737 |
/* Probe a range of stack addresses from REG1 to REG2 inclusive. These are
|
|
|
4dd737 |
- absolute addresses. */
|
|
|
4dd737 |
+ addresses, not offsets. */
|
|
|
4dd737 |
|
|
|
4dd737 |
-const char *
|
|
|
4dd737 |
-output_probe_stack_range (rtx reg1, rtx reg2)
|
|
|
4dd737 |
+static const char *
|
|
|
4dd737 |
+output_probe_stack_range_1 (rtx reg1, rtx reg2)
|
|
|
4dd737 |
{
|
|
|
4dd737 |
static int labelno = 0;
|
|
|
4dd737 |
char loop_lab[32], end_lab[32];
|
|
|
4dd737 |
@@ -22546,6 +22748,63 @@ output_probe_stack_range (rtx reg1, rtx reg2)
|
|
|
4dd737 |
return "";
|
|
|
4dd737 |
}
|
|
|
4dd737 |
|
|
|
4dd737 |
+/* Probe a range of stack addresses from REG1 to REG3 inclusive. These are
|
|
|
4dd737 |
+ addresses, not offsets.
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ REG2 contains the backchain that must be stored into *sp at each allocation.
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ This is subtly different than the Ada probing above in that it tries hard
|
|
|
4dd737 |
+ to prevent attacks that jump the stack guard. Thus, it is never allowed
|
|
|
4dd737 |
+ to allocate more than PROBE_INTERVAL bytes of stack space without a
|
|
|
4dd737 |
+ suitable probe. */
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+static const char *
|
|
|
4dd737 |
+output_probe_stack_range_stack_clash (rtx reg1, rtx reg2, rtx reg3)
|
|
|
4dd737 |
+{
|
|
|
4dd737 |
+ static int labelno = 0;
|
|
|
4dd737 |
+ char loop_lab[32];
|
|
|
4dd737 |
+ rtx xops[3];
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ HOST_WIDE_INT probe_interval = get_stack_clash_protection_probe_interval ();
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno++);
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ /* This allocates and probes. */
|
|
|
4dd737 |
+ xops[0] = reg1;
|
|
|
4dd737 |
+ xops[1] = reg2;
|
|
|
4dd737 |
+ xops[2] = GEN_INT (-probe_interval);
|
|
|
4dd737 |
+ if (TARGET_64BIT)
|
|
|
4dd737 |
+ output_asm_insn ("stdu %1,%2(%0)", xops);
|
|
|
4dd737 |
+ else
|
|
|
4dd737 |
+ output_asm_insn ("stwu %1,%2(%0)", xops);
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ /* Jump to LOOP_LAB if TEST_ADDR != LAST_ADDR. */
|
|
|
4dd737 |
+ xops[0] = reg1;
|
|
|
4dd737 |
+ xops[1] = reg3;
|
|
|
4dd737 |
+ if (TARGET_64BIT)
|
|
|
4dd737 |
+ output_asm_insn ("cmpd 0,%0,%1", xops);
|
|
|
4dd737 |
+ else
|
|
|
4dd737 |
+ output_asm_insn ("cmpw 0,%0,%1", xops);
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ fputs ("\tbne 0,", asm_out_file);
|
|
|
4dd737 |
+ assemble_name_raw (asm_out_file, loop_lab);
|
|
|
4dd737 |
+ fputc ('\n', asm_out_file);
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ return "";
|
|
|
4dd737 |
+}
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+/* Wrapper around the output_probe_stack_range routines. */
|
|
|
4dd737 |
+const char *
|
|
|
4dd737 |
+output_probe_stack_range (rtx reg1, rtx reg2, rtx reg3)
|
|
|
4dd737 |
+{
|
|
|
4dd737 |
+ if (flag_stack_clash_protection)
|
|
|
4dd737 |
+ return output_probe_stack_range_stack_clash (reg1, reg2, reg3);
|
|
|
4dd737 |
+ else
|
|
|
4dd737 |
+ return output_probe_stack_range_1 (reg1, reg3);
|
|
|
4dd737 |
+}
|
|
|
4dd737 |
+
|
|
|
4dd737 |
/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
|
|
|
4dd737 |
with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
|
|
|
4dd737 |
is not NULL. It would be nice if dwarf2out_frame_debug_expr could
|
|
|
4dd737 |
@@ -23857,6 +24116,13 @@ rs6000_emit_prologue (void)
|
|
|
4dd737 |
}
|
|
|
4dd737 |
}
|
|
|
4dd737 |
|
|
|
4dd737 |
+ /* If we are emitting stack probes, but allocate no stack, then
|
|
|
4dd737 |
+ just note that in the dump file. */
|
|
|
4dd737 |
+ if (flag_stack_clash_protection
|
|
|
4dd737 |
+ && dump_file
|
|
|
4dd737 |
+ && !info->push_p)
|
|
|
4dd737 |
+ dump_stack_clash_frame_info (NO_PROBE_NO_FRAME, false);
|
|
|
4dd737 |
+
|
|
|
4dd737 |
/* Update stack and set back pointer unless this is V.4,
|
|
|
4dd737 |
for which it was done previously. */
|
|
|
4dd737 |
if (!WORLD_SAVE_P (info) && info->push_p
|
|
|
4dd737 |
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
|
|
|
4dd737 |
index cd197213480..3cd70e592c1 100644
|
|
|
4dd737 |
--- a/gcc/config/rs6000/rs6000.md
|
|
|
4dd737 |
+++ b/gcc/config/rs6000/rs6000.md
|
|
|
4dd737 |
@@ -11822,10 +11822,20 @@
|
|
|
4dd737 |
;;
|
|
|
4dd737 |
;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
|
|
|
4dd737 |
;; We move the back-chain and decrement the stack pointer.
|
|
|
4dd737 |
-
|
|
|
4dd737 |
+;;
|
|
|
4dd737 |
+;; Operand1 is more naturally reg_or_short_operand. However, for a large
|
|
|
4dd737 |
+;; constant alloca, using that predicate will force the generic code to put
|
|
|
4dd737 |
+;; the constant size into a register before calling the expander.
|
|
|
4dd737 |
+;;
|
|
|
4dd737 |
+;; As a result the expander would not have the constant size information
|
|
|
4dd737 |
+;; in those cases and would have to generate less efficient code.
|
|
|
4dd737 |
+;;
|
|
|
4dd737 |
+;; Thus we allow reg_or_cint_operand instead so that the expander can see
|
|
|
4dd737 |
+;; the constant size. The value is forced into a register if necessary.
|
|
|
4dd737 |
+;;
|
|
|
4dd737 |
(define_expand "allocate_stack"
|
|
|
4dd737 |
[(set (match_operand 0 "gpc_reg_operand" "")
|
|
|
4dd737 |
- (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
|
|
|
4dd737 |
+ (minus (reg 1) (match_operand 1 "reg_or_cint_operand" "")))
|
|
|
4dd737 |
(set (reg 1)
|
|
|
4dd737 |
(minus (reg 1) (match_dup 1)))]
|
|
|
4dd737 |
""
|
|
|
4dd737 |
@@ -11835,6 +11845,15 @@
|
|
|
4dd737 |
rtx neg_op0;
|
|
|
4dd737 |
rtx insn, par, set, mem;
|
|
|
4dd737 |
|
|
|
4dd737 |
+ /* By allowing reg_or_cint_operand as the predicate we can get
|
|
|
4dd737 |
+ better code for stack-clash-protection because we do not lose
|
|
|
4dd737 |
+ size information. But the rest of the code expects the operand
|
|
|
4dd737 |
+ to be reg_or_short_operand. If it isn't, then force it into
|
|
|
4dd737 |
+ a register. */
|
|
|
4dd737 |
+ rtx orig_op1 = operands[1];
|
|
|
4dd737 |
+ if (!reg_or_short_operand (operands[1], Pmode))
|
|
|
4dd737 |
+ operands[1] = force_reg (Pmode, operands[1]);
|
|
|
4dd737 |
+
|
|
|
4dd737 |
emit_move_insn (chain, stack_bot);
|
|
|
4dd737 |
|
|
|
4dd737 |
/* Check stack bounds if necessary. */
|
|
|
4dd737 |
@@ -11847,6 +11866,51 @@
|
|
|
4dd737 |
emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
|
|
|
4dd737 |
}
|
|
|
4dd737 |
|
|
|
4dd737 |
+ /* Allocate and probe if requested.
|
|
|
4dd737 |
+ This may look similar to the loop we use for prologue allocations,
|
|
|
4dd737 |
+ but it is critically different. For the former we know the loop
|
|
|
4dd737 |
+ will iterate, but do not know that generally here. The former
|
|
|
4dd737 |
+ uses that knowledge to rotate the loop. Combining them would be
|
|
|
4dd737 |
+ possible with some performance cost. */
|
|
|
4dd737 |
+ if (flag_stack_clash_protection)
|
|
|
4dd737 |
+ {
|
|
|
4dd737 |
+ rtx rounded_size, last_addr, residual;
|
|
|
4dd737 |
+ HOST_WIDE_INT probe_interval;
|
|
|
4dd737 |
+ compute_stack_clash_protection_loop_data (&rounded_size, &last_addr,
|
|
|
4dd737 |
+ &residual, &probe_interval,
|
|
|
4dd737 |
+ orig_op1);
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ /* We do occasionally get in here with constant sizes, we might
|
|
|
4dd737 |
+ as well do a reasonable job when we obviously can. */
|
|
|
4dd737 |
+ if (rounded_size != const0_rtx)
|
|
|
4dd737 |
+ {
|
|
|
4dd737 |
+ rtx loop_lab, end_loop;
|
|
|
4dd737 |
+ bool rotated = CONST_INT_P (rounded_size);
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ emit_stack_clash_protection_probe_loop_start (&loop_lab, &end_loop,
|
|
|
4dd737 |
+ last_addr, rotated);
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ if (Pmode == SImode)
|
|
|
4dd737 |
+ emit_insn (gen_movsi_update_stack (stack_pointer_rtx,
|
|
|
4dd737 |
+ stack_pointer_rtx,
|
|
|
4dd737 |
+ GEN_INT (-probe_interval),
|
|
|
4dd737 |
+ chain));
|
|
|
4dd737 |
+ else
|
|
|
4dd737 |
+ emit_insn (gen_movdi_di_update_stack (stack_pointer_rtx,
|
|
|
4dd737 |
+ stack_pointer_rtx,
|
|
|
4dd737 |
+ GEN_INT (-probe_interval),
|
|
|
4dd737 |
+ chain));
|
|
|
4dd737 |
+ emit_stack_clash_protection_probe_loop_end (loop_lab, end_loop,
|
|
|
4dd737 |
+ last_addr, rotated);
|
|
|
4dd737 |
+ }
|
|
|
4dd737 |
+
|
|
|
4dd737 |
+ /* Now handle residuals. We just have to set operands[1] correctly
|
|
|
4dd737 |
+ and let the rest of the expander run. */
|
|
|
4dd737 |
+ operands[1] = residual;
|
|
|
4dd737 |
+ if (!CONST_INT_P (residual))
|
|
|
4dd737 |
+ operands[1] = force_reg (Pmode, operands[1]);
|
|
|
4dd737 |
+ }
|
|
|
4dd737 |
+
|
|
|
4dd737 |
if (GET_CODE (operands[1]) != CONST_INT
|
|
|
4dd737 |
|| INTVAL (operands[1]) < -32767
|
|
|
4dd737 |
|| INTVAL (operands[1]) > 32768)
|
|
|
4dd737 |
@@ -12994,12 +13058,13 @@
|
|
|
4dd737 |
(set_attr "length" "4")])
|
|
|
4dd737 |
|
|
|
4dd737 |
(define_insn "probe_stack_range<P:mode>"
|
|
|
4dd737 |
- [(set (match_operand:P 0 "register_operand" "=r")
|
|
|
4dd737 |
+ [(set (match_operand:P 0 "register_operand" "=&r")
|
|
|
4dd737 |
(unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
|
|
|
4dd737 |
- (match_operand:P 2 "register_operand" "r")]
|
|
|
4dd737 |
+ (match_operand:P 2 "register_operand" "r")
|
|
|
4dd737 |
+ (match_operand:P 3 "register_operand" "r")]
|
|
|
4dd737 |
UNSPECV_PROBE_STACK_RANGE))]
|
|
|
4dd737 |
""
|
|
|
4dd737 |
- "* return output_probe_stack_range (operands[0], operands[2]);"
|
|
|
4dd737 |
+ "* return output_probe_stack_range (operands[0], operands[2], operands[3]);"
|
|
|
4dd737 |
[(set_attr "type" "three")])
|
|
|
4dd737 |
|
|
|
4dd737 |
;; Compare insns are next. Note that the RS/6000 has two types of compares,
|
|
|
4dd737 |
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
|
|
|
4dd737 |
index 7c126e4122b..aba99513ed0 100644
|
|
|
4dd737 |
--- a/gcc/testsuite/lib/target-supports.exp
|
|
|
4dd737 |
+++ b/gcc/testsuite/lib/target-supports.exp
|
|
|
4dd737 |
@@ -5421,12 +5421,12 @@ proc check_effective_target_autoincdec { } {
|
|
|
4dd737 |
proc check_effective_target_supports_stack_clash_protection { } {
|
|
|
4dd737 |
|
|
|
4dd737 |
# Temporary until the target bits are fully ACK'd.
|
|
|
4dd737 |
-# if { [istarget aarch*-*-*]
|
|
|
4dd737 |
-# || [istarget powerpc*-*-*] || [istarget rs6000*-*-*] } {
|
|
|
4dd737 |
+# if { [istarget aarch*-*-*] } {
|
|
|
4dd737 |
# return 1
|
|
|
4dd737 |
# }
|
|
|
4dd737 |
|
|
|
4dd737 |
if { [istarget x86_64-*-*] || [istarget i?86-*-*]
|
|
|
4dd737 |
+ || [istarget powerpc*-*-*] || [istarget rs6000*-*-*]
|
|
|
4dd737 |
|| [istarget s390*-*-*] } {
|
|
|
4dd737 |
return 1
|
|
|
4dd737 |
}
|