]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
i686: Compile .op files and gmon tests with -mfentry
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 4 Sep 2025 23:24:14 +0000 (16:24 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 15 Sep 2025 18:14:03 +0000 (11:14 -0700)
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
CC/TEST_CC and glibc is configured with --disable-default-pie.  This
fixes BZ #33376.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Joseph Myers <josmyers@redhat.com>
sysdeps/i386/Makefile
sysdeps/i386/configure
sysdeps/i386/configure.ac

index 4fbaaa252b4991690252b2a52d0e59d853b4e97f..4f96f8e191a05204f873a7aea9ba991d747f8b86 100644 (file)
@@ -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
index a618692adf3843cbf48506f77727ebf3d2ca4e1b..71c334bf0de531d92a5513668d2003774b18daf9 100644 (file)
@@ -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"
+
index 7f68e6210a81f328a831ea6c79a4a3bef838009f..4d2850184b2fb497523a1ee86a4a5951395d439c 100644 (file)
@@ -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)