[binutils-gdb] gprof: Compile tst-gmon.c with -O2 -fno-omit-frame-pointer

H.J. Lu hjl@sourceware.org
Sat Mar 8 10:38:30 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1563d43f32090495d50f0c262d6e1bcc17807064

commit 1563d43f32090495d50f0c262d6e1bcc17807064
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sat Mar 8 17:13:17 2025 +0800

    gprof: Compile tst-gmon.c with -O2 -fno-omit-frame-pointer
    
    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-pointer.
            * 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>

Diff:
---
 gprof/configure             |  2 +-
 gprof/configure.ac          |  2 +-
 gprof/testsuite/Makefile.am | 10 +++++-----
 gprof/testsuite/Makefile.in | 10 ++++++----
 4 files changed, 13 insertions(+), 11 deletions(-)

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 $@


More information about the Binutils-cvs mailing list