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]
Other format: [Raw text]

Fix ARM EABI profiling


The -pg option (gprof profiling) is broken on ARM EABI targets.  The _mcount 
implementation we inherited from legacy targets assumes FP(r11) points to an 
old 4-word APCS frame layout. Recent gcc changes mean that the stack layout 
is no longer predictable, even when a frame pointer is used. This has always 
been true (and -pg broken) for Thumb-2 code.

The patch below changes EABI based targets to use a new function profiler 
entry point, using a different ABI that should work in all circumstances.

The corresponding glibc support has been available for some time: 
http://sourceware.org/ml/libc-ports/2008-04/msg00009.html

We current assume that the mcount implementation does not need to be passed a 
a counter variable. This is true of at least the Linux implementation. 
There's some discussion of other potential requirements here:
http://gcc.gnu.org/ml/gcc-patches/2005-05/msg01001.html
I'm deferring support for more needy mcount implementations until someone 
demonstrates actual need.

While Thumb profiling has been busted pretty much forever, ARM profiling has 
regressed from mostly working to not working at all. I believe this is ample 
qualification for making this change during stage 3.

Tested on arm-linux-gnueabi.
Applied to svn trunk

Paul

2008-10-08  Paul Brook  <paul@codesourcery.com>

	gcc/
	* config/arm/bpabi.h (ARM_FUNCTION_PROFILER): Define new EABI
	compatible profiler (__gnu_mcount_nc).
	(SUBTARGET_FRAME_POINTER_REQUIRED): Define.

Index: gcc/config/arm/bpabi.h
===================================================================
--- gcc/config/arm/bpabi.h	(revision 140937)
+++ gcc/config/arm/bpabi.h	(working copy)
@@ -147,3 +147,20 @@
 #undef FINI_SECTION_ASM_OP
 #define INIT_ARRAY_SECTION_ASM_OP ARM_EABI_CTORS_SECTION_OP
 #define FINI_ARRAY_SECTION_ASM_OP ARM_EABI_DTORS_SECTION_OP
+
+/* The legacy _mcount implementation assumes r11 points to a
+    4-word APCS frame.  This is generally not true for EABI targets,
+    particularly not in Thumb mode.  We assume the mcount
+    implementation does not require a counter variable (No Counter).
+    Note that __gnu_mcount_nc will be entered with a misaligned stack.
+    This is OK because it uses a special calling convention anyway.  */
+
+#undef  ARM_FUNCTION_PROFILER
+#define ARM_FUNCTION_PROFILER(STREAM, LABELNO)  			\
+{									\
+  fprintf (STREAM, "\tpush\t{lr}\n");					\
+  fprintf (STREAM, "\tbl\t__gnu_mcount_nc\n");				\
+}
+
+#undef SUBTARGET_FRAME_POINTER_REQUIRED
+#define SUBTARGET_FRAME_POINTER_REQUIRED 0


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