Patchwork [i386] : Add for win32 targets pre-prologue profiling feature

login
register
mail settings
Submitter Andi Kleen
Date July 17, 2010, 9:45 a.m.
Message ID <20100717094532.GB9340@basil.fritz.box>
Download mbox | patch
Permalink /patch/59134/
State New
Headers show

Comments

Andi Kleen - July 17, 2010, 9:45 a.m.
> Hmm, I can't reproduce this. Clear if PROFILE_BEFORE_PROLOGUE isn't
> set, then default remains profile counter call after prologue. But if
> you have 'defined(MCOUNT_NAME) && defined
> (MCOUNT_NAME_BEFORE_PROLOGUE)' the variable only_default is false, and
> so the error you are showing shouldn't be reachable. Do I miss here
> something?

Looks it was my fault.

It seems adding the define to linux.h is not enough for them to reach
i386.c (MCOUNT_NAME_BEFORE_PROLOGUE is undefined) on my configuration
(x86_64-linux)

If I add it to linux64.h too it works. I thought linux64 would inherit
linux, but apparently that's not the case. With this patch a simple
test program works for a 64bit build.

-Andi

2010-07-17  Andi Kleen  <ak@linux.intel.com>

	* config/i386/linux.h (MCOUNT_NAME_BEFORE_PROLOGUE): Define.
	* config/i386/linux64.h (MCOUNT_NAME_BEFORE_PROLOGUE): Define.
	(MCOUNT_NAME): Define
Kai Tietz - July 18, 2010, 11:37 a.m.
Hello,

I found one missing nit for cygwin/mingw, which is corrected by this
patch. For win32 target an initial call to _monstartup has to be done
in main before mcount get called. For this I added to cygming.h the
new macro PROFILE_HOOK_BEFORE_PROFILE to handle it.

So new patch with updated ChangeLog

	* config/i386/cygming.h (MCOUNT_NAME): New.
	(MCOUNT_NAME_BEFORE_PROLOGUE): New.
	(PROFILE_HOOK_BEFORE_PROFILE): New.
	(PROFILE_HOOK): Check if not fentry is active.
	* config/i386/i386.c (ix86_profile_before_prologue): New.
	(override_options): Add special handling for -mfentry.
	(ix86_function_regparm): Likewise.
	(ix86_function_sseregparm): Likewise.
	(ix86_frame_pointer_required): Likewise.
	(ix86_expand_prologue): Check for ms_hook_prologue.
	(x86_function_profiler): Adjust mcount output and
	call PROFILE_HOOK_BEFORE_PROFILE.
	(TARGET_PROFILE_BEFORE_PROLOGUE): Define hook.
	* config/i386/i386.opt (mfentry): New.
	* doc/invoke.texi (mfentry): Add documentation.
	* doc/tm.texi: Regenerated..
	* doc/tm.texi.in (TARGET_PROFILE_BEFORE_PROLOGUE): New.
	* final.c (final_start_function): Replace macro
	PROFILE_BEFORE_PROLOGUE by target hook.
	* function.c (thread_prologue_and_epilogue_insns): Likewise.
	* target.def (profile_before_prologue): New hook.
	* targhooks.c (default_profile_before_prologue): New.
	* targhooks.h (default_profile_before_prologue): New.


Tested for i686-pc-mingw32, i686-pc-cygwin, and x86_64-pc-mingw32. Ok for apply?

Regards,
Kai
Kai Tietz - July 18, 2010, 11:46 a.m.
2010/7/18 Kai Tietz <ktietz70@googlemail.com>:
> Hello,
>
> I found one missing nit for cygwin/mingw, which is corrected by this
> patch. For win32 target an initial call to _monstartup has to be done
> in main before mcount get called. For this I added to cygming.h the
> new macro PROFILE_HOOK_BEFORE_PROFILE to handle it.
>
> So new patch with updated ChangeLog
>
>        * config/i386/cygming.h (MCOUNT_NAME): New.
>        (MCOUNT_NAME_BEFORE_PROLOGUE): New.
>        (PROFILE_HOOK_BEFORE_PROFILE): New.
>        (PROFILE_HOOK): Check if not fentry is active.
>        * config/i386/i386.c (ix86_profile_before_prologue): New.
>        (override_options): Add special handling for -mfentry.
>        (ix86_function_regparm): Likewise.
>        (ix86_function_sseregparm): Likewise.
>        (ix86_frame_pointer_required): Likewise.
>        (ix86_expand_prologue): Check for ms_hook_prologue.
>        (x86_function_profiler): Adjust mcount output and
>        call PROFILE_HOOK_BEFORE_PROFILE.
>        (TARGET_PROFILE_BEFORE_PROLOGUE): Define hook.
>        * config/i386/i386.opt (mfentry): New.
>        * doc/invoke.texi (mfentry): Add documentation.
>        * doc/tm.texi: Regenerated..
>        * doc/tm.texi.in (TARGET_PROFILE_BEFORE_PROLOGUE): New.
>        * final.c (final_start_function): Replace macro
>        PROFILE_BEFORE_PROLOGUE by target hook.
>        * function.c (thread_prologue_and_epilogue_insns): Likewise.
>        * target.def (profile_before_prologue): New hook.
>        * targhooks.c (default_profile_before_prologue): New.
>        * targhooks.h (default_profile_before_prologue): New.
>
>
> Tested for i686-pc-mingw32, i686-pc-cygwin, and x86_64-pc-mingw32. Ok for apply?
>
> Regards,
> Kai
>

Hmm, it doesn't hurt, but it seems to me that for old behavior the
monstartup hook got called after the mcount function. So I am not sure
here if the last patch is necessary at all, so withdraw recent patch
and fallback to the patch before.

Sorry for the noise.
Kai

Patch

diff --git a/gcc/config/i386/linux.h b/gcc/config/i386/linux.h
index 81dfd1e..54051ed 100644
--- a/gcc/config/i386/linux.h
+++ b/gcc/config/i386/linux.h
@@ -48,6 +48,10 @@  along with GCC; see the file COPYING3.  If not see
 
 #define NO_PROFILE_COUNTERS	1
 
+/* Choose the correct profiler mcount name.  */
+#undef MCOUNT_NAME_BEFORE_PROLOGUE
+#define MCOUNT_NAME_BEFORE_PROLOGUE "__fentry__"
+
 #undef MCOUNT_NAME
 #define MCOUNT_NAME "mcount"
 
diff --git a/gcc/config/i386/linux64.h b/gcc/config/i386/linux64.h
index 33b4dc9..f40fa31 100644
--- a/gcc/config/i386/linux64.h
+++ b/gcc/config/i386/linux64.h
@@ -123,3 +123,10 @@  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    x86_64 glibc provides it in %fs:0x28.  */
 #define TARGET_THREAD_SSP_OFFSET	(TARGET_64BIT ? 0x28 : 0x14)
 #endif
+
+/* Choose the correct profiler mcount name.  */
+#undef MCOUNT_NAME_BEFORE_PROLOGUE
+#define MCOUNT_NAME_BEFORE_PROLOGUE "__fentry__"
+
+#undef MCOUNT_NAME
+#define MCOUNT_NAME "mcount"