The following patch align stack for mcount and there should be no problems with unwind as ix86_frame_pointer_required is true when crtl->profile is true and flag_fentry is false (we call mcount after function prolog). When flag_fentry is true it is set to false in 32bit PIC mode: if (!TARGET_64BIT_P (opts->x_ix86_isa_flags) && opts->x_flag_pic) { if (opts->x_flag_fentry > 0) sorry ("-mfentry isn%'t supported for 32-bit in combination " "with -fpic"); opts->x_flag_fentry = 0; }
2014-10-24 Evgeny Stupachenko <evstu...@gmail.com> PR target/63534 * config/i386/i386.c (x86_function_profiler): Add GOT register init for mcount call. diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 6235c4f..2dff29c 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -39124,13 +39124,22 @@ x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED) else x86_print_call_or_nop (file, mcount_name); } + /* At this stage we can't detrmine where GOT register is, as RA can allocate + it to any hard register. Therefore we need to set it once again. */ else if (flag_pic) { + pic_labels_used |= 1 << BX_REG; + fprintf (file,"\tsub\t$16, %%esp\n"); + fprintf (file,"\tmovl\t%%ebx, (%%esp)\n"); + fprintf (file,"\tcall\t__x86.get_pc_thunk.bx\n"); + fprintf (file,"\taddl\t$_GLOBAL_OFFSET_TABLE_, %%ebx\n"); #ifndef NO_PROFILE_COUNTERS fprintf (file, "\tleal\t%sP%d@GOTOFF(%%ebx),%%" PROFILE_COUNT_REGISTER "\n", LPREFIX, labelno); #endif fprintf (file, "1:\tcall\t*%s@GOT(%%ebx)\n", mcount_name); + fprintf (file,"\tmovl\t(%%esp), %%ebx\n"); + fprintf (file,"\tadd\t$16, %%esp\n"); } else { On Fri, Oct 17, 2014 at 6:38 PM, Jakub Jelinek <ja...@redhat.com> wrote: > On Fri, Oct 17, 2014 at 06:30:42PM +0400, Evgeny Stupachenko wrote: >> Hi, >> >> The patch fixes profile in 32bits PIC mode (only -p option affected). >> >> x86 bootstrap, make check passed >> >> spec2000 o2 -p train data on Corei7: >> CINT -5% >> CFP +1,5 >> compared to a compiler before "enabling ebx". >> >> There is a potential performance improve after the patch applied >> suggested by Jakub: >> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63534#c8 >> There is opened bug on this: PR63527. However the fix of the bug is >> more complicated. >> >> Is it ok? > > Unfortunately I don't think it is ok. > 1) you don't set the appropriate bit in pic_labels_used (for ebx) > 2) more importantly, it causes the stack to be misaligned (i.e. violating > ABI) for the _mcount call, and, break unwind info. > >> 2014-10-16 Evgeny Stupachenko <evstu...@gmail.com> >> >> PR target/63534 >> * config/i386/i386.c (x86_function_profiler): Add GOT register init >> for mcount call. >> >> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c >> index a3ca2ed..5117572 100644 >> --- a/gcc/config/i386/i386.c >> +++ b/gcc/config/i386/i386.c >> @@ -39119,11 +39126,15 @@ x86_function_profiler (FILE *file, int >> labelno ATTRIBUTE_UNUSED) >> } >> else if (flag_pic) >> { >> + fprintf (file,"\tpush\t%%ebx\n"); >> + fprintf (file,"\tcall\t__x86.get_pc_thunk.bx\n"); >> + fprintf (file,"\taddl\t$_GLOBAL_OFFSET_TABLE_, %%ebx\n"); >> #ifndef NO_PROFILE_COUNTERS >> fprintf (file, "\tleal\t%sP%d@GOTOFF(%%ebx),%%" >> PROFILE_COUNT_REGISTER "\n", >> LPREFIX, labelno); >> #endif >> fprintf (file, "1:\tcall\t*%s@GOT(%%ebx)\n", mcount_name); >> + fprintf (file,"\tpop\t%%ebx\n"); >> } >> else >> { > > Jakub