binutils/binutils: forward-port the patchset from 2.20 to 2.20.1
author"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Aug 17 19:48:49 2010 +0200 (2010-08-17)
changeset 20884f21ba5f8e91
parent 2087 fefd9a3f8180
child 2089 eddb1bbc7b30
binutils/binutils: forward-port the patchset from 2.20 to 2.20.1

Among other things, this should fix the issue reported by Thomas at:
http://sourceware.org/ml/crossgcc/2010-08/msg00115.html

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
patches/binutils/2.20.1/100-ppc64-pie.patch
patches/binutils/2.20.1/110-RPATH_ENVVAR-smack.patch
patches/binutils/2.20.1/120-sh-targets.patch
patches/binutils/2.20.1/130-ld-sysroot.patch
patches/binutils/2.20.1/140-check_ldrunpath_length.patch
patches/binutils/2.20.1/150-pt-pax-flags-20090909.patch
patches/binutils/2.20.1/160-amd64-32bit-path.patch
patches/binutils/2.20.1/170-warn-textrel.patch
patches/binutils/2.20.1/190-use-new-ld-dtags.patch
patches/binutils/2.20.1/200-document-new-dtags-behaviour.patch
patches/binutils/2.20.1/210-generate-gnu-hash.patch
patches/binutils/2.20.1/220-use-relro.patch
patches/binutils/2.20.1/230-libiberty-pic.patch
patches/binutils/2.20.1/240-ld_makefile.patch
patches/binutils/2.20.1/250-arm-eabi-conf.patch
patches/binutils/2.20.1/270-better_file_error.patch
patches/binutils/2.20.1/280-unexport_LD_LIBRARY_PATH.patch
patches/binutils/2.20.1/290-ld-stub-crash.patch
patches/binutils/2.20.1/300-mips64-defaultemul.patch
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/patches/binutils/2.20.1/100-ppc64-pie.patch	Tue Aug 17 19:48:49 2010 +0200
     1.3 @@ -0,0 +1,19 @@
     1.4 +
     1.5 +
     1.6 +diff -durN binutils-2.20.1.orig/bfd/elf64-ppc.c binutils-2.20.1/bfd/elf64-ppc.c
     1.7 +--- binutils-2.20.1.orig/bfd/elf64-ppc.c	2010-02-03 14:28:25.000000000 +0100
     1.8 ++++ binutils-2.20.1/bfd/elf64-ppc.c	2010-08-17 19:32:04.000000000 +0200
     1.9 +@@ -11991,7 +11991,12 @@
    1.10 + 	      else if (!SYMBOL_REFERENCES_LOCAL (info, &h->elf)
    1.11 + 		       && !is_opd
    1.12 + 		       && r_type != R_PPC64_TOC)
    1.13 +-		outrel.r_info = ELF64_R_INFO (h->elf.dynindx, r_type);
    1.14 ++		{
    1.15 ++		  outrel.r_info = ELF64_R_INFO (h->elf.dynindx, r_type);
    1.16 ++		  if (h->elf.dynindx == -1
    1.17 ++		      && h->elf.root.type == bfd_link_hash_undefweak)
    1.18 ++		  memset (&outrel, 0, sizeof outrel);
    1.19 ++		}
    1.20 + 	      else
    1.21 + 		{
    1.22 + 		  /* This symbol is local, or marked to become local,
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/patches/binutils/2.20.1/110-RPATH_ENVVAR-smack.patch	Tue Aug 17 19:48:49 2010 +0200
     2.3 @@ -0,0 +1,14 @@
     2.4 +http://sourceware.org/ml/binutils/2007-07/msg00401.html
     2.5 +http://sourceware.org/bugzilla/show_bug.cgi?id=4970
     2.6 +
     2.7 +diff -durN binutils-2.20.1.orig/configure binutils-2.20.1/configure
     2.8 +--- binutils-2.20.1.orig/configure	2010-03-03 14:59:02.000000000 +0100
     2.9 ++++ binutils-2.20.1/configure	2010-08-17 19:32:05.000000000 +0200
    2.10 +@@ -6466,6 +6466,7 @@
    2.11 +   *-*-mingw* | *-*-cygwin ) RPATH_ENVVAR=PATH ;;
    2.12 +   *) RPATH_ENVVAR=LD_LIBRARY_PATH ;;
    2.13 + esac
    2.14 ++RPATH_ENVVAR="cant_touch_this_nah_nah_nah"
    2.15 + 
    2.16 + # On systems where the dynamic library environment variable is PATH,
    2.17 + # gcc/ will put dynamic libraries into a subdirectory to avoid adding
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/patches/binutils/2.20.1/120-sh-targets.patch	Tue Aug 17 19:48:49 2010 +0200
     3.3 @@ -0,0 +1,44 @@
     3.4 +
     3.5 +
     3.6 +diff -durN binutils-2.20.1.orig/configure binutils-2.20.1/configure
     3.7 +--- binutils-2.20.1.orig/configure	2010-08-17 19:32:05.000000000 +0200
     3.8 ++++ binutils-2.20.1/configure	2010-08-17 19:32:07.000000000 +0200
     3.9 +@@ -3054,7 +3054,7 @@
    3.10 +   am33_2.0-*-linux*)
    3.11 +     noconfigdirs="$noconfigdirs ${libgcj} target-newlib target-libgloss"
    3.12 +     ;;
    3.13 +-  sh-*-linux*)
    3.14 ++  sh*-*-linux*)
    3.15 +     noconfigdirs="$noconfigdirs ${libgcj} target-newlib target-libgloss"
    3.16 +     ;;
    3.17 +   sh*-*-pe|mips*-*-pe|*arm-wince-pe)
    3.18 +@@ -3390,7 +3390,7 @@
    3.19 +   romp-*-*)
    3.20 +     noconfigdirs="$noconfigdirs bfd binutils ld gas opcodes target-libgloss ${libgcj}"
    3.21 +     ;;
    3.22 +-  sh-*-* | sh64-*-*)
    3.23 ++  sh*-*-* | sh64-*-*)
    3.24 +     case "${host}" in
    3.25 +       i[3456789]86-*-vsta) ;; # don't add gprof back in
    3.26 +       i[3456789]86-*-go32*) ;; # don't add gprof back in
    3.27 +diff -durN binutils-2.20.1.orig/configure.ac binutils-2.20.1/configure.ac
    3.28 +--- binutils-2.20.1.orig/configure.ac	2010-03-03 15:19:08.000000000 +0100
    3.29 ++++ binutils-2.20.1/configure.ac	2010-08-17 19:32:07.000000000 +0200
    3.30 +@@ -541,7 +541,7 @@
    3.31 +   am33_2.0-*-linux*)
    3.32 +     noconfigdirs="$noconfigdirs ${libgcj} target-newlib target-libgloss"
    3.33 +     ;;
    3.34 +-  sh-*-linux*)
    3.35 ++  sh*-*-linux*)
    3.36 +     noconfigdirs="$noconfigdirs ${libgcj} target-newlib target-libgloss"
    3.37 +     ;;    
    3.38 +   sh*-*-pe|mips*-*-pe|*arm-wince-pe)
    3.39 +@@ -877,7 +877,7 @@
    3.40 +   romp-*-*)
    3.41 +     noconfigdirs="$noconfigdirs bfd binutils ld gas opcodes target-libgloss ${libgcj}"
    3.42 +     ;;
    3.43 +-  sh-*-* | sh64-*-*)
    3.44 ++  sh*-*-* | sh64-*-*)
    3.45 +     case "${host}" in
    3.46 +       i[[3456789]]86-*-vsta) ;; # don't add gprof back in
    3.47 +       i[[3456789]]86-*-go32*) ;; # don't add gprof back in
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/patches/binutils/2.20.1/130-ld-sysroot.patch	Tue Aug 17 19:48:49 2010 +0200
     4.3 @@ -0,0 +1,37 @@
     4.4 +Signed-off-by: Sven Rebhan <odinshorse@googlemail.com>
     4.5 +
     4.6 +Always try to prepend the sysroot prefix to absolute filenames first.
     4.7 +
     4.8 +http://bugs.gentoo.org/275666
     4.9 +http://sourceware.org/bugzilla/show_bug.cgi?id=10340
    4.10 +
    4.11 +diff -durN binutils-2.20.1.orig/ld/ldfile.c binutils-2.20.1/ld/ldfile.c
    4.12 +--- binutils-2.20.1.orig/ld/ldfile.c	2009-08-30 00:11:01.000000000 +0200
    4.13 ++++ binutils-2.20.1/ld/ldfile.c	2010-08-17 19:32:08.000000000 +0200
    4.14 +@@ -308,18 +308,24 @@
    4.15 +      directory first.  */
    4.16 +   if (! entry->is_archive)
    4.17 +     {
    4.18 +-      if (entry->sysrooted && IS_ABSOLUTE_PATH (entry->filename))
    4.19 ++      /* For absolute pathnames, try to always open the file in the
    4.20 ++	 sysroot first. If this fails, try to open the file at the
    4.21 ++	 given location. */
    4.22 ++      entry->sysrooted = is_sysrooted_pathname(entry->filename, FALSE);
    4.23 ++      if (IS_ABSOLUTE_PATH (entry->filename) && ld_sysroot && ! entry->sysrooted)
    4.24 + 	{
    4.25 + 	  char *name = concat (ld_sysroot, entry->filename,
    4.26 + 			       (const char *) NULL);
    4.27 + 	  if (ldfile_try_open_bfd (name, entry))
    4.28 + 	    {
    4.29 + 	      entry->filename = name;
    4.30 ++	      entry->sysrooted = TRUE;
    4.31 + 	      return TRUE;
    4.32 + 	    }
    4.33 + 	  free (name);
    4.34 + 	}
    4.35 +-      else if (ldfile_try_open_bfd (entry->filename, entry))
    4.36 ++
    4.37 ++      if (ldfile_try_open_bfd (entry->filename, entry))
    4.38 + 	{
    4.39 + 	  entry->sysrooted = IS_ABSOLUTE_PATH (entry->filename)
    4.40 + 	    && is_sysrooted_pathname (entry->filename, TRUE);
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/patches/binutils/2.20.1/140-check_ldrunpath_length.patch	Tue Aug 17 19:48:49 2010 +0200
     5.3 @@ -0,0 +1,49 @@
     5.4 +#!/bin/sh -e
     5.5 +## 012_check_ldrunpath_length.dpatch by Chris Chimelis <chris@debian.org>
     5.6 +##
     5.7 +## All lines beginning with `## DP:' are a description of the patch.
     5.8 +## DP: Only generate an RPATH entry if LD_RUN_PATH is not empty, for
     5.9 +## DP: cases where -rpath isn't specified. (#151024)
    5.10 +
    5.11 +if [ $# -ne 1 ]; then
    5.12 +    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    5.13 +    exit 1
    5.14 +fi
    5.15 +
    5.16 +[ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts
    5.17 +patch_opts="${patch_opts:--f --no-backup-if-mismatch}"
    5.18 +
    5.19 +case "$1" in
    5.20 +       -patch) patch $patch_opts -p1 < $0;;
    5.21 +       -unpatch) patch $patch_opts -p1 -R < $0;;
    5.22 +        *)
    5.23 +                echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    5.24 +                exit 1;;
    5.25 +esac
    5.26 +
    5.27 +exit 0
    5.28 +
    5.29 +@DPATCH@
    5.30 +diff -urNad /home/james/debian/packages/binutils/new/binutils-2.15/ld/emultempl/elf32.em binutils-2.15/ld/emultempl/elf32.em
    5.31 +
    5.32 +diff -durN binutils-2.20.1.orig/ld/emultempl/elf32.em binutils-2.20.1/ld/emultempl/elf32.em
    5.33 +--- binutils-2.20.1.orig/ld/emultempl/elf32.em	2009-09-14 13:43:30.000000000 +0200
    5.34 ++++ binutils-2.20.1/ld/emultempl/elf32.em	2010-08-17 19:32:09.000000000 +0200
    5.35 +@@ -1233,6 +1233,8 @@
    5.36 + 	      && command_line.rpath == NULL)
    5.37 + 	    {
    5.38 + 	      lib_path = (const char *) getenv ("LD_RUN_PATH");
    5.39 ++	      if ((lib_path) && (strlen (lib_path) == 0))
    5.40 ++		  lib_path = NULL;
    5.41 + 	      if (gld${EMULATION_NAME}_search_needed (lib_path, &n,
    5.42 + 						      force))
    5.43 + 		break;
    5.44 +@@ -1418,6 +1420,8 @@
    5.45 +   rpath = command_line.rpath;
    5.46 +   if (rpath == NULL)
    5.47 +     rpath = (const char *) getenv ("LD_RUN_PATH");
    5.48 ++  if ((rpath) && (strlen (rpath) == 0))
    5.49 ++      rpath = NULL;
    5.50 +   if (! (bfd_elf_size_dynamic_sections
    5.51 + 	 (link_info.output_bfd, command_line.soname, rpath,
    5.52 + 	  command_line.filter_shlib,
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/patches/binutils/2.20.1/150-pt-pax-flags-20090909.patch	Tue Aug 17 19:48:49 2010 +0200
     6.3 @@ -0,0 +1,248 @@
     6.4 +
     6.5 +
     6.6 +diff -durN binutils-2.20.1.orig/bfd/elf-bfd.h binutils-2.20.1/bfd/elf-bfd.h
     6.7 +--- binutils-2.20.1.orig/bfd/elf-bfd.h	2009-09-10 13:47:12.000000000 +0200
     6.8 ++++ binutils-2.20.1/bfd/elf-bfd.h	2010-08-17 19:32:11.000000000 +0200
     6.9 +@@ -1531,6 +1531,9 @@
    6.10 +   /* Segment flags for the PT_GNU_STACK segment.  */
    6.11 +   unsigned int stack_flags;
    6.12 + 
    6.13 ++  /* Segment flags for the PT_PAX_FLAGS segment.  */
    6.14 ++  unsigned int pax_flags;
    6.15 ++
    6.16 +   /* Symbol version definitions in external objects.  */
    6.17 +   Elf_Internal_Verdef *verdef;
    6.18 + 
    6.19 +diff -durN binutils-2.20.1.orig/bfd/elf.c binutils-2.20.1/bfd/elf.c
    6.20 +--- binutils-2.20.1.orig/bfd/elf.c	2009-09-10 13:47:12.000000000 +0200
    6.21 ++++ binutils-2.20.1/bfd/elf.c	2010-08-17 19:32:11.000000000 +0200
    6.22 +@@ -1083,6 +1083,7 @@
    6.23 +     case PT_GNU_EH_FRAME: pt = "EH_FRAME"; break;
    6.24 +     case PT_GNU_STACK: pt = "STACK"; break;
    6.25 +     case PT_GNU_RELRO: pt = "RELRO"; break;
    6.26 ++    case PT_PAX_FLAGS: pt = "PAX_FLAGS"; break;
    6.27 +     default: pt = NULL; break;
    6.28 +     }
    6.29 +   return pt;
    6.30 +@@ -2396,6 +2397,9 @@
    6.31 +     case PT_GNU_RELRO:
    6.32 +       return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "relro");
    6.33 + 
    6.34 ++    case PT_PAX_FLAGS:
    6.35 ++      return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "pax_flags");
    6.36 ++
    6.37 +     default:
    6.38 +       /* Check for any processor-specific program segment types.  */
    6.39 +       bed = get_elf_backend_data (abfd);
    6.40 +@@ -3413,6 +3417,11 @@
    6.41 +       ++segs;
    6.42 +     }
    6.43 + 
    6.44 ++    {
    6.45 ++      /* We need a PT_PAX_FLAGS segment.  */
    6.46 ++      ++segs;
    6.47 ++    }
    6.48 ++
    6.49 +   for (s = abfd->sections; s != NULL; s = s->next)
    6.50 +     {
    6.51 +       if ((s->flags & SEC_LOAD) != 0
    6.52 +@@ -3994,6 +4003,20 @@
    6.53 + 	    }
    6.54 + 	}
    6.55 + 
    6.56 ++    {
    6.57 ++      amt = sizeof (struct elf_segment_map);
    6.58 ++      m = bfd_zalloc (abfd, amt);
    6.59 ++      if (m == NULL)
    6.60 ++	goto error_return;
    6.61 ++      m->next = NULL;
    6.62 ++      m->p_type = PT_PAX_FLAGS;
    6.63 ++      m->p_flags = elf_tdata (abfd)->pax_flags;
    6.64 ++      m->p_flags_valid = 1;
    6.65 ++
    6.66 ++      *pm = m;
    6.67 ++      pm = &m->next;
    6.68 ++    }
    6.69 ++
    6.70 +       free (sections);
    6.71 +       elf_tdata (abfd)->segment_map = mfirst;
    6.72 +     }
    6.73 +@@ -5198,7 +5221,8 @@
    6.74 +        6. PT_TLS segment includes only SHF_TLS sections.
    6.75 +        7. SHF_TLS sections are only in PT_TLS or PT_LOAD segments.
    6.76 +        8. PT_DYNAMIC should not contain empty sections at the beginning
    6.77 +-	  (with the possible exception of .dynamic).  */
    6.78 ++	  (with the possible exception of .dynamic).
    6.79 ++       9. PT_PAX_FLAGS segments do not include any sections.  */
    6.80 + #define IS_SECTION_IN_INPUT_SEGMENT(section, segment, bed)		\
    6.81 +   ((((segment->p_paddr							\
    6.82 +       ? IS_CONTAINED_BY_LMA (section, segment, segment->p_paddr)	\
    6.83 +@@ -5206,6 +5230,7 @@
    6.84 +      && (section->flags & SEC_ALLOC) != 0)				\
    6.85 +     || IS_NOTE (segment, section))					\
    6.86 +    && segment->p_type != PT_GNU_STACK					\
    6.87 ++   && segment->p_type != PT_PAX_FLAGS					\
    6.88 +    && (segment->p_type != PT_TLS					\
    6.89 +        || (section->flags & SEC_THREAD_LOCAL))				\
    6.90 +    && (segment->p_type == PT_LOAD					\
    6.91 +diff -durN binutils-2.20.1.orig/bfd/elflink.c binutils-2.20.1/bfd/elflink.c
    6.92 +--- binutils-2.20.1.orig/bfd/elflink.c	2009-09-10 13:47:12.000000000 +0200
    6.93 ++++ binutils-2.20.1/bfd/elflink.c	2010-08-17 19:32:11.000000000 +0200
    6.94 +@@ -5469,16 +5469,30 @@
    6.95 +     return TRUE;
    6.96 + 
    6.97 +   bed = get_elf_backend_data (output_bfd);
    6.98 ++
    6.99 ++  elf_tdata (output_bfd)->pax_flags = PF_NORANDEXEC;
   6.100 ++  if (info->execheap)
   6.101 ++    elf_tdata (output_bfd)->pax_flags |= PF_NOMPROTECT;
   6.102 ++  else if (info->noexecheap)
   6.103 ++    elf_tdata (output_bfd)->pax_flags |= PF_MPROTECT;
   6.104 ++
   6.105 +   if (info->execstack)
   6.106 +-    elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
   6.107 ++    {
   6.108 ++      elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
   6.109 ++      elf_tdata (output_bfd)->pax_flags |= PF_EMUTRAMP;
   6.110 ++    }
   6.111 +   else if (info->noexecstack)
   6.112 +-    elf_tdata (output_bfd)->stack_flags = PF_R | PF_W;
   6.113 ++    {
   6.114 ++      elf_tdata (output_bfd)->stack_flags = PF_R | PF_W;
   6.115 ++      elf_tdata (output_bfd)->pax_flags |= PF_NOEMUTRAMP;
   6.116 ++    }
   6.117 +   else
   6.118 +     {
   6.119 +       bfd *inputobj;
   6.120 +       asection *notesec = NULL;
   6.121 +       int exec = 0;
   6.122 + 
   6.123 ++      elf_tdata (output_bfd)->pax_flags |= PF_NOEMUTRAMP;
   6.124 +       for (inputobj = info->input_bfds;
   6.125 + 	   inputobj;
   6.126 + 	   inputobj = inputobj->link_next)
   6.127 +@@ -5491,7 +5505,11 @@
   6.128 + 	  if (s)
   6.129 + 	    {
   6.130 + 	      if (s->flags & SEC_CODE)
   6.131 +-		exec = PF_X;
   6.132 ++		{
   6.133 ++		  elf_tdata (output_bfd)->pax_flags &= ~PF_NOEMUTRAMP;
   6.134 ++		  elf_tdata (output_bfd)->pax_flags |= PF_EMUTRAMP;
   6.135 ++		  exec = PF_X;
   6.136 ++		}
   6.137 + 	      notesec = s;
   6.138 + 	    }
   6.139 + 	  else if (bed->default_execstack)
   6.140 +diff -durN binutils-2.20.1.orig/binutils/readelf.c binutils-2.20.1/binutils/readelf.c
   6.141 +--- binutils-2.20.1.orig/binutils/readelf.c	2010-01-14 11:48:23.000000000 +0100
   6.142 ++++ binutils-2.20.1/binutils/readelf.c	2010-08-17 19:32:11.000000000 +0200
   6.143 +@@ -2569,6 +2569,7 @@
   6.144 + 			return "GNU_EH_FRAME";
   6.145 +     case PT_GNU_STACK:	return "GNU_STACK";
   6.146 +     case PT_GNU_RELRO:  return "GNU_RELRO";
   6.147 ++    case PT_PAX_FLAGS:  return "PAX_FLAGS";
   6.148 + 
   6.149 +     default:
   6.150 +       if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
   6.151 +diff -durN binutils-2.20.1.orig/include/bfdlink.h binutils-2.20.1/include/bfdlink.h
   6.152 +--- binutils-2.20.1.orig/include/bfdlink.h	2009-09-10 13:47:30.000000000 +0200
   6.153 ++++ binutils-2.20.1/include/bfdlink.h	2010-08-17 19:32:11.000000000 +0200
   6.154 +@@ -321,6 +321,14 @@
   6.155 +   /* TRUE if PT_GNU_RELRO segment should be created.  */
   6.156 +   unsigned int relro: 1;
   6.157 + 
   6.158 ++  /* TRUE if PT_PAX_FLAGS segment should be created with PF_NOMPROTECT
   6.159 ++     flags.  */
   6.160 ++  unsigned int execheap: 1;
   6.161 ++
   6.162 ++  /* TRUE if PT_PAX_FLAGS segment should be created with PF_MPROTECT
   6.163 ++     flags.  */
   6.164 ++  unsigned int noexecheap: 1;
   6.165 ++
   6.166 +   /* TRUE if we should warn when adding a DT_TEXTREL to a shared object.  */
   6.167 +   unsigned int warn_shared_textrel: 1;
   6.168 + 
   6.169 +diff -durN binutils-2.20.1.orig/include/elf/common.h binutils-2.20.1/include/elf/common.h
   6.170 +--- binutils-2.20.1.orig/include/elf/common.h	2009-08-09 15:42:26.000000000 +0200
   6.171 ++++ binutils-2.20.1/include/elf/common.h	2010-08-17 19:32:11.000000000 +0200
   6.172 +@@ -422,6 +422,7 @@
   6.173 + #define PT_SUNW_EH_FRAME PT_GNU_EH_FRAME      /* Solaris uses the same value */
   6.174 + #define PT_GNU_STACK	(PT_LOOS + 0x474e551) /* Stack flags */
   6.175 + #define PT_GNU_RELRO	(PT_LOOS + 0x474e552) /* Read-only after relocation */
   6.176 ++#define PT_PAX_FLAGS	(PT_LOOS + 0x5041580) /* PaX flags */
   6.177 + 
   6.178 + /* Program segment permissions, in program header p_flags field.  */
   6.179 + 
   6.180 +@@ -432,6 +433,21 @@
   6.181 + #define PF_MASKOS	0x0FF00000	/* New value, Oct 4, 1999 Draft */
   6.182 + #define PF_MASKPROC	0xF0000000	/* Processor-specific reserved bits */
   6.183 + 
   6.184 ++/* Flags to control PaX behavior.  */
   6.185 ++
   6.186 ++#define PF_PAGEEXEC	(1 << 4)	/* Enable  PAGEEXEC */
   6.187 ++#define PF_NOPAGEEXEC	(1 << 5)	/* Disable PAGEEXEC */
   6.188 ++#define PF_SEGMEXEC	(1 << 6)	/* Enable  SEGMEXEC */
   6.189 ++#define PF_NOSEGMEXEC	(1 << 7)	/* Disable SEGMEXEC */
   6.190 ++#define PF_MPROTECT	(1 << 8)	/* Enable  MPROTECT */
   6.191 ++#define PF_NOMPROTECT	(1 << 9)	/* Disable MPROTECT */
   6.192 ++#define PF_RANDEXEC	(1 << 10)	/* Enable  RANDEXEC */
   6.193 ++#define PF_NORANDEXEC	(1 << 11)	/* Disable RANDEXEC */
   6.194 ++#define PF_EMUTRAMP	(1 << 12)	/* Enable  EMUTRAMP */
   6.195 ++#define PF_NOEMUTRAMP	(1 << 13)	/* Disable EMUTRAMP */
   6.196 ++#define PF_RANDMMAP	(1 << 14)	/* Enable  RANDMMAP */
   6.197 ++#define PF_NORANDMMAP	(1 << 15)	/* Disable RANDMMAP */
   6.198 ++
   6.199 + /* Values for section header, sh_type field.  */
   6.200 + 
   6.201 + #define SHT_NULL	0		/* Section header table entry unused */
   6.202 +diff -durN binutils-2.20.1.orig/ld/emultempl/elf32.em binutils-2.20.1/ld/emultempl/elf32.em
   6.203 +--- binutils-2.20.1.orig/ld/emultempl/elf32.em	2010-08-17 19:32:09.000000000 +0200
   6.204 ++++ binutils-2.20.1/ld/emultempl/elf32.em	2010-08-17 19:32:11.000000000 +0200
   6.205 +@@ -2165,6 +2165,16 @@
   6.206 + 	  link_info.noexecstack = TRUE;
   6.207 + 	  link_info.execstack = FALSE;
   6.208 + 	}
   6.209 ++      else if (strcmp (optarg, "execheap") == 0)
   6.210 ++	{
   6.211 ++	  link_info.execheap = TRUE;
   6.212 ++	  link_info.noexecheap = FALSE;
   6.213 ++	}
   6.214 ++      else if (strcmp (optarg, "noexecheap") == 0)
   6.215 ++	{
   6.216 ++	  link_info.noexecheap = TRUE;
   6.217 ++	  link_info.execheap = FALSE;
   6.218 ++	}
   6.219 + EOF
   6.220 + 
   6.221 +   if test -n "$COMMONPAGESIZE"; then
   6.222 +@@ -2243,6 +2253,8 @@
   6.223 +   fprintf (file, _("\
   6.224 +   -z execstack                Mark executable as requiring executable stack\n"));
   6.225 +   fprintf (file, _("\
   6.226 ++  -z execheap                 Mark executable as requiring executable heap\n"));
   6.227 ++  fprintf (file, _("\
   6.228 +   -z initfirst                Mark DSO to be initialized first at runtime\n"));
   6.229 +   fprintf (file, _("\
   6.230 +   -z interpose                Mark object to interpose all DSOs but executable\n"));
   6.231 +@@ -2266,6 +2278,8 @@
   6.232 +   -z nodump                   Mark DSO not available to dldump\n"));
   6.233 +   fprintf (file, _("\
   6.234 +   -z noexecstack              Mark executable as not requiring executable stack\n"));
   6.235 ++  fprintf (file, _("\
   6.236 ++  -z noexecheap               Mark executable as not requiring executable heap\n"));
   6.237 + EOF
   6.238 + 
   6.239 +   if test -n "$COMMONPAGESIZE"; then
   6.240 +diff -durN binutils-2.20.1.orig/ld/ldgram.y binutils-2.20.1/ld/ldgram.y
   6.241 +--- binutils-2.20.1.orig/ld/ldgram.y	2009-09-02 09:25:35.000000000 +0200
   6.242 ++++ binutils-2.20.1/ld/ldgram.y	2010-08-17 19:32:11.000000000 +0200
   6.243 +@@ -1116,6 +1116,8 @@
   6.244 + 			    $$ = exp_intop (0x6474e550);
   6.245 + 			  else if (strcmp (s, "PT_GNU_STACK") == 0)
   6.246 + 			    $$ = exp_intop (0x6474e551);
   6.247 ++			  else if (strcmp (s, "PT_PAX_FLAGS") == 0)
   6.248 ++			    $$ = exp_intop (0x65041580);
   6.249 + 			  else
   6.250 + 			    {
   6.251 + 			      einfo (_("\
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/patches/binutils/2.20.1/160-amd64-32bit-path.patch	Tue Aug 17 19:48:49 2010 +0200
     7.3 @@ -0,0 +1,19 @@
     7.4 +
     7.5 +
     7.6 +diff -durN binutils-2.20.1.orig/ld/emulparams/elf_i386.sh binutils-2.20.1/ld/emulparams/elf_i386.sh
     7.7 +--- binutils-2.20.1.orig/ld/emulparams/elf_i386.sh	2009-07-29 16:59:23.000000000 +0200
     7.8 ++++ binutils-2.20.1/ld/emulparams/elf_i386.sh	2010-08-17 19:32:12.000000000 +0200
     7.9 +@@ -13,3 +13,13 @@
    7.10 + NO_SMALL_DATA=yes
    7.11 + SEPARATE_GOTPLT=12
    7.12 + IREL_IN_PLT=
    7.13 ++
    7.14 ++# In Gentoo, we install 32bit libs into /lib32 in an
    7.15 ++# ABI setup with amd64/x86
    7.16 ++case "$target" in
    7.17 ++  x86_64*-linux*)
    7.18 ++    case "$EMULATION_NAME" in
    7.19 ++      *i386*) LIBPATH_SUFFIX=32  ;;
    7.20 ++    esac
    7.21 ++  ;;
    7.22 ++esac
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/patches/binutils/2.20.1/170-warn-textrel.patch	Tue Aug 17 19:48:49 2010 +0200
     8.3 @@ -0,0 +1,66 @@
     8.4 +textrels are bad for forcing copy-on-write (this affects everyone),
     8.5 +and for security/runtime code generation, this affects security ppl.
     8.6 +But in either case, it doesn't matter who needs textrels, it's
     8.7 +the very fact that they're needed at all.
     8.8 +
     8.9 +2006-06-10  Ned Ludd  <solar@gentoo.org>, Mike Frysinger <vapier@gentoo.org>
    8.10 +
    8.11 +	* bfd/elflink.c (bfd_elf_final_link): Check all objects for TEXTRELs.
    8.12 +	* ld/ldmain.c (main): Change textrel warning default to true.
    8.13 +	* ld/testsuite/lib/ld-lib.exp (default_ld_simple_link): Scrub TEXTREL
    8.14 +	warnings from ld output.
    8.15 +
    8.16 +diff -durN binutils-2.20.1.orig/bfd/elflink.c binutils-2.20.1/bfd/elflink.c
    8.17 +--- binutils-2.20.1.orig/bfd/elflink.c	2010-08-17 19:32:11.000000000 +0200
    8.18 ++++ binutils-2.20.1/bfd/elflink.c	2010-08-17 19:32:13.000000000 +0200
    8.19 +@@ -10988,14 +10988,12 @@
    8.20 + 	goto error_return;
    8.21 + 
    8.22 +       /* Check for DT_TEXTREL (late, in case the backend removes it).  */
    8.23 +-      if (info->warn_shared_textrel && info->shared)
    8.24 ++      o = bfd_get_section_by_name (dynobj, ".dynamic");
    8.25 ++      if (info->warn_shared_textrel && o != NULL)
    8.26 + 	{
    8.27 + 	  bfd_byte *dyncon, *dynconend;
    8.28 + 
    8.29 + 	  /* Fix up .dynamic entries.  */
    8.30 +-	  o = bfd_get_section_by_name (dynobj, ".dynamic");
    8.31 +-	  BFD_ASSERT (o != NULL);
    8.32 +-
    8.33 + 	  dyncon = o->contents;
    8.34 + 	  dynconend = o->contents + o->size;
    8.35 + 	  for (; dyncon < dynconend; dyncon += bed->s->sizeof_dyn)
    8.36 +@@ -11007,7 +11005,7 @@
    8.37 + 	      if (dyn.d_tag == DT_TEXTREL)
    8.38 + 		{
    8.39 + 		 info->callbacks->einfo
    8.40 +-		    (_("%P: warning: creating a DT_TEXTREL in a shared object.\n"));
    8.41 ++		    (_("%P: warning: creating a DT_TEXTREL in object.\n"));
    8.42 + 		  break;
    8.43 + 		}
    8.44 + 	    }
    8.45 +diff -durN binutils-2.20.1.orig/ld/ldmain.c binutils-2.20.1/ld/ldmain.c
    8.46 +--- binutils-2.20.1.orig/ld/ldmain.c	2009-09-14 13:43:29.000000000 +0200
    8.47 ++++ binutils-2.20.1/ld/ldmain.c	2010-08-17 19:32:13.000000000 +0200
    8.48 +@@ -280,6 +280,7 @@
    8.49 +   emulation = get_emulation (argc, argv);
    8.50 +   ldemul_choose_mode (emulation);
    8.51 +   default_target = ldemul_choose_target (argc, argv);
    8.52 ++  link_info.warn_shared_textrel = TRUE;
    8.53 +   config.maxpagesize = bfd_emul_get_maxpagesize (default_target);
    8.54 +   config.commonpagesize = bfd_emul_get_commonpagesize (default_target);
    8.55 +   lang_init ();
    8.56 +diff -durN binutils-2.20.1.orig/ld/testsuite/lib/ld-lib.exp binutils-2.20.1/ld/testsuite/lib/ld-lib.exp
    8.57 +--- binutils-2.20.1.orig/ld/testsuite/lib/ld-lib.exp	2009-10-02 12:51:13.000000000 +0200
    8.58 ++++ binutils-2.20.1/ld/testsuite/lib/ld-lib.exp	2010-08-17 19:32:13.000000000 +0200
    8.59 +@@ -196,6 +196,10 @@
    8.60 +     # symbol, since the default linker script might use ENTRY.
    8.61 +     regsub -all "(^|\n)(\[^\n\]*: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
    8.62 + 
    8.63 ++    # Gentoo tweak:
    8.64 ++    # We want to ignore TEXTREL warnings since we force enable them by default
    8.65 ++    regsub -all "^lt-ld-new: warning: creating a DT_TEXTREL in object\." $exec_output "\\1" exec_output
    8.66 ++
    8.67 +     if [string match "" $exec_output] then {
    8.68 + 	return 1
    8.69 +     } else {
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/patches/binutils/2.20.1/190-use-new-ld-dtags.patch	Tue Aug 17 19:48:49 2010 +0200
     9.3 @@ -0,0 +1,13 @@
     9.4 +
     9.5 +
     9.6 +diff -durN binutils-2.20.1.orig/ld/ldmain.c binutils-2.20.1/ld/ldmain.c
     9.7 +--- binutils-2.20.1.orig/ld/ldmain.c	2010-08-17 19:32:13.000000000 +0200
     9.8 ++++ binutils-2.20.1/ld/ldmain.c	2010-08-17 19:32:15.000000000 +0200
     9.9 +@@ -262,6 +262,7 @@
    9.10 + 
    9.11 +   link_info.allow_undefined_version = TRUE;
    9.12 +   link_info.keep_memory = TRUE;
    9.13 ++  link_info.new_dtags = TRUE;
    9.14 +   link_info.combreloc = TRUE;
    9.15 +   link_info.strip_discarded = TRUE;
    9.16 +   link_info.emit_hash = TRUE;
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/patches/binutils/2.20.1/200-document-new-dtags-behaviour.patch	Tue Aug 17 19:48:49 2010 +0200
    10.3 @@ -0,0 +1,18 @@
    10.4 +Index: binutils-2.19.51.0.5/ld/ld.texinfo
    10.5 +===================================================================
    10.6 +
    10.7 +diff -durN binutils-2.20.1.orig/ld/ld.texinfo binutils-2.20.1/ld/ld.texinfo
    10.8 +--- binutils-2.20.1.orig/ld/ld.texinfo	2009-07-06 15:48:51.000000000 +0200
    10.9 ++++ binutils-2.20.1/ld/ld.texinfo	2010-08-17 19:32:16.000000000 +0200
   10.10 +@@ -2026,8 +2026,9 @@
   10.11 + systems may not understand them. If you specify
   10.12 + @option{--enable-new-dtags}, the dynamic tags will be created as needed.
   10.13 + If you specify @option{--disable-new-dtags}, no new dynamic tags will be
   10.14 +-created. By default, the new dynamic tags are not created. Note that
   10.15 +-those options are only available for ELF systems.
   10.16 ++created. On Gentoo, by default, the new dynamic tags are created (this
   10.17 ++differs from upstream behaviour). Note that those options are only
   10.18 ++available for ELF systems.
   10.19 + 
   10.20 + @kindex --hash-size=@var{number}
   10.21 + @item --hash-size=@var{number}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/patches/binutils/2.20.1/210-generate-gnu-hash.patch	Tue Aug 17 19:48:49 2010 +0200
    11.3 @@ -0,0 +1,15 @@
    11.4 +
    11.5 +
    11.6 +diff -durN binutils-2.20.1.orig/ld/ldmain.c binutils-2.20.1/ld/ldmain.c
    11.7 +--- binutils-2.20.1.orig/ld/ldmain.c	2010-08-17 19:32:15.000000000 +0200
    11.8 ++++ binutils-2.20.1/ld/ldmain.c	2010-08-17 19:32:17.000000000 +0200
    11.9 +@@ -266,6 +266,9 @@
   11.10 +   link_info.combreloc = TRUE;
   11.11 +   link_info.strip_discarded = TRUE;
   11.12 +   link_info.emit_hash = TRUE;
   11.13 ++#ifndef __mips__
   11.14 ++  link_info.emit_gnu_hash = TRUE;
   11.15 ++#endif
   11.16 +   link_info.callbacks = &link_callbacks;
   11.17 +   link_info.input_bfds_tail = &link_info.input_bfds;
   11.18 +   /* SVR4 linkers seem to set DT_INIT and DT_FINI based on magic _init
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/patches/binutils/2.20.1/220-use-relro.patch	Tue Aug 17 19:48:49 2010 +0200
    12.3 @@ -0,0 +1,13 @@
    12.4 +
    12.5 +
    12.6 +diff -durN binutils-2.20.1.orig/ld/ldmain.c binutils-2.20.1/ld/ldmain.c
    12.7 +--- binutils-2.20.1.orig/ld/ldmain.c	2010-08-17 19:32:17.000000000 +0200
    12.8 ++++ binutils-2.20.1/ld/ldmain.c	2010-08-17 19:32:18.000000000 +0200
    12.9 +@@ -264,6 +264,7 @@
   12.10 +   link_info.keep_memory = TRUE;
   12.11 +   link_info.new_dtags = TRUE;
   12.12 +   link_info.combreloc = TRUE;
   12.13 ++  link_info.relro = TRUE;
   12.14 +   link_info.strip_discarded = TRUE;
   12.15 +   link_info.emit_hash = TRUE;
   12.16 + #ifndef __mips__
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/patches/binutils/2.20.1/230-libiberty-pic.patch	Tue Aug 17 19:48:49 2010 +0200
    13.3 @@ -0,0 +1,13 @@
    13.4 +
    13.5 +
    13.6 +diff -durN binutils-2.20.1.orig/libiberty/Makefile.in binutils-2.20.1/libiberty/Makefile.in
    13.7 +--- binutils-2.20.1.orig/libiberty/Makefile.in	2009-08-23 21:03:58.000000000 +0200
    13.8 ++++ binutils-2.20.1/libiberty/Makefile.in	2010-08-17 19:32:19.000000000 +0200
    13.9 +@@ -227,6 +227,7 @@
   13.10 + 	  $(AR) $(AR_FLAGS) $(TARGETLIB) \
   13.11 + 	    $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS); \
   13.12 + 	  $(RANLIB) $(TARGETLIB); \
   13.13 ++	  cp $(TARGETLIB) ../ ; \
   13.14 + 	  cd ..; \
   13.15 + 	else true; fi
   13.16 + 
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/patches/binutils/2.20.1/240-ld_makefile.patch	Tue Aug 17 19:48:49 2010 +0200
    14.3 @@ -0,0 +1,27 @@
    14.4 +Description: correct where ld scripts are installed
    14.5 +Author: Chris Chimelis <chris@debian.org>
    14.6 +
    14.7 +diff -durN binutils-2.20.1.orig/ld/Makefile.am binutils-2.20.1/ld/Makefile.am
    14.8 +--- binutils-2.20.1.orig/ld/Makefile.am	2010-02-22 09:07:01.000000000 +0100
    14.9 ++++ binutils-2.20.1/ld/Makefile.am	2010-08-17 19:32:21.000000000 +0200
   14.10 +@@ -24,7 +24,7 @@
   14.11 + # We put the scripts in the directory $(scriptdir)/ldscripts.
   14.12 + # We can't put the scripts in $(datadir) because the SEARCH_DIR
   14.13 + # directives need to be different for native and cross linkers.
   14.14 +-scriptdir = $(tooldir)/lib
   14.15 ++scriptdir = $(libdir)
   14.16 + 
   14.17 + EMUL = @EMUL@
   14.18 + EMULATION_OFILES = @EMULATION_OFILES@
   14.19 +diff -durN binutils-2.20.1.orig/ld/Makefile.in binutils-2.20.1/ld/Makefile.in
   14.20 +--- binutils-2.20.1.orig/ld/Makefile.in	2010-03-03 15:06:21.000000000 +0100
   14.21 ++++ binutils-2.20.1/ld/Makefile.in	2010-08-17 19:32:21.000000000 +0200
   14.22 +@@ -333,7 +333,7 @@
   14.23 + # We put the scripts in the directory $(scriptdir)/ldscripts.
   14.24 + # We can't put the scripts in $(datadir) because the SEARCH_DIR
   14.25 + # directives need to be different for native and cross linkers.
   14.26 +-scriptdir = $(tooldir)/lib
   14.27 ++scriptdir = $(libdir)
   14.28 + BASEDIR = $(srcdir)/..
   14.29 + BFDDIR = $(BASEDIR)/bfd
   14.30 + INCDIR = $(BASEDIR)/include
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/patches/binutils/2.20.1/250-arm-eabi-conf.patch	Tue Aug 17 19:48:49 2010 +0200
    15.3 @@ -0,0 +1,26 @@
    15.4 +diff -u binutils-2.20.orig/configure binutils-2.20/configure
    15.5 +
    15.6 +diff -durN binutils-2.20.1.orig/configure binutils-2.20.1/configure
    15.7 +--- binutils-2.20.1.orig/configure	2010-08-17 19:32:07.000000000 +0200
    15.8 ++++ binutils-2.20.1/configure	2010-08-17 19:32:22.000000000 +0200
    15.9 +@@ -3086,7 +3086,7 @@
   15.10 +     noconfigdirs="$noconfigdirs target-libffi target-qthreads"
   15.11 +     libgloss_dir=arm
   15.12 +     ;;
   15.13 +-  arm*-*-linux-gnueabi)
   15.14 ++  arm*-*-linux-*gnueabi)
   15.15 +     noconfigdirs="$noconfigdirs target-qthreads"
   15.16 +     case ${with_newlib} in
   15.17 +       no) noconfigdirs="$noconfigdirs target-newlib target-libgloss"
   15.18 +diff -durN binutils-2.20.1.orig/configure.ac binutils-2.20.1/configure.ac
   15.19 +--- binutils-2.20.1.orig/configure.ac	2010-08-17 19:32:07.000000000 +0200
   15.20 ++++ binutils-2.20.1/configure.ac	2010-08-17 19:32:22.000000000 +0200
   15.21 +@@ -573,7 +573,7 @@
   15.22 +     noconfigdirs="$noconfigdirs target-libffi target-qthreads"
   15.23 +     libgloss_dir=arm
   15.24 +     ;;
   15.25 +-  arm*-*-linux-gnueabi)
   15.26 ++  arm*-*-linux-*gnueabi)
   15.27 +     noconfigdirs="$noconfigdirs target-qthreads"
   15.28 +     case ${with_newlib} in
   15.29 +       no) noconfigdirs="$noconfigdirs target-newlib target-libgloss"
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/patches/binutils/2.20.1/270-better_file_error.patch	Tue Aug 17 19:48:49 2010 +0200
    16.3 @@ -0,0 +1,45 @@
    16.4 +#!/bin/sh -e
    16.5 +## 006_better_file_error.dpatch by David Kimdon <dwhedon@gordian.com>
    16.6 +##
    16.7 +## All lines beginning with `## DP:' are a description of the patch.
    16.8 +## DP: Specify which filename is causing an error if the filename is a
    16.9 +## DP: directory. (#45832)
   16.10 +
   16.11 +if [ $# -ne 1 ]; then
   16.12 +    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
   16.13 +    exit 1
   16.14 +fi
   16.15 +
   16.16 +[ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts
   16.17 +patch_opts="${patch_opts:--f --no-backup-if-mismatch}"
   16.18 +
   16.19 +case "$1" in
   16.20 +       -patch) patch $patch_opts -p1 < $0;;
   16.21 +       -unpatch) patch $patch_opts -p1 -R < $0;;
   16.22 +        *)
   16.23 +                echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
   16.24 +                exit 1;;
   16.25 +esac
   16.26 +
   16.27 +exit 0
   16.28 +
   16.29 +@DPATCH@
   16.30 +diff -urNad /home/james/debian/packages/binutils/binutils-2.14.90.0.6/bfd/opncls.c binutils-2.14.90.0.6/bfd/opncls.c
   16.31 +
   16.32 +diff -durN binutils-2.20.1.orig/bfd/opncls.c binutils-2.20.1/bfd/opncls.c
   16.33 +--- binutils-2.20.1.orig/bfd/opncls.c	2010-01-14 11:48:22.000000000 +0100
   16.34 ++++ binutils-2.20.1/bfd/opncls.c	2010-08-17 19:32:23.000000000 +0200
   16.35 +@@ -183,6 +183,13 @@
   16.36 + {
   16.37 +   bfd *nbfd;
   16.38 +   const bfd_target *target_vec;
   16.39 ++  struct stat s;
   16.40 ++
   16.41 ++  if (stat (filename, &s) == 0)
   16.42 ++    if (S_ISDIR(s.st_mode)) {
   16.43 ++      bfd_set_error (bfd_error_file_not_recognized);
   16.44 ++      return NULL;
   16.45 ++    }
   16.46 + 
   16.47 +   nbfd = _bfd_new_bfd ();
   16.48 +   if (nbfd == NULL)
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/patches/binutils/2.20.1/280-unexport_LD_LIBRARY_PATH.patch	Tue Aug 17 19:48:49 2010 +0200
    17.3 @@ -0,0 +1,96 @@
    17.4 +Description:
    17.5 +
    17.6 +This patch is needed in situations where build system is running same version of
    17.7 +binutils that is intended to be built  cross-native ( build != host = target)
    17.8 + and has shared libraries enabled. binutils/binutils
    17.9 +Makefile has some tools which are built to run on build system. Toplevel makefile
   17.10 +for binutils passes HOST_EXPORTS to sub-makefiles which also include RPATH_ENVVARS
   17.11 +containing LD_LIBRARY_PATH which is modified so that it also includes host libraries
   17.12 +like opcodes and libbfd which are just built for the host system. 
   17.13 +
   17.14 +Now the problem is that same LD_LIBRARY_PATH value gets set in environment even
   17.15 +for the tools that are being built for build system using CC_FOR_BUILD and the tools
   17.16 +like as,ld it invokes from build machine get the LD_LIBRARY_PATH set to search
   17.17 +the newly build host libraries like opcodes and bfd and if host is like a big endian
   17.18 +system say (mips-linux) the build system linker and assembler do not run because
   17.19 +ld.so tries to load these shared libraries instead of the ones from /usr/lib for 
   17.20 +the build tools. 
   17.21 +
   17.22 +This patch fixes the issue by clearing LD_LIBRARY_PATH for BUILD tools
   17.23 +
   17.24 +This patch would be needed on other versions of binutils. I just cared about 2.20
   17.25 +May be upstream is also interested in such a patch.
   17.26 +
   17.27 +-Khem
   17.28 +
   17.29 +Index: binutils-2.20/binutils/Makefile.am
   17.30 +===================================================================
   17.31 +
   17.32 +diff -durN binutils-2.20.1.orig/binutils/Makefile.am binutils-2.20.1/binutils/Makefile.am
   17.33 +--- binutils-2.20.1.orig/binutils/Makefile.am	2010-01-14 11:48:22.000000000 +0100
   17.34 ++++ binutils-2.20.1/binutils/Makefile.am	2010-08-17 19:32:24.000000000 +0200
   17.35 +@@ -251,24 +251,24 @@
   17.36 + 	./sysinfo$(EXEEXT_FOR_BUILD) -d <$(srcdir)/sysroff.info >sysroff.h
   17.37 + 
   17.38 + sysinfo$(EXEEXT_FOR_BUILD): sysinfo.o syslex.o
   17.39 +-	$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@ sysinfo.o syslex.o
   17.40 ++	LD_LIBRARY_PATH= $(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@ sysinfo.o syslex.o
   17.41 + 
   17.42 + syslex.o: syslex.c sysinfo.h config.h
   17.43 + 	if [ -r syslex.c ]; then \
   17.44 +-	  $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) syslex.c ; \
   17.45 ++	  LD_LIBRARY_PATH= $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) syslex.c ; \
   17.46 + 	else \
   17.47 +-	  $(CC_FOR_BUILD) -c -I. -I$(srcdir) $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) $(srcdir)/syslex.c ;\
   17.48 ++	  LD_LIBRARY_PATH= $(CC_FOR_BUILD) -c -I. -I$(srcdir) $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) $(srcdir)/syslex.c ;\
   17.49 + 	fi
   17.50 + 
   17.51 + sysinfo.o: sysinfo.c
   17.52 + 	if [ -r sysinfo.c ]; then \
   17.53 +-	  $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) sysinfo.c ; \
   17.54 ++	  LD_LIBRARY_PATH= $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) sysinfo.c ; \
   17.55 + 	else \
   17.56 +-	  $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) $(srcdir)/sysinfo.c ; \
   17.57 ++	  LD_LIBRARY_PATH= $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) $(srcdir)/sysinfo.c ; \
   17.58 + 	fi
   17.59 + 
   17.60 + bin2c$(EXEEXT_FOR_BUILD):
   17.61 +-	$(CC_FOR_BUILD) -o $@ $(AM_CPPFLAGS) $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $(srcdir)/bin2c.c $(srcdir)/version.c
   17.62 ++	LD_LIBRARY_PATH= $(CC_FOR_BUILD) -o $@ $(AM_CPPFLAGS) $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $(srcdir)/bin2c.c $(srcdir)/version.c
   17.63 + 
   17.64 + embedspu: embedspu.sh
   17.65 + 	sed "s@^program_transform_name=@program_transform_name=$(program_transform_name)@" < $< > $@
   17.66 +diff -durN binutils-2.20.1.orig/binutils/Makefile.in binutils-2.20.1/binutils/Makefile.in
   17.67 +--- binutils-2.20.1.orig/binutils/Makefile.in	2010-03-03 14:59:46.000000000 +0100
   17.68 ++++ binutils-2.20.1/binutils/Makefile.in	2010-08-17 19:32:24.000000000 +0200
   17.69 +@@ -1193,24 +1193,24 @@
   17.70 + 	./sysinfo$(EXEEXT_FOR_BUILD) -d <$(srcdir)/sysroff.info >sysroff.h
   17.71 + 
   17.72 + sysinfo$(EXEEXT_FOR_BUILD): sysinfo.o syslex.o
   17.73 +-	$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@ sysinfo.o syslex.o
   17.74 ++	LD_LIBRARY_PATH= $(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@ sysinfo.o syslex.o
   17.75 + 
   17.76 + syslex.o: syslex.c sysinfo.h config.h
   17.77 + 	if [ -r syslex.c ]; then \
   17.78 +-	  $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) syslex.c ; \
   17.79 ++	  LD_LIBRARY_PATH= $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) syslex.c ; \
   17.80 + 	else \
   17.81 +-	  $(CC_FOR_BUILD) -c -I. -I$(srcdir) $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) $(srcdir)/syslex.c ;\
   17.82 ++	  LD_LIBRARY_PATH= $(CC_FOR_BUILD) -c -I. -I$(srcdir) $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) $(srcdir)/syslex.c ;\
   17.83 + 	fi
   17.84 + 
   17.85 + sysinfo.o: sysinfo.c
   17.86 + 	if [ -r sysinfo.c ]; then \
   17.87 +-	  $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) sysinfo.c ; \
   17.88 ++	  LD_LIBRARY_PATH= $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) sysinfo.c ; \
   17.89 + 	else \
   17.90 +-	  $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) $(srcdir)/sysinfo.c ; \
   17.91 ++	  LD_LIBRARY_PATH= $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(NO_WERROR) $(srcdir)/sysinfo.c ; \
   17.92 + 	fi
   17.93 + 
   17.94 + bin2c$(EXEEXT_FOR_BUILD):
   17.95 +-	$(CC_FOR_BUILD) -o $@ $(AM_CPPFLAGS) $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $(srcdir)/bin2c.c $(srcdir)/version.c
   17.96 ++	LD_LIBRARY_PATH= $(CC_FOR_BUILD) -o $@ $(AM_CPPFLAGS) $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $(srcdir)/bin2c.c $(srcdir)/version.c
   17.97 + 
   17.98 + embedspu: embedspu.sh
   17.99 + 	sed "s@^program_transform_name=@program_transform_name=$(program_transform_name)@" < $< > $@
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/patches/binutils/2.20.1/290-ld-stub-crash.patch	Tue Aug 17 19:48:49 2010 +0200
    18.3 @@ -0,0 +1,24 @@
    18.4 +diff -p -c -u -r1.196 elf32-arm.c
    18.5 +
    18.6 +diff -durN binutils-2.20.1.orig/bfd/elf32-arm.c binutils-2.20.1/bfd/elf32-arm.c
    18.7 +--- binutils-2.20.1.orig/bfd/elf32-arm.c	2010-02-22 09:06:48.000000000 +0100
    18.8 ++++ binutils-2.20.1/bfd/elf32-arm.c	2010-08-17 19:32:25.000000000 +0200
    18.9 +@@ -3194,11 +3194,15 @@
   18.10 + 
   18.11 + 	  /* We have an extra 2-bytes reach because of
   18.12 + 	     the mode change (bit 24 (H) of BLX encoding).  */
   18.13 ++	  /* A stub is needed only if this call is not throught a PLT
   18.14 ++	     entry, because PLT stubs handle mode switching
   18.15 ++	     already.  */
   18.16 + 	  if (branch_offset > (ARM_MAX_FWD_BRANCH_OFFSET + 2)
   18.17 + 	      || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET)
   18.18 +-	      || ((r_type == R_ARM_CALL) && !globals->use_blx)
   18.19 +-	      || (r_type == R_ARM_JUMP24)
   18.20 +-	      || (r_type == R_ARM_PLT32))
   18.21 ++	      || ( (((r_type == R_ARM_CALL) && !globals->use_blx)
   18.22 ++		    || (r_type == R_ARM_JUMP24)
   18.23 ++		    || (r_type == R_ARM_PLT32))
   18.24 ++		   && !use_plt))
   18.25 + 	    {
   18.26 + 	      stub_type = (info->shared | globals->pic_veneer)
   18.27 + 		/* PIC stubs.  */
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/patches/binutils/2.20.1/300-mips64-defaultemul.patch	Tue Aug 17 19:48:49 2010 +0200
    19.3 @@ -0,0 +1,21 @@
    19.4 +
    19.5 +
    19.6 +diff -durN binutils-2.20.1.orig/ld/configure.tgt binutils-2.20.1/ld/configure.tgt
    19.7 +--- binutils-2.20.1.orig/ld/configure.tgt	2009-08-06 19:38:03.000000000 +0200
    19.8 ++++ binutils-2.20.1/ld/configure.tgt	2010-08-17 19:32:26.000000000 +0200
    19.9 +@@ -400,11 +400,11 @@
   19.10 + mips*-*-vxworks*)	targ_emul=elf32ebmipvxworks
   19.11 + 		        targ_extra_emuls="elf32elmipvxworks" ;;
   19.12 + mips*-*-windiss)	targ_emul=elf32mipswindiss ;;
   19.13 +-mips64*el-*-linux-*)	targ_emul=elf32ltsmipn32
   19.14 +-			targ_extra_emuls="elf32btsmipn32 elf32ltsmip elf32btsmip elf64ltsmip elf64btsmip"
   19.15 ++mips64*el-*-linux-*)	targ_emul=elf64ltsmip
   19.16 ++			targ_extra_emuls="elf32ltsmipn32 elf32btsmipn32 elf32ltsmip elf32btsmip elf64btsmip"
   19.17 + 			targ_extra_libpath=$targ_extra_emuls ;;
   19.18 +-mips64*-*-linux-*)	targ_emul=elf32btsmipn32
   19.19 +-			targ_extra_emuls="elf32ltsmipn32 elf32btsmip elf32ltsmip elf64btsmip elf64ltsmip"
   19.20 ++mips64*-*-linux-*)	targ_emul=elf64btsmip
   19.21 ++			targ_extra_emuls="elf32btsmipn32 elf32ltsmipn32 elf32btsmip elf32ltsmip elf64ltsmip"
   19.22 + 			targ_extra_libpath=$targ_extra_emuls ;;
   19.23 + mips*el-*-linux-*)	targ_emul=elf32ltsmip
   19.24 + 			targ_extra_emuls="elf32btsmip elf32ltsmipn32 elf64ltsmip elf32btsmipn32 elf64btsmip"