[gcc r11-6552] x86-64: Use R10 and R11 for profiling large model with PIC

H.J. Lu hjl@gcc.gnu.org
Fri Jan 8 14:48:03 GMT 2021


https://gcc.gnu.org/g:76be18f442948d1a4bc49a7d670b07097f9e5983

commit r11-6552-g76be18f442948d1a4bc49a7d670b07097f9e5983
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Jan 8 05:20:19 2021 -0800

    x86-64: Use R10 and R11 for profiling large model with PIC
    
    For NO_PROFILE_COUNTERS targets, R11 is a scratch register.  We can use
    R10 and R11 to call mcount in large model with PIC.
    
    gcc/
    
            PR target/98482
            * config/i386/i386.c (x86_function_profiler): Use R10 and R11
            to call mcount in large model with PIC for NO_PROFILE_COUNTERS
            targets.
    
    gcc/testsuite/
    
            PR target/98482
            * gcc.target/i386/pr98482-2.c: Updated.

Diff:
---
 gcc/config/i386/i386.c                    | 12 ++++++++++--
 gcc/testsuite/gcc.target/i386/pr98482-2.c |  3 ++-
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index d3068462fcd..d35af37a49c 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -20806,12 +20806,20 @@ x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
 		       mcount_name);
 	      break;
 	    case CM_LARGE_PIC:
+#ifdef NO_PROFILE_COUNTERS
+	      fprintf (file, "1:\tmovabsq\t$_GLOBAL_OFFSET_TABLE_-1b, %%r11\n");
+	      fprintf (file, "\tleaq\t1b(%%rip), %%r10\n");
+	      fprintf (file, "\taddq\t%%r11, %%r10\n");
+	      fprintf (file, "\tmovabsq\t$%s@PLTOFF, %%r11\n", mcount_name);
+	      fprintf (file, "\taddq\t%%r11, %%r10\n");
+	      fprintf (file, "\tcall\t*%%r10\n");
+#else
 	      sorry ("profiling %<-mcmodel=large%> with PIC is not supported");
+#endif
 	      break;
 	    case CM_SMALL_PIC:
 	    case CM_MEDIUM_PIC:
-	      fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n",
-		       mcount_name);
+	      fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n", mcount_name);
 	      break;
 	    default:
 	      x86_print_call_or_nop (file, mcount_name);
diff --git a/gcc/testsuite/gcc.target/i386/pr98482-2.c b/gcc/testsuite/gcc.target/i386/pr98482-2.c
index aed3ca4b6ff..0ee142db12c 100644
--- a/gcc/testsuite/gcc.target/i386/pr98482-2.c
+++ b/gcc/testsuite/gcc.target/i386/pr98482-2.c
@@ -2,8 +2,9 @@
 /* { dg-require-effective-target mfentry } */
 /* { dg-require-effective-target fpic } */
 /* { dg-options "-fpic -fprofile -mfentry -O2 -mcmodel=large" } */
+/* { dg-final { scan-assembler "movabsq\t\\\$__fentry__@PLTOFF, %r11\n\taddq\t%r11, %r10\n\tcall\t\\*%r10" } } */
 
 void
 func (void)
 {
-} /* { dg-message "sorry, unimplemented: profiling '-mcmodel=large' with PIC is not supported" } */
+}


More information about the Gcc-cvs mailing list