gprof: Compile tst-gmon.c with -O2 -fno-omit-frame-pointer

Message ID 20250308094656.674813-1-hjl.tools@gmail.com
State New
Headers
Series gprof: Compile tst-gmon.c with -O2 -fno-omit-frame-pointer |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

H.J. Lu March 8, 2025, 9:46 a.m. UTC
  Compile tst-gmon.c with -O2 -fno-omit-frame-pointer to ensure proper call
graph generation.

	PR gprof/32768
	* configure.ac: Compile tst-gmon.c with -fno-omit-frame-pointe.
	* configure: Regenerated.
	* testsuite/Makefile.am (GPROF_FLAGS): Add -O2
	-fno-omit-frame-pointer.
	(AM_CFLAGS): Removed.
	(COMPILE): Append $(GPROF_FLAGS).
	(LINK): Likewise.
	* testsuite/Makefile.in: Regenerated.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
 gprof/configure             |  2 +-
 gprof/configure.ac          |  2 +-
 gprof/testsuite/Makefile.am | 10 +++++-----
 gprof/testsuite/Makefile.in | 10 ++++++----
 4 files changed, 13 insertions(+), 11 deletions(-)
  

Comments

Alan Modra March 8, 2025, 10:20 a.m. UTC | #1
On Sat, Mar 08, 2025 at 05:46:56PM +0800, H.J. Lu wrote:
> +# NB: -O2 -fno-omit-frame-pointer is needed for expected call graph.  See
> +# https://sourceware.org/bugzilla/show_bug.cgi?id=32768
> +GPROF_FLAGS = -O2 -fno-omit-frame-pointer -pg

Thanks.  Fair enough.  x86_64 at least complains if you have -pg and
-fomit-frame-pointer together, and -O2 on x86_64 puts functions on
16-byte boundaries.
  
H.J. Lu March 8, 2025, 10:25 a.m. UTC | #2
On Sat, Mar 8, 2025 at 6:20 PM Alan Modra <amodra@gmail.com> wrote:
>
> On Sat, Mar 08, 2025 at 05:46:56PM +0800, H.J. Lu wrote:
> > +# NB: -O2 -fno-omit-frame-pointer is needed for expected call graph.  See
> > +# https://sourceware.org/bugzilla/show_bug.cgi?id=32768
> > +GPROF_FLAGS = -O2 -fno-omit-frame-pointer -pg
>
> Thanks.  Fair enough.  x86_64 at least complains if you have -pg and
> -fomit-frame-pointer together, and -O2 on x86_64 puts functions on
> 16-byte boundaries.
>

This test works in glibc for many targets compiled with
-O2 -fno-omit-frame-pointer -pg.   I am checking it in.

Thanks.
  

Patch

diff --git a/gprof/configure b/gprof/configure
index b830da03289..2acae7bcd0a 100755
--- a/gprof/configure
+++ b/gprof/configure
@@ -13972,7 +13972,7 @@  if ${gprof_cv_sys_native+:} false; then :
 else
     gprof_cv_sys_native=no
   if test x"${host}" = x"${target}" \
-     && ${CC-cc} -O2 -pg -o tst-gmon $srcdir/testsuite/tst-gmon.c; then
+     && ${CC-cc} -O2 -fno-omit-frame-pointer -pg -o tst-gmon $srcdir/testsuite/tst-gmon.c; then
     rm -f gmon.out
     ./tst-gmon
     if test -s gmon.out; then
diff --git a/gprof/configure.ac b/gprof/configure.ac
index f74da7d309a..166e16cbb3d 100644
--- a/gprof/configure.ac
+++ b/gprof/configure.ac
@@ -77,7 +77,7 @@  AC_CACHE_CHECK([whether gprof tests can run],
   [gprof_cv_sys_native], [dnl
   gprof_cv_sys_native=no
   if test x"${host}" = x"${target}" \
-     && ${CC-cc} -O2 -pg -o tst-gmon $srcdir/testsuite/tst-gmon.c; then
+     && ${CC-cc} -O2 -fno-omit-frame-pointer -pg -o tst-gmon $srcdir/testsuite/tst-gmon.c; then
     rm -f gmon.out
     ./tst-gmon
     if test -s gmon.out; then
diff --git a/gprof/testsuite/Makefile.am b/gprof/testsuite/Makefile.am
index 7cc95e33f1b..6a3eb726294 100644
--- a/gprof/testsuite/Makefile.am
+++ b/gprof/testsuite/Makefile.am
@@ -4,13 +4,13 @@  AUTOMAKE_OPTIONS = foreign
 
 GPROF = ../gprof$(EXEEXT)
 
-GPROF_FLAGS = -pg
-
-AM_CFLAGS = $(GPROF_FLAGS)
+# NB: -O2 -fno-omit-frame-pointer is needed for expected call graph.  See
+# https://sourceware.org/bugzilla/show_bug.cgi?id=32768
+GPROF_FLAGS = -O2 -fno-omit-frame-pointer -pg
 
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
-	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-LINK = $(CC) $(AM_CFLAGS) $(CFLAGS) $(OPT_NO_PLUGINS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(GPROF_FLAGS)
+LINK = $(CC) $(AM_CFLAGS) $(CFLAGS) $(OPT_NO_PLUGINS) $(GPROF_FLAGS) \
 	$(AM_LDFLAGS) $(LDFLAGS) -o $@
 
 # We will add to these later, for each individual test.  Note
diff --git a/gprof/testsuite/Makefile.in b/gprof/testsuite/Makefile.in
index 91d2854c438..3e26c2c952c 100644
--- a/gprof/testsuite/Makefile.in
+++ b/gprof/testsuite/Makefile.in
@@ -493,12 +493,14 @@  top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 AUTOMAKE_OPTIONS = foreign
 GPROF = ../gprof$(EXEEXT)
-GPROF_FLAGS = -pg
-AM_CFLAGS = $(GPROF_FLAGS)
+
+# NB: -O2 -fno-omit-frame-pointer is needed for expected call graph.  See
+# https://sourceware.org/bugzilla/show_bug.cgi?id=32768
+GPROF_FLAGS = -O2 -fno-omit-frame-pointer -pg
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
-	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(GPROF_FLAGS)
 
-LINK = $(CC) $(AM_CFLAGS) $(CFLAGS) $(OPT_NO_PLUGINS) \
+LINK = $(CC) $(AM_CFLAGS) $(CFLAGS) $(OPT_NO_PLUGINS) $(GPROF_FLAGS) \
 	$(AM_LDFLAGS) $(LDFLAGS) -o $@