patches/binutils/2.19/140-pt-pax-flags-20081101.patch
author Arnaud Lacombe <lacombar@gmail.com>
Tue Aug 03 06:17:51 2010 +0200 (2010-08-03)
changeset 2064 f5ebe8c429dc
permissions -rw-r--r--
libc/uClibc: add uClibc 0.9.30.3

This version has been released a couple of month ago, but it never reached
crosstool-ng tree. This may be linked to the fact that the current 0.9.30.2,
once patched, has nothing much different from 0.9.30.3, released.

I'm not including any patch with this upgrade, on purpose.

Signed-off-by: Arnaud Lacombe <lacombar@gmail.com>
     1 Original patch from Gentoo:
     2 gentoo/src/patchsets/binutils/2.19/63_all_binutils-2.19-pt-pax-flags-20081101.patch
     3 
     4 diff -durN binutils-2.19.orig/bfd/elf-bfd.h binutils-2.19/bfd/elf-bfd.h
     5 --- binutils-2.19.orig/bfd/elf-bfd.h	2008-08-21 01:28:58.000000000 +0200
     6 +++ binutils-2.19/bfd/elf-bfd.h	2008-11-23 16:31:09.000000000 +0100
     7 @@ -1526,6 +1526,9 @@
     8    /* Segment flags for the PT_GNU_STACK segment.  */
     9    unsigned int stack_flags;
    10  
    11 +  /* Segment flags for the PT_PAX_FLAGS segment.  */
    12 +  unsigned int pax_flags;
    13 +
    14    /* Symbol version definitions in external objects.  */
    15    Elf_Internal_Verdef *verdef;
    16  
    17 diff -durN binutils-2.19.orig/bfd/elf.c binutils-2.19/bfd/elf.c
    18 --- binutils-2.19.orig/bfd/elf.c	2008-10-09 14:18:23.000000000 +0200
    19 +++ binutils-2.19/bfd/elf.c	2008-11-23 16:31:09.000000000 +0100
    20 @@ -1136,6 +1136,7 @@
    21      case PT_GNU_EH_FRAME: pt = "EH_FRAME"; break;
    22      case PT_GNU_STACK: pt = "STACK"; break;
    23      case PT_GNU_RELRO: pt = "RELRO"; break;
    24 +    case PT_PAX_FLAGS: pt = "PAX_FLAGS"; break;
    25      default: pt = NULL; break;
    26      }
    27    return pt;
    28 @@ -2442,6 +2443,9 @@
    29      case PT_GNU_RELRO:
    30        return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "relro");
    31  
    32 +    case PT_PAX_FLAGS:
    33 +      return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "pax_flags");
    34 +
    35      default:
    36        /* Check for any processor-specific program segment types.  */
    37        bed = get_elf_backend_data (abfd);
    38 @@ -3404,6 +3408,11 @@
    39        ++segs;
    40      }
    41  
    42 +    {
    43 +      /* We need a PT_PAX_FLAGS segment.  */
    44 +      ++segs;
    45 +    }
    46 +
    47    for (s = abfd->sections; s != NULL; s = s->next)
    48      {
    49        if ((s->flags & SEC_LOAD) != 0
    50 @@ -3983,6 +3992,20 @@
    51  	    }
    52  	}
    53  
    54 +    {
    55 +      amt = sizeof (struct elf_segment_map);
    56 +      m = bfd_zalloc (abfd, amt);
    57 +      if (m == NULL)
    58 +	goto error_return;
    59 +      m->next = NULL;
    60 +      m->p_type = PT_PAX_FLAGS;
    61 +      m->p_flags = elf_tdata (abfd)->pax_flags;
    62 +      m->p_flags_valid = 1;
    63 +
    64 +      *pm = m;
    65 +      pm = &m->next;
    66 +    }
    67 +
    68        free (sections);
    69        elf_tdata (abfd)->segment_map = mfirst;
    70      }
    71 @@ -5173,7 +5196,8 @@
    72         6. PT_TLS segment includes only SHF_TLS sections.
    73         7. SHF_TLS sections are only in PT_TLS or PT_LOAD segments.
    74         8. PT_DYNAMIC should not contain empty sections at the beginning
    75 -	  (with the possible exception of .dynamic).  */
    76 +	  (with the possible exception of .dynamic).
    77 +       9. PT_PAX_FLAGS segments does not include any sections.  */
    78  #define IS_SECTION_IN_INPUT_SEGMENT(section, segment, bed)		\
    79    ((((segment->p_paddr							\
    80        ? IS_CONTAINED_BY_LMA (section, segment, segment->p_paddr)	\
    81 @@ -5181,6 +5205,7 @@
    82       && (section->flags & SEC_ALLOC) != 0)				\
    83      || IS_NOTE (segment, section))					\
    84     && segment->p_type != PT_GNU_STACK					\
    85 +   && segment->p_type != PT_PAX_FLAGS					\
    86     && (segment->p_type != PT_TLS					\
    87         || (section->flags & SEC_THREAD_LOCAL))				\
    88     && (segment->p_type == PT_LOAD					\
    89 diff -durN binutils-2.19.orig/bfd/elflink.c binutils-2.19/bfd/elflink.c
    90 --- binutils-2.19.orig/bfd/elflink.c	2008-08-22 10:32:39.000000000 +0200
    91 +++ binutils-2.19/bfd/elflink.c	2008-11-23 16:31:09.000000000 +0100
    92 @@ -5397,16 +5397,30 @@
    93      return TRUE;
    94  
    95    bed = get_elf_backend_data (output_bfd);
    96 +  elf_tdata (output_bfd)->pax_flags = PF_NORANDEXEC;
    97 +
    98 +  if (info->execheap)
    99 +    elf_tdata (output_bfd)->pax_flags |= PF_NOMPROTECT;
   100 +  else if (info->noexecheap)
   101 +    elf_tdata (output_bfd)->pax_flags |= PF_MPROTECT;
   102 +
   103    if (info->execstack)
   104 -    elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
   105 +    {
   106 +      elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
   107 +      elf_tdata (output_bfd)->pax_flags |= PF_EMUTRAMP;
   108 +    }
   109    else if (info->noexecstack)
   110 -    elf_tdata (output_bfd)->stack_flags = PF_R | PF_W;
   111 +    {
   112 +      elf_tdata (output_bfd)->stack_flags = PF_R | PF_W;
   113 +      elf_tdata (output_bfd)->pax_flags |= PF_NOEMUTRAMP;
   114 +    }
   115    else
   116      {
   117        bfd *inputobj;
   118        asection *notesec = NULL;
   119        int exec = 0;
   120  
   121 +      elf_tdata (output_bfd)->pax_flags |= PF_NOEMUTRAMP;
   122        for (inputobj = info->input_bfds;
   123  	   inputobj;
   124  	   inputobj = inputobj->link_next)
   125 @@ -5419,7 +5433,11 @@
   126  	  if (s)
   127  	    {
   128  	      if (s->flags & SEC_CODE)
   129 -		exec = PF_X;
   130 +		{
   131 +		  elf_tdata (output_bfd)->pax_flags &= ~PF_NOEMUTRAMP;
   132 +		  elf_tdata (output_bfd)->pax_flags |= PF_EMUTRAMP;
   133 +		  exec = PF_X;
   134 +		}
   135  	      notesec = s;
   136  	    }
   137  	  else if (bed->default_execstack)
   138 diff -durN binutils-2.19.orig/binutils/readelf.c binutils-2.19/binutils/readelf.c
   139 --- binutils-2.19.orig/binutils/readelf.c	2008-09-17 11:00:44.000000000 +0200
   140 +++ binutils-2.19/binutils/readelf.c	2008-11-23 16:31:09.000000000 +0100
   141 @@ -2505,6 +2505,7 @@
   142  			return "GNU_EH_FRAME";
   143      case PT_GNU_STACK:	return "GNU_STACK";
   144      case PT_GNU_RELRO:  return "GNU_RELRO";
   145 +    case PT_PAX_FLAGS:  return "PAX_FLAGS";
   146  
   147      default:
   148        if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
   149 diff -durN binutils-2.19.orig/include/bfdlink.h binutils-2.19/include/bfdlink.h
   150 --- binutils-2.19.orig/include/bfdlink.h	2008-08-17 05:12:50.000000000 +0200
   151 +++ binutils-2.19/include/bfdlink.h	2008-11-23 16:31:09.000000000 +0100
   152 @@ -319,6 +319,14 @@
   153    /* TRUE if PT_GNU_RELRO segment should be created.  */
   154    unsigned int relro: 1;
   155  
   156 +  /* TRUE if PT_PAX_FLAGS segment should be created with PF_NOMPROTECT
   157 +     flags.  */
   158 +  unsigned int execheap: 1;
   159 +
   160 +  /* TRUE if PT_PAX_FLAGS segment should be created with PF_MPROTECT
   161 +     flags.  */
   162 +  unsigned int noexecheap: 1;
   163 +
   164    /* TRUE if we should warn when adding a DT_TEXTREL to a shared object.  */
   165    unsigned int warn_shared_textrel: 1;
   166  
   167 diff -durN binutils-2.19.orig/include/elf/common.h binutils-2.19/include/elf/common.h
   168 --- binutils-2.19.orig/include/elf/common.h	2008-08-04 01:20:42.000000000 +0200
   169 +++ binutils-2.19/include/elf/common.h	2008-11-23 16:31:09.000000000 +0100
   170 @@ -360,6 +360,7 @@
   171  #define PT_SUNW_EH_FRAME PT_GNU_EH_FRAME      /* Solaris uses the same value */
   172  #define PT_GNU_STACK	(PT_LOOS + 0x474e551) /* Stack flags */
   173  #define PT_GNU_RELRO	(PT_LOOS + 0x474e552) /* Read-only after relocation */
   174 +#define PT_PAX_FLAGS	(PT_LOOS + 0x5041580) /* PaX flags */
   175  
   176  /* Program segment permissions, in program header p_flags field.  */
   177  
   178 @@ -370,6 +371,21 @@
   179  #define PF_MASKOS	0x0FF00000	/* New value, Oct 4, 1999 Draft */
   180  #define PF_MASKPROC	0xF0000000	/* Processor-specific reserved bits */
   181  
   182 +/* Flags to control PaX behavior.  */
   183 +
   184 +#define PF_PAGEEXEC	(1 << 4)	/* Enable  PAGEEXEC */
   185 +#define PF_NOPAGEEXEC	(1 << 5)	/* Disable PAGEEXEC */
   186 +#define PF_SEGMEXEC	(1 << 6)	/* Enable  SEGMEXEC */
   187 +#define PF_NOSEGMEXEC	(1 << 7)	/* Disable SEGMEXEC */
   188 +#define PF_MPROTECT	(1 << 8)	/* Enable  MPROTECT */
   189 +#define PF_NOMPROTECT	(1 << 9)	/* Disable MPROTECT */
   190 +#define PF_RANDEXEC	(1 << 10)	/* Enable  RANDEXEC */
   191 +#define PF_NORANDEXEC	(1 << 11)	/* Disable RANDEXEC */
   192 +#define PF_EMUTRAMP	(1 << 12)	/* Enable  EMUTRAMP */
   193 +#define PF_NOEMUTRAMP	(1 << 13)	/* Disable EMUTRAMP */
   194 +#define PF_RANDMMAP	(1 << 14)	/* Enable  RANDMMAP */
   195 +#define PF_NORANDMMAP	(1 << 15)	/* Disable RANDMMAP */
   196 +
   197  /* Values for section header, sh_type field.  */
   198  
   199  #define SHT_NULL	0		/* Section header table entry unused */
   200 diff -durN binutils-2.19.orig/ld/emultempl/elf32.em binutils-2.19/ld/emultempl/elf32.em
   201 --- binutils-2.19.orig/ld/emultempl/elf32.em	2008-11-23 16:30:36.000000000 +0100
   202 +++ binutils-2.19/ld/emultempl/elf32.em	2008-11-23 16:31:09.000000000 +0100
   203 @@ -2146,6 +2146,16 @@
   204  	  link_info.noexecstack = TRUE;
   205  	  link_info.execstack = FALSE;
   206  	}
   207 +      else if (strcmp (optarg, "execheap") == 0)
   208 +	{
   209 +	  link_info.execheap = TRUE;
   210 +	  link_info.noexecheap = FALSE;
   211 +	}
   212 +      else if (strcmp (optarg, "noexecheap") == 0)
   213 +	{
   214 +	  link_info.noexecheap = TRUE;
   215 +	  link_info.execheap = FALSE;
   216 +	}
   217  EOF
   218  
   219    if test -n "$COMMONPAGESIZE"; then
   220 @@ -2229,6 +2239,8 @@
   221    fprintf (file, _("\
   222    -z execstack                Mark executable as requiring executable stack\n"));
   223    fprintf (file, _("\
   224 +  -z execheap\t\tMark executable as requiring executable heap\n"));
   225 +  fprintf (file, _("\
   226    -z initfirst                Mark DSO to be initialized first at runtime\n"));
   227    fprintf (file, _("\
   228    -z interpose                Mark object to interpose all DSOs but executable\n"));
   229 @@ -2252,6 +2264,8 @@
   230    -z nodump                   Mark DSO not available to dldump\n"));
   231    fprintf (file, _("\
   232    -z noexecstack              Mark executable as not requiring executable stack\n"));
   233 +  fprintf (file, _("\
   234 +  -z noexecheap\tMark executable as not requiring executable heap\n"));
   235  EOF
   236  
   237    if test -n "$COMMONPAGESIZE"; then
   238 diff -durN binutils-2.19.orig/ld/ldgram.y binutils-2.19/ld/ldgram.y
   239 --- binutils-2.19.orig/ld/ldgram.y	2008-07-06 15:38:36.000000000 +0200
   240 +++ binutils-2.19/ld/ldgram.y	2008-11-23 16:31:09.000000000 +0100
   241 @@ -1112,6 +1112,8 @@
   242  			    $$ = exp_intop (0x6474e550);
   243  			  else if (strcmp (s, "PT_GNU_STACK") == 0)
   244  			    $$ = exp_intop (0x6474e551);
   245 +			  else if (strcmp (s, "PT_PAX_FLAGS") == 0)
   246 +			    $$ = exp_intop (0x65041580);
   247  			  else
   248  			    {
   249  			      einfo (_("\