This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: making naked attr generally available


Jeffrey A Law wrote:
>   > Do I just put
>   > an `if (DECL_NAKED_FUNCTION(decl)) ...' around the p/e generation
> Something like that.  DECL_NAKED_FUNCTION_P (current_function_decl)) is
> probably more correct.

Oops, that was meant to have a _P at the end.  BTW, what does it mean?


Well, some good news and some bad news.

First the good news: I got it working, but see the bad news.

Bad news: the return statement (ie ret on i386) still gets output.  I
still have to find the code that generates that.

I haven't tested it yet with debug or profiling code, but normal,
optimised code seems to be ok.  I failed to notice wheter the function
label gets output, but I imagine it does (I'm at work and my build tree
is at home).

That was actually pretty easy.  I've attached the patch for feedback on
whether I'm on the right track or made some bad assumptions.  This is
against a recent (NZ Saturday's) CVS snapshot.

NOTE: this is *NOT* the final patch, as I still have to find that last
bit of code to conditionalize to stop generating `ret' for naked
functions.

Bill
-- 
Leave others their otherness
diff -ur egcs-/gcc/c-common.c egcs/gcc/c-common.c
--- egcs-/gcc/c-common.c	Tue Apr 20 12:36:31 1999
+++ egcs/gcc/c-common.c	Mon May 31 21:44:05 1999
@@ -54,7 +54,7 @@
 enum attrs {A_PACKED, A_NOCOMMON, A_COMMON, A_NORETURN, A_CONST, A_T_UNION,
 	    A_NO_CHECK_MEMORY_USAGE, A_NO_INSTRUMENT_FUNCTION,
 	    A_CONSTRUCTOR, A_DESTRUCTOR, A_MODE, A_SECTION, A_ALIGNED,
-	    A_UNUSED, A_FORMAT, A_FORMAT_ARG, A_WEAK, A_ALIAS};
+	    A_UNUSED, A_FORMAT, A_FORMAT_ARG, A_WEAK, A_ALIAS, A_NAKED};
 
 enum format_type { printf_format_type, scanf_format_type,
 		   strftime_format_type };
@@ -394,6 +394,7 @@
   add_attribute (A_ALIAS, "alias", 1, 1, 1);
   add_attribute (A_NO_INSTRUMENT_FUNCTION, "no_instrument_function", 0, 0, 1);
   add_attribute (A_NO_CHECK_MEMORY_USAGE, "no_check_memory_usage", 0, 0, 1);
+  add_attribute (A_NAKED, "naked", 0, 0, 1);
 }
 
 /* Default implementation of valid_lang_attribute, below.  By default, there
@@ -942,6 +943,16 @@
 	    }
 	  else
 	    DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
+	  break;
+	case A_NAKED:
+	  if (TREE_CODE (decl) == FUNCTION_DECL
+	      && TREE_CODE (type) == FUNCTION_TYPE
+	      && decl_function_context (decl) == 0)
+	    {
+	      DECL_NAKED_FUNCTION_P (decl) = 1;
+	    }
+	  else
+	    warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
 	  break;
 	}
     }
diff -ur egcs-/gcc/toplev.c egcs/gcc/toplev.c
--- egcs-/gcc/toplev.c	Sat May 29 20:40:10 1999
+++ egcs/gcc/toplev.c	Mon May 31 22:14:38 1999
@@ -4263,7 +4263,8 @@
      it and the rest of the code and also allows delayed branch
      scheduling to operate in the epilogue.  */
 
-  thread_prologue_and_epilogue_insns (insns);
+  if (!DECL_NAKED_FUNCTION_P (decl))
+    thread_prologue_and_epilogue_insns (insns);
 
   if (flow2_dump)
     {
@@ -4390,9 +4391,11 @@
 	     fnname = XSTR (x, 0);
 
 	     assemble_start_function (decl, fnname);
-	     final_start_function (insns, asm_out_file, optimize);
+	     if (!DECL_NAKED_FUNCTION_P (decl))
+	       final_start_function (insns, asm_out_file, optimize);
 	     final (insns, asm_out_file, optimize, 0);
-	     final_end_function (insns, asm_out_file, optimize);
+	     if (!DECL_NAKED_FUNCTION_P (decl))
+	       final_end_function (insns, asm_out_file, optimize);
 	     assemble_end_function (decl, fnname);
 	     if (! quiet_flag)
 	       fflush (asm_out_file);
diff -ur egcs-/gcc/tree.h egcs/gcc/tree.h
--- egcs-/gcc/tree.h	Sat May 29 20:40:10 1999
+++ egcs/gcc/tree.h	Mon May 31 21:44:09 1999
@@ -1279,6 +1279,11 @@
    an address constant.  */
 #define DECL_NON_ADDR_CONST_P(NODE) (DECL_CHECK (NODE)->decl.non_addr_const_p)
 
+/* Used to indicate that the functions referred to by this decl will not
+   have prolog/epilog code generated.  The programmer is assumed to do
+   the right thing using (eg) asm statements.  */
+#define DECL_NAKED_FUNCTION_P(NODE) (DECL_CHECK (NODE)->decl.naked_function_p)
+
 /* Used to indicate an alias set for the memory pointed to by this
    particular FIELD_DECL, PARM_DECL, or VAR_DECL, which must have
    pointer (or reference) type.  */
@@ -1333,6 +1338,7 @@
   unsigned no_instrument_function_entry_exit : 1;
   unsigned no_check_memory_usage : 1;
   unsigned comdat_flag : 1;
+  unsigned naked_function_p : 1;
 
   /* For a FUNCTION_DECL, if inline, this is the size of frame needed.
      If built-in, this is the code for which built-in function.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]