i686: Compile .op files and gmon tests with -mfentry

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>
This commit is contained in:
H.J. Lu 2025-09-04 16:24:14 -07:00
parent 9be489d778
commit d6666eea3e
3 changed files with 89 additions and 0 deletions

View 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

View 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"

View 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)