All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Add __enable_execute_stack() if required
@ 2008-09-16 19:42 Christian Franke
  2008-09-17 13:58 ` Robert Millan
  0 siblings, 1 reply; 5+ messages in thread
From: Christian Franke @ 2008-09-16 19:42 UTC (permalink / raw)
  To: grub-devel

[-- 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
+

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add __enable_execute_stack() if required
  2008-09-16 19:42 [PATCH] Add __enable_execute_stack() if required Christian Franke
@ 2008-09-17 13:58 ` Robert Millan
  2008-09-17 19:06   ` Christian Franke
  2008-09-18  0:01   ` walt
  0 siblings, 2 replies; 5+ messages in thread
From: Robert Millan @ 2008-09-17 13:58 UTC (permalink / raw)
  To: The development of GRUB 2

On Tue, Sep 16, 2008 at 09:42:50PM +0200, Christian Franke wrote:
> 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?

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add __enable_execute_stack() if required
  2008-09-17 13:58 ` Robert Millan
@ 2008-09-17 19:06   ` Christian Franke
  2008-09-18  0:01   ` walt
  1 sibling, 0 replies; 5+ messages in thread
From: Christian Franke @ 2008-09-17 19:06 UTC (permalink / raw)
  To: The development of GRUB 2

Robert Millan wrote:
> On Tue, Sep 16, 2008 at 09:42:50PM +0200, Christian Franke wrote:
>   
>> 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?
>
>   

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




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add __enable_execute_stack() if required
  2008-09-17 13:58 ` Robert Millan
  2008-09-17 19:06   ` Christian Franke
@ 2008-09-18  0:01   ` walt
  2008-09-19  7:05     ` Christian Franke
  1 sibling, 1 reply; 5+ messages in thread
From: walt @ 2008-09-18  0:01 UTC (permalink / raw)
  To: grub-devel

Robert Millan wrote:
> On Tue, Sep 16, 2008 at 09:42:50PM +0200, Christian Franke wrote:
>> 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?

It does fix the problem on NetBSD, thanks Christian.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add __enable_execute_stack() if required
  2008-09-18  0:01   ` walt
@ 2008-09-19  7:05     ` Christian Franke
  0 siblings, 0 replies; 5+ messages in thread
From: Christian Franke @ 2008-09-19  7:05 UTC (permalink / raw)
  To: The development of GRUB 2

walt wrote:
> Robert Millan wrote:
>> On Tue, Sep 16, 2008 at 09:42:50PM +0200, Christian Franke wrote:
>>> 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?
>
> 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




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-09-19  7:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-16 19:42 [PATCH] Add __enable_execute_stack() if required Christian Franke
2008-09-17 13:58 ` Robert Millan
2008-09-17 19:06   ` Christian Franke
2008-09-18  0:01   ` walt
2008-09-19  7:05     ` Christian Franke

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.