[PATCH v2] i686: Compile .op files and gmon tests with -mfentry
H.J. Lu
hjl.tools@gmail.com
Fri Sep 5 16:02:48 GMT 2025
On i686, after GCC 16 commit:
commit 07d8de9174c421d719649639a1452b8b9f2eee32
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 .op files and gmon tests
with error:
cc1: error: ‘-pg’ without ‘-mfentry’ may be unreliable with shrink wrapping [-Werror]
Compile .op files and gmon tests 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 | 13 ++++++++
sysdeps/i386/configure | 62 +++++++++++++++++++++++++++++++++++++++
sysdeps/i386/configure.ac | 14 +++++++++
3 files changed, 89 insertions(+)
diff --git a/sysdeps/i386/Makefile b/sysdeps/i386/Makefile
index 4fbaaa252b..4f96f8e191 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)
@@ -63,3 +70,9 @@ generated += check-gnu-tls.out
else
CFLAGS-.os += $(if $(filter rtld-%.os,$(@F)), $(rtld-CFLAGS))
endif
+
+ifeq ($(build-pie-default)$(build-profile)$(have-cc-cflags-mfentry),noyesyes)
+# Compile .op files with -mfentry to avoid GCC 16 error:
+# cc1: error: ‘-pg’ without ‘-mfentry’ may be unreliable with shrink wrapping [-Werror]
+CFLAGS-.op += -mfentry
+endif
diff --git a/sysdeps/i386/configure b/sysdeps/i386/configure
index a618692adf..71c334bf0d 100644
--- a/sysdeps/i386/configure
+++ b/sysdeps/i386/configure
@@ -95,3 +95,65 @@ if test x"$multi_arch" != xno; then
fi
+
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking -mfentry" >&5
+printf %s "checking -mfentry... " >&6; }
+if test ${libc_cv_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_cc_cflags_mfentry=yes
+else case e in #(
+ e) libc_cv_cc_cflags_mfentry=no ;;
+esac
+fi ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_cflags_mfentry" >&5
+printf "%s\n" "$libc_cv_cc_cflags_mfentry" >&6; }
+if test "$TEST_CC" = "$CC"; then
+ libc_cv_test_cc_cflags_mfentry=$libc_cv_cc_cflags_mfentry
+else
+
+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"
+
+fi
+
+config_vars="$config_vars
+have-cc-cflags-mfentry = $libc_cv_cc_cflags_mfentry"
+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..4d2850184b 100644
--- a/sysdeps/i386/configure.ac
+++ b/sysdeps/i386/configure.ac
@@ -63,3 +63,17 @@ 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 CC and TEST_CC support -mfentry.
+LIBC_TRY_CC_AND_TEST_CC_OPTION([-mfentry],
+ [-Werror -mfentry],
+ libc_cv_cc_cflags_mfentry,
+ [libc_cv_cc_cflags_mfentry=yes],
+ [libc_cv_cc_cflags_mfentry=no],
+ libc_cv_test_cc_cflags_mfentry,
+ [libc_cv_test_cc_cflags_mfentry=yes],
+ [libc_cv_test_cc_cflags_mfentry=no]
+)
+LIBC_CONFIG_VAR(have-cc-cflags-mfentry, $libc_cv_cc_cflags_mfentry)
+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