From 658e203c9c9fb27b576911037bd432523335a93a Mon Sep 17 00:00:00 2001 From: carlos Date: Fri, 23 May 2008 20:36:57 +0000 Subject: [PATCH] gcc/ 2008-05-23 Paul Brook Carlos O'Donell * doc/extend.texi: Clarify use of __attribute__((naked)). * doc/tm.texi: Document TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS. * target.h (gcc_target): Add allocate_stack_slots_for_args. * function.c (use_register_for_decl): Use targetm.calls.allocate_stack_slots_for_args. * target-def.h (TARGET_CALLS): Add TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS. * config/arm/arm.c (arm_allocate_stack_slots_for_args): New function. (TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS): Define. gcc/testsuite/ 2008-05-23 Paul Brook Carlos O'Donell * gcc.target/arm/naked-1.c: New test. * gcc.target/arm/naked-2.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@135831 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 14 ++++++++++++++ gcc/config/arm/arm.c | 12 ++++++++++++ gcc/doc/extend.texi | 8 +++++++- gcc/doc/tm.texi | 11 +++++++++++ gcc/function.c | 3 +++ gcc/target-def.h | 4 +++- gcc/target.h | 5 +++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gcc.target/arm/naked-1.c | 13 +++++++++++++ gcc/testsuite/gcc.target/arm/naked-2.c | 12 ++++++++++++ 10 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/arm/naked-1.c create mode 100644 gcc/testsuite/gcc.target/arm/naked-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 25e09df..c1712af 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,17 @@ +2008-05-23 Paul Brook + Carlos O'Donell + + * doc/extend.texi: Clarify use of __attribute__((naked)). + * doc/tm.texi: Document TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS. + * target.h (gcc_target): Add allocate_stack_slots_for_args. + * function.c (use_register_for_decl): Use + targetm.calls.allocate_stack_slots_for_args. + * target-def.h (TARGET_CALLS): Add + TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS. + * config/arm/arm.c (arm_allocate_stack_slots_for_args): + New function. + (TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS): Define. + 2008-05-23 Eric Botcazou * expr.c (highest_pow2_factor) : New case. diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 1c7002b..38d4a2d 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -189,6 +189,7 @@ static bool arm_cannot_copy_insn_p (rtx); static bool arm_tls_symbol_p (rtx x); static int arm_issue_rate (void); static void arm_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED; +static bool arm_allocate_stack_slots_for_args (void); /* Initialize the GCC target structure. */ @@ -289,6 +290,9 @@ static void arm_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED; #undef TARGET_SETUP_INCOMING_VARARGS #define TARGET_SETUP_INCOMING_VARARGS arm_setup_incoming_varargs +#undef TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS +#define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS arm_allocate_stack_slots_for_args + #undef TARGET_DEFAULT_SHORT_ENUMS #define TARGET_DEFAULT_SHORT_ENUMS arm_default_short_enums @@ -1619,6 +1623,14 @@ arm_current_func_type (void) return cfun->machine->func_type; } + +bool +arm_allocate_stack_slots_for_args (void) +{ + /* Naked functions should not allocate stack slots for arguments. */ + return !IS_NAKED (arm_current_func_type ()); +} + /* Return 1 if it is possible to return using a single instruction. If SIBLING is non-null, this is a test for a return before a sibling diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 78d581d..f0e8593 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -2512,7 +2512,13 @@ defined by shared libraries. @cindex function without a prologue/epilogue code Use this attribute on the ARM, AVR, IP2K and SPU ports to indicate that the specified function does not need prologue/epilogue sequences generated by -the compiler. It is up to the programmer to provide these sequences. +the compiler. It is up to the programmer to provide these sequences. The +only statements that can be safely included in naked functions are +@code{asm} statements that do not have operands. All other statements, +including declarations of local variables, @code{if} statements, and so +forth, should be avoided. Naked functions should be used to implement the +body of an assembly function, while allowing the compiler to construct +the requisite function declaration for the assembler. @item near @cindex functions which do not handle memory bank switching on 68HC11/68HC12 diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 12a2740..8c0de3b 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -10465,3 +10465,14 @@ to the functions in @file{libgcc} that provide low-level support for call stack unwinding. It is used in declarations in @file{unwind-generic.h} and the associated definitions of those functions. @end defmac + +@deftypefn {Target Hook} {bool} TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS (void) +When optimization is disabled, this hook indicates whether or not +arguments should be allocated to stack slots. Normally, GCC allocates +stacks slots for arguments when not optimizing in order to make +debugging easier. However, when a function is declared with +@code{__attribute__((naked))}, there is no stack frame, and the compiler +cannot safely move arguments from the registers in which they are passed +to the stack. Therefore, this hook should return true in general, but +false for naked functions. The default implementation always returns true. +@end deftypefn diff --git a/gcc/function.c b/gcc/function.c index 29d4c1e..5f9c3a5 100644 --- a/gcc/function.c +++ b/gcc/function.c @@ -1776,6 +1776,9 @@ aggregate_value_p (const_tree exp, const_tree fntype) bool use_register_for_decl (const_tree decl) { + if (!targetm.calls.allocate_stack_slots_for_args()) + return true; + /* Honor volatile. */ if (TREE_SIDE_EFFECTS (decl)) return false; diff --git a/gcc/target-def.h b/gcc/target-def.h index c4bc696..19e882f 100644 --- a/gcc/target-def.h +++ b/gcc/target-def.h @@ -568,6 +568,7 @@ #define TARGET_FUNCTION_VALUE default_function_value #define TARGET_INTERNAL_ARG_POINTER default_internal_arg_pointer +#define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS hook_bool_void_true #define TARGET_CALLS { \ TARGET_PROMOTE_FUNCTION_ARGS, \ @@ -587,7 +588,8 @@ TARGET_ARG_PARTIAL_BYTES, \ TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN, \ TARGET_FUNCTION_VALUE, \ - TARGET_INTERNAL_ARG_POINTER \ + TARGET_INTERNAL_ARG_POINTER, \ + TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS \ } #ifndef TARGET_UNWIND_TABLES_DEFAULT diff --git a/gcc/target.h b/gcc/target.h index c331020..fa85e7c 100644 --- a/gcc/target.h +++ b/gcc/target.h @@ -830,6 +830,11 @@ struct gcc_target /* Return an rtx for the argument pointer incoming to the current function. */ rtx (*internal_arg_pointer) (void); + + /* Return true if all function parameters should be spilled to the + stack. */ + bool (*allocate_stack_slots_for_args) (void); + } calls; /* Return the diagnostic message string if conversion from FROMTYPE diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d18afd8..1c457cc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2008-05-23 Paul Brook + Carlos O'Donell + + * gcc.target/arm/naked-1.c: New test. + * gcc.target/arm/naked-2.c: New test. + 2008-05-23 Tobias Burnus PR fortran/36314 diff --git a/gcc/testsuite/gcc.target/arm/naked-1.c b/gcc/testsuite/gcc.target/arm/naked-1.c new file mode 100644 index 0000000..8f9ff71 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/naked-1.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O0" } */ +/* Check that function arguments aren't assigned and copied to stack slots + in naked functions. This ususally happens at -O0 (presumably for + better debugging), but is highly undesirable if we haven't created + a stack frame. */ +void __attribute__((naked)) +foo(int n) +{ + __asm__ volatile ("frob r0\n"); +} +/* { dg-final { scan-assembler "\tfrob r0" } } */ +/* { dg-final { scan-assembler-not "\tstr" } } */ diff --git a/gcc/testsuite/gcc.target/arm/naked-2.c b/gcc/testsuite/gcc.target/arm/naked-2.c new file mode 100644 index 0000000..92e7db4 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/naked-2.c @@ -0,0 +1,12 @@ +/* Verify that __attribute__((naked)) produces a naked function + that does not use bx to return. Naked functions could be used + to implement interrupt routines and must not return using bx. */ +/* { dg-do compile } */ +/* { dg-options "-O0" } */ +/* Use more arguments than we have argument registers. */ +int __attribute__((naked)) foo(int a, int b, int c, int d, int e, int f) +{ + __asm__ volatile ("@ naked"); +} +/* { dg-final { scan-assembler "\t@ naked" } } */ +/* { dg-final { scan-assembler-not "\tbx\tlr" } } */ -- 2.7.4