From de927194c98f2382976bf7a33fc9182e349214fa Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Sat, 19 Jun 2004 10:30:08 +0000 Subject: [PATCH] Include ProPolice suport for GCC 3.4. Obtained-from: http://www.trl.ibm.com/projects/security/ssp Adjust Makefile.langs to use the patched common.opts from cc_prep. --- gnu/usr.bin/cc34/Makefile.langs | 4 +- .../cc34/cc_prep/patches/calls.c.patch | 18 +++ .../cc34/cc_prep/patches/combine.c.patch | 66 ++++++++++ .../cc34/cc_prep/patches/common.opt.patch | 30 +++++ gnu/usr.bin/cc34/cc_prep/patches/cse.c.patch | 35 ++++++ .../cc34/cc_prep/patches/explow.c.patch | 51 ++++++++ gnu/usr.bin/cc34/cc_prep/patches/expr.c.patch | 102 ++++++++++++++++ .../cc34/cc_prep/patches/flags.h.patch | 28 +++++ .../cc34/cc_prep/patches/function.c.patch | 115 ++++++++++++++++++ gnu/usr.bin/cc34/cc_prep/patches/gcse.c.patch | 13 ++ .../cc34/cc_prep/patches/integrate.c.patch | 26 ++++ gnu/usr.bin/cc34/cc_prep/patches/loop.c.patch | 19 +++ .../cc34/cc_prep/patches/optabs.c.patch | 31 +++++ gnu/usr.bin/cc34/cc_prep/patches/opts.c.patch | 40 ++++++ .../cc34/cc_prep/patches/reload1.c.patch | 62 ++++++++++ gnu/usr.bin/cc34/cc_prep/patches/rtl.h.patch | 54 ++++++++ .../cc34/cc_prep/patches/simplify-rtx.c.patch | 79 ++++++++++++ .../cc34/cc_prep/patches/toplev.c.patch | 65 ++++++++++ gnu/usr.bin/cc34/cc_prep/patches/tree.h.patch | 15 +++ gnu/usr.bin/cc34/libbackend/Makefile | 5 +- 20 files changed, 855 insertions(+), 3 deletions(-) create mode 100644 gnu/usr.bin/cc34/cc_prep/patches/calls.c.patch create mode 100644 gnu/usr.bin/cc34/cc_prep/patches/combine.c.patch create mode 100644 gnu/usr.bin/cc34/cc_prep/patches/common.opt.patch create mode 100644 gnu/usr.bin/cc34/cc_prep/patches/cse.c.patch create mode 100644 gnu/usr.bin/cc34/cc_prep/patches/explow.c.patch create mode 100644 gnu/usr.bin/cc34/cc_prep/patches/expr.c.patch create mode 100644 gnu/usr.bin/cc34/cc_prep/patches/flags.h.patch create mode 100644 gnu/usr.bin/cc34/cc_prep/patches/function.c.patch create mode 100644 gnu/usr.bin/cc34/cc_prep/patches/gcse.c.patch create mode 100644 gnu/usr.bin/cc34/cc_prep/patches/integrate.c.patch create mode 100644 gnu/usr.bin/cc34/cc_prep/patches/loop.c.patch create mode 100644 gnu/usr.bin/cc34/cc_prep/patches/optabs.c.patch create mode 100644 gnu/usr.bin/cc34/cc_prep/patches/opts.c.patch create mode 100644 gnu/usr.bin/cc34/cc_prep/patches/reload1.c.patch create mode 100644 gnu/usr.bin/cc34/cc_prep/patches/rtl.h.patch create mode 100644 gnu/usr.bin/cc34/cc_prep/patches/simplify-rtx.c.patch create mode 100644 gnu/usr.bin/cc34/cc_prep/patches/toplev.c.patch create mode 100644 gnu/usr.bin/cc34/cc_prep/patches/tree.h.patch diff --git a/gnu/usr.bin/cc34/Makefile.langs b/gnu/usr.bin/cc34/Makefile.langs index 6ac7a85b76..3ca360038a 100644 --- a/gnu/usr.bin/cc34/Makefile.langs +++ b/gnu/usr.bin/cc34/Makefile.langs @@ -1,10 +1,10 @@ -# $DragonFly: src/gnu/usr.bin/cc34/Makefile.langs,v 1.1 2004/06/14 22:27:52 joerg Exp $ +# $DragonFly: src/gnu/usr.bin/cc34/Makefile.langs,v 1.2 2004/06/19 10:30:08 joerg Exp $ gencheck_defs= cp/cp-tree.def gencheck_defs+= objc/objc-tree.def optionsfiles= ${GCCDIR}/gcc/c.opt -optionsfiles+= ${GCCDIR}/gcc/common.opt +optionsfiles+= ${OTOPDIR}/cc_prep/common.opt optionsfiles+= ${GCCDIR}/gcc/f/lang.opt options.c options.h: ${optionsfiles} ${STOPDIR}/Makefile.langs diff --git a/gnu/usr.bin/cc34/cc_prep/patches/calls.c.patch b/gnu/usr.bin/cc34/cc_prep/patches/calls.c.patch new file mode 100644 index 0000000000..29ceb7e0ea --- /dev/null +++ b/gnu/usr.bin/cc34/cc_prep/patches/calls.c.patch @@ -0,0 +1,18 @@ +$DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/calls.c.patch,v 1.1 2004/06/19 10:30:08 joerg Exp $ + +--- ../gcc.orig/calls.c 2004-06-18 23:08:10.000000000 +0200 ++++ calls.c 2004-06-18 23:09:50.000000000 +0200 +@@ -2321,7 +2321,12 @@ + { + /* For variable-sized objects, we must be called with a target + specified. If we were to allocate space on the stack here, +- we would have no way of knowing when to free it. */ ++ we would have no way of knowing when to free it. ++ ++ This is the structure of a function return object and it isn't ++ a character array for the stack protection, so it is ++ marked using the assignment of the KEEP argument to 5. */ ++ + rtx d = assign_temp (TREE_TYPE (exp), 1, 1, 1); + + mark_temp_addr_taken (d); diff --git a/gnu/usr.bin/cc34/cc_prep/patches/combine.c.patch b/gnu/usr.bin/cc34/cc_prep/patches/combine.c.patch new file mode 100644 index 0000000000..1f834e22f4 --- /dev/null +++ b/gnu/usr.bin/cc34/cc_prep/patches/combine.c.patch @@ -0,0 +1,66 @@ +$DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/combine.c.patch,v 1.1 2004/06/19 10:30:08 joerg Exp $ + +--- ../gcc.orig/combine.c 2004-06-18 23:08:10.000000000 +0200 ++++ combine.c 2004-06-18 23:13:41.000000000 +0200 +@@ -1401,6 +1401,10 @@ + && ! fixed_regs[REGNO (dest)] + && CLASS_LIKELY_SPILLED_P (REGNO_REG_CLASS (REGNO (dest)))))) + return 1; ++ /* Never combine loads and stores protecting argument that use set insn ++ with used flag on. */ ++ if (SET_VOLATILE_P (set)) ++ return 1; + + return 0; + } +@@ -3781,6 +3785,19 @@ + rtx inner_op1 = XEXP (x, 1); + rtx inner; + ++#ifndef FRAME_GROWS_DOWNWARD ++ /* For the case where the frame grows upward, ++ the stack protector keeps the offset of the frame pointer ++ positive integer. */ ++ if (flag_propolice_protection ++ && code == PLUS ++ && other == frame_pointer_rtx ++ && GET_CODE (inner_op0) == CONST_INT ++ && GET_CODE (inner_op1) == CONST_INT ++ && INTVAL (inner_op0) > 0 ++ && INTVAL (inner_op0) + INTVAL (inner_op1) <= 0) ++ return x; ++#endif + /* Make sure we pass the constant operand if any as the second + one if this is a commutative operation. */ + if (CONSTANT_P (inner_op0) && GET_RTX_CLASS (code) == 'c') +@@ -4143,6 +4160,13 @@ + outermost. That's because that's the way indexed addresses are + supposed to appear. This code used to check many more cases, but + they are now checked elsewhere. */ ++#ifndef FRAME_GROWS_DOWNWARD ++ /* The stack protector keeps the addressing style of a local variable ++ to be able to change its stack position. */ ++ if (! (flag_propolice_protection ++ && XEXP (XEXP (x, 0), 0) == frame_pointer_rtx ++ && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)) ++#endif + if (GET_CODE (XEXP (x, 0)) == PLUS + && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1))) + return gen_binary (PLUS, mode, +@@ -4272,8 +4296,14 @@ + } + + /* Canonicalize (minus A (plus B C)) to (minus (minus A B) C) for +- integers. */ +- if (GET_CODE (XEXP (x, 1)) == PLUS && INTEGRAL_MODE_P (mode)) ++ integers. ++ ++ The stack protector keeps the addressing style of ++ a local variable. */ ++ if (GET_CODE (XEXP (x, 1)) == PLUS && INTEGRAL_MODE_P (mode) ++ && (! (flag_propolice_protection ++ && XEXP (XEXP (x, 1), 0) == frame_pointer_rtx ++ && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT))) + return gen_binary (MINUS, mode, + gen_binary (MINUS, mode, XEXP (x, 0), + XEXP (XEXP (x, 1), 0)), diff --git a/gnu/usr.bin/cc34/cc_prep/patches/common.opt.patch b/gnu/usr.bin/cc34/cc_prep/patches/common.opt.patch new file mode 100644 index 0000000000..d449f768ad --- /dev/null +++ b/gnu/usr.bin/cc34/cc_prep/patches/common.opt.patch @@ -0,0 +1,30 @@ +$DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/common.opt.patch,v 1.1 2004/06/19 10:30:08 joerg Exp $ + +--- ../gcc.orig/common.opt 2004-06-18 23:08:10.000000000 +0200 ++++ common.opt 2004-06-18 23:14:47.000000000 +0200 +@@ -152,6 +152,10 @@ + Common + Warn when a variable is unused + ++Wstack-protector ++Common ++Warn when not issuing stack smashing protection for some reason ++ + aux-info + Common Separate + -aux-info Emit declaration information into +@@ -738,6 +742,14 @@ + Common + Put zero initialized data in the bss section + ++fstack-protector ++Common ++Enables stack protection ++ ++fstack-protector-all ++Common ++Enables stack protection of every function ++ + g + Common JoinedOrMissing + Generate debug information in default format diff --git a/gnu/usr.bin/cc34/cc_prep/patches/cse.c.patch b/gnu/usr.bin/cc34/cc_prep/patches/cse.c.patch new file mode 100644 index 0000000000..1bd23783cc --- /dev/null +++ b/gnu/usr.bin/cc34/cc_prep/patches/cse.c.patch @@ -0,0 +1,35 @@ +$DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/cse.c.patch,v 1.1 2004/06/19 10:30:08 joerg Exp $ + +--- ../gcc.orig/cse.c 2004-06-18 23:08:11.000000000 +0200 ++++ cse.c 2004-06-18 23:16:13.000000000 +0200 +@@ -4203,7 +4203,14 @@ + + if (new_const == 0) + break; +- ++#ifndef FRAME_GROWS_DOWNWARD ++ if (flag_propolice_protection ++ && GET_CODE (y) == PLUS ++ && XEXP (y, 0) == frame_pointer_rtx ++ && INTVAL (inner_const) > 0 ++ && INTVAL (new_const) <= 0) ++ break; ++#endif + /* If we are associating shift operations, don't let this + produce a shift of the size of the object or larger. + This could occur when we follow a sign-extend by a right +@@ -4735,6 +4742,14 @@ + if (SET_DEST (x) == pc_rtx + && GET_CODE (SET_SRC (x)) == LABEL_REF) + ; ++ /* cut the reg propagation of stack-protected argument. */ ++ else if (SET_VOLATILE_P (x)) { ++ rtx x1 = SET_DEST (x); ++ if (GET_CODE (x1) == SUBREG && GET_CODE (SUBREG_REG (x1)) == REG) ++ x1 = SUBREG_REG (x1); ++ if (! REGNO_QTY_VALID_P(REGNO (x1))) ++ make_new_qty (REGNO (x1), GET_MODE (x1)); ++ } + + /* Don't count call-insns, (set (reg 0) (call ...)), as a set. + The hard function value register is used only once, to copy to diff --git a/gnu/usr.bin/cc34/cc_prep/patches/explow.c.patch b/gnu/usr.bin/cc34/cc_prep/patches/explow.c.patch new file mode 100644 index 0000000000..443b9b48f0 --- /dev/null +++ b/gnu/usr.bin/cc34/cc_prep/patches/explow.c.patch @@ -0,0 +1,51 @@ +$DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/explow.c.patch,v 1.1 2004/06/19 10:30:08 joerg Exp $ + +--- ../gcc.orig/explow.c 2004-06-18 23:08:11.000000000 +0200 ++++ explow.c 2004-06-18 23:18:11.000000000 +0200 +@@ -84,7 +84,8 @@ + rtx tem; + int all_constant = 0; + +- if (c == 0) ++ if (c == 0 ++ && ! (flag_propolice_protection && x == virtual_stack_vars_rtx)) + return x; + + restart: +@@ -185,7 +186,8 @@ + break; + } + +- if (c != 0) ++ if (c != 0 ++ || (flag_propolice_protection && x == virtual_stack_vars_rtx)) + x = gen_rtx_PLUS (mode, x, GEN_INT (c)); + + if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF) +@@ -474,6 +476,26 @@ + if (memory_address_p (mode, oldx)) + goto win2; + ++ /* The stack protector keeps the addressing style of a local variable. ++ LEGITIMIZE_ADDRESS changes the addressing to the machine-dependent ++ style, so the protector split the frame address to a register using ++ force_reg. */ ++ if (flag_propolice_protection) ++ { ++#define FRAMEADDR_P(X) (GET_CODE (X) == PLUS \ ++ && XEXP (X, 0) == virtual_stack_vars_rtx \ ++ && GET_CODE (XEXP (X, 1)) == CONST_INT) ++ rtx y; ++ if (FRAMEADDR_P (x)) ++ goto win; ++ for (y = x; y != 0 && GET_CODE (y) == PLUS; y = XEXP (y, 0)) ++ { ++ if (FRAMEADDR_P (XEXP (y, 0))) ++ XEXP (y, 0) = force_reg (GET_MODE (XEXP (y, 0)), XEXP (y, 0)); ++ if (FRAMEADDR_P (XEXP (y, 1))) ++ XEXP (y, 1) = force_reg (GET_MODE (XEXP (y, 1)), XEXP (y, 1)); ++ } ++ } + /* Perform machine-dependent transformations on X + in certain cases. This is not necessary since the code + below can handle all possible cases, but machine-dependent diff --git a/gnu/usr.bin/cc34/cc_prep/patches/expr.c.patch b/gnu/usr.bin/cc34/cc_prep/patches/expr.c.patch new file mode 100644 index 0000000000..ed9de5f4e9 --- /dev/null +++ b/gnu/usr.bin/cc34/cc_prep/patches/expr.c.patch @@ -0,0 +1,102 @@ +$DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/expr.c.patch,v 1.1 2004/06/19 10:30:08 joerg Exp $ + +--- ../gcc.orig/expr.c 2004-06-18 23:08:11.000000000 +0200 ++++ expr.c 2004-06-18 23:22:24.000000000 +0200 +@@ -48,6 +48,7 @@ + #include "intl.h" + #include "tm_p.h" + #include "target.h" ++#include "protector.h" + + /* Decide whether a function's arguments should be processed + from first to last or from last to first. +@@ -1060,7 +1061,11 @@ + + If ENDP is 0 return to, if ENDP is 1 return memory at the end ala + mempcpy, and if ENDP is 2 return memory the end minus one byte ala +- stpcpy. */ ++ stpcpy. ++ ++ When the stack protector is used at the reverse move, it starts the move ++ instruction from the address within the region of a variable. ++ So it eliminates the first address decrement instruction. */ + + rtx + move_by_pieces (rtx to, rtx from, unsigned HOST_WIDE_INT len, +@@ -1123,6 +1128,8 @@ + + if (USE_LOAD_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_from) + { ++ if (flag_propolice_protection) ++ len = len - GET_MODE_SIZE (mode); + data.from_addr = copy_addr_to_reg (plus_constant (from_addr, len)); + data.autinc_from = 1; + data.explicit_inc_from = -1; +@@ -1137,6 +1144,8 @@ + data.from_addr = copy_addr_to_reg (from_addr); + if (USE_STORE_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_to) + { ++ if (flag_propolice_protection) ++ len = len - GET_MODE_SIZE (mode); + data.to_addr = copy_addr_to_reg (plus_constant (to_addr, len)); + data.autinc_to = 1; + data.explicit_inc_to = -1; +@@ -1280,11 +1289,15 @@ + from1 = adjust_address (data->from, mode, data->offset); + + if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0) +- emit_insn (gen_add2_insn (data->to_addr, +- GEN_INT (-(HOST_WIDE_INT)size))); ++ /* The stack protector skips the first address decrement instruction ++ at the reverse move. */ ++ if (!flag_propolice_protection || data->explicit_inc_to < -1) ++ emit_insn (gen_add2_insn (data->to_addr, ++ GEN_INT (-(HOST_WIDE_INT)size))); + if (HAVE_PRE_DECREMENT && data->explicit_inc_from < 0) +- emit_insn (gen_add2_insn (data->from_addr, +- GEN_INT (-(HOST_WIDE_INT)size))); ++ if (!flag_propolice_protection || data->explicit_inc_from < -1) ++ emit_insn (gen_add2_insn (data->from_addr, ++ GEN_INT (-(HOST_WIDE_INT)size))); + + if (data->to) + emit_insn ((*genfun) (to1, from1)); +@@ -2475,7 +2488,12 @@ + + if (USE_STORE_PRE_DECREMENT (mode) && data->reverse && ! data->autinc_to) + { +- data->to_addr = copy_addr_to_reg (plus_constant (to_addr, data->len)); ++ int len = data->len; ++ /* The stack protector starts the store instruction from ++ the address within the region of a variable. */ ++ if (flag_propolice_protection) ++ len -= GET_MODE_SIZE (mode); ++ data->to_addr = copy_addr_to_reg (plus_constant (to_addr, len)); + data->autinc_to = 1; + data->explicit_inc_to = -1; + } +@@ -2544,8 +2562,11 @@ + to1 = adjust_address (data->to, mode, data->offset); + + if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0) +- emit_insn (gen_add2_insn (data->to_addr, +- GEN_INT (-(HOST_WIDE_INT) size))); ++ /* The stack protector skips the first address decrement instruction ++ at the reverse store. */ ++ if (!flag_propolice_protection || data->explicit_inc_to < -1) ++ emit_insn (gen_add2_insn (data->to_addr, ++ GEN_INT (-(HOST_WIDE_INT) size))); + + cst = (*data->constfun) (data->constfundata, data->offset, mode); + emit_insn ((*genfun) (to1, cst)); +@@ -5701,7 +5722,9 @@ + && GET_CODE (XEXP (value, 0)) == PLUS + && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG + && REGNO (XEXP (XEXP (value, 0), 0)) >= FIRST_VIRTUAL_REGISTER +- && REGNO (XEXP (XEXP (value, 0), 0)) <= LAST_VIRTUAL_REGISTER) ++ && REGNO (XEXP (XEXP (value, 0), 0)) <= LAST_VIRTUAL_REGISTER ++ && (!flag_propolice_protection ++ || XEXP (XEXP (value, 0), 0) != virtual_stack_vars_rtx)) + { + rtx temp = expand_simple_binop (GET_MODE (value), code, + XEXP (XEXP (value, 0), 0), op2, diff --git a/gnu/usr.bin/cc34/cc_prep/patches/flags.h.patch b/gnu/usr.bin/cc34/cc_prep/patches/flags.h.patch new file mode 100644 index 0000000000..9f044617e4 --- /dev/null +++ b/gnu/usr.bin/cc34/cc_prep/patches/flags.h.patch @@ -0,0 +1,28 @@ +$DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/flags.h.patch,v 1.1 2004/06/19 10:30:08 joerg Exp $ + +--- ../gcc.orig/flags.h 2004-06-18 23:08:11.000000000 +0200 ++++ flags.h 2004-06-18 23:23:31.000000000 +0200 +@@ -186,6 +186,10 @@ + + extern bool warn_strict_aliasing; + ++/* Warn when not issuing stack smashing protection for some reason. */ ++ ++extern bool warn_stack_protector; ++ + /* Nonzero if generating code to do profiling. */ + + extern int profile_flag; +@@ -771,4 +775,12 @@ + #define HONOR_SIGN_DEPENDENT_ROUNDING(MODE) \ + (MODE_HAS_SIGN_DEPENDENT_ROUNDING (MODE) && flag_rounding_math) + ++/* Nonzero means use propolice as a stack protection method. */ ++ ++extern int flag_propolice_protection; ++ ++/* Nonzero means use a stack protection method for every function. */ ++ ++extern int flag_stack_protection; ++ + #endif /* ! GCC_FLAGS_H */ diff --git a/gnu/usr.bin/cc34/cc_prep/patches/function.c.patch b/gnu/usr.bin/cc34/cc_prep/patches/function.c.patch new file mode 100644 index 0000000000..634607f0df --- /dev/null +++ b/gnu/usr.bin/cc34/cc_prep/patches/function.c.patch @@ -0,0 +1,115 @@ +$DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/function.c.patch,v 1.1 2004/06/19 10:30:08 joerg Exp $ + +--- ../gcc.orig/function.c 2004-06-18 23:08:11.000000000 +0200 ++++ function.c 2004-06-18 23:27:25.000000000 +0200 +@@ -63,6 +63,7 @@ + #include "integrate.h" + #include "langhooks.h" + #include "target.h" ++#include "protector.h" + + #ifndef TRAMPOLINE_ALIGNMENT + #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY +@@ -155,6 +156,10 @@ + /* Array of INSN_UIDs to hold the INSN_UIDs for each sibcall epilogue + in this function. */ + static GTY(()) varray_type sibcall_epilogue; ++ ++/* Current boundary mark for character arrays. */ ++static int temp_boundary_mark = 0; ++ + + /* In order to evaluate some expressions, such as function calls returning + structures in memory, we need to temporarily allocate stack locations. +@@ -208,6 +213,8 @@ + /* The size of the slot, including extra space for alignment. This + info is for combine_temp_slots. */ + HOST_WIDE_INT full_size; ++ /* Boundary mark of a character array and the others. This info is for propolice. */ ++ int boundary_mark; + }; + + /* This structure is used to record MEMs or pseudos used to replace VAR, any +@@ -638,6 +645,7 @@ + whose lifetime is controlled by CLEANUP_POINT_EXPRs. KEEP is 3 + if we are to allocate something at an inner level to be treated as + a variable in the block (e.g., a SAVE_EXPR). ++ KEEP is 5 if we allocate a place to return structure. + + TYPE is the type that will be used for the stack slot. */ + +@@ -648,6 +656,8 @@ + unsigned int align; + struct temp_slot *p, *best_p = 0; + rtx slot; ++ int char_array = (flag_propolice_protection ++ && keep == 1 && search_string_def (type)); + + /* If SIZE is -1 it means that somebody tried to allocate a temporary + of a variable size. */ +@@ -673,7 +683,8 @@ + && ! p->in_use + && objects_must_conflict_p (p->type, type) + && (best_p == 0 || best_p->size > p->size +- || (best_p->size == p->size && best_p->align > p->align))) ++ || (best_p->size == p->size && best_p->align > p->align)) ++ && (! char_array || p->boundary_mark != 0)) + { + if (p->align == align && p->size == size) + { +@@ -708,6 +719,7 @@ + p->address = 0; + p->rtl_expr = 0; + p->type = best_p->type; ++ p->boundary_mark = best_p->boundary_mark; + p->next = temp_slots; + temp_slots = p; + +@@ -768,6 +780,7 @@ + p->full_size = frame_offset - frame_offset_old; + #endif + p->address = 0; ++ p->boundary_mark = char_array ? ++temp_boundary_mark : 0; + p->next = temp_slots; + temp_slots = p; + } +@@ -932,14 +945,16 @@ + int delete_q = 0; + if (! q->in_use && GET_MODE (q->slot) == BLKmode) + { +- if (p->base_offset + p->full_size == q->base_offset) ++ if (p->base_offset + p->full_size == q->base_offset && ++ p->boundary_mark == q->boundary_mark) + { + /* Q comes after P; combine Q into P. */ + p->size += q->size; + p->full_size += q->full_size; + delete_q = 1; + } +- else if (q->base_offset + q->full_size == p->base_offset) ++ else if (q->base_offset + q->full_size == p->base_offset && ++ p->boundary_mark == q->boundary_mark) + { + /* P comes after Q; combine P into Q. */ + q->size += p->size; +@@ -1449,7 +1464,9 @@ + } + + if (new == 0) +- new = assign_stack_local_1 (decl_mode, GET_MODE_SIZE (decl_mode), 0, func); ++ new = function ? ++ assign_stack_local_1 (decl_mode, GET_MODE_SIZE (decl_mode), 0, func) ++ : assign_stack_local_for_pseudo_reg (decl_mode, GET_MODE_SIZE (decl_mode), 0); + + PUT_CODE (reg, MEM); + PUT_MODE (reg, decl_mode); +@@ -3930,7 +3947,8 @@ + constant with that register. */ + temp = gen_reg_rtx (Pmode); + XEXP (x, 0) = new; +- if (validate_change (object, &XEXP (x, 1), temp, 0)) ++ if (validate_change (object, &XEXP (x, 1), temp, 0) ++ && !flag_propolice_protection) + emit_insn_before (gen_move_insn (temp, new_offset), object); + else + { diff --git a/gnu/usr.bin/cc34/cc_prep/patches/gcse.c.patch b/gnu/usr.bin/cc34/cc_prep/patches/gcse.c.patch new file mode 100644 index 0000000000..7aea7d15fd --- /dev/null +++ b/gnu/usr.bin/cc34/cc_prep/patches/gcse.c.patch @@ -0,0 +1,13 @@ +$DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/gcse.c.patch,v 1.1 2004/06/19 10:30:08 joerg Exp $ + +--- ../gcc.orig/gcse.c 2004-06-18 23:08:11.000000000 +0200 ++++ gcse.c 2004-06-18 23:27:46.000000000 +0200 +@@ -4178,7 +4178,7 @@ + /* Find an assignment that sets reg_used and is available + at the start of the block. */ + set = find_avail_set (regno, insn); +- if (! set) ++ if (! set || SET_VOLATILE_P (set->expr)) + continue; + + pat = set->expr; diff --git a/gnu/usr.bin/cc34/cc_prep/patches/integrate.c.patch b/gnu/usr.bin/cc34/cc_prep/patches/integrate.c.patch new file mode 100644 index 0000000000..5d8ba324fc --- /dev/null +++ b/gnu/usr.bin/cc34/cc_prep/patches/integrate.c.patch @@ -0,0 +1,26 @@ +$DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/integrate.c.patch,v 1.1 2004/06/19 10:30:08 joerg Exp $ + +--- ../gcc.orig/integrate.c 2004-06-18 23:08:11.000000000 +0200 ++++ integrate.c 2004-06-18 23:28:25.000000000 +0200 +@@ -393,6 +393,10 @@ + /* These args would always appear unused, if not for this. */ + TREE_USED (copy) = 1; + ++ /* The inlined variable is marked as INLINE not to sweep by propolice */ ++ if (flag_propolice_protection && TREE_CODE (copy) == VAR_DECL) ++ DECL_COPIED (copy) = 1; ++ + /* Set the context for the new declaration. */ + if (!DECL_CONTEXT (decl)) + /* Globals stay global. */ +@@ -1970,6 +1974,10 @@ + + seq = get_insns (); + end_sequence (); ++#ifdef ARGS_GROWS_DOWNWARD ++ if (flag_propolice_protection && GET_CODE (seq) == SET) ++ RTX_INTEGRATED_P (SET_SRC (seq)) = 1; ++#endif + emit_insn_after (seq, map->insns_at_start); + return temp; + } diff --git a/gnu/usr.bin/cc34/cc_prep/patches/loop.c.patch b/gnu/usr.bin/cc34/cc_prep/patches/loop.c.patch new file mode 100644 index 0000000000..7f31f4a7ad --- /dev/null +++ b/gnu/usr.bin/cc34/cc_prep/patches/loop.c.patch @@ -0,0 +1,19 @@ +$DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/loop.c.patch,v 1.1 2004/06/19 10:30:08 joerg Exp $ + +--- ../gcc.orig/loop.c 2004-06-18 23:08:12.000000000 +0200 ++++ loop.c 2004-06-18 23:30:01.000000000 +0200 +@@ -6513,6 +6513,14 @@ + if (GET_CODE (*mult_val) == USE) + *mult_val = XEXP (*mult_val, 0); + ++#ifndef FRAME_GROWS_DOWNWARD ++ if (flag_propolice_protection ++ && GET_CODE (*add_val) == PLUS ++ && (XEXP (*add_val, 0) == frame_pointer_rtx ++ || XEXP (*add_val, 1) == frame_pointer_rtx)) ++ return 0; ++#endif ++ + if (is_addr) + *pbenefit += address_cost (orig_x, addr_mode) - reg_address_cost; + else diff --git a/gnu/usr.bin/cc34/cc_prep/patches/optabs.c.patch b/gnu/usr.bin/cc34/cc_prep/patches/optabs.c.patch new file mode 100644 index 0000000000..1321a0ee0d --- /dev/null +++ b/gnu/usr.bin/cc34/cc_prep/patches/optabs.c.patch @@ -0,0 +1,31 @@ +$DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/optabs.c.patch,v 1.1 2004/06/19 10:30:08 joerg Exp $ + +--- ../gcc.orig/optabs.c 2004-06-18 23:08:12.000000000 +0200 ++++ optabs.c 2004-06-18 23:30:52.000000000 +0200 +@@ -678,6 +678,26 @@ + if (target) + target = protect_from_queue (target, 1); + ++ if (flag_propolice_protection ++ && binoptab->code == PLUS ++ && op0 == virtual_stack_vars_rtx ++ && GET_CODE(op1) == CONST_INT) ++ { ++ int icode = (int) binoptab->handlers[(int) mode].insn_code; ++ if (target) ++ temp = target; ++ else ++ temp = gen_reg_rtx (mode); ++ ++ if (! (*insn_data[icode].operand[0].predicate) (temp, mode) ++ || GET_CODE (temp) != REG) ++ temp = gen_reg_rtx (mode); ++ ++ emit_insn (gen_rtx_SET (VOIDmode, temp, ++ gen_rtx_PLUS (GET_MODE (op0), op0, op1))); ++ return temp; ++ } ++ + if (flag_force_mem) + { + /* Load duplicate non-volatile operands once. */ diff --git a/gnu/usr.bin/cc34/cc_prep/patches/opts.c.patch b/gnu/usr.bin/cc34/cc_prep/patches/opts.c.patch new file mode 100644 index 0000000000..7b7f2a79f3 --- /dev/null +++ b/gnu/usr.bin/cc34/cc_prep/patches/opts.c.patch @@ -0,0 +1,40 @@ +$DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/opts.c.patch,v 1.1 2004/06/19 10:30:08 joerg Exp $ + +--- ../gcc.orig/opts.c 2004-06-18 23:08:12.000000000 +0200 ++++ opts.c 2004-06-18 23:31:58.000000000 +0200 +@@ -125,6 +125,9 @@ + bool warn_unused_variable; + bool warn_unused_value; + ++/* Warn when not issuing stack smashing protection for some reason */ ++bool warn_stack_protector; ++ + /* Hack for cooperation between set_Wunused and set_Wextra. */ + static bool maybe_warn_unused_parameter; + +@@ -798,6 +801,10 @@ + warn_unused_variable = value; + break; + ++ case OPT_Wstack_protector: ++ warn_stack_protector = value; ++ break; ++ + case OPT_aux_info: + case OPT_aux_info_: + aux_info_file_name = arg; +@@ -1361,6 +1368,14 @@ + stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg)); + break; + ++ case OPT_fstack_protector: ++ flag_propolice_protection = value; ++ break; ++ ++ case OPT_fstack_protector_all: ++ flag_stack_protection = value; ++ break; ++ + case OPT_fstrength_reduce: + flag_strength_reduce = value; + break; diff --git a/gnu/usr.bin/cc34/cc_prep/patches/reload1.c.patch b/gnu/usr.bin/cc34/cc_prep/patches/reload1.c.patch new file mode 100644 index 0000000000..62b9d8a75a --- /dev/null +++ b/gnu/usr.bin/cc34/cc_prep/patches/reload1.c.patch @@ -0,0 +1,62 @@ +$DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/reload1.c.patch,v 1.1 2004/06/19 10:30:08 joerg Exp $ + +--- ../gcc.orig/reload1.c 2004-06-18 23:08:13.000000000 +0200 ++++ reload1.c 2004-06-18 23:34:14.000000000 +0200 +@@ -43,6 +43,7 @@ + #include "toplev.h" + #include "except.h" + #include "tree.h" ++#include "protector.h" + + /* This file contains the reload pass of the compiler, which is + run after register allocation has been done. It checks that +@@ -891,7 +892,7 @@ + if (cfun->stack_alignment_needed) + assign_stack_local (BLKmode, 0, cfun->stack_alignment_needed); + +- starting_frame_size = get_frame_size (); ++ starting_frame_size = get_frame_size () - get_frame_free_size (); + + set_initial_elim_offsets (); + set_initial_label_offsets (); +@@ -955,7 +956,7 @@ + setup_save_areas (); + + /* If we allocated another stack slot, redo elimination bookkeeping. */ +- if (starting_frame_size != get_frame_size ()) ++ if (starting_frame_size != get_frame_size () - get_frame_free_size ()) + continue; + + if (caller_save_needed) +@@ -974,7 +975,7 @@ + + /* If we allocated any new memory locations, make another pass + since it might have changed elimination offsets. */ +- if (starting_frame_size != get_frame_size ()) ++ if (starting_frame_size != get_frame_size () - get_frame_free_size ()) + something_changed = 1; + + { +@@ -1066,11 +1067,11 @@ + if (insns_need_reload != 0 || something_needs_elimination + || something_needs_operands_changed) + { +- HOST_WIDE_INT old_frame_size = get_frame_size (); ++ HOST_WIDE_INT old_frame_size = get_frame_size () - get_frame_free_size (); + + reload_as_needed (global); + +- if (old_frame_size != get_frame_size ()) ++ if (old_frame_size != get_frame_size () - get_frame_free_size ()) + abort (); + + if (num_eliminable) +@@ -1958,7 +1959,7 @@ + if (from_reg == -1) + { + /* No known place to spill from => no slot to reuse. */ +- x = assign_stack_local (GET_MODE (regno_reg_rtx[i]), total_size, ++ x = assign_stack_local_for_pseudo_reg (GET_MODE (regno_reg_rtx[i]), total_size, + inherent_size == total_size ? 0 : -1); + if (BYTES_BIG_ENDIAN) + /* Cancel the big-endian correction done in assign_stack_local. diff --git a/gnu/usr.bin/cc34/cc_prep/patches/rtl.h.patch b/gnu/usr.bin/cc34/cc_prep/patches/rtl.h.patch new file mode 100644 index 0000000000..2871ab01f2 --- /dev/null +++ b/gnu/usr.bin/cc34/cc_prep/patches/rtl.h.patch @@ -0,0 +1,54 @@ +$DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/rtl.h.patch,v 1.1 2004/06/19 10:30:08 joerg Exp $ + +--- ../gcc.orig/rtl.h 2004-06-18 23:08:13.000000000 +0200 ++++ rtl.h 2004-06-18 23:36:04.000000000 +0200 +@@ -473,6 +473,18 @@ + __FUNCTION__); \ + _rtx; }) + ++#define RTL_FLAG_CHECK9(NAME, RTX, C1, C2, C3, C4, C5, C6, C7, C8, C9) \ ++ __extension__ \ ++({ rtx const _rtx = (RTX); \ ++ if (GET_CODE(_rtx) != C1 && GET_CODE(_rtx) != C2 \ ++ && GET_CODE(_rtx) != C3 && GET_CODE(_rtx) != C4 \ ++ && GET_CODE(_rtx) != C5 && GET_CODE(_rtx) != C6 \ ++ && GET_CODE(_rtx) != C7 && GET_CODE(_rtx) != C8 \ ++ && GET_CODE(_rtx) != C9) \ ++ rtl_check_failed_flag (NAME, _rtx, __FILE__, __LINE__, \ ++ __FUNCTION__); \ ++ _rtx; }) ++ + extern void rtl_check_failed_flag (const char *, rtx, const char *, + int, const char *) + ATTRIBUTE_NORETURN +@@ -488,6 +500,7 @@ + #define RTL_FLAG_CHECK6(NAME, RTX, C1, C2, C3, C4, C5, C6) (RTX) + #define RTL_FLAG_CHECK7(NAME, RTX, C1, C2, C3, C4, C5, C6, C7) (RTX) + #define RTL_FLAG_CHECK8(NAME, RTX, C1, C2, C3, C4, C5, C6, C7, C8) (RTX) ++#define RTL_FLAG_CHECK9(NAME, RTX, C1, C2, C3, C4, C5, C6, C7, C8, C9) (RTX) + #endif + + #define CLEAR_RTX_FLAGS(RTX) \ +@@ -583,9 +596,9 @@ + #define LOG_LINKS(INSN) XEXP(INSN, 7) + + #define RTX_INTEGRATED_P(RTX) \ +- (RTL_FLAG_CHECK8("RTX_INTEGRATED_P", (RTX), INSN, CALL_INSN, \ ++ (RTL_FLAG_CHECK9("RTX_INTEGRATED_P", (RTX), INSN, CALL_INSN, \ + JUMP_INSN, INSN_LIST, BARRIER, CODE_LABEL, CONST, \ +- NOTE)->integrated) ++ PLUS, NOTE)->integrated) + #define RTX_UNCHANGING_P(RTX) \ + (RTL_FLAG_CHECK3("RTX_UNCHANGING_P", (RTX), REG, MEM, CONCAT)->unchanging) + #define RTX_FRAME_RELATED_P(RTX) \ +@@ -1125,6 +1138,10 @@ + (RTL_FLAG_CHECK3("MEM_VOLATILE_P", (RTX), MEM, ASM_OPERANDS, \ + ASM_INPUT)->volatil) + ++/* 1 if RTX is an SET rtx that is not eliminated for the stack protection. */ ++#define SET_VOLATILE_P(RTX) \ ++ (RTL_FLAG_CHECK1("SET_VOLATILE_P", (RTX), SET)->volatil) ++ + /* 1 if RTX is a mem that refers to an aggregate, either to the + aggregate itself of to a field of the aggregate. If zero, RTX may + or may not be such a reference. */ diff --git a/gnu/usr.bin/cc34/cc_prep/patches/simplify-rtx.c.patch b/gnu/usr.bin/cc34/cc_prep/patches/simplify-rtx.c.patch new file mode 100644 index 0000000000..304dcf25e9 --- /dev/null +++ b/gnu/usr.bin/cc34/cc_prep/patches/simplify-rtx.c.patch @@ -0,0 +1,79 @@ +$DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/simplify-rtx.c.patch,v 1.1 2004/06/19 10:30:08 joerg Exp $ + +--- ../gcc.orig/simplify-rtx.c 2004-06-18 23:08:13.000000000 +0200 ++++ simplify-rtx.c 2004-06-18 23:38:36.000000000 +0200 +@@ -2252,6 +2252,7 @@ + int n_ops = 2, input_ops = 2, input_consts = 0, n_consts; + int first, changed; + int i, j; ++ HOST_WIDE_INT fp_offset = 0; + + memset (ops, 0, sizeof ops); + +@@ -2277,6 +2278,10 @@ + switch (this_code) + { + case PLUS: ++ if (flag_propolice_protection ++ && XEXP (this_op, 0) == virtual_stack_vars_rtx ++ && GET_CODE (XEXP (this_op, 1)) == CONST_INT) ++ fp_offset = INTVAL (XEXP (this_op, 1)); + case MINUS: + if (n_ops == 7) + return NULL_RTX; +@@ -2438,11 +2443,24 @@ + && GET_CODE (ops[n_ops - 1].op) == CONST_INT + && CONSTANT_P (ops[n_ops - 2].op)) + { +- rtx value = ops[n_ops - 1].op; +- if (ops[n_ops - 1].neg ^ ops[n_ops - 2].neg) +- value = neg_const_int (mode, value); +- ops[n_ops - 2].op = plus_constant (ops[n_ops - 2].op, INTVAL (value)); +- n_ops--; ++ if (!flag_propolice_protection) ++ { ++ rtx value = ops[n_ops - 1].op; ++ if (ops[n_ops - 1].neg ^ ops[n_ops - 2].neg) ++ value = neg_const_int (mode, value); ++ ops[n_ops - 2].op = plus_constant (ops[n_ops - 2].op, INTVAL (value)); ++ n_ops--; ++ } ++ /* The stack protector keeps the addressing style of a local variable, ++ so it doesn't use neg_const_int function not to change ++ the offset value. */ ++ else { ++ HOST_WIDE_INT value = INTVAL (ops[n_ops - 1].op); ++ if (ops[n_ops - 1].neg ^ ops[n_ops - 2].neg) ++ value = -value; ++ ops[n_ops - 2].op = plus_constant (ops[n_ops - 2].op, value); ++ n_ops--; ++ } + } + + /* Count the number of CONSTs that we generated. */ +@@ -2460,6 +2478,25 @@ + || (n_ops + n_consts == input_ops && n_consts <= input_consts))) + return NULL_RTX; + ++ if (!flag_propolice_protection) ++ { ++ rtx value = ops[n_ops - 1].op; ++ if (ops[n_ops - 1].neg ^ ops[n_ops - 2].neg) ++ value = neg_const_int (mode, value); ++ ops[n_ops - 2].op = plus_constant (ops[n_ops - 2].op, INTVAL (value)); ++ n_ops--; ++ } ++ /* The stack protector keeps the addressing style of a local variable, ++ so it doesn't use neg_const_int function not to change ++ the offset value. */ ++ else { ++ HOST_WIDE_INT value = INTVAL (ops[n_ops - 1].op); ++ if (ops[n_ops - 1].neg ^ ops[n_ops - 2].neg) ++ value = -value; ++ ops[n_ops - 2].op = plus_constant (ops[n_ops - 2].op, value); ++ n_ops--; ++ } ++ + /* Put a non-negated operand first, if possible. */ + + for (i = 0; i < n_ops && ops[i].neg; i++) diff --git a/gnu/usr.bin/cc34/cc_prep/patches/toplev.c.patch b/gnu/usr.bin/cc34/cc_prep/patches/toplev.c.patch new file mode 100644 index 0000000000..9002e22d02 --- /dev/null +++ b/gnu/usr.bin/cc34/cc_prep/patches/toplev.c.patch @@ -0,0 +1,65 @@ +$DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/toplev.c.patch,v 1.1 2004/06/19 10:30:08 joerg Exp $ + +--- ../gcc.orig/toplev.c 2004-06-18 23:08:13.000000000 +0200 ++++ toplev.c 2004-06-18 23:40:29.000000000 +0200 +@@ -97,6 +97,10 @@ + declarations for e.g. AIX 4.x. */ + #endif + ++#ifdef STACK_PROTECTOR ++#include "protector.h" ++#endif ++ + #ifndef HAVE_conditional_execution + #define HAVE_conditional_execution 0 + #endif +@@ -979,6 +983,15 @@ + minimum function alignment. Zero means no alignment is forced. */ + int force_align_functions_log; + ++#if defined(STACK_PROTECTOR) && defined(STACK_GROWS_DOWNWARD) ++/* Nonzero means use propolice as a stack protection method */ ++int flag_propolice_protection = 1; ++int flag_stack_protection = 0; ++#else ++int flag_propolice_protection = 0; ++int flag_stack_protection = 0; ++#endif ++ + typedef struct + { + const char *const string; +@@ -1154,7 +1167,9 @@ + {"mem-report", &mem_report, 1 }, + { "trapv", &flag_trapv, 1 }, + { "wrapv", &flag_wrapv, 1 }, +- { "new-ra", &flag_new_regalloc, 1 } ++ { "new-ra", &flag_new_regalloc, 1 }, ++ {"stack-protector", &flag_propolice_protection, 1 }, ++ {"stack-protector-all", &flag_stack_protection, 1 } + }; + + /* Here is a table, controlled by the tm.h file, listing each -m switch +@@ -2687,6 +2702,9 @@ + + insns = get_insns (); + ++ if (flag_propolice_protection) ++ prepare_stack_protection (inlinable); ++ + /* Dump the rtl code if we are dumping rtl. */ + + if (open_dump_file (DFI_rtl, decl)) +@@ -4482,6 +4500,12 @@ + /* The presence of IEEE signaling NaNs, implies all math can trap. */ + if (flag_signaling_nans) + flag_trapping_math = 1; ++ ++ /* This combination makes optimized frame addressings and causes ++ a internal compilation error at prepare_stack_protection. ++ so don't allow it. */ ++ if (flag_stack_protection && !flag_propolice_protection) ++ flag_propolice_protection = TRUE; + } + + /* Initialize the compiler back end. */ diff --git a/gnu/usr.bin/cc34/cc_prep/patches/tree.h.patch b/gnu/usr.bin/cc34/cc_prep/patches/tree.h.patch new file mode 100644 index 0000000000..59e1052f8c --- /dev/null +++ b/gnu/usr.bin/cc34/cc_prep/patches/tree.h.patch @@ -0,0 +1,15 @@ +$DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/tree.h.patch,v 1.1 2004/06/19 10:30:08 joerg Exp $ + +--- ../gcc.orig/tree.h 2004-06-18 23:08:13.000000000 +0200 ++++ tree.h 2004-06-18 23:41:01.000000000 +0200 +@@ -1489,6 +1489,10 @@ + where it is called. */ + #define DECL_INLINE(NODE) (FUNCTION_DECL_CHECK (NODE)->decl.inline_flag) + ++/* In a VAR_DECL, nonzero if the declaration is copied for inlining. ++ The stack protector should keep its location in the stack. */ ++#define DECL_COPIED(NODE) (VAR_DECL_CHECK (NODE)->decl.inline_flag) ++ + /* Nonzero in a FUNCTION_DECL means that this function was declared inline, + such as via the `inline' keyword in C/C++. This flag controls the linkage + semantics of 'inline'; whether or not the function is inlined is diff --git a/gnu/usr.bin/cc34/libbackend/Makefile b/gnu/usr.bin/cc34/libbackend/Makefile index bf111b981b..ded7677ee2 100644 --- a/gnu/usr.bin/cc34/libbackend/Makefile +++ b/gnu/usr.bin/cc34/libbackend/Makefile @@ -1,4 +1,4 @@ -# $DragonFly: src/gnu/usr.bin/cc34/libbackend/Makefile,v 1.1 2004/06/14 22:27:56 joerg Exp $ +# $DragonFly: src/gnu/usr.bin/cc34/libbackend/Makefile,v 1.2 2004/06/19 10:30:08 joerg Exp $ .include "../Makefile.inc" .include "../cc_tools/Makefile.tools" @@ -40,4 +40,7 @@ SRCS+= insn-config.h genrtl.h insn-codes.h tm-preds.h insn-modes.h SRCS+= insn-constants.h insn-flags.h tree-check.h gtype-desc.h SRCS+= insn-attr.h gcov-iov.h +# ProPolice +SRCS+= protector.c + .include -- 2.41.0