Skip to contentSkip to conversation

Add __enable_execute_stack() if required

PATCH In review Christian Franke 3 participants 5 messages Sep 16, 2008 – Sep 19, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add __enable_execute_stack() if required

Some gcc versions generate a call to __enable_execute_stack() in trampolines for nested functions. This is the case for new Cygwin gcc-4.3.2.

Other GRUB2 target platforms may be affected - the following files in 'gcc-4.3.2/gcc/config' source directory contains implementations of this function for libgcc:

alpha/osf.h
darwin.h
netbsd.h
openbsd.h
sol2.h
sparc/freebsd.h

This patch adds a dummy version of this function if necessary.

Christian

2008-09-16 Christian Franke <[email protected]>

* aclocal.m4 (grub_CHECK_ENABLE_EXECUTE_STACK): New function.
* configure.ac: Call grub_CHECK_ENABLE_EXECUTE_STACK.
* include/grub/misc.h [NEED_ENABLE_EXECUTE_STACK]:
Export __enable_execute_stack() to modules.
* kern/misc.c [NEED_ENABLE_EXECUTE_STACK] (__enable_execute_stack):
New function.

aclocal.m4 +27 -0
index ee6c4db..7be8d3b 100644
@@ -379,6 +379,33 @@ dnl So use regparm 2 until a better test is found.
 	[Catch gcc bug])
 fi
 ])
+
+dnl Check if the C compiler generates calls to `__enable_execute_stack()'.
+AC_DEFUN(grub_CHECK_ENABLE_EXECUTE_STACK,[
+AC_MSG_CHECKING([whether `$CC' generates calls to `__enable_execute_stack()'])
+AC_LANG_CONFTEST([[
+void f (int (*p) (void));
+void g (int i)
+{
+  int nestedfunc (void) { return i; }
+  f (nestedfunc);
+}
+]])
+if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then
+  true
+else
+  AC_MSG_ERROR([${CC-cc} failed to produce assembly code])
+fi
+if grep __enable_execute_stack conftest.s >/dev/null 2>&1; then
+  AC_DEFINE([NEED_ENABLE_EXECUTE_STACK], 1,
+	    [Define to 1 if GCC generates calls to __enable_execute_stack()])
+  AC_MSG_RESULT([yes])
+else
+  AC_MSG_RESULT([no])
+fi
+rm -f conftest*
+])
+
 
 dnl Check if the C compiler supports `-fstack-protector'.
 AC_DEFUN(grub_CHECK_STACK_PROTECTOR,[
configure.ac +3 -0
index c367454..2b0d146 100644
@@ -305,6 +305,9 @@ fi
 # Compiler features.
 #
 
+# Need __enable_execute_stack() for nested function trampolines?
+grub_CHECK_ENABLE_EXECUTE_STACK
+
 # Smashing stack protector.
 grub_CHECK_STACK_PROTECTOR
 # Need that, because some distributions ship compilers that include
include/grub/misc.h +4 -0
index 3d89a60..15c18f5 100644
@@ -82,6 +82,10 @@ grub_ssize_t EXPORT_FUNC(grub_utf8_to_ucs4) (grub_uint32_t *dest,
 grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n,
 					  grub_uint32_t d, grub_uint32_t *r);
 
+#ifdef NEED_ENABLE_EXECUTE_STACK
+void EXPORT_FUNC(__enable_execute_stack) (void *addr);
+#endif
+
 /* Inline functions.  */
 
 static inline unsigned int
kern/misc.c +9 -0
index bec6ebd..635eb72 100644
@@ -1036,3 +1036,12 @@ grub_abort (void)
 }
 /* GCC emits references to abort().  */
 void abort (void) __attribute__ ((alias ("grub_abort")));
+
+#ifdef NEED_ENABLE_EXECUTE_STACK
+/* Some gcc versions generate a call to this function
+   in trampolines for nested functions.  */
+__enable_execute_stack (void *addr __attribute__ ((unused)))
+{
+}
+#endif
+
#1 lore raw
Quoted 10 lines · Christian Franke

Some gcc versions generate a call to __enable_execute_stack() in trampolines for nested functions. This is the case for new Cygwin gcc-4.3.2.

Other GRUB2 target platforms may be affected - the following files in 'gcc-4.3.2/gcc/config' source directory contains implementations of this function for libgcc:

alpha/osf.h
darwin.h
netbsd.h

I recall this was also an issue for NetBSD indeed. Could someone confirm it fixes the problem there?

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#2 lore raw
Quoted 6 lines · Robert Millan
Quoted 4 lines · Christian Franke

Some gcc versions generate a call to __enable_execute_stack() in trampolines for nested functions. This is the case for new Cygwin gcc-4.3.2.

Other GRUB2 target platforms may be affected - the following files in 'gcc-4.3.2/gcc/config' source directory contains implementations of this function for libgcc:

Quoted 9 lines
Quoted 4 lines

alpha/osf.h
darwin.h
netbsd.h

I recall this was also an issue for NetBSD indeed. Could someone confirm it fixes the problem there?

There was also a related discussion for Mac OS X here:
http://lists.gnu.org/archive/html/grub-devel/2005-12/msg00044.html

If there are no complaints, I will commit the patch on friday.

Christian

#3 lore raw
In reply to Robert Millan
Quoted 8 lines · Robert Millan
Quoted 7 lines · Christian Franke

Some gcc versions generate a call to __enable_execute_stack() in trampolines for nested functions. This is the case for new Cygwin gcc-4.3.2.

Other GRUB2 target platforms may be affected - the following files in 'gcc-4.3.2/gcc/config' source directory contains implementations of this function for libgcc:

Quoted 6 lines
Quoted 3 lines

alpha/osf.h
darwin.h
netbsd.h

I recall this was also an issue for NetBSD indeed. Could someone confirm it fixes the problem there?

It does fix the problem on NetBSD, thanks Christian.

#4 lore raw
Quoted 9 lines · walt
Quoted 8 lines · Robert Millan
Quoted 7 lines · Christian Franke

Some gcc versions generate a call to __enable_execute_stack() in trampolines for nested functions. This is the case for new Cygwin gcc-4.3.2.

Other GRUB2 target platforms may be affected - the following files in 'gcc-4.3.2/gcc/config' source directory contains implementations of this function for libgcc:

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

alpha/osf.h
darwin.h
netbsd.h

I recall this was also an issue for NetBSD indeed. Could someone confirm it fixes the problem there?

It does fix the problem on NetBSD, thanks Christian.

You're welcome. Thanks for testing.

Patch committed.

If more such functions are necessary in the future, it is probably better to collect those in some libgcc.a replacement module. This would be the case if e.g. for the 64-bit integer division. On 32-bit architectures, gcc typically generates a call to __divdi3().

Christian