This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] pr 63354 - gcc -pg -mprofile-kernel creates unused stack frames on leaf functions on ppc64le
- From: Martin Sebor <msebor at redhat dot com>
- To: Iain Sandoe <iain at codesourcery dot com>
- Cc: Segher Boessenkool <segher at kernel dot crashing dot org>, Gcc Patch List <gcc-patches at gcc dot gnu dot org>, anton at samba dot org
- Date: Tue, 24 Mar 2015 14:18:07 -0600
- Subject: Re: [PATCH] pr 63354 - gcc -pg -mprofile-kernel creates unused stack frames on leaf functions on ppc64le
- Authentication-results: sourceware.org; auth=none
- References: <55035CB1 dot 4020801 at redhat dot com> <20150314143434 dot GC3690 at gate dot crashing dot org> <5506184F dot 8090006 at redhat dot com> <210B149C-A8AB-4A0C-98AA-90D72741A7AF at codesourcery dot com> <5510D0F3 dot 4060606 at redhat dot com> <1209B144-07A2-40DE-974E-47DA5A8B7DE9 at codesourcery dot com>
I'm assuming that you mean a cross-compile (which is a stage1 without -werror). If you look in the build output (I just repeated this on x86_64-darwin12 X powerpc-darwin9) you'll see:
/GCC/gcc-trunk/gcc/config/rs6000/rs6000.c:24404:1: warning: ‘bool rs6000_keep_leaf_when_profiled()’ defined but not used [-Wunused-function]
rs6000_keep_leaf_when_profiled (void)
^
this becomes a bootstrap error at stage#2. If you don't see that, then I have don't have the same patch applied as you :).
Yes, I meant a cross-compile. I don't have a Darwin environment
but I managed to reproduce it while building stage1 with -Werror
(after fixing a number of problems that cause the build to fail
earlier on). Thanks for your patience.
Attached is an updated patch with your suggested change (i.e.,
defining the TARGET_KEEP_LEAF_WHEN_PROFILED macro in rs6000.h
instead of linux64.h).
I tested the patch by building stage1 with -Werror for both
powerpc64-darwin9 and powerpc64-unknown-linux-gnu (both on
the latter target).
Martin
2015-03-24 Anton Blanchard <anton@samba.org>
PR target/63354
* config/rs6000/rs6000.h (TARGET_KEEP_LEAF_WHEN_PROFILED): Define.
* config/rs6000/rs6000.c (rs6000_keep_leaf_when_profiled): New
function.
2015-03-24 Martin Sebor <msebor@redhat.com>
PR target/63354
* gcc.target/powerpc/pr63354.c: New test.
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 31b46ea..f1508b9 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -24397,6 +24397,23 @@ rs6000_output_function_prologue (FILE *file,
rs6000_pic_labelno++;
}
+/* -mprofile-kernel code calls mcount before the function prologue,
+ so a profiled leaf function should stay a leaf function. */
+
+static bool
+rs6000_keep_leaf_when_profiled (void)
+{
+ switch (DEFAULT_ABI)
+ {
+ case ABI_AIX:
+ case ABI_ELFv2:
+ return TARGET_PROFILE_KERNEL;
+
+ default:
+ return true;
+ }
+}
+
/* Non-zero if vmx regs are restored before the frame pop, zero if
we restore after the pop when possible. */
#define ALWAYS_RESTORE_ALTIVEC_BEFORE_POP 0
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index ef6bb2f..50394b0 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -703,6 +703,9 @@ extern unsigned char rs6000_recip_bits[];
#define TARGET_CPU_CPP_BUILTINS() \
rs6000_cpu_cpp_builtins (pfile)
+#undef TARGET_KEEP_LEAF_WHEN_PROFILED
+#define TARGET_KEEP_LEAF_WHEN_PROFILED rs6000_keep_leaf_when_profiled
+
/* This is used by rs6000_cpu_cpp_builtins to indicate the byte order
we're compiling for. Some configurations may need to override it. */
#define RS6000_CPU_CPP_ENDIAN_BUILTINS() \
diff --git a/gcc/testsuite/gcc.target/powerpc/pr63354.c b/gcc/testsuite/gcc.target/powerpc/pr63354.c
new file mode 100644
index 0000000..9e635cc
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr63354.c
@@ -0,0 +1,10 @@
+/* { dg-do compile { target { powerpc64*-*-linux* } } } */
+/* { dg-options "-O2 -pg -mprofile-kernel" } */
+
+int foo (void)
+{
+ return 1;
+}
+
+/* { dg-final { scan-assembler "bl _mcount" } } */
+/* { dg-final { scan-assembler-not "(addi|stdu) 1," } } */