This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v4] Mips support for PT_GNU_STACK

From: "Dragan Mladjenovic" <>

Hello everyone,

This is fourth attempt to enable glibc to safely handle PT_GNU_STACK on Linux/Mips.
You can check out the previous discussion about this issue at [1], [2] and [3].

A brief summary of the issue this is trying to address:

Up until the Linux kernel version 4.8 [4] MIPS FPU emulator used a small trampoline,
created on user stack, to handle delay slots when emulating FPU branches.
Because of this non-executable stack could not be enabled by default on MIPS.
The compatibility issue is that these old kernels respect PT_GNU_STACK,
making the stack non-executable if requested, and could crash the user process if
there would be need to emulate an instruction in the delay slot of a FPU branch.

In order to allow for the glibc to be safely compiled with potential future gcc that
emits .note.GNU-stack, that is without silently producing RW PT_GNU_STACK libc that
might crash at runtime, this patch forces executable stack for all build objects if
configured to run against minimum kernel version less than 4.8.

The gcc side of the patch can be found at [5]. It allows gcc to emit .note.GNU-stack
by default on hard-float mips targets that are configured against the future release
of glibc.

Best regards,



2019-08-20  Dragan Mladjenovic  <>

	* sysdeps/mips/Makefile (CFLAGS-.o*, ASFLAGS-.o*): New rules.
	Apply -Wa,-execstack if mips-force-execstack == yes.
	* sysdeps/mips/configure: Regenerated.
	* sysdeps/mips/ (mips-force-execstack): New var.
	Set to yes for minimum_kernel < 4.8.0, hard-float, Linux builds.
	(mips-has-gnustack): New var.
	Use value of libc_cv_as_noexecstack if mips-force-execstack != yes,
	otherwise set to no.
	* sysdeps/unix/sysv/linux/mips/Makefile (test-xfail-check-execstack):
	Move under mips-has-gnustack != yes.
 sysdeps/mips/Makefile                 | 12 ++++++++++++
 sysdeps/mips/             | 28 ++++++++++++++++++++++++++++
 sysdeps/unix/sysv/linux/mips/Makefile |  9 ++++-----
 3 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/sysdeps/mips/Makefile b/sysdeps/mips/Makefile
index 7ac6fa5..6a9ba90 100644
--- a/sysdeps/mips/Makefile
+++ b/sysdeps/mips/Makefile
@@ -82,3 +82,15 @@ $(objpfx)tst-mode-switch-2: $(shared-thread-library)
+ifeq ($(mips-force-execstack),yes)
+CFLAGS-.o += -Wa,-execstack
+CFLAGS-.os += -Wa,-execstack
+CFLAGS-.op += -Wa,-execstack
+CFLAGS-.oS += -Wa,-execstack
+ASFLAGS-.o += -Wa,-execstack
+ASFLAGS-.os += -Wa,-execstack
+ASFLAGS-.op += -Wa,-execstack
+ASFLAGS-.oS += -Wa,-execstack
diff --git a/sysdeps/mips/ b/sysdeps/mips/
index bcbdaff..f0f89ae 100644
--- a/sysdeps/mips/
+++ b/sysdeps/mips/
@@ -13,3 +13,31 @@ yes
 if test x$libc_cv_mips_nan2008 = xyes; then
+# Moved here to allow linux configure fragment to set minimum_kernel
+# beforehand.
+AC_CACHE_CHECK([checking whether the compiler must use executable stack],
+				libc_cv_mips_force_execstack, [dnl
+case $os in linux*)
+  if test x"$libc_mips_float" = xhard -a -n "$minimum_kernel"; then
+     changequote(,)
+     min_version=$((`echo "$minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \* 65536 + \2 \* 256 + \3/'`))
+     changequote([,])
+     if test $min_version -lt 264192; then
+       libc_cv_mips_force_execstack=yes
+     fi
+  fi
+  ;;
+if test $libc_cv_mips_force_execstack = yes; then
+  libc_mips_has_gnustack=no
+  AC_MSG_WARN([forcing executable stack for pre-4.8.0 Linux kernels])
diff --git a/sysdeps/unix/sysv/linux/mips/Makefile b/sysdeps/unix/sysv/linux/mips/Makefile
index 8217f42..e9206fa 100644
--- a/sysdeps/unix/sysv/linux/mips/Makefile
+++ b/sysdeps/unix/sysv/linux/mips/Makefile
@@ -63,13 +63,12 @@ sysdep-dl-routines += dl-static
 sysdep_routines += dl-vdso
-# Supporting non-executable stacks on MIPS requires changes to both
-# the Linux kernel and glibc.  See
-# <> and
-# <>.
+# If the compiler doesn't use GNU.stack note,
+# this test is expected to fail.
+ifneq ($(mips-has-gnustack),yes)
 test-xfail-check-execstack = yes
 ifeq ($(subdir),stdlib)
 gen-as-const-headers += ucontext_i.sym

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]