binutils/binutils: do not fwd declare struct stat (2.22).
For canadian cross to host i686-mingw32 fwd declaring
struct stat is not possible.
Instead #include <sys/stat.h>
Signed-off-by: Titus von Boxberg <titus@v9g.de>
Message-Id: <417a15d4277913841ddd.1353100974@tschetwerikow.boxberg.lan>
Patchwork-Id: 199733
1 Original patch from: ../crosstool-NG/ct-ng.trunk/patches/binutils/2.19/140-pt-pax-flags-20081101.patch
3 -= BEGIN original header =-
4 Original patch from Gentoo:
5 gentoo/src/patchsets/binutils/2.19/63_all_binutils-2.19-pt-pax-flags-20081101.patch
7 -= END original header =-
9 diff -durN binutils-2.19.1.orig/bfd/elf-bfd.h binutils-2.19.1/bfd/elf-bfd.h
10 --- binutils-2.19.1.orig/bfd/elf-bfd.h 2008-08-21 01:28:58.000000000 +0200
11 +++ binutils-2.19.1/bfd/elf-bfd.h 2009-03-08 11:57:02.000000000 +0100
13 /* Segment flags for the PT_GNU_STACK segment. */
14 unsigned int stack_flags;
16 + /* Segment flags for the PT_PAX_FLAGS segment. */
17 + unsigned int pax_flags;
19 /* Symbol version definitions in external objects. */
20 Elf_Internal_Verdef *verdef;
22 diff -durN binutils-2.19.1.orig/bfd/elf.c binutils-2.19.1/bfd/elf.c
23 --- binutils-2.19.1.orig/bfd/elf.c 2008-12-23 14:54:48.000000000 +0100
24 +++ binutils-2.19.1/bfd/elf.c 2009-03-08 11:57:02.000000000 +0100
26 case PT_GNU_EH_FRAME: pt = "EH_FRAME"; break;
27 case PT_GNU_STACK: pt = "STACK"; break;
28 case PT_GNU_RELRO: pt = "RELRO"; break;
29 + case PT_PAX_FLAGS: pt = "PAX_FLAGS"; break;
30 default: pt = NULL; break;
35 return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "relro");
38 + return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "pax_flags");
41 /* Check for any processor-specific program segment types. */
42 bed = get_elf_backend_data (abfd);
43 @@ -3404,6 +3408,11 @@
48 + /* We need a PT_PAX_FLAGS segment. */
52 for (s = abfd->sections; s != NULL; s = s->next)
54 if ((s->flags & SEC_LOAD) != 0
55 @@ -3983,6 +3992,20 @@
60 + amt = sizeof (struct elf_segment_map);
61 + m = bfd_zalloc (abfd, amt);
65 + m->p_type = PT_PAX_FLAGS;
66 + m->p_flags = elf_tdata (abfd)->pax_flags;
67 + m->p_flags_valid = 1;
74 elf_tdata (abfd)->segment_map = mfirst;
77 6. PT_TLS segment includes only SHF_TLS sections.
78 7. SHF_TLS sections are only in PT_TLS or PT_LOAD segments.
79 8. PT_DYNAMIC should not contain empty sections at the beginning
80 - (with the possible exception of .dynamic). */
81 + (with the possible exception of .dynamic).
82 + 9. PT_PAX_FLAGS segments does not include any sections. */
83 #define IS_SECTION_IN_INPUT_SEGMENT(section, segment, bed) \
84 ((((segment->p_paddr \
85 ? IS_CONTAINED_BY_LMA (section, segment, segment->p_paddr) \
87 && (section->flags & SEC_ALLOC) != 0) \
88 || IS_NOTE (segment, section)) \
89 && segment->p_type != PT_GNU_STACK \
90 + && segment->p_type != PT_PAX_FLAGS \
91 && (segment->p_type != PT_TLS \
92 || (section->flags & SEC_THREAD_LOCAL)) \
93 && (segment->p_type == PT_LOAD \
94 diff -durN binutils-2.19.1.orig/bfd/elflink.c binutils-2.19.1/bfd/elflink.c
95 --- binutils-2.19.1.orig/bfd/elflink.c 2008-08-22 10:32:39.000000000 +0200
96 +++ binutils-2.19.1/bfd/elflink.c 2009-03-08 11:57:02.000000000 +0100
97 @@ -5397,16 +5397,30 @@
100 bed = get_elf_backend_data (output_bfd);
101 + elf_tdata (output_bfd)->pax_flags = PF_NORANDEXEC;
103 + if (info->execheap)
104 + elf_tdata (output_bfd)->pax_flags |= PF_NOMPROTECT;
105 + else if (info->noexecheap)
106 + elf_tdata (output_bfd)->pax_flags |= PF_MPROTECT;
109 - elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
111 + elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
112 + elf_tdata (output_bfd)->pax_flags |= PF_EMUTRAMP;
114 else if (info->noexecstack)
115 - elf_tdata (output_bfd)->stack_flags = PF_R | PF_W;
117 + elf_tdata (output_bfd)->stack_flags = PF_R | PF_W;
118 + elf_tdata (output_bfd)->pax_flags |= PF_NOEMUTRAMP;
123 asection *notesec = NULL;
126 + elf_tdata (output_bfd)->pax_flags |= PF_NOEMUTRAMP;
127 for (inputobj = info->input_bfds;
129 inputobj = inputobj->link_next)
130 @@ -5419,7 +5433,11 @@
133 if (s->flags & SEC_CODE)
136 + elf_tdata (output_bfd)->pax_flags &= ~PF_NOEMUTRAMP;
137 + elf_tdata (output_bfd)->pax_flags |= PF_EMUTRAMP;
142 else if (bed->default_execstack)
143 diff -durN binutils-2.19.1.orig/binutils/readelf.c binutils-2.19.1/binutils/readelf.c
144 --- binutils-2.19.1.orig/binutils/readelf.c 2008-09-17 11:00:44.000000000 +0200
145 +++ binutils-2.19.1/binutils/readelf.c 2009-03-08 11:57:02.000000000 +0100
146 @@ -2505,6 +2505,7 @@
147 return "GNU_EH_FRAME";
148 case PT_GNU_STACK: return "GNU_STACK";
149 case PT_GNU_RELRO: return "GNU_RELRO";
150 + case PT_PAX_FLAGS: return "PAX_FLAGS";
153 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
154 diff -durN binutils-2.19.1.orig/include/bfdlink.h binutils-2.19.1/include/bfdlink.h
155 --- binutils-2.19.1.orig/include/bfdlink.h 2008-08-17 05:12:50.000000000 +0200
156 +++ binutils-2.19.1/include/bfdlink.h 2009-03-08 11:57:02.000000000 +0100
158 /* TRUE if PT_GNU_RELRO segment should be created. */
159 unsigned int relro: 1;
161 + /* TRUE if PT_PAX_FLAGS segment should be created with PF_NOMPROTECT
163 + unsigned int execheap: 1;
165 + /* TRUE if PT_PAX_FLAGS segment should be created with PF_MPROTECT
167 + unsigned int noexecheap: 1;
169 /* TRUE if we should warn when adding a DT_TEXTREL to a shared object. */
170 unsigned int warn_shared_textrel: 1;
172 diff -durN binutils-2.19.1.orig/include/elf/common.h binutils-2.19.1/include/elf/common.h
173 --- binutils-2.19.1.orig/include/elf/common.h 2008-08-04 01:20:42.000000000 +0200
174 +++ binutils-2.19.1/include/elf/common.h 2009-03-08 11:57:02.000000000 +0100
176 #define PT_SUNW_EH_FRAME PT_GNU_EH_FRAME /* Solaris uses the same value */
177 #define PT_GNU_STACK (PT_LOOS + 0x474e551) /* Stack flags */
178 #define PT_GNU_RELRO (PT_LOOS + 0x474e552) /* Read-only after relocation */
179 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580) /* PaX flags */
181 /* Program segment permissions, in program header p_flags field. */
184 #define PF_MASKOS 0x0FF00000 /* New value, Oct 4, 1999 Draft */
185 #define PF_MASKPROC 0xF0000000 /* Processor-specific reserved bits */
187 +/* Flags to control PaX behavior. */
189 +#define PF_PAGEEXEC (1 << 4) /* Enable PAGEEXEC */
190 +#define PF_NOPAGEEXEC (1 << 5) /* Disable PAGEEXEC */
191 +#define PF_SEGMEXEC (1 << 6) /* Enable SEGMEXEC */
192 +#define PF_NOSEGMEXEC (1 << 7) /* Disable SEGMEXEC */
193 +#define PF_MPROTECT (1 << 8) /* Enable MPROTECT */
194 +#define PF_NOMPROTECT (1 << 9) /* Disable MPROTECT */
195 +#define PF_RANDEXEC (1 << 10) /* Enable RANDEXEC */
196 +#define PF_NORANDEXEC (1 << 11) /* Disable RANDEXEC */
197 +#define PF_EMUTRAMP (1 << 12) /* Enable EMUTRAMP */
198 +#define PF_NOEMUTRAMP (1 << 13) /* Disable EMUTRAMP */
199 +#define PF_RANDMMAP (1 << 14) /* Enable RANDMMAP */
200 +#define PF_NORANDMMAP (1 << 15) /* Disable RANDMMAP */
202 /* Values for section header, sh_type field. */
204 #define SHT_NULL 0 /* Section header table entry unused */
205 diff -durN binutils-2.19.1.orig/ld/emultempl/elf32.em binutils-2.19.1/ld/emultempl/elf32.em
206 --- binutils-2.19.1.orig/ld/emultempl/elf32.em 2009-03-08 11:57:01.000000000 +0100
207 +++ binutils-2.19.1/ld/emultempl/elf32.em 2009-03-08 11:57:02.000000000 +0100
208 @@ -2146,6 +2146,16 @@
209 link_info.noexecstack = TRUE;
210 link_info.execstack = FALSE;
212 + else if (strcmp (optarg, "execheap") == 0)
214 + link_info.execheap = TRUE;
215 + link_info.noexecheap = FALSE;
217 + else if (strcmp (optarg, "noexecheap") == 0)
219 + link_info.noexecheap = TRUE;
220 + link_info.execheap = FALSE;
224 if test -n "$COMMONPAGESIZE"; then
225 @@ -2229,6 +2239,8 @@
227 -z execstack Mark executable as requiring executable stack\n"));
229 + -z execheap\t\tMark executable as requiring executable heap\n"));
230 + fprintf (file, _("\
231 -z initfirst Mark DSO to be initialized first at runtime\n"));
233 -z interpose Mark object to interpose all DSOs but executable\n"));
234 @@ -2252,6 +2264,8 @@
235 -z nodump Mark DSO not available to dldump\n"));
237 -z noexecstack Mark executable as not requiring executable stack\n"));
238 + fprintf (file, _("\
239 + -z noexecheap\tMark executable as not requiring executable heap\n"));
242 if test -n "$COMMONPAGESIZE"; then
243 diff -durN binutils-2.19.1.orig/ld/ldgram.y binutils-2.19.1/ld/ldgram.y
244 --- binutils-2.19.1.orig/ld/ldgram.y 2008-07-06 15:38:36.000000000 +0200
245 +++ binutils-2.19.1/ld/ldgram.y 2009-03-08 11:57:02.000000000 +0100
246 @@ -1112,6 +1112,8 @@
247 $$ = exp_intop (0x6474e550);
248 else if (strcmp (s, "PT_GNU_STACK") == 0)
249 $$ = exp_intop (0x6474e551);
250 + else if (strcmp (s, "PT_PAX_FLAGS") == 0)
251 + $$ = exp_intop (0x65041580);