patches/glibc/2.9/380-2.3.6-dl_execstack-PaX-support.patch
author "Benoît Thébaudeau" <benoit.thebaudeau@advansee.com>
Fri Jan 27 13:31:16 2012 +0100 (2012-01-27)
changeset 2854 a70abdbfa342
parent 1201 c9967a6e3b25
permissions -rw-r--r--
complibs/cloog: fix linking with libm

In Ubuntu 11.04 and 11.10, the default options for ld have changed.
--no-copy-dt-needed-entries and --as-needed are now enabled by default, which
causes errors like:

[EXTRA] Checking CLooG/ppl
[DEBUG] ==> Executing: 'make' '-j3' '-s' 'check'
[ALL ] Making check in .
[ALL ] config.status: creating include/cloog/cloog-config.h
[ALL ] config.status: include/cloog/cloog-config.h is unchanged
[ALL ] libtool: link: i686-build_pc-linux-gnu-gcc -Wall -fomit-frame-pointer
-pipe -o cloog cloog.o -L/<snip>/build/static/lib ./.libs/libcloog.a -lm
/<snip>/build/static/lib/libppl_c.a /<snip>/build/static/lib/libpwl.a
/<snip>/build/static/lib/libppl.a /<snip>/build/static/lib/libgmpxx.a
/<snip>/build/static/lib/libgmp.a -lstdc++
[ALL ] /usr/bin/ld: /<snip>/build/static/lib/libppl.a(MIP_Problem.o):
undefined reference to symbol 'sqrt@@GLIBC_2.0'
[ALL ] /usr/bin/ld: note: 'sqrt@@GLIBC_2.0' is defined in DSO
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/libm.so so try adding
it to the linker command line
[ALL ] /usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/libm.so:
could not read symbols: Invalid operation
[ALL ] collect2: ld returned 1 exit status
[ERROR] make[2]: *** [cloog] Error 1
[ERROR] make[1]: *** [check-recursive] Error 1

See:
https://wiki.ubuntu.com/NattyNarwhal/ToolchainTransition

This patch fixes these errors by placing '-lm' at the right place on the command
line as libppl requires libm when linking cloog.

Signed-off-by: "Benoît Thébaudeau" <benoit.thebaudeau@advansee.com>
     1 Original patch from: gentoo/src/patchsets/glibc/2.9/3000_all_2.3.6-dl_execstack-PaX-support.patch
     2 
     3 -= BEGIN original header =-
     4 	With latest versions of glibc, a lot of apps failed on a PaX enabled
     5 	system with:
     6 		 cannot enable executable stack as shared object requires: Permission denied
     7 	
     8 	This is due to PaX 'exec-protecting' the stack, and ld.so then trying
     9 	to make the stack executable due to some libraries not containing the
    10 	PT_GNU_STACK section.  Bug #32960.  <azarah@gentoo.org> (12 Nov 2003).
    11 
    12 	Patch also NPTL. Bug #116086. <kevquinn@gentoo.org> (20 Dec 2005).
    13 
    14 -= END original header =-
    15 
    16 diff -durN glibc-2_9.orig/nptl/allocatestack.c glibc-2_9/nptl/allocatestack.c
    17 --- glibc-2_9.orig/nptl/allocatestack.c	2008-08-16 00:35:27.000000000 +0200
    18 +++ glibc-2_9/nptl/allocatestack.c	2009-02-02 22:01:20.000000000 +0100
    19 @@ -299,7 +299,8 @@
    20  # error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
    21  #endif
    22    if (mprotect (stack, len, PROT_READ | PROT_WRITE | PROT_EXEC) != 0)
    23 -    return errno;
    24 +    if (errno != EACCES) /* PAX is enabled */
    25 +    	return errno;
    26  
    27    return 0;
    28  }
    29 diff -durN glibc-2_9.orig/sysdeps/unix/sysv/linux/dl-execstack.c glibc-2_9/sysdeps/unix/sysv/linux/dl-execstack.c
    30 --- glibc-2_9.orig/sysdeps/unix/sysv/linux/dl-execstack.c	2006-01-08 09:21:15.000000000 +0100
    31 +++ glibc-2_9/sysdeps/unix/sysv/linux/dl-execstack.c	2009-02-02 22:01:20.000000000 +0100
    32 @@ -63,7 +63,10 @@
    33        else
    34  # endif
    35  	{
    36 -	  result = errno;
    37 +	  if (errno == EACCES)  /* PAX is enabled */
    38 +	    result = 0;
    39 +	  else
    40 +	    result = errno;
    41  	  goto out;
    42  	}
    43      }
    44 @@ -89,7 +92,12 @@
    45  	page -= size;
    46        else
    47  	{
    48 -	  if (errno != ENOMEM)	/* Unexpected failure mode.  */
    49 +	  if (errno == EACCES)		/* PAX is enabled */
    50 +	    {
    51 +	      result = 0;
    52 +	      goto out;
    53 +	    }
    54 +	  else if (errno != ENOMEM)	/* Unexpected failure mode.  */
    55  	    {
    56  	      result = errno;
    57  	      goto out;
    58 @@ -115,7 +123,12 @@
    59  	page += size;
    60        else
    61  	{
    62 -	  if (errno != ENOMEM)	/* Unexpected failure mode.  */
    63 +	  if (errno == EACCES)		/* PAX is enabled */
    64 +	    {
    65 +	      result = 0;
    66 +	      goto out;
    67 +	    }
    68 +	  else if (errno != ENOMEM)	/* Unexpected failure mode.  */
    69  	    {
    70  	      result = errno;
    71  	      goto out;