[PATCH] Allow -pg without frame pointer on x86
Richard Guenther
richard.guenther@gmail.com
Sun Oct 12 11:20:00 GMT 2008
On Sun, Oct 12, 2008 at 6:06 AM, Andi Kleen <andi@firstfloor.org> wrote:
>
> There are some plans to use -pg/mcount tracing even in production
> versions of the Linux kernel. That is there is a special tracer
> which is able to nop out the calls when not needed. Unfortunately
> right now enabling -pg always requires enabling the frame pointer
> too, which has measurable cost in macro benchmarks.
>
> This patch allows to use -pg without frame pointer on x86. The only
> change that is needed it is to always call mcount before
> setting up the local stack frame instead of after. This way the tracer
> can always find the return address of the function directly above
> its own. Luckily gcc supported this already, it was just
> an #ifdef for some targets. I turned it into a target vector
> entry instead.
>
> Also the tracer function has to get the caller information from the
> stack now instead of through the frame pointer. To avoid incompatibility
> I use a new entry point "mcount_nofp" in this case.
>
> Unfortunately this change is incompatible (previously frame pointer
> was always forced on functions with mcount calls and also old
> glibcs don't have mcount_nofp), so I added a new option
> -mcount-nofp to enable this behaviour.
>
> I also got a glibc patch to add mcount_nofp support there.
>
> I know the patch is very late in the development cycle, but
> perhaps it could be still considered? By default it doesn't
> change any behaviour.
>
> Patch passes bootstrap and test suite (including its own test case)
Please move the testcase to gcc.target/i386 instead. The patch looks ok, but
how is your copyright assignment paperwork going?
Thanks,
Richard.
> -Andi
>
> 2008-10-05 Andi Kleen <ak@linux.intel.com>
>
> * target.c (struct gcc_target): Add profile_before_prologue.
> * target-def.h (TARGET_FUNCTION_RROFILE): Add.
> (TARGET_INITIALIZER): Add TARGET_FUNCTION_PROFILE.
> * final.c: (final_start_function): Check target vector instead
> of PROFILE_BEFORE_PROLOGUE.
> (profile_after_prologue): dito.
> * gcc.c: (TARGET_PG_OPTION_SPEC): Add.
> (cc1_options): Move pg into TARGET_PG_OPTION_SPEC.
> * config/i386/i386.h (TARGET_PG_OPTION_SPEC): Add.
> * config/i386/i386.c (override_options): Add check for
> -pg && no frame pointer.
> (x86_function_profiler): Emit _nofp mcount prefix when needed.
> (ix86_frame_pointer_required): Add check for x86_mcount_nofp.
> * config/i386/i386.opt: Add -mmcount-nofp
> * gcc/doc/invoke.texi: Document -mmcount-nofp
> * gcc/gcc/testsuite/gcc.dg/tfp.c: Add.
More information about the Gcc-patches
mailing list