diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-09-27 19:48:20 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-09-27 19:48:20 +0000 |
commit | 48b14f5076a521887a2286eb84e6b51de6c50fd8 (patch) | |
tree | 69a38455d6a1f5425700674e4dc6483284eed579 /gcc/explow.c | |
parent | f8ee0563dfbffc5c24cc4424fca8cd070ee6121c (diff) | |
download | gcc-48b14f5076a521887a2286eb84e6b51de6c50fd8.tar.gz |
gcc/:
* common.opt (fsplit-stack): New option.
* opts.c (decode_options): Set flag_split_stack to final value.
* target.def (supports_split_stack): New hook.
* gcc.c (STACK_SPLIT_SPEC): Define.
(LINK_COMMAND_SPEC): Use STACK_SPLIT_SPEC.
* doc/invoke.texi (Option Summary): Mention -fsplit-stack.
(Code Gen Options): Document -fsplit-stack.
* doc/extend.texi (Function Attributes): Mention no_split_stack.
(Function Attributes): Document no_split_stack.
* doc/tm.texi.in (Stack Smashing Protection): Add @hook
TARGET_SUPPORTS_SPLIT_STACK.
* doc/tm.texi: Rebuild.
* function.c (thread_prologue_and_epilogue_insns): If
flag_split_stack, add split stack prologue.
* explow.c (allocate_dynamic_stack_space): Support -fsplit-stack.
* varasm.c (saw_no_split_stack): New static variable.
(assemble_start_function): Set saw_no_split_stack if the function
has the no_split_stack attribute.
(file_end_indicate_split_stack): New function.
* output.h (file_end_indicate_split_stack): Declare.
* libgcc-std.ver (GCC_4.6.0): Add -fsplit-stack support variables
and function.
* doc/libgcc.texi (Miscellaneous routines): Document -fsplit-stack
routines.
* config/i386/i386.c (ix86_option_override_internal): Don't set
expand_builtin_va_start to NULL if -fsplit-stack.
(ix86_function_regparm): Reduce local regparm by 1 for 32-bit
-fsplit-stack.
(ix86_va_start): If -fsplit-stack, get overflow pointer from
scratch register set by prologue.
(ix86_code_end): If -fsplit-stack, call
file_end_indicate_split_stack.
(ix86_supports_split_stack): New static function.
(SPLIT_STACK_AVAILABLE): Define.
(split_stack_prologue_scratch_regno): New static function.
(split_stack_fn): New static variable.
(ix86_expand_split_stack_prologue): New function.
(ix86_live_on_entry): New static function.
(ix86_legitimate_address_p): Handle UNSPEC_STACK_CHECK.
(output_pic_addr_const): Likewise.
(i386_asm_output_addr_const_extra): Likewise.
(ix86_expand_call): Change return type to rtx. Return the new
call instruction.
(TARGET_SUPPORTS_SPLIT_STACK): Define.
(TARGET_EXTRA_LIVE_ON_ENTRY): Define.
* config/i386/i386.md (UNSPEC_STACK_CHECK): Define.
(split_stack_prologue, split_stack_return): New insns.
(split_stack_space_check): New insn.
* config/i386/i386.h (struct machine_function): Add
split_stack_varargs_pointer field.
* config/i386/linux.h (TARGET_CAN_SPLIT_STACK): Define.
(TARGET_THREAD_SPLIT_STACK_OFFSET): Define.
* config/i386/linux64.h (TARGET_CAN_SPLIT_STACK): Define.
(TARGET_THREAD_SPLIT_STACK_OFFSET): Define.
* config/i386/i386-protos.h (ix86_expand_split_stack_prologue):
Declare.
(ix86_expand_call): Update declaration.
gcc/c-family/:
* c-common.c (c_common_attribute_table): Add no_split_stack.
(handle_no_split_stack_attribute): New static function.
gcc/testsuite/:
* lib/target-supports.exp (check_effective_target_split_stack):
New procedure.
* gcc.dg/split-1.c: New test.
* gcc.dg/split-2.c: New test.
* gcc.dg/split-3.c: New test.
* gcc.dg/split-4.c: New test.
libgcc/:
* generic-morestack.h: New file.
* generic-morestack.c: New file.
* generic-morestack-thread.c: New file.
* config/i386/morestack.S: New file.
* config/t-stack: New file.
* config/i386/t-stack-i386: New file.
* config.host (i[34567]86-*-linux* and friends): Add t-stack and
i386/t-stack-i386 to tmake_file.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@164661 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/explow.c')
-rw-r--r-- | gcc/explow.c | 74 |
1 files changed, 65 insertions, 9 deletions
diff --git a/gcc/explow.c b/gcc/explow.c index 2024b5324d8..21af58a7c81 100644 --- a/gcc/explow.c +++ b/gcc/explow.c @@ -1,6 +1,6 @@ /* Subroutines for manipulating rtx's in semantically interesting ways. Copyright (C) 1987, 1991, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 + 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. This file is part of GCC. @@ -1146,6 +1146,7 @@ allocate_dynamic_stack_space (rtx size, rtx target, int known_align, { HOST_WIDE_INT stack_usage_size = -1; bool known_align_valid = true; + rtx final_label, final_target; /* If we're asking for zero bytes, it doesn't matter what we point to since we can't dereference it. But return a reasonable @@ -1284,6 +1285,14 @@ allocate_dynamic_stack_space (rtx size, rtx target, int known_align, } } + /* Don't use a TARGET that isn't a pseudo or is the wrong mode. */ + if (target == 0 || !REG_P (target) + || REGNO (target) < FIRST_PSEUDO_REGISTER + || GET_MODE (target) != Pmode) + target = gen_reg_rtx (Pmode); + + mark_reg_pointer (target, known_align); + /* The size is supposed to be fully adjusted at this point so record it if stack usage info is requested. */ if (flag_stack_usage) @@ -1296,6 +1305,52 @@ allocate_dynamic_stack_space (rtx size, rtx target, int known_align, current_function_has_unbounded_dynamic_stack_size = 1; } + final_label = NULL_RTX; + final_target = NULL_RTX; + + /* If we are splitting the stack, we need to ask the backend whether + there is enough room on the current stack. If there isn't, or if + the backend doesn't know how to tell is, then we need to call a + function to allocate memory in some other way. This memory will + be released when we release the current stack segment. The + effect is that stack allocation becomes less efficient, but at + least it doesn't cause a stack overflow. */ + if (flag_split_stack) + { + rtx available_label, space, func; + + available_label = NULL_RTX; + +#ifdef HAVE_split_stack_space_check + if (HAVE_split_stack_space_check) + { + available_label = gen_label_rtx (); + + /* This instruction will branch to AVAILABLE_LABEL if there + are SIZE bytes available on the stack. */ + emit_insn (gen_split_stack_space_check (size, available_label)); + } +#endif + + func = init_one_libfunc ("__morestack_allocate_stack_space"); + + space = emit_library_call_value (func, target, LCT_NORMAL, Pmode, + 1, size, Pmode); + + if (available_label == NULL_RTX) + return space; + + final_target = gen_reg_rtx (Pmode); + mark_reg_pointer (final_target, known_align); + + emit_move_insn (final_target, space); + + final_label = gen_label_rtx (); + emit_jump (final_label); + + emit_label (available_label); + } + do_pending_stack_adjust (); /* We ought to be called always on the toplevel and stack ought to be aligned @@ -1313,14 +1368,6 @@ allocate_dynamic_stack_space (rtx size, rtx target, int known_align, else if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK) probe_stack_range (STACK_CHECK_PROTECT, size); - /* Don't use a TARGET that isn't a pseudo or is the wrong mode. */ - if (target == 0 || !REG_P (target) - || REGNO (target) < FIRST_PSEUDO_REGISTER - || GET_MODE (target) != Pmode) - target = gen_reg_rtx (Pmode); - - mark_reg_pointer (target, known_align); - /* Perform the required allocation from the stack. Some systems do this differently than simply incrementing/decrementing from the stack pointer, such as acquiring the space by calling malloc(). */ @@ -1413,6 +1460,15 @@ allocate_dynamic_stack_space (rtx size, rtx target, int known_align, if (cfun->nonlocal_goto_save_area != 0) update_nonlocal_goto_save_area (); + /* Finish up the split stack handling. */ + if (final_label != NULL_RTX) + { + gcc_assert (flag_split_stack); + emit_move_insn (final_target, target); + emit_label (final_label); + target = final_target; + } + return target; } |