]> git.pld-linux.org Git - packages/binutils.git/blame - binutils-pt_pax_flags.patch
- PaX support.
[packages/binutils.git] / binutils-pt_pax_flags.patch
CommitLineData
60005366
PS
1diff -uNr binutils-2.15.90.0.1.1.orig/bfd/elf-bfd.h binutils-2.15.90.0.1.1/bfd/elf-bfd.h
2--- binutils-2.15.90.0.1.1.orig/bfd/elf-bfd.h 2004-03-03 21:24:33.000000000 +0100
3+++ binutils-2.15.90.0.1.1/bfd/elf-bfd.h 2004-03-17 11:51:20.951912544 +0100
4@@ -1225,6 +1225,9 @@
5 /* Segment flags for the PT_GNU_STACK segment. */
6 unsigned int stack_flags;
7
8+ /* Segment flags for the PT_PAX_FLAGS segment. */
9+ unsigned int pax_flags;
10+
11 /* Symbol version definitions in external objects. */
12 Elf_Internal_Verdef *verdef;
13
14diff -uNr binutils-2.15.90.0.1.1.orig/bfd/elf.c binutils-2.15.90.0.1.1/bfd/elf.c
15--- binutils-2.15.90.0.1.1.orig/bfd/elf.c 2004-03-03 21:24:33.000000000 +0100
16+++ binutils-2.15.90.0.1.1/bfd/elf.c 2004-03-17 11:57:20.657229024 +0100
17@@ -968,6 +968,7 @@
18 case PT_TLS: pt = "TLS"; break;
19 case PT_GNU_EH_FRAME: pt = "EH_FRAME"; break;
20 case PT_GNU_STACK: pt = "STACK"; break;
21+ case PT_PAX_FLAGS: pt = "PAX_FLAGS"; break;
22 default: sprintf (buf, "0x%lx", p->p_type); pt = buf; break;
23 }
24 fprintf (f, "%8s off 0x", pt);
25@@ -2292,6 +2293,9 @@
26 case PT_GNU_STACK:
27 return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "stack");
28
29+ case PT_PAX_FLAGS:
30+ return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "pax_flags");
31+
32 default:
33 /* Check for any processor-specific program segment types.
34 If no handler for them, default to making "segment" sections. */
35@@ -3502,6 +3506,20 @@
36 pm = &m->next;
37 }
38
39+ {
40+ amt = sizeof (struct elf_segment_map);
41+ m = bfd_zalloc (abfd, amt);
42+ if (m == NULL)
43+ goto error_return;
44+ m->next = NULL;
45+ m->p_type = PT_PAX_FLAGS;
46+ m->p_flags = elf_tdata (abfd)->pax_flags;
47+ m->p_flags_valid = 1;
48+
49+ *pm = m;
50+ pm = &m->next;
51+ }
52+
53 free (sections);
54 sections = NULL;
55
56@@ -4123,6 +4141,11 @@
57 ++segs;
58 }
59
60+ {
61+ /* We need a PT_PAX_FLAGS segment. */
62+ ++segs;
63+ }
64+
65 for (s = abfd->sections; s != NULL; s = s->next)
66 {
67 if ((s->flags & SEC_LOAD) != 0
68@@ -4672,6 +4695,7 @@
69 || IS_COREFILE_NOTE (segment, section)) \
70 && section->output_section != NULL \
71 && segment->p_type != PT_GNU_STACK \
72+ && segment->p_type != PT_PAX_FLAGS \
73 && (segment->p_type != PT_TLS \
74 || (section->flags & SEC_THREAD_LOCAL)) \
75 && (segment->p_type == PT_LOAD \
76diff -uNr binutils-2.15.90.0.1.1.orig/bfd/elflink.h binutils-2.15.90.0.1.1/bfd/elflink.h
77--- binutils-2.15.90.0.1.1.orig/bfd/elflink.h 2004-03-03 21:24:33.000000000 +0100
78+++ binutils-2.15.90.0.1.1/bfd/elflink.h 2004-03-17 12:05:53.403279776 +0100
79@@ -1654,16 +1654,30 @@
80 if (!is_elf_hash_table (info->hash))
81 return TRUE;
82
83+ elf_tdata (output_bfd)->pax_flags = PF_NORANDEXEC;
84+
85+ if (info->execheap)
86+ elf_tdata (output_bfd)->pax_flags |= PF_NOMPROTECT;
87+ else if (info->noexecheap)
88+ elf_tdata (output_bfd)->pax_flags |= PF_MPROTECT;
89+
90 if (info->execstack)
91+ {
92 elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
93+ elf_tdata (output_bfd)->pax_flags |= PF_EMUTRAMP;
94+ }
95 else if (info->noexecstack)
96+ {
97 elf_tdata (output_bfd)->stack_flags = PF_R | PF_W;
98+ elf_tdata (output_bfd)->pax_flags |= PF_NOEMUTRAMP;
99+ }
100 else
101 {
102 bfd *inputobj;
103 asection *notesec = NULL;
104 int exec = 0;
105
106+ elf_tdata (output_bfd)->pax_flags |= PF_NOEMUTRAMP;
107 for (inputobj = info->input_bfds;
108 inputobj;
109 inputobj = inputobj->link_next)
110@@ -1676,7 +1690,11 @@
111 if (s)
112 {
113 if (s->flags & SEC_CODE)
114- exec = PF_X;
115+ {
116+ elf_tdata (output_bfd)->pax_flags &= ~PF_NOEMUTRAMP;
117+ elf_tdata (output_bfd)->pax_flags |= PF_EMUTRAMP;
118+ exec = PF_X;
119+ }
120 notesec = s;
121 }
122 else
123diff -uNr binutils-2.15.90.0.1.1.orig/binutils/readelf.c binutils-2.15.90.0.1.1/binutils/readelf.c
124--- binutils-2.15.90.0.1.1.orig/binutils/readelf.c 2004-03-03 21:24:34.000000000 +0100
125+++ binutils-2.15.90.0.1.1/binutils/readelf.c 2004-03-17 12:07:27.989900424 +0100
126@@ -2144,6 +2144,7 @@
127 case PT_GNU_EH_FRAME:
128 return "GNU_EH_FRAME";
129 case PT_GNU_STACK: return "STACK";
130+ case PT_PAX_FLAGS: return "PAX_FLAGS";
131
132 default:
133 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
134diff -uNr binutils-2.15.90.0.1.1.orig/include/bfdlink.h binutils-2.15.90.0.1.1/include/bfdlink.h
135--- binutils-2.15.90.0.1.1.orig/include/bfdlink.h 2004-01-14 22:07:51.000000000 +0100
136+++ binutils-2.15.90.0.1.1/include/bfdlink.h 2004-03-17 11:51:21.109888528 +0100
137@@ -302,6 +302,14 @@
138 flags. */
139 unsigned int noexecstack: 1;
140
141+ /* TRUE if PT_PAX_FLAGS segment should be created with PF_NOMPROTECT
142+ flags. */
143+ unsigned int execheap: 1;
144+
145+ /* TRUE if PT_PAX_FLAGS segment should be created with PF_MPROTECT
146+ flags. */
147+ unsigned int noexecheap: 1;
148+
149 /* What to do with unresolved symbols in an object file.
150 When producing static binaries the default is GENERATE_ERROR.
151 When producing dynamic binaries the default is IGNORE. The
152diff -uNr binutils-2.15.90.0.1.1.orig/include/elf/common.h binutils-2.15.90.0.1.1/include/elf/common.h
153--- binutils-2.15.90.0.1.1.orig/include/elf/common.h 2004-03-03 21:24:34.000000000 +0100
154+++ binutils-2.15.90.0.1.1/include/elf/common.h 2004-03-17 11:55:02.074296832 +0100
155@@ -289,12 +289,27 @@
156
157 #define PT_GNU_EH_FRAME (PT_LOOS + 0x474e550)
158 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
159+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
160
161 /* Program segment permissions, in program header p_flags field. */
162
163 #define PF_X (1 << 0) /* Segment is executable */
164 #define PF_W (1 << 1) /* Segment is writable */
165 #define PF_R (1 << 2) /* Segment is readable */
166+
167+#define PF_PAGEEXEC (1 << 4) /* Enable PAGEEXEC */
168+#define PF_NOPAGEEXEC (1 << 5) /* Disable PAGEEXEC */
169+#define PF_SEGMEXEC (1 << 6) /* Enable SEGMEXEC */
170+#define PF_NOSEGMEXEC (1 << 7) /* Disable SEGMEXEC */
171+#define PF_MPROTECT (1 << 8) /* Enable MPROTECT */
172+#define PF_NOMPROTECT (1 << 9) /* Disable MPROTECT */
173+#define PF_RANDEXEC (1 << 10) /* Enable RANDEXEC */
174+#define PF_NORANDEXEC (1 << 11) /* Disable RANDEXEC */
175+#define PF_EMUTRAMP (1 << 12) /* Enable EMUTRAMP */
176+#define PF_NOEMUTRAMP (1 << 13) /* Disable EMUTRAMP */
177+#define PF_RANDMMAP (1 << 14) /* Enable RANDMMAP */
178+#define PF_NORANDMMAP (1 << 15) /* Disable RANDMMAP */
179+
180 /* #define PF_MASKOS 0x0F000000 *//* OS-specific reserved bits */
181 #define PF_MASKOS 0x0FF00000 /* New value, Oct 4, 1999 Draft */
182 #define PF_MASKPROC 0xF0000000 /* Processor-specific reserved bits */
183diff -uNr binutils-2.15.90.0.1.1.orig/ld/emultempl/elf32.em binutils-2.15.90.0.1.1/ld/emultempl/elf32.em
184--- binutils-2.15.90.0.1.1.orig/ld/emultempl/elf32.em 2004-01-14 22:07:53.000000000 +0100
185+++ binutils-2.15.90.0.1.1/ld/emultempl/elf32.em 2004-03-17 12:12:08.072321424 +0100
186@@ -1645,6 +1645,16 @@
187 link_info.noexecstack = TRUE;
188 link_info.execstack = FALSE;
189 }
190+ else if (strcmp (optarg, "execheap") == 0)
191+ {
192+ link_info.execheap = TRUE;
193+ link_info.noexecheap = FALSE;
194+ }
195+ else if (strcmp (optarg, "noexecheap") == 0)
196+ {
197+ link_info.noexecheap = TRUE;
198+ link_info.execheap = FALSE;
199+ }
200 /* What about the other Solaris -z options? FIXME. */
201 break;
202 EOF
203@@ -1681,6 +1691,7 @@
204 fprintf (file, _(" -z combreloc\t\tMerge dynamic relocs into one section and sort\n"));
205 fprintf (file, _(" -z defs\t\tReport unresolved symbols in object files.\n"));
206 fprintf (file, _(" -z execstack\t\tMark executable as requiring executable stack\n"));
207+ fprintf (file, _(" -z execheap\t\tMark executable as requiring executable heap\n"));
208 fprintf (file, _(" -z initfirst\t\tMark DSO to be initialized first at runtime\n"));
209 fprintf (file, _(" -z interpose\t\tMark object to interpose all DSOs but executable\n"));
210 fprintf (file, _(" -z loadfltr\t\tMark object requiring immediate process\n"));
211@@ -1692,6 +1703,7 @@
212 fprintf (file, _(" -z nodlopen\t\tMark DSO not available to dlopen\n"));
213 fprintf (file, _(" -z nodump\t\tMark DSO not available to dldump\n"));
214 fprintf (file, _(" -z noexecstack\tMark executable as not requiring executable stack\n"));
215+ fprintf (file, _(" -z noexecheap\t\tMark executable as not requiring executable heap\n"));
216 fprintf (file, _(" -z now\t\tMark object non-lazy runtime binding\n"));
217 fprintf (file, _(" -z origin\t\tMark object requiring immediate \$ORIGIN processing\n\t\t\t at runtime\n"));
218 fprintf (file, _(" -z KEYWORD\t\tIgnored for Solaris compatibility\n"));
219diff -uNr binutils-2.15.90.0.1.1.orig/ld/ldgram.y binutils-2.15.90.0.1.1/ld/ldgram.y
220--- binutils-2.15.90.0.1.1.orig/ld/ldgram.y 2004-03-03 21:24:34.000000000 +0100
221+++ binutils-2.15.90.0.1.1/ld/ldgram.y 2004-03-17 11:51:21.123886400 +0100
222@@ -1019,6 +1019,8 @@
223 $$ = exp_intop (0x6474e550);
224 else if (strcmp (s, "PT_GNU_STACK") == 0)
225 $$ = exp_intop (0x6474e551);
226+ else if (strcmp (s, "PT_PAX_FLAGS") == 0)
227+ $$ = exp_intop (0x65041580);
228 else
229 {
230 einfo (_("\
This page took 0.176769 seconds and 4 git commands to generate.