All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Franke <Christian.Franke@t-online.de>
To: grub-devel@gnu.org
Subject: [PATCH] Add __enable_execute_stack() if required
Date: Tue, 16 Sep 2008 21:42:50 +0200	[thread overview]
Message-ID: <48D00C3A.9000804@t-online.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 804 bytes --]

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  <franke@computer.org>

	* 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.



[-- Attachment #2: grub2-enable-execute-stack.patch --]
[-- Type: text/x-diff, Size: 2392 bytes --]

diff --git a/aclocal.m4 b/aclocal.m4
index ee6c4db..7be8d3b 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -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*
+])
+
 \f
 dnl Check if the C compiler supports `-fstack-protector'.
 AC_DEFUN(grub_CHECK_STACK_PROTECTOR,[
diff --git a/configure.ac b/configure.ac
index c367454..2b0d146 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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
diff --git a/include/grub/misc.h b/include/grub/misc.h
index 3d89a60..15c18f5 100644
--- a/include/grub/misc.h
+++ b/include/grub/misc.h
@@ -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
diff --git a/kern/misc.c b/kern/misc.c
index bec6ebd..635eb72 100644
--- a/kern/misc.c
+++ b/kern/misc.c
@@ -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
+

             reply	other threads:[~2008-09-16 19:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-16 19:42 Christian Franke [this message]
2008-09-17 13:58 ` [PATCH] Add __enable_execute_stack() if required Robert Millan
2008-09-17 19:06   ` Christian Franke
2008-09-18  0:01   ` walt
2008-09-19  7:05     ` Christian Franke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48D00C3A.9000804@t-online.de \
    --to=christian.franke@t-online.de \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.