From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1KfgSB-0005ck-Cm for mharc-grub-devel@gnu.org; Tue, 16 Sep 2008 15:43:15 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KfgS9-0005be-V5 for grub-devel@gnu.org; Tue, 16 Sep 2008 15:43:13 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KfgS7-0005a0-VA for grub-devel@gnu.org; Tue, 16 Sep 2008 15:43:13 -0400 Received: from [199.232.76.173] (port=47578 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KfgS7-0005Zu-O0 for grub-devel@gnu.org; Tue, 16 Sep 2008 15:43:11 -0400 Received: from mailout01.t-online.de ([194.25.134.80]:45910) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KfgS6-0004Wg-OJ for grub-devel@gnu.org; Tue, 16 Sep 2008 15:43:11 -0400 Received: from fwd03.aul.t-online.de by mailout01.t-online.de with smtp id 1KfgS0-0001ha-02; Tue, 16 Sep 2008 21:43:04 +0200 Received: from [10.3.2.2] (V8vLRsZSYh6Yegw0q28BfKf51BZPVLRTWk8GC33xHOWPgBg0uZGfmSuiIWZpEXkwD2@[217.235.235.17]) by fwd03.aul.t-online.de with esmtp id 1KfgRp-1y0lRQ0; Tue, 16 Sep 2008 21:42:53 +0200 Message-ID: <48D00C3A.9000804@t-online.de> Date: Tue, 16 Sep 2008 21:42:50 +0200 From: Christian Franke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 SeaMonkey/1.1.11 MIME-Version: 1.0 To: grub-devel@gnu.org Content-Type: multipart/mixed; boundary="------------080606090305070102010505" X-ID: V8vLRsZSYh6Yegw0q28BfKf51BZPVLRTWk8GC33xHOWPgBg0uZGfmSuiIWZpEXkwD2 X-TOI-MSGID: f168fa22-fc92-4b05-a39b-c1974f9c4220 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [PATCH] Add __enable_execute_stack() if required X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Sep 2008 19:43:14 -0000 This is a multi-part message in MIME format. --------------080606090305070102010505 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 * 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. --------------080606090305070102010505 Content-Type: text/x-diff; name="grub2-enable-execute-stack.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="grub2-enable-execute-stack.patch" 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* +]) + 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 + --------------080606090305070102010505--