This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Marking the end of a function
- From: Andrew Haley <aph at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 25 Sep 2002 18:42:45 +0100
- Subject: Marking the end of a function
I need to be able to determine the extent of a function at runtime.
This is because some Java methods need to be able to identify who they
are being called by, in order to support the Java security framework.
We can find the PC of a caller at runtime by walking the stack, but we
need to be able to know that a given PC value is within the bounds of
a particular function.
In a way, gcc already outputs this info, but only as part of the
debugging information.
So, I wrote the following patch to spit out a somewhat mangled label
at the end of a function. It uses "__functionname__end" as the
mangled form, but this is quite arbitrary and I imagine there will be
name collisions.
So, a couple of questions:
1. Is there any reason we should not mark the end of a function in
this way?
2. What might be a better way to mangle a function's name?
Andrew.
Index: varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.311
diff -c -2 -p -r1.311 varasm.c
*** varasm.c 20 Sep 2002 17:50:47 -0000 1.311
--- varasm.c 25 Sep 2002 16:54:36 -0000
*************** assemble_end_function (decl, fnname)
*** 1237,1243 ****
--- 1237,1262 ----
const char *fnname;
{
+ char *endname = xmalloc (strlen ("__") + strlen (fnname)
+ + strlen ("__end") + 1);
+ strcpy (endname, "__");
+ strcat (endname, fnname);
+ strcat (endname, "__end");
+
+ if (TREE_PUBLIC (decl))
+ {
+ tree lab = build_decl (FUNCTION_DECL, get_identifier (endname),
+ TREE_TYPE (decl));
+ DECL_WEAK (lab) = DECL_WEAK (decl);
+ TREE_PUBLIC (lab) = TREE_PUBLIC (decl);
+ make_decl_rtl (decl, NULL);
+ globalize_decl (lab);
+ }
+
+ assemble_label (endname);
+
#ifdef ASM_DECLARE_FUNCTION_SIZE
ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
#endif
+
if (! CONSTANT_POOL_BEFORE_FUNCTION)
{