public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/3] S/390: Implement -mfentry
  2018-07-16  7:49 [PATCH, S/390] Improved support for the Linux kernel Ftrace Ilya Leoshkevich
  2018-07-16  7:49 ` [PATCH 3/3] S/390: Implement -mnop-mcount Ilya Leoshkevich
  2018-07-16  7:49 ` [PATCH 2/3] S/390: Implement -mrecord-mcount Ilya Leoshkevich
@ 2018-07-16  7:49 ` Ilya Leoshkevich
  2018-07-16 14:33   ` Andreas Krebbel
  2 siblings, 1 reply; 7+ messages in thread
From: Ilya Leoshkevich @ 2018-07-16  7:49 UTC (permalink / raw)
  To: gcc-patches; +Cc: krebbel, Ilya Leoshkevich

This is the counterpart of the i386 feature introduced by
39a5a6a4: Add direct support for Linux kernel __fentry__ patching.

On i386, the difference between mcount and fentry is that fentry
comes before the prolog. On s390 mcount already comes before the
prolog, but takes 4 instructions. This patch introduces the more
efficient implementation (just 1 instruction) and puts it under
-mfentry flag.

The produced code is compatible only with newer glibc versions,
which provide the __fentry__ symbol and do not clobber %r0 when
resolving lazily bound functions. Because 31-bit PLT stubs assume
%r12 contains GOT address, which is not the case when the code runs
before the prolog, -mfentry is allowed only for 64-bit code.

Also, code compiled with -mfentry cannot be used for the nested C
functions, since they both use %r0. In this case instrumentation is
not insterted, and a new warning is issued for each affected nested
function.

        * gcc/common.opt: Add the new warning.
        * gcc/config/s390/s390.c (s390_function_profiler): Emit
        "brasl %r0,__fentry__" when -mfentry is specified.
        (s390_option_override_internal): Disallow -mfentry for
        31-bit CPUs.
        * gcc/config/s390/s390.opt: Add the new option.
        * gcc/testsuite/gcc.target/s390/mfentry-m64.c:
        New testcase.
---
 gcc/common.opt                              |  5 +++++
 gcc/config/s390/s390.c                      | 18 ++++++++++++++++--
 gcc/config/s390/s390.opt                    |  5 +++++
 gcc/testsuite/gcc.target/s390/mfentry-m64.c |  8 ++++++++
 4 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/s390/mfentry-m64.c

diff --git a/gcc/common.opt b/gcc/common.opt
index c29abdb5cb1..4d031e81b09 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -571,6 +571,11 @@ Wattribute-alias
 Common Var(warn_attributes) Init(1) Warning
 Warn about type safety and similar errors in attribute alias and related.
 
+Wcannot-profile
+Common Var(warn_cannot_profile) Init(1) Warning
+Warn when profiling instrumentation was requested, but could not be applied to
+a certain function.
+
 Wcast-align
 Common Var(warn_cast_align) Warning
 Warn about pointer casts which increase alignment.
diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index 23c3f3db621..3a406b955a0 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -13144,14 +13144,22 @@ s390_function_profiler (FILE *file, int labelno)
   op[3] = gen_rtx_SYMBOL_REF (Pmode, label);
   SYMBOL_REF_FLAGS (op[3]) = SYMBOL_FLAG_LOCAL;
 
-  op[4] = gen_rtx_SYMBOL_REF (Pmode, "_mcount");
+  op[4] = gen_rtx_SYMBOL_REF (Pmode, flag_fentry ? "__fentry__" : "_mcount");
   if (flag_pic)
     {
       op[4] = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op[4]), UNSPEC_PLT);
       op[4] = gen_rtx_CONST (Pmode, op[4]);
     }
 
-  if (TARGET_64BIT)
+  if (flag_fentry)
+    {
+      if (cfun->static_chain_decl)
+        warning (OPT_Wcannot_profile, "nested functions cannot be profiled "
+                 "with -mfentry on s390");
+      else
+        output_asm_insn ("brasl\t0,%4", op);
+    }
+  else if (TARGET_64BIT)
     {
       output_asm_insn ("stg\t%0,%1", op);
       output_asm_insn ("larl\t%2,%3", op);
@@ -15562,6 +15570,12 @@ s390_option_override_internal (bool main_args_p,
   /* Call target specific restore function to do post-init work.  At the moment,
      this just sets opts->x_s390_cost_pointer.  */
   s390_function_specific_restore (opts, NULL);
+
+  /* Check whether -mfentry is supported. It cannot be used in 31-bit mode,
+     because 31-bit PLT stubs assume that %r12 contains GOT address, which is
+     not the case when the code runs before the prolog. */
+  if (opts->x_flag_fentry && !TARGET_64BIT)
+    error ("-mfentry is supported only for 64-bit CPUs");
 }
 
 static void
diff --git a/gcc/config/s390/s390.opt b/gcc/config/s390/s390.opt
index eb16f9c821f..59e97d031b4 100644
--- a/gcc/config/s390/s390.opt
+++ b/gcc/config/s390/s390.opt
@@ -293,3 +293,8 @@ locations which have been patched as part of using one of the
 -mindirect-branch* or -mfunction-return* options.  The sections
 consist of an array of 32 bit elements. Each entry holds the offset
 from the entry to the patched location.
+
+mfentry
+Target Report Var(flag_fentry)
+Emit profiling counter call at function entry before prologue. The compiled
+code will require a 64-bit CPU and glibc 2.29 or newer to run.
diff --git a/gcc/testsuite/gcc.target/s390/mfentry-m64.c b/gcc/testsuite/gcc.target/s390/mfentry-m64.c
new file mode 100644
index 00000000000..aa3fc81248f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/mfentry-m64.c
@@ -0,0 +1,8 @@
+/* { dg-do compile { target { lp64 } } } */
+/* { dg-options "-pg -mfentry" } */
+
+void
+profileme (void)
+{
+  /* { dg-final { scan-assembler "brasl\t0,__fentry__" } } */
+}
-- 
2.17.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/3] S/390: Implement -mnop-mcount
  2018-07-16  7:49 [PATCH, S/390] Improved support for the Linux kernel Ftrace Ilya Leoshkevich
@ 2018-07-16  7:49 ` Ilya Leoshkevich
  2018-07-16 14:43   ` Andreas Krebbel
  2018-07-16  7:49 ` [PATCH 2/3] S/390: Implement -mrecord-mcount Ilya Leoshkevich
  2018-07-16  7:49 ` [PATCH 1/3] S/390: Implement -mfentry Ilya Leoshkevich
  2 siblings, 1 reply; 7+ messages in thread
From: Ilya Leoshkevich @ 2018-07-16  7:49 UTC (permalink / raw)
  To: gcc-patches; +Cc: krebbel, Ilya Leoshkevich

This is the counterpart of the i386 feature introduced by
39a5a6a4: Add direct support for Linux kernel __fentry__ patching.

On i386 the profiler call sequence always consists of 1 call
instruction, so -mnop-mcount generates a single nop with the same
length as a call. For S/390 longer sequences may be used in some
cases, so -mnop-mcount generates the corresponding amount of nops.

        * gcc/config/s390/s390.c (s390_function_profiler): Generate
        nops instead of profiler call sequences.
        * gcc/config/s390/s390.opt: Add the new option.
        * gcc/testsuite/gcc.target/s390/mnop-mcount-m31-fpic.c:
        New testcase.
        * gcc/testsuite/gcc.target/s390/mnop-mcount-m31-mzarch.c
        New testcase.
        * gcc/testsuite/gcc.target/s390/mnop-mcount-m31.c
        New testcase.
        * gcc/testsuite/gcc.target/s390/mnop-mcount-m64-mfentry.c
        New testcase.
        * gcc/testsuite/gcc.target/s390/mnop-mcount-m64.c
        New testcase.
---
 gcc/config/s390/s390.c                        | 113 +++++++++++++-----
 gcc/config/s390/s390.opt                      |   5 +
 .../gcc.target/s390/mnop-mcount-m31-fpic.c    |   8 ++
 .../gcc.target/s390/mnop-mcount-m31-mzarch.c  |   8 ++
 .../gcc.target/s390/mnop-mcount-m31.c         |   8 ++
 .../gcc.target/s390/mnop-mcount-m64-mfentry.c |   8 ++
 .../gcc.target/s390/mnop-mcount-m64.c         |   8 ++
 7 files changed, 129 insertions(+), 29 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/s390/mnop-mcount-m31-fpic.c
 create mode 100644 gcc/testsuite/gcc.target/s390/mnop-mcount-m31-mzarch.c
 create mode 100644 gcc/testsuite/gcc.target/s390/mnop-mcount-m31.c
 create mode 100644 gcc/testsuite/gcc.target/s390/mnop-mcount-m64-mfentry.c
 create mode 100644 gcc/testsuite/gcc.target/s390/mnop-mcount-m64.c

diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index 600501c1e27..ba18cb1c39a 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -13123,6 +13123,30 @@ s390_trampoline_init (rtx m_tramp, tree fndecl, rtx cxt)
   emit_move_insn (mem, fnaddr);
 }
 
+static void
+output_asm_nops (const char *user, int hw)
+{
+  asm_fprintf (asm_out_file, "\t# NOPs for %s (%d halfwords)\n", user, hw);
+  while (hw > 0)
+    {
+      if (TARGET_CPU_ZARCH && hw >= 3)
+        {
+          output_asm_insn ("brcl\t0,0", NULL);
+          hw -= 3;
+        }
+      else if (hw >= 2)
+        {
+          output_asm_insn ("bc\t0,0", NULL);
+          hw -= 2;
+        }
+      else
+        {
+          output_asm_insn ("bcr\t0,0", NULL);
+          hw -= 1;
+        }
+    }
+}
+
 /* Output assembler code to FILE to increment profiler label # LABELNO
    for profiling a function entry.  */
 
@@ -13156,7 +13180,9 @@ s390_function_profiler (FILE *file, int labelno)
 
   if (flag_fentry)
     {
-      if (cfun->static_chain_decl)
+      if (flag_nop_mcount)
+        output_asm_nops ("-mnop-mcount", /* brasl */ 3);
+      else if (cfun->static_chain_decl)
         warning (OPT_Wcannot_profile, "nested functions cannot be profiled "
                  "with -mfentry on s390");
       else
@@ -13164,48 +13190,77 @@ s390_function_profiler (FILE *file, int labelno)
     }
   else if (TARGET_64BIT)
     {
-      output_asm_insn ("stg\t%0,%1", op);
-      output_asm_insn ("larl\t%2,%3", op);
-      output_asm_insn ("brasl\t%0,%4", op);
-      output_asm_insn ("lg\t%0,%1", op);
+      if (flag_nop_mcount)
+        output_asm_nops ("-mnop-mcount", /* stg */ 3 + /* larl */ 3 +
+                         /* brasl */ 3 + /* lg */ 3);
+      else
+        {
+          output_asm_insn ("stg\t%0,%1", op);
+          output_asm_insn ("larl\t%2,%3", op);
+          output_asm_insn ("brasl\t%0,%4", op);
+          output_asm_insn ("lg\t%0,%1", op);
+        }
     }
   else if (TARGET_CPU_ZARCH)
     {
-      output_asm_insn ("st\t%0,%1", op);
-      output_asm_insn ("larl\t%2,%3", op);
-      output_asm_insn ("brasl\t%0,%4", op);
-      output_asm_insn ("l\t%0,%1", op);
+      if (flag_nop_mcount)
+        output_asm_nops ("-mnop-mcount", /* st */ 2 + /* larl */ 3 +
+                         /* brasl */ 3 + /* l */ 2);
+      else
+        {
+          output_asm_insn ("st\t%0,%1", op);
+          output_asm_insn ("larl\t%2,%3", op);
+          output_asm_insn ("brasl\t%0,%4", op);
+          output_asm_insn ("l\t%0,%1", op);
+        }
     }
   else if (!flag_pic)
     {
       op[6] = gen_label_rtx ();
 
-      output_asm_insn ("st\t%0,%1", op);
-      output_asm_insn ("bras\t%2,%l6", op);
-      output_asm_insn (".long\t%4", op);
-      output_asm_insn (".long\t%3", op);
-      targetm.asm_out.internal_label (file, "L", CODE_LABEL_NUMBER (op[6]));
-      output_asm_insn ("l\t%0,0(%2)", op);
-      output_asm_insn ("l\t%2,4(%2)", op);
-      output_asm_insn ("basr\t%0,%0", op);
-      output_asm_insn ("l\t%0,%1", op);
+      if (flag_nop_mcount)
+        output_asm_nops ("-mnop-mcount", /* st */ 2 + /* bras */ 2 +
+                         /* .long */ 2 + /* .long */ 2 + /* l */ 2 +
+                         /* l */ 2 + /* basr */ 1 + /* l */ 2);
+      else
+        {
+          output_asm_insn ("st\t%0,%1", op);
+          output_asm_insn ("bras\t%2,%l6", op);
+          output_asm_insn (".long\t%4", op);
+          output_asm_insn (".long\t%3", op);
+          targetm.asm_out.internal_label (file, "L",
+                                          CODE_LABEL_NUMBER (op[6]));
+          output_asm_insn ("l\t%0,0(%2)", op);
+          output_asm_insn ("l\t%2,4(%2)", op);
+          output_asm_insn ("basr\t%0,%0", op);
+          output_asm_insn ("l\t%0,%1", op);
+        }
     }
   else
     {
       op[5] = gen_label_rtx ();
       op[6] = gen_label_rtx ();
 
-      output_asm_insn ("st\t%0,%1", op);
-      output_asm_insn ("bras\t%2,%l6", op);
-      targetm.asm_out.internal_label (file, "L", CODE_LABEL_NUMBER (op[5]));
-      output_asm_insn (".long\t%4-%l5", op);
-      output_asm_insn (".long\t%3-%l5", op);
-      targetm.asm_out.internal_label (file, "L", CODE_LABEL_NUMBER (op[6]));
-      output_asm_insn ("lr\t%0,%2", op);
-      output_asm_insn ("a\t%0,0(%2)", op);
-      output_asm_insn ("a\t%2,4(%2)", op);
-      output_asm_insn ("basr\t%0,%0", op);
-      output_asm_insn ("l\t%0,%1", op);
+      if (flag_nop_mcount)
+        output_asm_nops ("-mnop-mcount", /* st */ 2 + /* bras */ 2 +
+                         /* .long */ 2 + /* .long */ 2 + /* lr */ 1 +
+                         /* a */ 2 + /* a */ 2 + /* basr */ 1 + /* l */ 2);
+      else
+        {
+          output_asm_insn ("st\t%0,%1", op);
+          output_asm_insn ("bras\t%2,%l6", op);
+          targetm.asm_out.internal_label (file, "L",
+                                          CODE_LABEL_NUMBER (op[5]));
+          output_asm_insn (".long\t%4-%l5", op);
+          output_asm_insn (".long\t%3-%l5", op);
+          targetm.asm_out.internal_label (file, "L",
+                                          CODE_LABEL_NUMBER (op[6]));
+          output_asm_insn ("lr\t%0,%2", op);
+          output_asm_insn ("a\t%0,0(%2)", op);
+          output_asm_insn ("a\t%2,4(%2)", op);
+          output_asm_insn ("basr\t%0,%0", op);
+          output_asm_insn ("l\t%0,%1", op);
+        }
     }
 
   if (flag_record_mcount)
diff --git a/gcc/config/s390/s390.opt b/gcc/config/s390/s390.opt
index 9a3ed651450..4214b1714c2 100644
--- a/gcc/config/s390/s390.opt
+++ b/gcc/config/s390/s390.opt
@@ -302,3 +302,8 @@ code will require a 64-bit CPU and glibc 2.29 or newer to run.
 mrecord-mcount
 Target Report Var(flag_record_mcount)
 Generate __mcount_loc section with all _mcount and __fentry__ calls.
+
+mnop-mcount
+Target Report Var(flag_nop_mcount)
+Generate mcount/__fentry__ calls as nops. To activate they need to be
+patched in.
diff --git a/gcc/testsuite/gcc.target/s390/mnop-mcount-m31-fpic.c b/gcc/testsuite/gcc.target/s390/mnop-mcount-m31-fpic.c
new file mode 100644
index 00000000000..5b00ab65668
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/mnop-mcount-m31-fpic.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-m31 -mesa -march=g5 -fPIC -pg -mnop-mcount -Wno-deprecated" } */
+
+void
+profileme (void)
+{
+  /* { dg-final { scan-assembler "NOPs for -mnop-mcount \\(16 halfwords\\)\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0" } } */
+}
diff --git a/gcc/testsuite/gcc.target/s390/mnop-mcount-m31-mzarch.c b/gcc/testsuite/gcc.target/s390/mnop-mcount-m31-mzarch.c
new file mode 100644
index 00000000000..b2ad9f5bced
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/mnop-mcount-m31-mzarch.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-m31 -mzarch -pg -mnop-mcount" } */
+
+void
+profileme (void)
+{
+  /* { dg-final { scan-assembler "NOPs for -mnop-mcount \\(10 halfwords\\)\n.*brcl\t0,0\n.*brcl\t0,0\n.*brcl\t0,0\n.*bcr\t0,0" } } */
+}
diff --git a/gcc/testsuite/gcc.target/s390/mnop-mcount-m31.c b/gcc/testsuite/gcc.target/s390/mnop-mcount-m31.c
new file mode 100644
index 00000000000..e64c8d7d7bc
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/mnop-mcount-m31.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-m31 -mesa -march=g5 -pg -mnop-mcount -Wno-deprecated" } */
+
+void
+profileme (void)
+{
+  /* { dg-final { scan-assembler "NOPs for -mnop-mcount \\(15 halfwords\\)\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bcr\t0,0" } } */
+}
diff --git a/gcc/testsuite/gcc.target/s390/mnop-mcount-m64-mfentry.c b/gcc/testsuite/gcc.target/s390/mnop-mcount-m64-mfentry.c
new file mode 100644
index 00000000000..9c1504e8d63
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/mnop-mcount-m64-mfentry.c
@@ -0,0 +1,8 @@
+/* { dg-do compile { target { lp64 } } } */
+/* { dg-options "-pg -mfentry -mnop-mcount" } */
+
+void
+profileme (void)
+{
+  /* { dg-final { scan-assembler "NOPs for -mnop-mcount \\(3 halfwords\\)\n.*brcl\t0,0" } } */
+}
diff --git a/gcc/testsuite/gcc.target/s390/mnop-mcount-m64.c b/gcc/testsuite/gcc.target/s390/mnop-mcount-m64.c
new file mode 100644
index 00000000000..c0e3c4e91b1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/mnop-mcount-m64.c
@@ -0,0 +1,8 @@
+/* { dg-do compile { target { lp64 } } } */
+/* { dg-options "-pg -mnop-mcount" } */
+
+void
+profileme (void)
+{
+  /* { dg-final { scan-assembler "NOPs for -mnop-mcount \\(12 halfwords\\)\n.*brcl\t0,0\n.*brcl\t0,0\n.*brcl\t0,0\n.*brcl\t0,0" } } */
+}
-- 
2.17.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/3] S/390: Implement -mrecord-mcount
  2018-07-16  7:49 [PATCH, S/390] Improved support for the Linux kernel Ftrace Ilya Leoshkevich
  2018-07-16  7:49 ` [PATCH 3/3] S/390: Implement -mnop-mcount Ilya Leoshkevich
@ 2018-07-16  7:49 ` Ilya Leoshkevich
  2018-07-16 14:42   ` Andreas Krebbel
  2018-07-16  7:49 ` [PATCH 1/3] S/390: Implement -mfentry Ilya Leoshkevich
  2 siblings, 1 reply; 7+ messages in thread
From: Ilya Leoshkevich @ 2018-07-16  7:49 UTC (permalink / raw)
  To: gcc-patches; +Cc: krebbel, Ilya Leoshkevich

This is the counterpart of the i386 feature introduced by
39a5a6a4: Add direct support for Linux kernel __fentry__ patching.

        * gcc/config/s390/s390.c (s390_function_profiler): Generate
        __mcount_loc section.
        * gcc/config/s390/s390.opt: Add the new option.
        * gcc/testsuite/gcc.target/s390/mrecord-mcount.c:
        New testcase.
---
 gcc/config/s390/s390.c                         | 10 ++++++++++
 gcc/config/s390/s390.opt                       |  4 ++++
 gcc/testsuite/gcc.target/s390/mrecord-mcount.c | 10 ++++++++++
 3 files changed, 24 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/s390/mrecord-mcount.c

diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index 3a406b955a0..600501c1e27 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -13151,6 +13151,9 @@ s390_function_profiler (FILE *file, int labelno)
       op[4] = gen_rtx_CONST (Pmode, op[4]);
     }
 
+  if (flag_record_mcount)
+    fprintf (file, "1:\n");
+
   if (flag_fentry)
     {
       if (cfun->static_chain_decl)
@@ -13204,6 +13207,13 @@ s390_function_profiler (FILE *file, int labelno)
       output_asm_insn ("basr\t%0,%0", op);
       output_asm_insn ("l\t%0,%1", op);
     }
+
+  if (flag_record_mcount)
+    {
+      fprintf (file, "\t.section __mcount_loc, \"a\",@progbits\n");
+      fprintf (file, "\t.%s 1b\n", TARGET_64BIT ? "quad" : "long");
+      fprintf (file, "\t.previous\n");
+    }
 }
 
 /* Encode symbol attributes (local vs. global, tls model) of a SYMBOL_REF
diff --git a/gcc/config/s390/s390.opt b/gcc/config/s390/s390.opt
index 59e97d031b4..9a3ed651450 100644
--- a/gcc/config/s390/s390.opt
+++ b/gcc/config/s390/s390.opt
@@ -298,3 +298,7 @@ mfentry
 Target Report Var(flag_fentry)
 Emit profiling counter call at function entry before prologue. The compiled
 code will require a 64-bit CPU and glibc 2.29 or newer to run.
+
+mrecord-mcount
+Target Report Var(flag_record_mcount)
+Generate __mcount_loc section with all _mcount and __fentry__ calls.
diff --git a/gcc/testsuite/gcc.target/s390/mrecord-mcount.c b/gcc/testsuite/gcc.target/s390/mrecord-mcount.c
new file mode 100644
index 00000000000..d8a23ffdca4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/mrecord-mcount.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-pg -mrecord-mcount" } */
+
+void
+profileme (void)
+{
+  /* { dg-final { scan-assembler ".section __mcount_loc, \"a\",@progbits" } } */
+  /* { dg-final { scan-assembler ".quad 1b" } } */
+  /* { dg-final { scan-assembler ".previous" } } */
+}
-- 
2.17.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH, S/390] Improved support for the Linux kernel Ftrace
@ 2018-07-16  7:49 Ilya Leoshkevich
  2018-07-16  7:49 ` [PATCH 3/3] S/390: Implement -mnop-mcount Ilya Leoshkevich
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Ilya Leoshkevich @ 2018-07-16  7:49 UTC (permalink / raw)
  To: gcc-patches; +Cc: krebbel

This is the counterpart of the i386 feature introduced by
39a5a6a4: Add direct support for Linux kernel __fentry__ patching.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] S/390: Implement -mfentry
  2018-07-16  7:49 ` [PATCH 1/3] S/390: Implement -mfentry Ilya Leoshkevich
@ 2018-07-16 14:33   ` Andreas Krebbel
  0 siblings, 0 replies; 7+ messages in thread
From: Andreas Krebbel @ 2018-07-16 14:33 UTC (permalink / raw)
  To: Ilya Leoshkevich, gcc-patches

On 07/16/2018 09:48 AM, Ilya Leoshkevich wrote:
> This is the counterpart of the i386 feature introduced by
> 39a5a6a4: Add direct support for Linux kernel __fentry__ patching.
> 
> On i386, the difference between mcount and fentry is that fentry
> comes before the prolog. On s390 mcount already comes before the
> prolog, but takes 4 instructions. This patch introduces the more
> efficient implementation (just 1 instruction) and puts it under
> -mfentry flag.
> 
> The produced code is compatible only with newer glibc versions,
> which provide the __fentry__ symbol and do not clobber %r0 when
> resolving lazily bound functions. Because 31-bit PLT stubs assume
> %r12 contains GOT address, which is not the case when the code runs
> before the prolog, -mfentry is allowed only for 64-bit code.
> 
> Also, code compiled with -mfentry cannot be used for the nested C
> functions, since they both use %r0. In this case instrumentation is
> not insterted, and a new warning is issued for each affected nested
> function.
> 
>         * gcc/common.opt: Add the new warning.
>         * gcc/config/s390/s390.c (s390_function_profiler): Emit
>         "brasl %r0,__fentry__" when -mfentry is specified.
>         (s390_option_override_internal): Disallow -mfentry for
>         31-bit CPUs.
>         * gcc/config/s390/s390.opt: Add the new option.
>         * gcc/testsuite/gcc.target/s390/mfentry-m64.c:
>         New testcase.

Thanks! I've committed your patch with a modified changelog entry.

There are several ChangeLog files in the GCC source tree.  Paths have to be relative to these. There
is e.g. a separate ChangeLog file for the testsuite.

Bye,

Andreas


> ---
>  gcc/common.opt                              |  5 +++++
>  gcc/config/s390/s390.c                      | 18 ++++++++++++++++--
>  gcc/config/s390/s390.opt                    |  5 +++++
>  gcc/testsuite/gcc.target/s390/mfentry-m64.c |  8 ++++++++
>  4 files changed, 34 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/s390/mfentry-m64.c
> 
> diff --git a/gcc/common.opt b/gcc/common.opt
> index c29abdb5cb1..4d031e81b09 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -571,6 +571,11 @@ Wattribute-alias
>  Common Var(warn_attributes) Init(1) Warning
>  Warn about type safety and similar errors in attribute alias and related.
>  
> +Wcannot-profile
> +Common Var(warn_cannot_profile) Init(1) Warning
> +Warn when profiling instrumentation was requested, but could not be applied to
> +a certain function.
> +
>  Wcast-align
>  Common Var(warn_cast_align) Warning
>  Warn about pointer casts which increase alignment.
> diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
> index 23c3f3db621..3a406b955a0 100644
> --- a/gcc/config/s390/s390.c
> +++ b/gcc/config/s390/s390.c
> @@ -13144,14 +13144,22 @@ s390_function_profiler (FILE *file, int labelno)
>    op[3] = gen_rtx_SYMBOL_REF (Pmode, label);
>    SYMBOL_REF_FLAGS (op[3]) = SYMBOL_FLAG_LOCAL;
>  
> -  op[4] = gen_rtx_SYMBOL_REF (Pmode, "_mcount");
> +  op[4] = gen_rtx_SYMBOL_REF (Pmode, flag_fentry ? "__fentry__" : "_mcount");
>    if (flag_pic)
>      {
>        op[4] = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op[4]), UNSPEC_PLT);
>        op[4] = gen_rtx_CONST (Pmode, op[4]);
>      }
>  
> -  if (TARGET_64BIT)
> +  if (flag_fentry)
> +    {
> +      if (cfun->static_chain_decl)
> +        warning (OPT_Wcannot_profile, "nested functions cannot be profiled "
> +                 "with -mfentry on s390");
> +      else
> +        output_asm_insn ("brasl\t0,%4", op);
> +    }
> +  else if (TARGET_64BIT)
>      {
>        output_asm_insn ("stg\t%0,%1", op);
>        output_asm_insn ("larl\t%2,%3", op);
> @@ -15562,6 +15570,12 @@ s390_option_override_internal (bool main_args_p,
>    /* Call target specific restore function to do post-init work.  At the moment,
>       this just sets opts->x_s390_cost_pointer.  */
>    s390_function_specific_restore (opts, NULL);
> +
> +  /* Check whether -mfentry is supported. It cannot be used in 31-bit mode,
> +     because 31-bit PLT stubs assume that %r12 contains GOT address, which is
> +     not the case when the code runs before the prolog. */
> +  if (opts->x_flag_fentry && !TARGET_64BIT)
> +    error ("-mfentry is supported only for 64-bit CPUs");
>  }
>  
>  static void
> diff --git a/gcc/config/s390/s390.opt b/gcc/config/s390/s390.opt
> index eb16f9c821f..59e97d031b4 100644
> --- a/gcc/config/s390/s390.opt
> +++ b/gcc/config/s390/s390.opt
> @@ -293,3 +293,8 @@ locations which have been patched as part of using one of the
>  -mindirect-branch* or -mfunction-return* options.  The sections
>  consist of an array of 32 bit elements. Each entry holds the offset
>  from the entry to the patched location.
> +
> +mfentry
> +Target Report Var(flag_fentry)
> +Emit profiling counter call at function entry before prologue. The compiled
> +code will require a 64-bit CPU and glibc 2.29 or newer to run.
> diff --git a/gcc/testsuite/gcc.target/s390/mfentry-m64.c b/gcc/testsuite/gcc.target/s390/mfentry-m64.c
> new file mode 100644
> index 00000000000..aa3fc81248f
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/s390/mfentry-m64.c
> @@ -0,0 +1,8 @@
> +/* { dg-do compile { target { lp64 } } } */
> +/* { dg-options "-pg -mfentry" } */
> +
> +void
> +profileme (void)
> +{
> +  /* { dg-final { scan-assembler "brasl\t0,__fentry__" } } */
> +}
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] S/390: Implement -mrecord-mcount
  2018-07-16  7:49 ` [PATCH 2/3] S/390: Implement -mrecord-mcount Ilya Leoshkevich
@ 2018-07-16 14:42   ` Andreas Krebbel
  0 siblings, 0 replies; 7+ messages in thread
From: Andreas Krebbel @ 2018-07-16 14:42 UTC (permalink / raw)
  To: Ilya Leoshkevich, gcc-patches

On 07/16/2018 09:48 AM, Ilya Leoshkevich wrote:
> This is the counterpart of the i386 feature introduced by
> 39a5a6a4: Add direct support for Linux kernel __fentry__ patching.
> 
>         * gcc/config/s390/s390.c (s390_function_profiler): Generate
>         __mcount_loc section.
>         * gcc/config/s390/s390.opt: Add the new option.
>         * gcc/testsuite/gcc.target/s390/mrecord-mcount.c:
>         New testcase.

Applied. Thanks!

Andreas

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] S/390: Implement -mnop-mcount
  2018-07-16  7:49 ` [PATCH 3/3] S/390: Implement -mnop-mcount Ilya Leoshkevich
@ 2018-07-16 14:43   ` Andreas Krebbel
  0 siblings, 0 replies; 7+ messages in thread
From: Andreas Krebbel @ 2018-07-16 14:43 UTC (permalink / raw)
  To: Ilya Leoshkevich, gcc-patches

On 07/16/2018 09:48 AM, Ilya Leoshkevich wrote:
> This is the counterpart of the i386 feature introduced by
> 39a5a6a4: Add direct support for Linux kernel __fentry__ patching.
> 
> On i386 the profiler call sequence always consists of 1 call
> instruction, so -mnop-mcount generates a single nop with the same
> length as a call. For S/390 longer sequences may be used in some
> cases, so -mnop-mcount generates the corresponding amount of nops.
> 
>         * gcc/config/s390/s390.c (s390_function_profiler): Generate
>         nops instead of profiler call sequences.
>         * gcc/config/s390/s390.opt: Add the new option.
>         * gcc/testsuite/gcc.target/s390/mnop-mcount-m31-fpic.c:
>         New testcase.
>         * gcc/testsuite/gcc.target/s390/mnop-mcount-m31-mzarch.c
>         New testcase.
>         * gcc/testsuite/gcc.target/s390/mnop-mcount-m31.c
>         New testcase.
>         * gcc/testsuite/gcc.target/s390/mnop-mcount-m64-mfentry.c
>         New testcase.
>         * gcc/testsuite/gcc.target/s390/mnop-mcount-m64.c
>         New testcase.

Applied. Thanks!

Andreas

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-07-16 14:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-16  7:49 [PATCH, S/390] Improved support for the Linux kernel Ftrace Ilya Leoshkevich
2018-07-16  7:49 ` [PATCH 3/3] S/390: Implement -mnop-mcount Ilya Leoshkevich
2018-07-16 14:43   ` Andreas Krebbel
2018-07-16  7:49 ` [PATCH 2/3] S/390: Implement -mrecord-mcount Ilya Leoshkevich
2018-07-16 14:42   ` Andreas Krebbel
2018-07-16  7:49 ` [PATCH 1/3] S/390: Implement -mfentry Ilya Leoshkevich
2018-07-16 14:33   ` Andreas Krebbel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).