[PATCH] i686: Compile gmon tests with -mfentry

H.J. Lu hjl.tools@gmail.com
Fri Sep 5 01:02:59 GMT 2025


On i686, after GCC 16 commit:

Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jul 2 08:58:23 2025 +0800

    x86-64: Add --enable-x86-64-mfentry

which warns ‘-pg’ without ‘-mfentry’, when glibc is configured with
--disable-default-pie, GCC 16 fails to compile gmon tests with error:

cc1: error: ‘-pg’ without ‘-mfentry’ may be unreliable with shrink wrapping [-Werror]

Compile tst-gmon.c, tst-mcleanup.c and tst-mcount-overflow.c with
-mfentry if it is supported by TEST_CC and glibc is configured with
--disable-default-pie.  This fixes BZ #33376.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
 sysdeps/i386/Makefile     |  7 +++++++
 sysdeps/i386/configure    | 34 ++++++++++++++++++++++++++++++++++
 sysdeps/i386/configure.ac | 10 ++++++++++
 3 files changed, 51 insertions(+)

diff --git a/sysdeps/i386/Makefile b/sysdeps/i386/Makefile
index 4fbaaa252b..d8d016b3b5 100644
--- a/sysdeps/i386/Makefile
+++ b/sysdeps/i386/Makefile
@@ -15,6 +15,13 @@ endif
 
 ifeq ($(subdir),gmon)
 sysdep_routines += i386-mcount
+ifeq ($(build-pie-default)$(have-test-cc-cflags-mfentry),noyes)
+# Compile with -mfentry to avoid GCC 16 error:
+# cc1: error: ‘-pg’ without ‘-mfentry’ may be unreliable with shrink wrapping [-Werror]
+CFLAGS-tst-gmon.c += -mfentry
+CFLAGS-tst-mcleanup.c += -mfentry
+CFLAGS-tst-mcount-overflow.c += -mfentry
+endif
 endif
 
 ifeq ($(subdir),csu)
diff --git a/sysdeps/i386/configure b/sysdeps/i386/configure
index a618692adf..242cb37789 100644
--- a/sysdeps/i386/configure
+++ b/sysdeps/i386/configure
@@ -95,3 +95,37 @@ if test x"$multi_arch" != xno; then
 
 fi
 
+
+
+saved_CC="$CC"
+CC="$TEST_CC"
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking -mfentry in testing" >&5
+printf %s "checking -mfentry in testing... " >&6; }
+if test ${libc_cv_test_cc_cflags_mfentry+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e) if { ac_try='${CC-cc} -Werror -mfentry -xc /dev/null -S -o /dev/null'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+then :
+  libc_cv_test_cc_cflags_mfentry=yes
+else case e in #(
+  e) libc_cv_test_cc_cflags_mfentry=no
+ ;;
+esac
+fi ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_test_cc_cflags_mfentry" >&5
+printf "%s\n" "$libc_cv_test_cc_cflags_mfentry" >&6; }
+
+CC="$saved_CC"
+
+
+config_vars="$config_vars
+have-test-cc-cflags-mfentry = $libc_cv_test_cc_cflags_mfentry"
+
diff --git a/sysdeps/i386/configure.ac b/sysdeps/i386/configure.ac
index 7f68e6210a..763df21e90 100644
--- a/sysdeps/i386/configure.ac
+++ b/sysdeps/i386/configure.ac
@@ -63,3 +63,13 @@ dnl via PIC PLT in PIE, which requires setting up EBX register.
 if test x"$multi_arch" != xno; then
   AC_DEFINE(NO_HIDDEN_EXTERN_FUNC_IN_PIE)
 fi
+
+dnl Check if TEST_CC supports -mfentry.
+LIBC_TRY_TEST_CC_OPTION([-mfentry],
+  [-Werror -mfentry],
+  libc_cv_test_cc_cflags_mfentry,
+  [libc_cv_test_cc_cflags_mfentry=yes],
+  [libc_cv_test_cc_cflags_mfentry=no]
+)
+LIBC_CONFIG_VAR(have-test-cc-cflags-mfentry,
+		$libc_cv_test_cc_cflags_mfentry)
-- 
2.51.0



More information about the Libc-alpha mailing list