[PATCH] mips: Fix mips16 build

Adhemerval Zanella adhemerval.zanella@linaro.org
Tue Sep 23 18:56:03 GMT 2025


The build has been broken since commit 035c012e32 (version 2.34), which
changed the start.S file. Additionally, the BZ#12683 fix (commit
89b53077d2) did not include MIPS16 support.

Additionally, MIPS16 does not support -pg, so add a configure check to
error if —enable-profile is used and to disable gmon tests.

Checked with a build for mips-linux-gnu and mipel-linux-gnu. The loader
runs with qemu, but the libc fails due to a SIGBUS. I did not dig into
what is happening.
---
 configure                                     | 33 +++++++++++++++++++
 configure.ac                                  | 10 ++++++
 gmon/Makefile                                 |  2 ++
 sysdeps/mips/start.S                          |  4 +--
 .../sysv/linux/mips/mips32/syscall_cancel.S   |  2 ++
 .../sysv/linux/mips/mips64/syscall_cancel.S   |  1 +
 6 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 222f04db22..4e40adceb0 100755
--- a/configure
+++ b/configure
@@ -9492,6 +9492,39 @@ enable-gsframe = $enable_gsframe"
 libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
 
 
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for profile supporti" >&5
+printf %s "checking for profile supporti... " >&6; }
+if test ${libc_cv_pg+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e) old_CFLAGS="$CFLAGS"
+CFLAGS="-pg $CFLAGS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+void foo(void) {}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"
+then :
+  libc_cv_pg=yes
+else case e in #(
+  e) libc_cv_pg=no ;;
+esac
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
+CFLAGS="$old_CFLAGS" ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pg" >&5
+printf "%s\n" "$libc_cv_pg" >&6; }
+if test "x$profile" = xyes && test $libc_cv_pg = no; then
+  { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
+printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
+as_fn_error $? "profile support requires -pg compiler support
+See 'config.log' for more details" "$LINENO" 5; }
+fi
+config_vars="$config_vars
+have-pg = $libc_cv_pg"
 
 
 
diff --git a/configure.ac b/configure.ac
index af57b0cbae..28f4df6e2e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2177,6 +2177,16 @@ LIBC_CONFIG_VAR([enable-gsframe], [$enable_gsframe])
 libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
 AC_SUBST(libc_cv_multidir)
 
+AC_CACHE_CHECK([for profile supporti], libc_cv_pg, [dnl
+old_CFLAGS="$CFLAGS"
+CFLAGS="-pg $CFLAGS"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([[void foo(void) {}]])],
+                  [libc_cv_pg=yes], [libc_cv_pg=no])
+CFLAGS="$old_CFLAGS"])
+if test "x$profile" = xyes && test $libc_cv_pg = no; then
+  AC_MSG_FAILURE([profile support requires -pg compiler support])
+fi
+LIBC_CONFIG_VAR([have-pg], [$libc_cv_pg])
 AC_SUBST(profile)
 AC_SUBST(static_nss)
 
diff --git a/gmon/Makefile b/gmon/Makefile
index b42c14aa83..0d62e2988f 100644
--- a/gmon/Makefile
+++ b/gmon/Makefile
@@ -36,6 +36,7 @@ routines := \
   sprofil \
   # routines
 
+ifeq ($(have-pg),yes)
 tests = \
   tst-gmon \
   tst-mcleanup \
@@ -117,6 +118,7 @@ ifeq ($(run-built-tests),yes)
 tests-special += $(objpfx)tst-gmon-static-pie-gprof.out
 endif
 endif
+endif # $(have-pg) == yes
 
 
 include ../Rules
diff --git a/sysdeps/mips/start.S b/sysdeps/mips/start.S
index c58915c134..8c1962f8ad 100644
--- a/sysdeps/mips/start.S
+++ b/sysdeps/mips/start.S
@@ -144,7 +144,7 @@ ENTRY_POINT:
 # ifdef __PIC__
 	sw	$7, 24($sp)			/* stack_end */
 	move	$4, $0				/* Used to be ini.  */
-	sw	$0, 16($sp)			/* Used to be fini.  */
+	sw	$4, 16($sp)			/* Used to be fini.  */
 	lw	$4, %got(main)($3)		/* main */
 	lw	$3, %call16(__libc_start_main)($3)
 	sw	$2, 20($sp)			/* rtld_fini */
@@ -153,7 +153,7 @@ ENTRY_POINT:
 # else
 	sw	$7, 24($sp)			/* stack_end */
 	move	$7, $0				/* Used to be init.  */
-	sw	$0, 16($sp)			/* Used to be fini.  */
+	sw	$7, 16($sp)			/* Used to be fini.  */
 	lw	$4, 3f				/* main */
 	sw	$2, 20($sp)			/* rtld_fini */
 	/* Load and call __libc_start_main().  */
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S b/sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S
index 1190f089e3..2c95794601 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S
+++ b/sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S
@@ -32,6 +32,8 @@
 
 #define FRAME_SIZE 56
 
+	.text
+	.set    nomips16
 NESTED (__syscall_cancel_arch, FRAME_SIZE, fp)
 	.mask	0xc0070000,-SZREG
 	.fmask	0x00000000,0
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/syscall_cancel.S b/sysdeps/unix/sysv/linux/mips/mips64/syscall_cancel.S
index edd7c4d71d..209446b2ea 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/syscall_cancel.S
+++ b/sysdeps/unix/sysv/linux/mips/mips64/syscall_cancel.S
@@ -33,6 +33,7 @@
 #define FRAME_SIZE 32
 
 	.text
+	.set    nomips16
 NESTED (__syscall_cancel_arch, FRAME_SIZE, ra)
 	.mask	0x90010000, -SZREG
 	.fmask	0x00000000, 0
-- 
2.43.0



More information about the Libc-alpha mailing list