3 diff -durN binutils-2.20.1.orig/bfd/elf-bfd.h binutils-2.20.1/bfd/elf-bfd.h
4 --- binutils-2.20.1.orig/bfd/elf-bfd.h 2009-09-10 13:47:12.000000000 +0200
5 +++ binutils-2.20.1/bfd/elf-bfd.h 2010-08-17 19:32:11.000000000 +0200
7 /* Segment flags for the PT_GNU_STACK segment. */
8 unsigned int stack_flags;
10 + /* Segment flags for the PT_PAX_FLAGS segment. */
11 + unsigned int pax_flags;
13 /* Symbol version definitions in external objects. */
14 Elf_Internal_Verdef *verdef;
16 diff -durN binutils-2.20.1.orig/bfd/elf.c binutils-2.20.1/bfd/elf.c
17 --- binutils-2.20.1.orig/bfd/elf.c 2009-09-10 13:47:12.000000000 +0200
18 +++ binutils-2.20.1/bfd/elf.c 2010-08-17 19:32:11.000000000 +0200
20 case PT_GNU_EH_FRAME: pt = "EH_FRAME"; break;
21 case PT_GNU_STACK: pt = "STACK"; break;
22 case PT_GNU_RELRO: pt = "RELRO"; break;
23 + case PT_PAX_FLAGS: pt = "PAX_FLAGS"; break;
24 default: pt = NULL; break;
29 return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "relro");
32 + return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "pax_flags");
35 /* Check for any processor-specific program segment types. */
36 bed = get_elf_backend_data (abfd);
37 @@ -3413,6 +3417,11 @@
42 + /* We need a PT_PAX_FLAGS segment. */
46 for (s = abfd->sections; s != NULL; s = s->next)
48 if ((s->flags & SEC_LOAD) != 0
49 @@ -3994,6 +4003,20 @@
54 + amt = sizeof (struct elf_segment_map);
55 + m = bfd_zalloc (abfd, amt);
59 + m->p_type = PT_PAX_FLAGS;
60 + m->p_flags = elf_tdata (abfd)->pax_flags;
61 + m->p_flags_valid = 1;
68 elf_tdata (abfd)->segment_map = mfirst;
71 6. PT_TLS segment includes only SHF_TLS sections.
72 7. SHF_TLS sections are only in PT_TLS or PT_LOAD segments.
73 8. PT_DYNAMIC should not contain empty sections at the beginning
74 - (with the possible exception of .dynamic). */
75 + (with the possible exception of .dynamic).
76 + 9. PT_PAX_FLAGS segments do not include any sections. */
77 #define IS_SECTION_IN_INPUT_SEGMENT(section, segment, bed) \
78 ((((segment->p_paddr \
79 ? IS_CONTAINED_BY_LMA (section, segment, segment->p_paddr) \
81 && (section->flags & SEC_ALLOC) != 0) \
82 || IS_NOTE (segment, section)) \
83 && segment->p_type != PT_GNU_STACK \
84 + && segment->p_type != PT_PAX_FLAGS \
85 && (segment->p_type != PT_TLS \
86 || (section->flags & SEC_THREAD_LOCAL)) \
87 && (segment->p_type == PT_LOAD \
88 diff -durN binutils-2.20.1.orig/bfd/elflink.c binutils-2.20.1/bfd/elflink.c
89 --- binutils-2.20.1.orig/bfd/elflink.c 2009-09-10 13:47:12.000000000 +0200
90 +++ binutils-2.20.1/bfd/elflink.c 2010-08-17 19:32:11.000000000 +0200
91 @@ -5469,16 +5469,30 @@
94 bed = get_elf_backend_data (output_bfd);
96 + elf_tdata (output_bfd)->pax_flags = PF_NORANDEXEC;
98 + elf_tdata (output_bfd)->pax_flags |= PF_NOMPROTECT;
99 + else if (info->noexecheap)
100 + elf_tdata (output_bfd)->pax_flags |= PF_MPROTECT;
103 - elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
105 + elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
106 + elf_tdata (output_bfd)->pax_flags |= PF_EMUTRAMP;
108 else if (info->noexecstack)
109 - elf_tdata (output_bfd)->stack_flags = PF_R | PF_W;
111 + elf_tdata (output_bfd)->stack_flags = PF_R | PF_W;
112 + elf_tdata (output_bfd)->pax_flags |= PF_NOEMUTRAMP;
117 asection *notesec = NULL;
120 + elf_tdata (output_bfd)->pax_flags |= PF_NOEMUTRAMP;
121 for (inputobj = info->input_bfds;
123 inputobj = inputobj->link_next)
124 @@ -5491,7 +5505,11 @@
127 if (s->flags & SEC_CODE)
130 + elf_tdata (output_bfd)->pax_flags &= ~PF_NOEMUTRAMP;
131 + elf_tdata (output_bfd)->pax_flags |= PF_EMUTRAMP;
136 else if (bed->default_execstack)
137 diff -durN binutils-2.20.1.orig/binutils/readelf.c binutils-2.20.1/binutils/readelf.c
138 --- binutils-2.20.1.orig/binutils/readelf.c 2010-01-14 11:48:23.000000000 +0100
139 +++ binutils-2.20.1/binutils/readelf.c 2010-08-17 19:32:11.000000000 +0200
140 @@ -2569,6 +2569,7 @@
141 return "GNU_EH_FRAME";
142 case PT_GNU_STACK: return "GNU_STACK";
143 case PT_GNU_RELRO: return "GNU_RELRO";
144 + case PT_PAX_FLAGS: return "PAX_FLAGS";
147 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
148 diff -durN binutils-2.20.1.orig/include/bfdlink.h binutils-2.20.1/include/bfdlink.h
149 --- binutils-2.20.1.orig/include/bfdlink.h 2009-09-10 13:47:30.000000000 +0200
150 +++ binutils-2.20.1/include/bfdlink.h 2010-08-17 19:32:11.000000000 +0200
152 /* TRUE if PT_GNU_RELRO segment should be created. */
153 unsigned int relro: 1;
155 + /* TRUE if PT_PAX_FLAGS segment should be created with PF_NOMPROTECT
157 + unsigned int execheap: 1;
159 + /* TRUE if PT_PAX_FLAGS segment should be created with PF_MPROTECT
161 + unsigned int noexecheap: 1;
163 /* TRUE if we should warn when adding a DT_TEXTREL to a shared object. */
164 unsigned int warn_shared_textrel: 1;
166 diff -durN binutils-2.20.1.orig/include/elf/common.h binutils-2.20.1/include/elf/common.h
167 --- binutils-2.20.1.orig/include/elf/common.h 2009-08-09 15:42:26.000000000 +0200
168 +++ binutils-2.20.1/include/elf/common.h 2010-08-17 19:32:11.000000000 +0200
170 #define PT_SUNW_EH_FRAME PT_GNU_EH_FRAME /* Solaris uses the same value */
171 #define PT_GNU_STACK (PT_LOOS + 0x474e551) /* Stack flags */
172 #define PT_GNU_RELRO (PT_LOOS + 0x474e552) /* Read-only after relocation */
173 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580) /* PaX flags */
175 /* Program segment permissions, in program header p_flags field. */
178 #define PF_MASKOS 0x0FF00000 /* New value, Oct 4, 1999 Draft */
179 #define PF_MASKPROC 0xF0000000 /* Processor-specific reserved bits */
181 +/* Flags to control PaX behavior. */
183 +#define PF_PAGEEXEC (1 << 4) /* Enable PAGEEXEC */
184 +#define PF_NOPAGEEXEC (1 << 5) /* Disable PAGEEXEC */
185 +#define PF_SEGMEXEC (1 << 6) /* Enable SEGMEXEC */
186 +#define PF_NOSEGMEXEC (1 << 7) /* Disable SEGMEXEC */
187 +#define PF_MPROTECT (1 << 8) /* Enable MPROTECT */
188 +#define PF_NOMPROTECT (1 << 9) /* Disable MPROTECT */
189 +#define PF_RANDEXEC (1 << 10) /* Enable RANDEXEC */
190 +#define PF_NORANDEXEC (1 << 11) /* Disable RANDEXEC */
191 +#define PF_EMUTRAMP (1 << 12) /* Enable EMUTRAMP */
192 +#define PF_NOEMUTRAMP (1 << 13) /* Disable EMUTRAMP */
193 +#define PF_RANDMMAP (1 << 14) /* Enable RANDMMAP */
194 +#define PF_NORANDMMAP (1 << 15) /* Disable RANDMMAP */
196 /* Values for section header, sh_type field. */
198 #define SHT_NULL 0 /* Section header table entry unused */
199 diff -durN binutils-2.20.1.orig/ld/emultempl/elf32.em binutils-2.20.1/ld/emultempl/elf32.em
200 --- binutils-2.20.1.orig/ld/emultempl/elf32.em 2010-08-17 19:32:09.000000000 +0200
201 +++ binutils-2.20.1/ld/emultempl/elf32.em 2010-08-17 19:32:11.000000000 +0200
202 @@ -2165,6 +2165,16 @@
203 link_info.noexecstack = TRUE;
204 link_info.execstack = FALSE;
206 + else if (strcmp (optarg, "execheap") == 0)
208 + link_info.execheap = TRUE;
209 + link_info.noexecheap = FALSE;
211 + else if (strcmp (optarg, "noexecheap") == 0)
213 + link_info.noexecheap = TRUE;
214 + link_info.execheap = FALSE;
218 if test -n "$COMMONPAGESIZE"; then
219 @@ -2243,6 +2253,8 @@
221 -z execstack Mark executable as requiring executable stack\n"));
223 + -z execheap Mark executable as requiring executable heap\n"));
224 + fprintf (file, _("\
225 -z initfirst Mark DSO to be initialized first at runtime\n"));
227 -z interpose Mark object to interpose all DSOs but executable\n"));
228 @@ -2266,6 +2278,8 @@
229 -z nodump Mark DSO not available to dldump\n"));
231 -z noexecstack Mark executable as not requiring executable stack\n"));
232 + fprintf (file, _("\
233 + -z noexecheap Mark executable as not requiring executable heap\n"));
236 if test -n "$COMMONPAGESIZE"; then
237 diff -durN binutils-2.20.1.orig/ld/ldgram.y binutils-2.20.1/ld/ldgram.y
238 --- binutils-2.20.1.orig/ld/ldgram.y 2009-09-02 09:25:35.000000000 +0200
239 +++ binutils-2.20.1/ld/ldgram.y 2010-08-17 19:32:11.000000000 +0200
240 @@ -1116,6 +1116,8 @@
241 $$ = exp_intop (0x6474e550);
242 else if (strcmp (s, "PT_GNU_STACK") == 0)
243 $$ = exp_intop (0x6474e551);
244 + else if (strcmp (s, "PT_PAX_FLAGS") == 0)
245 + $$ = exp_intop (0x65041580);