• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

修訂c935ff02abfbf5bb80aa043340f7d101aac262f2 (tree)
時間2018-01-13 01:30:10
作者H.J. Lu <hjl.tools@gmai...>
CommiterH.J. Lu

Log Message

Revert "Add "-z textonly" option to ELF linker"

This reverts commit e87d0965bb97fa186749c8386822cdeb9752df38.

"-z separate-code" has been checked into master branch.

Change Summary

  • delete: patches/0001-ld-Add-z-textonly-option-to-ELF-linker.patch
  • delete: patches/0002-ld-Add-TEXT_SEGMENT_ALIGN-TEXT_SEGMENT_-RELRO_-END.patch
  • delete: patches/0003-ld-Create-a-new-LOAD-segment-for-text-only-LOAD-segm.patch
  • delete: patches/0004-ld-ppc-spu-Also-set-expld.textseg.phase-to-exp_seg_n.patch
  • delete: patches/0005-ld-Add-tests-for-z-textonly-and-z-notextonly.patch
  • delete: patches/0006-x86-64-Add-tests-for-z-textonly-z-max-page-size-0x10.patch
  • modified: patches/README (diff)

差異

--- a/patches/0001-ld-Add-z-textonly-option-to-ELF-linker.patch
+++ /dev/null
@@ -1,479 +0,0 @@
1-From 10728c17a5b63dff7301970c3d58285c77eb955a Mon Sep 17 00:00:00 2001
2-From: "H.J. Lu" <hjl.tools@gmail.com>
3-Date: Thu, 9 Nov 2017 14:14:08 -0800
4-Subject: [PATCH 1/6] ld: Add "-z textonly" option to ELF linker
5-
6-Text-only LOAD segment has the same requirement for segment alignment
7-and page sizes as GNU_RELRO segment. But for GNU_RELRO segment, the
8-segment may not end at the same address of the end of data segment. But
9-for text-only LOAD segment, it is exactly the same as text LOAD segment.
10-
11-The new "-z textonly" option will turn on both text-only LOAD segment and
12-GNU_RELRO segment. The new "-z notextonly" option will turn off only
13-text-only LOAD segment. "-z relro" is updated not to turn off text-only
14-LOAD segment. "-z norelro" is updated to turn off both GNU_RELRO segment
15-and text-only LOAD segment.
16-
17-include/
18-
19- PR ld/22393
20- * bfdlink.h (bfd_link_info): Change the relro field to 2 bits.
21-
22-ld/
23-
24- PR ld/22393
25- * NEWS: Mention "-z textonly".
26- * emultempl/elf32.em (gld${EMULATION_NAME}_get_script): Get
27- builtin linker scripts and return linker scripts from disk for
28- "-z textonly".
29- (gld${EMULATION_NAME}_handle_option): Set the first bit of
30- link_info.relro for "-z relro". Clear link_info.relro for
31- "-z norelro". Set link_info.relro to 2 for "-z textonly".
32- Keep only the first bit of link_info.relro for "notextonly".
33- * genscripts.sh: Generate linker scripts for "-z textonly".
34- (LD_FLAG): Set to *textonly for "-z textonly".
35- * lexsup.c (elf_shlib_list_options): Update linker help messsages
36- for "-z relro" and "-z norelro". Add linker help messsages for
37- "-z textonly" and "-z notextonly".
38- * ld.texinfo: Update "-z norelro". Document "-z textonly".
39----
40- include/bfdlink.h | 6 ++-
41- ld/NEWS | 2 +
42- ld/emultempl/elf32.em | 104 ++++++++++++++++++++++++++++++++++++++++++++------
43- ld/genscripts.sh | 76 ++++++++++++++++++++++++++++++++----
44- ld/ld.texinfo | 10 ++++-
45- ld/lexsup.c | 8 +++-
46- 6 files changed, 182 insertions(+), 24 deletions(-)
47-
48-diff --git a/include/bfdlink.h b/include/bfdlink.h
49-index 2370c0d45a..d283429fdb 100644
50---- a/include/bfdlink.h
51-+++ b/include/bfdlink.h
52-@@ -383,8 +383,10 @@ struct bfd_link_info
53- executable. */
54- unsigned int emitrelocations: 1;
55-
56-- /* TRUE if PT_GNU_RELRO segment should be created. */
57-- unsigned int relro: 1;
58-+ /* Non-zero if PT_GNU_RELRO and text-only PT_LOAD segments should be
59-+ created. 1 for PT_GNU_RELRO segment only, > 1 for PT_GNU_RELRO
60-+ segment as well as text-only PT_LOAD segment. */
61-+ unsigned int relro: 2;
62-
63- /* Nonzero if .eh_frame_hdr section and PT_GNU_EH_FRAME ELF segment
64- should be created. 1 for DWARF2 tables, 2 for compact tables. */
65-diff --git a/ld/NEWS b/ld/NEWS
66-index 8f67fbe179..4da1cc07b3 100644
67---- a/ld/NEWS
68-+++ b/ld/NEWS
69-@@ -1,4 +1,6 @@
70- -*- text -*-
71-+* Add -z textonly to generate text-only PT_LOAD segment.
72-+
73- * Add -z globalaudit command line option to force audit libraries to be run
74- for every dynamic object loaded by an executable - provided that the loader
75- supports this functionality.
76-diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
77-index edd8944f04..b633977438 100644
78---- a/ld/emultempl/elf32.em
79-+++ b/ld/emultempl/elf32.em
80-@@ -2367,13 +2367,25 @@ if test -n "$GENERATE_PIE_SCRIPT" ; then
81- if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
82- echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
83- echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
84-+echo ' && link_info.relro > 1' >> e${EMULATION_NAME}.c
85-+echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
86-+sed $sc ldscripts/${EMULATION_NAME}.xdwe >> e${EMULATION_NAME}.c
87-+echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
88-+echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
89- echo ' && link_info.relro' >> e${EMULATION_NAME}.c
90- echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
91- sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c
92- echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
93-+echo ' && link_info.relro > 1' >> e${EMULATION_NAME}.c
94-+echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
95-+sed $sc ldscripts/${EMULATION_NAME}.xdce >> e${EMULATION_NAME}.c
96-+echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
97- echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
98- sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c
99- fi
100-+echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
101-+echo ' && link_info.relro > 1) return' >> e${EMULATION_NAME}.c
102-+sed $sc ldscripts/${EMULATION_NAME}.xde >> e${EMULATION_NAME}.c
103- echo ' ; else if (bfd_link_pie (&link_info)) return' >> e${EMULATION_NAME}.c
104- sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c
105- fi
106-@@ -2381,24 +2393,45 @@ if test -n "$GENERATE_SHLIB_SCRIPT" ; then
107- if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
108- echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
109- echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
110-+echo ' && link_info.relro > 1' >> e${EMULATION_NAME}.c
111-+echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
112-+sed $sc ldscripts/${EMULATION_NAME}.xswe >> e${EMULATION_NAME}.c
113-+echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
114-+echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
115- echo ' && link_info.relro' >> e${EMULATION_NAME}.c
116- echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
117- sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c
118- echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
119-+echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
120-+echo ' && link_info.relro > 1) return' >> e${EMULATION_NAME}.c
121-+sed $sc ldscripts/${EMULATION_NAME}.xsce >> e${EMULATION_NAME}.c
122-+echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
123- echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
124- sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c
125- fi
126-+echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
127-+echo ' && link_info.relro > 1) return' >> e${EMULATION_NAME}.c
128-+sed $sc ldscripts/${EMULATION_NAME}.xse >> e${EMULATION_NAME}.c
129- echo ' ; else if (bfd_link_dll (&link_info)) return' >> e${EMULATION_NAME}.c
130- sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
131- fi
132- if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
133- echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
134-+echo ' && link_info.relro > 1' >> e${EMULATION_NAME}.c
135-+echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
136-+sed $sc ldscripts/${EMULATION_NAME}.xwe >> e${EMULATION_NAME}.c
137-+echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
138- echo ' && link_info.relro' >> e${EMULATION_NAME}.c
139- echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
140- sed $sc ldscripts/${EMULATION_NAME}.xw >> e${EMULATION_NAME}.c
141-+echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
142-+echo ' && link_info.relro > 1) return' >> e${EMULATION_NAME}.c
143-+sed $sc ldscripts/${EMULATION_NAME}.xce >> e${EMULATION_NAME}.c
144- echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c
145- sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c
146- fi
147-+echo ' ; else if (link_info.relro > 1) return' >> e${EMULATION_NAME}.c
148-+sed $sc ldscripts/${EMULATION_NAME}.xe >> e${EMULATION_NAME}.c
149- echo ' ; else return' >> e${EMULATION_NAME}.c
150- sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
151- echo '; }' >> e${EMULATION_NAME}.c
152-@@ -2431,15 +2464,30 @@ fragment <<EOF
153- && link_info.combreloc
154- && link_info.relro
155- && (link_info.flags & DF_BIND_NOW))
156-- return "ldscripts/${EMULATION_NAME}.xdw";
157-+ {
158-+ if (link_info.relro > 1)
159-+ return "ldscripts/${EMULATION_NAME}.xdwe";
160-+ else
161-+ return "ldscripts/${EMULATION_NAME}.xdw";
162-+ }
163- else if (bfd_link_pie (&link_info)
164- && link_info.combreloc)
165-- return "ldscripts/${EMULATION_NAME}.xdc";
166-+ {
167-+ if (link_info.relro > 1)
168-+ return "ldscripts/${EMULATION_NAME}.xdce";
169-+ else
170-+ return "ldscripts/${EMULATION_NAME}.xdc";
171-+ }
172- EOF
173- fi
174- fragment <<EOF
175- else if (bfd_link_pie (&link_info))
176-- return "ldscripts/${EMULATION_NAME}.xd";
177-+ {
178-+ if (link_info.relro > 1)
179-+ return "ldscripts/${EMULATION_NAME}.xde";
180-+ else
181-+ return "ldscripts/${EMULATION_NAME}.xd";
182-+ }
183- EOF
184- fi
185- if test -n "$GENERATE_SHLIB_SCRIPT" ; then
186-@@ -2447,28 +2495,58 @@ if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
187- fragment <<EOF
188- else if (bfd_link_dll (&link_info) && link_info.combreloc
189- && link_info.relro && (link_info.flags & DF_BIND_NOW))
190-- return "ldscripts/${EMULATION_NAME}.xsw";
191-+ {
192-+ if (link_info.relro > 1)
193-+ return "ldscripts/${EMULATION_NAME}.xswe";
194-+ else
195-+ return "ldscripts/${EMULATION_NAME}.xsw";
196-+ }
197- else if (bfd_link_dll (&link_info) && link_info.combreloc)
198-- return "ldscripts/${EMULATION_NAME}.xsc";
199-+ {
200-+ if (link_info.relro > 1)
201-+ return "ldscripts/${EMULATION_NAME}.xsce";
202-+ else
203-+ return "ldscripts/${EMULATION_NAME}.xsc";
204-+ }
205- EOF
206- fi
207- fragment <<EOF
208- else if (bfd_link_dll (&link_info))
209-- return "ldscripts/${EMULATION_NAME}.xs";
210-+ {
211-+ if (link_info.relro > 1)
212-+ return "ldscripts/${EMULATION_NAME}.xse";
213-+ else
214-+ return "ldscripts/${EMULATION_NAME}.xs";
215-+ }
216- EOF
217- fi
218- if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
219- fragment <<EOF
220- else if (link_info.combreloc && link_info.relro
221- && (link_info.flags & DF_BIND_NOW))
222-- return "ldscripts/${EMULATION_NAME}.xw";
223-+ {
224-+ if (link_info.relro > 1)
225-+ return "ldscripts/${EMULATION_NAME}.xwe";
226-+ else
227-+ return "ldscripts/${EMULATION_NAME}.xw";
228-+ }
229- else if (link_info.combreloc)
230-- return "ldscripts/${EMULATION_NAME}.xc";
231-+ {
232-+ if (link_info.relro > 1)
233-+ return "ldscripts/${EMULATION_NAME}.xce";
234-+ else
235-+ return "ldscripts/${EMULATION_NAME}.xc";
236-+ }
237- EOF
238- fi
239- fragment <<EOF
240- else
241-- return "ldscripts/${EMULATION_NAME}.x";
242-+ {
243-+ if (link_info.relro > 1)
244-+ return "ldscripts/${EMULATION_NAME}.xe";
245-+ else
246-+ return "ldscripts/${EMULATION_NAME}.x";
247-+ }
248- }
249-
250- EOF
251-@@ -2735,9 +2813,13 @@ fragment <<EOF
252- else if (strcmp (optarg, "nocopyreloc") == 0)
253- link_info.nocopyreloc = TRUE;
254- else if (strcmp (optarg, "relro") == 0)
255-- link_info.relro = TRUE;
256-+ link_info.relro |= 1;
257- else if (strcmp (optarg, "norelro") == 0)
258-- link_info.relro = FALSE;
259-+ link_info.relro = 0;
260-+ else if (strcmp (optarg, "textonly") == 0)
261-+ link_info.relro = 2;
262-+ else if (strcmp (optarg, "notextonly") == 0)
263-+ link_info.relro &= 1;
264- else if (strcmp (optarg, "common") == 0)
265- link_info.elf_stt_common = elf_stt_common;
266- else if (strcmp (optarg, "nocommon") == 0)
267-diff --git a/ld/genscripts.sh b/ld/genscripts.sh
268-index 53cd5ad95c..9d4edc04d1 100755
269---- a/ld/genscripts.sh
270-+++ b/ld/genscripts.sh
271-@@ -290,14 +290,20 @@ CONSTRUCTING=" "
272- . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
273- ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xu
274-
275--LD_FLAG=
276- DATA_ALIGNMENT=${DATA_ALIGNMENT_}
277- RELOCATING=" "
278-+LD_FLAG=
279- ( echo "/* Default linker script, for normal executables */"
280- . ${CUSTOMIZER_SCRIPT}
281- . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
282- ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.x
283-
284-+LD_FLAG=textonly
285-+( echo "/* Script for -z textonly: generate normal executables with text-only segment */"
286-+ . ${CUSTOMIZER_SCRIPT}
287-+ . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
288-+) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xe
289-+
290- LD_FLAG=n
291- DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
292- ( echo "/* Script for -n: mix text and data on same page */"
293-@@ -321,44 +327,78 @@ if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
294- . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
295- ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xc
296- rm -f ${COMBRELOC}
297-- LD_FLAG=w
298-+ LD_FLAG=ctextonly
299-+ COMBRELOC=ldscripts/${EMULATION_NAME}.xce.tmp
300-+ ( echo "/* Script for -z combreloc -z textonly: combine and sort reloc sections with text-only segment */"
301-+ . ${CUSTOMIZER_SCRIPT}
302-+ . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
303-+ ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xce
304-+ rm -f ${COMBRELOC}
305- RELRO_NOW=" "
306-+ LD_FLAG=w
307- COMBRELOC=ldscripts/${EMULATION_NAME}.xw.tmp
308- ( echo "/* Script for -z combreloc -z now -z relro: combine and sort reloc sections */"
309- . ${CUSTOMIZER_SCRIPT}
310- . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
311- ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xw
312- rm -f ${COMBRELOC}
313-+ LD_FLAG=wtextonly
314-+ COMBRELOC=ldscripts/${EMULATION_NAME}.xwe.tmp
315-+ ( echo "/* Script for -z combreloc -z now -z relro -z textonly: combine and sort reloc sections with text-only segment */"
316-+ . ${CUSTOMIZER_SCRIPT}
317-+ . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
318-+ ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xwe
319-+ rm -f ${COMBRELOC}
320- COMBRELOC=
321- unset RELRO_NOW
322- fi
323-
324- if test -n "$GENERATE_SHLIB_SCRIPT"; then
325-- LD_FLAG=shared
326- DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
327- CREATE_SHLIB=" "
328-+ LD_FLAG=shared
329- (
330- echo "/* Script for ld --shared: link shared library */"
331- . ${CUSTOMIZER_SCRIPT}
332- . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
333- ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xs
334-+ LD_FLAG=sharedtextonly
335-+ (
336-+ echo "/* Script for ld --shared -z textonly: link shared library with text-only segment */"
337-+ . ${CUSTOMIZER_SCRIPT}
338-+ . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
339-+ ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xse
340- if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
341-- LD_FLAG=cshared
342- DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
343-+ LD_FLAG=cshared
344- COMBRELOC=ldscripts/${EMULATION_NAME}.xsc.tmp
345- ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */"
346- . ${CUSTOMIZER_SCRIPT}
347- . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
348- ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc
349- rm -f ${COMBRELOC}
350-- LD_FLAG=wshared
351-+ LD_FLAG=csharedtextonly
352-+ COMBRELOC=ldscripts/${EMULATION_NAME}.xsce.tmp
353-+ ( echo "/* Script for --shared -z combreloc -z textonly: shared library, combine & sort relocs with text-only segment */"
354-+ . ${CUSTOMIZER_SCRIPT}
355-+ . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
356-+ ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsce
357-+ rm -f ${COMBRELOC}
358- RELRO_NOW=" "
359-+ LD_FLAG=wshared
360- COMBRELOC=ldscripts/${EMULATION_NAME}.xsw.tmp
361- ( echo "/* Script for --shared -z combreloc -z now -z relro: shared library, combine & sort relocs */"
362- . ${CUSTOMIZER_SCRIPT}
363- . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
364- ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsw
365- rm -f ${COMBRELOC}
366-+ LD_FLAG=wsharedtextonly
367-+ COMBRELOC=ldscripts/${EMULATION_NAME}.xswe.tmp
368-+ ( echo "/* Script for --shared -z combreloc -z now -z relro -z textonly: shared library, combine & sort relocs with text-only segment */"
369-+ . ${CUSTOMIZER_SCRIPT}
370-+ . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
371-+ ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xswe
372-+ rm -f ${COMBRELOC}
373- COMBRELOC=
374- unset RELRO_NOW
375- fi
376-@@ -366,31 +406,51 @@ if test -n "$GENERATE_SHLIB_SCRIPT"; then
377- fi
378-
379- if test -n "$GENERATE_PIE_SCRIPT"; then
380-- LD_FLAG=pie
381- DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
382- CREATE_PIE=" "
383-+ LD_FLAG=pie
384- (
385- echo "/* Script for ld -pie: link position independent executable */"
386- . ${CUSTOMIZER_SCRIPT}
387- . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
388- ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xd
389-+ LD_FLAG=pietextonly
390-+ (
391-+ echo "/* Script for ld -pie -z textonly: link position independent executable with text-only segment */"
392-+ . ${CUSTOMIZER_SCRIPT}
393-+ . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
394-+ ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xde
395- if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
396-- LD_FLAG=cpie
397- DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
398- COMBRELOC=ldscripts/${EMULATION_NAME}.xdc.tmp
399-+ LD_FLAG=cpie
400- ( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */"
401- . ${CUSTOMIZER_SCRIPT}
402- . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
403- ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdc
404- rm -f ${COMBRELOC}
405-- LD_FLAG=wpie
406-+ LD_FLAG=cpietextonly
407-+ COMBRELOC=ldscripts/${EMULATION_NAME}.xdce.tmp
408-+ ( echo "/* Script for -pie -z combreloc -z textonly: position independent executable, combine & sort relocs with text-only segment */"
409-+ . ${CUSTOMIZER_SCRIPT}
410-+ . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
411-+ ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdce
412-+ rm -f ${COMBRELOC}
413- RELRO_NOW=" "
414-+ LD_FLAG=wpie
415- COMBRELOC=ldscripts/${EMULATION_NAME}.xdw.tmp
416- ( echo "/* Script for -pie -z combreloc -z now -z relro: position independent executable, combine & sort relocs */"
417- . ${CUSTOMIZER_SCRIPT}
418- . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
419- ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdw
420- rm -f ${COMBRELOC}
421-+ LD_FLAG=wpietextonly
422-+ COMBRELOC=ldscripts/${EMULATION_NAME}.xdwe.tmp
423-+ ( echo "/* Script for -pie -z combreloc -z now -z relro -z textonly: position independent executable, combine & sort relocs with text-only segment */"
424-+ . ${CUSTOMIZER_SCRIPT}
425-+ . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
426-+ ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdwe
427-+ rm -f ${COMBRELOC}
428- COMBRELOC=
429- unset RELRO_NOW
430- fi
431-diff --git a/ld/ld.texinfo b/ld/ld.texinfo
432-index 14788884cc..88f0f9b27f 100644
433---- a/ld/ld.texinfo
434-+++ b/ld/ld.texinfo
435-@@ -1262,7 +1262,15 @@ Create an ELF @code{PT_GNU_RELRO} segment header in the object. This
436- specifies a memory segment that should be made read-only after
437- relocation, if supported. Specifying @samp{common-page-size} smaller
438- than the system page size will render this protection ineffective.
439--Don't create an ELF @code{PT_GNU_RELRO} segment if @samp{norelro}.
440-+Don't create an ELF @code{PT_GNU_RELRO} segment if @samp{norelro} is
441-+used, which also implies @option{-z notextonly}.
442-+
443-+@item textonly
444-+@itemx notextonly
445-+Create an ELF text-only @code{PT_LOAD} segment header in the object.
446-+This specifies a memory segment that should contain only instructions.
447-+This option also implies @option{-z relro}. Don't create an ELF
448-+text-only @code{PT_LOAD} segment if @samp{notext} is used.
449-
450- @item shstk
451- Generate GNU_PROPERTY_X86_FEATURE_1_SHSTK in .note.gnu.property section
452-diff --git a/ld/lexsup.c b/ld/lexsup.c
453-index cb9edaf7a6..9e977c88fc 100644
454---- a/ld/lexsup.c
455-+++ b/ld/lexsup.c
456-@@ -1780,14 +1780,18 @@ elf_shlib_list_options (FILE *file)
457- fprintf (file, _("\
458- -z relro Create RELRO program header (default)\n"));
459- fprintf (file, _("\
460-- -z norelro Don't create RELRO program header\n"));
461-+ -z norelro Don't create RELRO nor text-only LOAD program header\n"));
462- #else
463- fprintf (file, _("\
464- -z relro Create RELRO program header\n"));
465- fprintf (file, _("\
466-- -z norelro Don't create RELRO program header (default)\n"));
467-+ -z norelro Don't create RELRO nor text-only LOAD program header (default)\n"));
468- #endif
469- fprintf (file, _("\
470-+ -z textonly Create RELRO and text-only LOAD program header\n"));
471-+ fprintf (file, _("\
472-+ -z notextonly Don't create text-only LOAD program header (default)\n"));
473-+ fprintf (file, _("\
474- -z common Generate common symbols with STT_COMMON type\n"));
475- fprintf (file, _("\
476- -z nocommon Generate common symbols with STT_OBJECT type\n"));
477---
478-2.13.6
479-
--- a/patches/0002-ld-Add-TEXT_SEGMENT_ALIGN-TEXT_SEGMENT_-RELRO_-END.patch
+++ /dev/null
@@ -1,410 +0,0 @@
1-From e7528d011919097b241c86a5e3adc776219dbec8 Mon Sep 17 00:00:00 2001
2-From: "H.J. Lu" <hjl.tools@gmail.com>
3-Date: Fri, 10 Nov 2017 13:53:20 -0800
4-Subject: [PATCH 2/6] ld: Add TEXT_SEGMENT_ALIGN/TEXT_SEGMENT_{RELRO_}END
5-
6-Text-only LOAD segment has the same requirement for segment alignment
7-and page sizes as GNU_RELRO segment. But for GNU_RELRO segment, the
8-segment may not end at the same address of the end of data segment. But
9-text-only LOAD segment is exactly the same as text LOAD segment.
10-
11-This patch adds TEXT_SEGMENT_ALIGN, TEXT_SEGMENT_RELRO_END and
12-TEXT_SEGMENT_END, which mimic DATA_SEGMENT_ALIGN, DATA_SEGMENT_RELRO_END
13-and DATA_SEGMENT_END. They work on text segment, instead of data
14-segment. TEXT_SEGMENT_ALIGN is placed at the start of text sections.
15-Both TEXT_SEGMENT_RELRO_END and TEXT_SEGMENT_END are placed at the end
16-of text sections. TEXT_SEGMENT_ALIGN is created from DATA_SEGMENT_ALIGN
17-by replacing DATA_SEGMENT_ALIGN with TEXT_SEGMENT_ALIGN. It simply sets
18-text_start and text_end from TEXT_SEGMENT_ALIGN, TEXT_SEGMENT_RELRO_END
19-and TEXT_SEGMENT_END the same way as relro_start and relro_end are set
20-from DATA_SEGMENT_ALIGN, DATA_SEGMENT_RELRO_END and DATA_SEGMENT_END.
21-
22-include/
23-
24- PR ld/22393
25- * bfdlink.h (bfd_link_info): Add text_start and text_end.
26-
27-ld/
28-
29- PR ld/22393
30- * ldexp.c (exp_print_token): Add TEXT_SEGMENT_ALIGN,
31- TEXT_SEGMENT_RELRO_END and TEXT_SEGMENT_END.
32- (fold_unary): Handle TEXT_SEGMENT_END.
33- (fold_binary): Handle TEXT_SEGMENT_RELRO_END and
34- TEXT_SEGMENT_END.
35- (exp_unop): Also check TEXT_SEGMENT_END.
36- * ldexp.h (ldexp_control): Add textseg.
37- * ldgram.y: Handle TEXT_SEGMENT_ALIGN, TEXT_SEGMENT_RELRO_END
38- and TEXT_SEGMENT_END.
39- * ldlang.c (strip_excluded_output_sections): Also set
40- expld.textseg.phase to exp_seg_none.
41- (lang_size_sections_1): Also call ldlang_check_relro_region with
42- &expld.textseg.
43- (lang_size_relro_segment): Also handle expld.textseg.
44- (lang_size_sections): Also handle expld.textseg. Set
45- link_info.text_start and link_info.text_end for -z textonly.
46- (lang_find_relro_sections): Also check expld.textseg.
47- * ldlex.l: Add TEXT_SEGMENT_ALIGN, TEXT_SEGMENT_RELRO_END and
48- TEXT_SEGMENT_END.
49- * scripttempl/elf.sc (TEXT_SEGMENT_ALIGN): New.
50- (TEXT_SEGMENT_RELRO_END): Likewise.
51- (TEXT_SEGMENT_END): Likewise.
52- Add ${TEXT_SEGMENT_ALIGN} before text sections and add
53- ${TEXT_SEGMENT_RELRO_END}/${TEXT_SEGMENT_END} after text
54- sections for non-relocatable link.
55----
56- include/bfdlink.h | 3 ++
57- ld/ldexp.c | 18 ++++++++-
58- ld/ldexp.h | 3 ++
59- ld/ldgram.y | 7 ++++
60- ld/ldlang.c | 109 +++++++++++++++++++++++++++++++++++++-------------
61- ld/ldlex.l | 3 ++
62- ld/scripttempl/elf.sc | 21 ++++++++++
63- 7 files changed, 135 insertions(+), 29 deletions(-)
64-
65-diff --git a/include/bfdlink.h b/include/bfdlink.h
66-index d283429fdb..2fdfb2ab71 100644
67---- a/include/bfdlink.h
68-+++ b/include/bfdlink.h
69-@@ -626,6 +626,9 @@ struct bfd_link_info
70- /* May be used to set DT_FLAGS_1 for ELF. */
71- bfd_vma flags_1;
72-
73-+ /* Start and end of text-only region. */
74-+ bfd_vma text_start, text_end;
75-+
76- /* Start and end of RELRO region. */
77- bfd_vma relro_start, relro_end;
78-
79-diff --git a/ld/ldexp.c b/ld/ldexp.c
80-index 83d9f8f2a7..71051ceb19 100644
81---- a/ld/ldexp.c
82-+++ b/ld/ldexp.c
83-@@ -134,6 +134,9 @@ exp_print_token (token_code_type code, int infix_p)
84- { DATA_SEGMENT_ALIGN, "DATA_SEGMENT_ALIGN" },
85- { DATA_SEGMENT_RELRO_END, "DATA_SEGMENT_RELRO_END" },
86- { DATA_SEGMENT_END, "DATA_SEGMENT_END" },
87-+ { TEXT_SEGMENT_ALIGN, "TEXT_SEGMENT_ALIGN" },
88-+ { TEXT_SEGMENT_RELRO_END, "TEXT_SEGMENT_RELRO_END" },
89-+ { TEXT_SEGMENT_END, "TEXT_SEGMENT_END" },
90- { ORIGIN, "ORIGIN" },
91- { LENGTH, "LENGTH" },
92- { SEGMENT_START, "SEGMENT_START" }
93-@@ -416,6 +419,10 @@ fold_unary (etree_type *tree)
94- fold_segment_end (&expld.dataseg);
95- break;
96-
97-+ case TEXT_SEGMENT_END:
98-+ fold_segment_end (&expld.textseg);
99-+ break;
100-+
101- default:
102- FAIL ();
103- break;
104-@@ -664,6 +671,14 @@ fold_binary (etree_type *tree)
105- fold_segment_relro_end (&expld.dataseg, &lhs);
106- break;
107-
108-+ case TEXT_SEGMENT_ALIGN:
109-+ fold_segment_align (&expld.textseg, &lhs);
110-+ break;
111-+
112-+ case TEXT_SEGMENT_RELRO_END:
113-+ fold_segment_relro_end (&expld.textseg, &lhs);
114-+ break;
115-+
116- default:
117- FAIL ();
118- }
119-@@ -1342,7 +1357,8 @@ exp_unop (int code, etree_type *child)
120- && code != ALIGN_K
121- && code != ABSOLUTE
122- && code != NEXT
123-- && code != DATA_SEGMENT_END)
124-+ && code != DATA_SEGMENT_END
125-+ && code != TEXT_SEGMENT_END)
126- exp_value_fold (new_e);
127- return new_e;
128- }
129-diff --git a/ld/ldexp.h b/ld/ldexp.h
130-index 5ff0fa0a1f..d1429353e1 100644
131---- a/ld/ldexp.h
132-+++ b/ld/ldexp.h
133-@@ -173,6 +173,9 @@ struct ldexp_control {
134-
135- /* State machine and results for DATASEG. */
136- seg_align_type dataseg;
137-+
138-+ /* State machine and results for TEXTSEG. */
139-+ seg_align_type textseg;
140- };
141-
142- extern struct ldexp_control expld;
143-diff --git a/ld/ldgram.y b/ld/ldgram.y
144-index d701e076a2..53da2d062a 100644
145---- a/ld/ldgram.y
146-+++ b/ld/ldgram.y
147-@@ -127,6 +127,7 @@ static int error_index;
148- %token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE
149- %token SECTIONS PHDRS INSERT_K AFTER BEFORE
150- %token DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END DATA_SEGMENT_END
151-+%token TEXT_SEGMENT_ALIGN TEXT_SEGMENT_RELRO_END TEXT_SEGMENT_END
152- %token SORT_BY_NAME SORT_BY_ALIGNMENT SORT_NONE
153- %token SORT_BY_INIT_PRIORITY
154- %token '{' '}'
155-@@ -993,6 +994,12 @@ exp :
156- { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); }
157- | DATA_SEGMENT_END '(' exp ')'
158- { $$ = exp_unop (DATA_SEGMENT_END, $3); }
159-+ | TEXT_SEGMENT_ALIGN '(' exp ',' exp ')'
160-+ { $$ = exp_binop (TEXT_SEGMENT_ALIGN, $3, $5); }
161-+ | TEXT_SEGMENT_RELRO_END '(' exp ',' exp ')'
162-+ { $$ = exp_binop (TEXT_SEGMENT_RELRO_END, $5, $3); }
163-+ | TEXT_SEGMENT_END '(' exp ')'
164-+ { $$ = exp_unop (TEXT_SEGMENT_END, $3); }
165- | SEGMENT_START '(' NAME ',' exp ')'
166- { /* The operands to the expression node are
167- placed in the opposite order from the way
168-diff --git a/ld/ldlang.c b/ld/ldlang.c
169-index 674004ee38..ea45bc5639 100644
170---- a/ld/ldlang.c
171-+++ b/ld/ldlang.c
172-@@ -3891,6 +3891,7 @@ strip_excluded_output_sections (void)
173- {
174- expld.phase = lang_mark_phase_enum;
175- expld.dataseg.phase = exp_seg_none;
176-+ expld.textseg.phase = exp_seg_none;
177- one_lang_size_sections_pass (NULL, FALSE);
178- lang_reset_memory_regions ();
179- }
180-@@ -5450,14 +5451,17 @@ lang_size_sections_1
181- bfd_vma newdot = dot;
182- etree_type *tree = s->assignment_statement.exp;
183-
184-+ expld.textseg.relro = exp_seg_relro_none;
185- expld.dataseg.relro = exp_seg_relro_none;
186-
187- exp_fold_tree (tree,
188- output_section_statement->bfd_section,
189- &newdot);
190-
191-+ ldlang_check_relro_region (s, &expld.textseg);
192- ldlang_check_relro_region (s, &expld.dataseg);
193-
194-+ expld.textseg.relro = exp_seg_relro_none;
195- expld.dataseg.relro = exp_seg_relro_none;
196-
197- /* This symbol may be relative to this section. */
198-@@ -5664,35 +5668,56 @@ static bfd_boolean
199- lang_size_relro_segment (bfd_boolean *relax, bfd_boolean check_regions)
200- {
201- bfd_boolean do_reset = FALSE;
202-- bfd_boolean do_data_relro;
203-- bfd_vma data_initial_base, data_relro_end;
204-+ bfd_boolean do_text_relro = FALSE;
205-+ bfd_boolean do_data_relro = FALSE;
206-
207-- if (link_info.relro && expld.dataseg.relro_end)
208-+ if (link_info.relro)
209- {
210-- do_data_relro = TRUE;
211-- data_initial_base = expld.dataseg.base;
212-- data_relro_end = lang_size_relro_segment_1 (&expld.dataseg);
213-- }
214-- else
215-- {
216-- do_data_relro = FALSE;
217-- data_initial_base = data_relro_end = 0;
218-- }
219-+ bfd_vma text_initial_base, text_relro_end;
220-+ bfd_vma data_initial_base, data_relro_end;
221-
222-- if (do_data_relro)
223-- {
224-- lang_reset_memory_regions ();
225-- one_lang_size_sections_pass (relax, check_regions);
226-+ if (link_info.relro > 1 && expld.textseg.relro_end)
227-+ {
228-+ do_text_relro = TRUE;
229-+ text_initial_base = expld.textseg.base;
230-+ text_relro_end = lang_size_relro_segment_1 (&expld.textseg);
231-+ }
232-+ else
233-+ text_initial_base = text_relro_end = 0;
234-
235-- /* Assignments to dot, or to output section address in a user
236-- script have increased padding over the original. Revert. */
237-- if (do_data_relro && expld.dataseg.relro_end > data_relro_end)
238-+ if (expld.dataseg.relro_end)
239- {
240-- expld.dataseg.base = data_initial_base;;
241-- do_reset = TRUE;
242-+ do_data_relro = TRUE;
243-+ data_initial_base = expld.dataseg.base;
244-+ data_relro_end = lang_size_relro_segment_1 (&expld.dataseg);
245-+ }
246-+ else
247-+ data_initial_base = data_relro_end = 0;
248-+
249-+ if (do_text_relro || do_data_relro)
250-+ {
251-+ lang_reset_memory_regions ();
252-+ one_lang_size_sections_pass (relax, check_regions);
253-+
254-+ /* Assignments to dot, or to output section address in a user
255-+ script have increased padding over the original. Revert. */
256-+ if (do_text_relro && expld.textseg.relro_end > text_relro_end)
257-+ {
258-+ expld.textseg.base = text_initial_base;
259-+ do_reset = TRUE;
260-+ }
261-+
262-+ if (do_data_relro && expld.dataseg.relro_end > data_relro_end)
263-+ {
264-+ expld.dataseg.base = data_initial_base;;
265-+ do_reset = TRUE;
266-+ }
267- }
268- }
269-
270-+ if (!do_text_relro && lang_size_segment (&expld.textseg))
271-+ do_reset = TRUE;
272-+
273- if (!do_data_relro && lang_size_segment (&expld.dataseg))
274- do_reset = TRUE;
275-
276-@@ -5704,13 +5729,17 @@ lang_size_sections (bfd_boolean *relax, bfd_boolean check_regions)
277- {
278- expld.phase = lang_allocating_phase_enum;
279- expld.dataseg.phase = exp_seg_none;
280-+ expld.textseg.phase = exp_seg_none;
281-
282- one_lang_size_sections_pass (relax, check_regions);
283-
284-+ if (expld.textseg.phase != exp_seg_end_seen)
285-+ expld.textseg.phase = exp_seg_done;
286- if (expld.dataseg.phase != exp_seg_end_seen)
287- expld.dataseg.phase = exp_seg_done;
288-
289-- if (expld.dataseg.phase == exp_seg_end_seen)
290-+ if (expld.textseg.phase == exp_seg_end_seen
291-+ || expld.dataseg.phase == exp_seg_end_seen)
292- {
293- bfd_boolean do_reset
294- = lang_size_relro_segment (relax, check_regions);
295-@@ -5721,6 +5750,12 @@ lang_size_sections (bfd_boolean *relax, bfd_boolean check_regions)
296- one_lang_size_sections_pass (relax, check_regions);
297- }
298-
299-+ if (link_info.relro > 1 && expld.textseg.relro_end)
300-+ {
301-+ link_info.text_start = expld.textseg.base;
302-+ link_info.text_end = expld.textseg.relro_end;
303-+ }
304-+
305- if (link_info.relro && expld.dataseg.relro_end)
306- {
307- link_info.relro_start = expld.dataseg.base;
308-@@ -6906,15 +6941,33 @@ lang_find_relro_sections_1 (lang_statement_union_type *s,
309- static void
310- lang_find_relro_sections (void)
311- {
312-- bfd_boolean has_relro_section = FALSE;
313--
314- /* Check all sections in the link script. */
315-+ if (link_info.relro)
316-+ {
317-+ bfd_boolean has_relro_section;
318-
319-- lang_find_relro_sections_1 (expld.dataseg.relro_start_stat,
320-- &expld.dataseg, &has_relro_section);
321-+ if (link_info.relro > 1)
322-+ {
323-+ has_relro_section = FALSE;
324-+ lang_find_relro_sections_1 (expld.textseg.relro_start_stat,
325-+ &expld.textseg,
326-+ &has_relro_section);
327-+ if (!has_relro_section)
328-+ link_info.relro = 1;
329-+ }
330-
331-- if (!has_relro_section)
332-- link_info.relro = FALSE;
333-+ /* We can't turn off RELRO if we need to generate read-only
334-+ PT_LOAD segment. */
335-+ if (link_info.relro == 1)
336-+ {
337-+ has_relro_section = FALSE;
338-+ lang_find_relro_sections_1 (expld.dataseg.relro_start_stat,
339-+ &expld.dataseg,
340-+ &has_relro_section);
341-+ if (!has_relro_section)
342-+ link_info.relro = 0;
343-+ }
344-+ }
345- }
346-
347- /* Relax all sections until bfd_relax_section gives up. */
348-diff --git a/ld/ldlex.l b/ld/ldlex.l
349-index 207c97f323..538c372a0f 100644
350---- a/ld/ldlex.l
351-+++ b/ld/ldlex.l
352-@@ -250,6 +250,9 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
353- <EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_ALIGN" { RTOKEN(DATA_SEGMENT_ALIGN);}
354- <EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_RELRO_END" { RTOKEN(DATA_SEGMENT_RELRO_END);}
355- <EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_END" { RTOKEN(DATA_SEGMENT_END);}
356-+<EXPRESSION,BOTH,SCRIPT>"TEXT_SEGMENT_ALIGN" { RTOKEN(TEXT_SEGMENT_ALIGN);}
357-+<EXPRESSION,BOTH,SCRIPT>"TEXT_SEGMENT_RELRO_END" { RTOKEN(TEXT_SEGMENT_RELRO_END);}
358-+<EXPRESSION,BOTH,SCRIPT>"TEXT_SEGMENT_END" { RTOKEN(TEXT_SEGMENT_END);}
359- <EXPRESSION,BOTH,SCRIPT>"ADDR" { RTOKEN(ADDR);}
360- <EXPRESSION,BOTH,SCRIPT>"LOADADDR" { RTOKEN(LOADADDR);}
361- <EXPRESSION,BOTH,SCRIPT>"ALIGNOF" { RTOKEN(ALIGNOF); }
362-diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc
363-index 9f291b359f..9eb024e809 100644
364---- a/ld/scripttempl/elf.sc
365-+++ b/ld/scripttempl/elf.sc
366-@@ -139,6 +139,23 @@ if test -z "$DATA_SEGMENT_ALIGN"; then
367- DATA_SEGMENT_RELRO_END=". = DATA_SEGMENT_RELRO_END (${SEPARATE_GOTPLT-0}, .);"
368- fi
369- fi
370-+# Don't bother with text-only segment when there are data sections between
371-+# .plt and .text.
372-+if test -n "$TINY_READONLY_SECTION"; then
373-+ TEXT_SEGMENT_ALIGN=" "
374-+ TEXT_SEGMENT_RELRO_END=" "
375-+ TEXT_SEGMENT_END=" "
376-+fi
377-+if test -z "$TEXT_SEGMENT_ALIGN" && test -n "$DATA_SEGMENT_ALIGN"; then
378-+ case "$LD_FLAG" in
379-+ *textonly*)
380-+ TEXT_SEGMENT_ALIGN=`echo $DATA_SEGMENT_ALIGN | sed -e "s/DATA/TEXT/g"`
381-+ TEXT_SEGMENT_ALIGN=". = $TEXT_SEGMENT_ALIGN;"
382-+ TEXT_SEGMENT_RELRO_END=". = TEXT_SEGMENT_RELRO_END (0, .);"
383-+ TEXT_SEGMENT_END=". = TEXT_SEGMENT_END (.);"
384-+ ;;
385-+ esac
386-+fi
387- if test -z "${INITIAL_READONLY_SECTIONS}${CREATE_SHLIB}"; then
388- INITIAL_READONLY_SECTIONS=".interp ${RELOCATING-0} : { *(.interp) }"
389- fi
390-@@ -478,6 +495,8 @@ emit_dyn()
391- test -n "${NON_ALLOC_DYN}${SEPARATE_CODE}" || emit_dyn
392-
393- cat <<EOF
394-+ ${RELOCATING+${TEXT_SEGMENT_ALIGN}}
395-+
396- .init ${RELOCATING-0}${RELOCATING+${INIT_ADDR}} :
397- {
398- ${RELOCATING+${INIT_START}}
399-@@ -508,6 +527,8 @@ cat <<EOF
400- ${RELOCATING+PROVIDE (__${ETEXT_NAME} = .);}
401- ${RELOCATING+PROVIDE (_${ETEXT_NAME} = .);}
402- ${RELOCATING+PROVIDE (${ETEXT_NAME} = .);}
403-+ ${RELOCATING+${TEXT_SEGMENT_RELRO_END}}
404-+ ${RELOCATING+${TEXT_SEGMENT_END}}
405- EOF
406-
407- if test -n "${SEPARATE_CODE}"; then
408---
409-2.13.6
410-
--- a/patches/0003-ld-Create-a-new-LOAD-segment-for-text-only-LOAD-segm.patch
+++ /dev/null
@@ -1,161 +0,0 @@
1-From cc2bcf62719bc5cf63105843ced20d0952667142 Mon Sep 17 00:00:00 2001
2-From: "H.J. Lu" <hjl.tools@gmail.com>
3-Date: Sun, 12 Nov 2017 11:34:03 -0800
4-Subject: [PATCH 3/6] ld: Create a new LOAD segment for text-only LOAD segment
5-
6-When there is a text-only LOAD segment, create a new LOAD segment if the
7-previous section contains text and the current section doesn't or vice
8-versa:
9-
10-Elf file type is DYN (Shared object file)
11-Entry point 0x200ff0
12-There are 7 program headers, starting at offset 52
13-
14-Program Headers:
15- Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
16- LOAD 0x000000 0x00000000 0x00000000 0x00200 0x00200 R 0x200000
17- LOAD 0x000fd0 0x00200fd0 0x00200fd0 0x0002b 0x0002b R E 0x200000
18- LOAD 0x001000 0x00201000 0x00201000 0x00058 0x00058 R 0x200000
19- LOAD 0x200f80 0x00400f80 0x00400f80 0x000a0 0x000a0 RW 0x200000
20- DYNAMIC 0x200f80 0x00400f80 0x00400f80 0x00080 0x00080 RW 0x4
21- GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x10
22- GNU_RELRO 0x200f80 0x00400f80 0x00400f80 0x00080 0x00080 R 0x1
23-
24- Section to Segment mapping:
25- Segment Sections...
26- 00 .hash .gnu.hash .dynsym .dynstr .rela.plt
27- 01 .plt .text
28- 02 .rodata .eh_frame
29- 03 .dynamic .got.plt
30- 04 .dynamic
31- 05
32- 06 .dynamic
33-
34-This is to prevent executing data in read-only sections as instructions.
35-
36-Also don't put a writable section in a read-only segment if there is a
37-RELRO segment.
38-
39-Since there are more than 2 LOAD segments, the minimum file size is
40-bigger than the maximum page size which is 2MB (0x200000):
41-
42--rwxr-xr-x 1 hjl hjl 2104892 Nov 12 11:53 libfoo.so
43-
44-"-z max-page-size=0x1000" can be used to reduce the maximum page size to
45-4KB (0x1000):
46-
47--rwxr-xr-x 1 hjl hjl 11836 Nov 12 13:22 libfoo.so
48-
49-Elf file type is DYN (Shared object file)
50-Entry point 0x1ff0
51-There are 7 program headers, starting at offset 52
52-
53-Program Headers:
54- Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
55- LOAD 0x000000 0x00000000 0x00000000 0x00200 0x00200 R 0x1000
56- LOAD 0x000fd0 0x00001fd0 0x00001fd0 0x0002b 0x0002b R E 0x1000
57- LOAD 0x001000 0x00002000 0x00002000 0x00058 0x00058 R 0x1000
58- LOAD 0x001f80 0x00002f80 0x00002f80 0x000a0 0x000a0 RW 0x1000
59- DYNAMIC 0x001f80 0x00002f80 0x00002f80 0x00080 0x00080 RW 0x4
60- GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x10
61- GNU_RELRO 0x001f80 0x00002f80 0x00002f80 0x00080 0x00080 R 0x1
62-
63- Section to Segment mapping:
64- Segment Sections...
65- 00 .hash .gnu.hash .dynsym .dynstr .rela.plt
66- 01 .plt .text
67- 02 .rodata .eh_frame
68- 03 .dynamic .got.plt
69- 04 .dynamic
70- 05
71- 06 .dynamic
72-
73- PR ld/22393
74- * elf.c (_bfd_elf_map_sections_to_segments): When there is a
75- text-only LOAD segment, create a new LOAD segment if the
76- previous section contains text and the current section doesn't
77- or vice versa. Don't put a writable section in a read-only
78- segment if there is a RELRO segment.
79----
80- bfd/elf.c | 32 +++++++++++++++++++++++++-------
81- 1 file changed, 25 insertions(+), 7 deletions(-)
82-
83-diff --git a/bfd/elf.c b/bfd/elf.c
84-index 694e43540f..9c5de9675c 100644
85---- a/bfd/elf.c
86-+++ b/bfd/elf.c
87-@@ -4555,6 +4555,7 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)
88- asection **hdrpp;
89- bfd_boolean phdr_in_segment = TRUE;
90- bfd_boolean writable;
91-+ bfd_boolean executable;
92- int tls_count = 0;
93- asection *first_tls = NULL;
94- asection *first_mbind = NULL;
95-@@ -4643,6 +4644,7 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)
96- if (maxpagesize == 0)
97- maxpagesize = 1;
98- writable = FALSE;
99-+ executable = FALSE;
100- dynsec = bfd_get_section_by_name (abfd, ".dynamic");
101- if (dynsec != NULL
102- && (dynsec->flags & SEC_LOAD) == 0)
103-@@ -4745,18 +4747,27 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)
104- file, then there is no other reason for a new segment. */
105- new_segment = FALSE;
106- }
107-+ else if (info != NULL
108-+ && info->text_end > info->text_start
109-+ && executable != ((hdr->flags & SEC_CODE) != 0))
110-+ {
111-+ new_segment = TRUE;
112-+ }
113- else if (! writable
114- && (hdr->flags & SEC_READONLY) == 0
115-- && (((last_hdr->lma + last_size - 1) & -maxpagesize)
116-- != (hdr->lma & -maxpagesize)))
117-+ && ((info != NULL
118-+ && info->relro_end > info->relro_start)
119-+ || (((last_hdr->lma + last_size - 1) & -maxpagesize)
120-+ != (hdr->lma & -maxpagesize))))
121- {
122- /* We don't want to put a writable section in a read only
123- segment, unless they are on the same page in memory
124-- anyhow. We already know that the last section does not
125-- bring us past the current section on the page, so the
126-- only case in which the new section is not on the same
127-- page as the previous section is when the previous section
128-- ends precisely on a page boundary. */
129-+ anyhow and there is no RELRO segment. We already
130-+ know that the last section does not bring us past the
131-+ current section on the page, so the only case in which
132-+ the new section is not on the same page as the previous
133-+ section is when the previous section ends precisely on
134-+ a page boundary. */
135- new_segment = TRUE;
136- }
137- else
138-@@ -4778,6 +4789,8 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)
139- {
140- if ((hdr->flags & SEC_READONLY) == 0)
141- writable = TRUE;
142-+ if ((hdr->flags & SEC_CODE) != 0)
143-+ executable = TRUE;
144- last_hdr = hdr;
145- /* .tbss sections effectively have zero size. */
146- if ((hdr->flags & (SEC_THREAD_LOCAL | SEC_LOAD))
147-@@ -4803,6 +4816,11 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)
148- else
149- writable = FALSE;
150-
151-+ if ((hdr->flags & SEC_CODE) == 0)
152-+ executable = FALSE;
153-+ else
154-+ executable = TRUE;
155-+
156- last_hdr = hdr;
157- /* .tbss sections effectively have zero size. */
158- if ((hdr->flags & (SEC_THREAD_LOCAL | SEC_LOAD)) != SEC_THREAD_LOCAL)
159---
160-2.13.6
161-
--- a/patches/0004-ld-ppc-spu-Also-set-expld.textseg.phase-to-exp_seg_n.patch
+++ /dev/null
@@ -1,54 +0,0 @@
1-From ab0d66f33a7b3ec2ba54057d3ab3e3b5b76f4975 Mon Sep 17 00:00:00 2001
2-From: "H.J. Lu" <hjl.tools@gmail.com>
3-Date: Mon, 13 Nov 2017 14:30:36 -0800
4-Subject: [PATCH 4/6] ld/ppc/spu: Also set expld.textseg.phase to exp_seg_none
5-
6- * emultempl/ppc32elf.em (ppc_before_allocation): Also set
7- expld.textseg.phase to exp_seg_none.
8- * emultempl/ppc64elf.em (prelim_size_sections): Likewise.
9- * emultempl/spuelf.em (spu_before_allocation): Likewise.
10----
11- ld/emultempl/ppc32elf.em | 1 +
12- ld/emultempl/ppc64elf.em | 1 +
13- ld/emultempl/spuelf.em | 1 +
14- 3 files changed, 3 insertions(+)
15-
16-diff --git a/ld/emultempl/ppc32elf.em b/ld/emultempl/ppc32elf.em
17-index f78a117222..5817fc99c0 100644
18---- a/ld/emultempl/ppc32elf.em
19-+++ b/ld/emultempl/ppc32elf.em
20-@@ -149,6 +149,7 @@ ppc_before_allocation (void)
21- if (expld.phase != lang_mark_phase_enum)
22- {
23- expld.phase = lang_mark_phase_enum;
24-+ expld.textseg.phase = exp_seg_none;
25- expld.dataseg.phase = exp_seg_none;
26- one_lang_size_sections_pass (NULL, FALSE);
27- lang_reset_memory_regions ();
28-diff --git a/ld/emultempl/ppc64elf.em b/ld/emultempl/ppc64elf.em
29-index d6d5b0acf3..131bae7b54 100644
30---- a/ld/emultempl/ppc64elf.em
31-+++ b/ld/emultempl/ppc64elf.em
32-@@ -266,6 +266,7 @@ prelim_size_sections (void)
33- if (expld.phase != lang_mark_phase_enum)
34- {
35- expld.phase = lang_mark_phase_enum;
36-+ expld.textseg.phase = exp_seg_none;
37- expld.dataseg.phase = exp_seg_none;
38- one_lang_size_sections_pass (NULL, FALSE);
39- /* We must not cache anything from the preliminary sizing. */
40-diff --git a/ld/emultempl/spuelf.em b/ld/emultempl/spuelf.em
41-index 8d8aa25d0a..3878086c0d 100644
42---- a/ld/emultempl/spuelf.em
43-+++ b/ld/emultempl/spuelf.em
44-@@ -272,6 +272,7 @@ spu_before_allocation (void)
45- /* Size the sections. This is premature, but we need to know the
46- rough layout so that overlays can be found. */
47- expld.phase = lang_mark_phase_enum;
48-+ expld.textseg.phase = exp_seg_none;
49- expld.dataseg.phase = exp_seg_none;
50- one_lang_size_sections_pass (NULL, TRUE);
51-
52---
53-2.13.6
54-
--- a/patches/0005-ld-Add-tests-for-z-textonly-and-z-notextonly.patch
+++ /dev/null
@@ -1,323 +0,0 @@
1-From 3eab3df1811338c4ee5bc4adafdf6dcd6935f560 Mon Sep 17 00:00:00 2001
2-From: "H.J. Lu" <hjl.tools@gmail.com>
3-Date: Mon, 13 Nov 2017 12:47:38 -0800
4-Subject: [PATCH 5/6] ld: Add tests for -z textonly and -z notextonly
5-
6-Verify that -z textonly works and -z notextonly doesn't disable -z relro.
7-
8- PR ld/22393
9- * testsuite/ld-elf/pr16322.d: Add -z notextonly.
10- * testsuite/ld-elf/pr22393-1.s: New file.
11- * testsuite/ld-elf/pr22393-1a.d: Likewise.
12- * testsuite/ld-elf/pr22393-1b.d: Likewise.
13- * testsuite/ld-elf/pr22393-1c.d: Likewise.
14- * testsuite/ld-elf/pr22393-1d.d: Likewise.
15- * testsuite/ld-elf/pr22393-1e.d: Likewise.
16- * testsuite/ld-elf/pr22393-1f.d: Likewise.
17- * testsuite/ld-elf/pr22393-2a.c: Likewise.
18- * testsuite/ld-elf/pr22393-2a.rd: Likewise.
19- * testsuite/ld-elf/pr22393-2b.c: Likewise.
20- * testsuite/ld-elf/pr22393-2b.rd: Likewise.
21- * testsuite/ld-elf/shared.exp: Run tests for -z textonly.
22----
23- ld/testsuite/ld-elf/pr16322.d | 2 +-
24- ld/testsuite/ld-elf/pr22393-1.s | 21 ++++++++++++
25- ld/testsuite/ld-elf/pr22393-1a.d | 9 +++++
26- ld/testsuite/ld-elf/pr22393-1b.d | 9 +++++
27- ld/testsuite/ld-elf/pr22393-1c.d | 9 +++++
28- ld/testsuite/ld-elf/pr22393-1d.d | 9 +++++
29- ld/testsuite/ld-elf/pr22393-1e.d | 9 +++++
30- ld/testsuite/ld-elf/pr22393-1f.d | 9 +++++
31- ld/testsuite/ld-elf/pr22393-2a.c | 7 ++++
32- ld/testsuite/ld-elf/pr22393-2a.rd | 9 +++++
33- ld/testsuite/ld-elf/pr22393-2b.c | 7 ++++
34- ld/testsuite/ld-elf/pr22393-2b.rd | 9 +++++
35- ld/testsuite/ld-elf/shared.exp | 71 +++++++++++++++++++++++++++++++++++++++
36- 13 files changed, 179 insertions(+), 1 deletion(-)
37- create mode 100644 ld/testsuite/ld-elf/pr22393-1.s
38- create mode 100644 ld/testsuite/ld-elf/pr22393-1a.d
39- create mode 100644 ld/testsuite/ld-elf/pr22393-1b.d
40- create mode 100644 ld/testsuite/ld-elf/pr22393-1c.d
41- create mode 100644 ld/testsuite/ld-elf/pr22393-1d.d
42- create mode 100644 ld/testsuite/ld-elf/pr22393-1e.d
43- create mode 100644 ld/testsuite/ld-elf/pr22393-1f.d
44- create mode 100644 ld/testsuite/ld-elf/pr22393-2a.c
45- create mode 100644 ld/testsuite/ld-elf/pr22393-2a.rd
46- create mode 100644 ld/testsuite/ld-elf/pr22393-2b.c
47- create mode 100644 ld/testsuite/ld-elf/pr22393-2b.rd
48-
49-diff --git a/ld/testsuite/ld-elf/pr16322.d b/ld/testsuite/ld-elf/pr16322.d
50-index 40a7975cb0..497537fbc9 100644
51---- a/ld/testsuite/ld-elf/pr16322.d
52-+++ b/ld/testsuite/ld-elf/pr16322.d
53-@@ -1,4 +1,4 @@
54--#ld: -shared -z relro
55-+#ld: -shared -z relro -z notextonly
56- #readelf: -l --wide
57- #target: *-*-linux-gnu *-*-gnu* *-*-nacl*
58-
59-diff --git a/ld/testsuite/ld-elf/pr22393-1.s b/ld/testsuite/ld-elf/pr22393-1.s
60-new file mode 100644
61-index 0000000000..ffdb620915
62---- /dev/null
63-+++ b/ld/testsuite/ld-elf/pr22393-1.s
64-@@ -0,0 +1,21 @@
65-+ .section .rodata,"a",%progbits
66-+ .globl fx1
67-+ .type fx1, %object
68-+fx1:
69-+ .zero 20
70-+ .section .data.rel.ro,"aw",%progbits
71-+ .globl px1
72-+ .type px1, %object
73-+px1:
74-+ .dc.a fx1
75-+
76-+ .text
77-+ .global start /* Used by SH targets. */
78-+start:
79-+ .global _start
80-+_start:
81-+ .global __start
82-+__start:
83-+ .global main /* Used by HPPA targets. */
84-+main:
85-+ .dc.a 0
86-diff --git a/ld/testsuite/ld-elf/pr22393-1a.d b/ld/testsuite/ld-elf/pr22393-1a.d
87-new file mode 100644
88-index 0000000000..8c5a8da37b
89---- /dev/null
90-+++ b/ld/testsuite/ld-elf/pr22393-1a.d
91-@@ -0,0 +1,9 @@
92-+#source: pr22393-1.s
93-+#ld: -shared -z textonly -z relro
94-+#readelf: -l --wide
95-+#target: *-*-linux-gnu *-*-gnu* *-*-nacl*
96-+
97-+#failif
98-+#...
99-+ +[0-9]+ +.*(\.note|\.gnu|\.hash|\.dyn|\.rel).*\.text.*
100-+#...
101-diff --git a/ld/testsuite/ld-elf/pr22393-1b.d b/ld/testsuite/ld-elf/pr22393-1b.d
102-new file mode 100644
103-index 0000000000..a8dbc39b19
104---- /dev/null
105-+++ b/ld/testsuite/ld-elf/pr22393-1b.d
106-@@ -0,0 +1,9 @@
107-+#source: pr22393-1.s
108-+#ld: -shared -z relro -z textonly
109-+#readelf: -l --wide
110-+#target: *-*-linux-gnu *-*-gnu* *-*-nacl*
111-+
112-+#failif
113-+#...
114-+ +[0-9]+ +.*.text.*(.eh_frame|\.rodata).*
115-+#...
116-diff --git a/ld/testsuite/ld-elf/pr22393-1c.d b/ld/testsuite/ld-elf/pr22393-1c.d
117-new file mode 100644
118-index 0000000000..e69281e4bb
119---- /dev/null
120-+++ b/ld/testsuite/ld-elf/pr22393-1c.d
121-@@ -0,0 +1,9 @@
122-+#source: pr22393-1.s
123-+#ld: -pie -z textonly
124-+#readelf: -l --wide
125-+#target: *-*-linux-gnu *-*-gnu* *-*-nacl*
126-+
127-+#failif
128-+#...
129-+ +[0-9]+ +.*(\.note|\.gnu|\.hash|\.dyn|\.rel).*\.text.*
130-+#...
131-diff --git a/ld/testsuite/ld-elf/pr22393-1d.d b/ld/testsuite/ld-elf/pr22393-1d.d
132-new file mode 100644
133-index 0000000000..83e8c3e4b6
134---- /dev/null
135-+++ b/ld/testsuite/ld-elf/pr22393-1d.d
136-@@ -0,0 +1,9 @@
137-+#source: pr22393-1.s
138-+#ld: -pie -z textonly
139-+#readelf: -l --wide
140-+#target: *-*-linux-gnu *-*-gnu* *-*-nacl*
141-+
142-+#failif
143-+#...
144-+ +[0-9]+ +.*.text.*(.eh_frame|\.rodata).*
145-+#...
146-diff --git a/ld/testsuite/ld-elf/pr22393-1e.d b/ld/testsuite/ld-elf/pr22393-1e.d
147-new file mode 100644
148-index 0000000000..df723921c2
149---- /dev/null
150-+++ b/ld/testsuite/ld-elf/pr22393-1e.d
151-@@ -0,0 +1,9 @@
152-+#source: pr22393-1.s
153-+#ld: -z textonly
154-+#readelf: -l --wide
155-+#target: *-*-linux-gnu *-*-gnu* *-*-nacl*
156-+
157-+#failif
158-+#...
159-+ +[0-9]+ +.*(\.note|\.gnu|\.hash|\.dyn|\.rel).*\.text.*
160-+#...
161-diff --git a/ld/testsuite/ld-elf/pr22393-1f.d b/ld/testsuite/ld-elf/pr22393-1f.d
162-new file mode 100644
163-index 0000000000..3c80e70da1
164---- /dev/null
165-+++ b/ld/testsuite/ld-elf/pr22393-1f.d
166-@@ -0,0 +1,9 @@
167-+#source: pr22393-1.s
168-+#ld: -z textonly
169-+#readelf: -l --wide
170-+#target: *-*-linux-gnu *-*-gnu* *-*-nacl*
171-+
172-+#failif
173-+#...
174-+ +[0-9]+ +.*.text.*(.eh_frame|\.rodata).*
175-+#...
176-diff --git a/ld/testsuite/ld-elf/pr22393-2a.c b/ld/testsuite/ld-elf/pr22393-2a.c
177-new file mode 100644
178-index 0000000000..68fa4a0dd0
179---- /dev/null
180-+++ b/ld/testsuite/ld-elf/pr22393-2a.c
181-@@ -0,0 +1,7 @@
182-+#include <stdio.h>
183-+
184-+void
185-+test()
186-+{
187-+ printf ("PASS\n");
188-+}
189-diff --git a/ld/testsuite/ld-elf/pr22393-2a.rd b/ld/testsuite/ld-elf/pr22393-2a.rd
190-new file mode 100644
191-index 0000000000..b7ba110095
192---- /dev/null
193-+++ b/ld/testsuite/ld-elf/pr22393-2a.rd
194-@@ -0,0 +1,9 @@
195-+#source: pr22393-1.s
196-+#ld: -shared -z textonly
197-+#readelf: -l --wide
198-+#target: *-*-linux-gnu *-*-gnu* *-*-nacl*
199-+
200-+#failif
201-+#...
202-+ +[0-9]+ +.*(\.note|\.gnu|\.hash|\.dyn|\.rel).*\.text.*
203-+#...
204-diff --git a/ld/testsuite/ld-elf/pr22393-2b.c b/ld/testsuite/ld-elf/pr22393-2b.c
205-new file mode 100644
206-index 0000000000..3033809b02
207---- /dev/null
208-+++ b/ld/testsuite/ld-elf/pr22393-2b.c
209-@@ -0,0 +1,7 @@
210-+void test(void);
211-+
212-+int main()
213-+{
214-+ test();
215-+ return 0;
216-+}
217-diff --git a/ld/testsuite/ld-elf/pr22393-2b.rd b/ld/testsuite/ld-elf/pr22393-2b.rd
218-new file mode 100644
219-index 0000000000..b7ba110095
220---- /dev/null
221-+++ b/ld/testsuite/ld-elf/pr22393-2b.rd
222-@@ -0,0 +1,9 @@
223-+#source: pr22393-1.s
224-+#ld: -shared -z textonly
225-+#readelf: -l --wide
226-+#target: *-*-linux-gnu *-*-gnu* *-*-nacl*
227-+
228-+#failif
229-+#...
230-+ +[0-9]+ +.*(\.note|\.gnu|\.hash|\.dyn|\.rel).*\.text.*
231-+#...
232-diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
233-index a40f8e0f59..b382a2591b 100644
234---- a/ld/testsuite/ld-elf/shared.exp
235-+++ b/ld/testsuite/ld-elf/shared.exp
236-@@ -756,6 +756,51 @@ if { [istarget *-*-linux*]
237- {} \
238- "libpr19579.so" \
239- ] \
240-+ [list \
241-+ "Build pr22393-2a.so" \
242-+ "-shared -Wl,-z,textonly" \
243-+ "-fPIC" \
244-+ {pr22393-2a.c} \
245-+ {{readelf -lW pr22393-2a.rd} \
246-+ {readelf -lW pr22393-2b.rd}} \
247-+ "pr22393-2a.so" \
248-+ ] \
249-+ [list \
250-+ "Build pr22393-2a-now.so" \
251-+ "-shared -Wl,-z,textonly,-z,now" \
252-+ "-fPIC" \
253-+ {pr22393-2a.c} \
254-+ {{readelf -lW pr22393-2a.rd} \
255-+ {readelf -lW pr22393-2b.rd}} \
256-+ "pr22393-2a-now.so" \
257-+ ] \
258-+ [list \
259-+ "Build pr22393-2" \
260-+ "$NOPIE_LDFLAGS -Wl,-z,textonly,--no-as-needed tmpdir/pr22393-2a.so" \
261-+ "$NOPIE_CFLAGS" \
262-+ {pr22393-2b.c} \
263-+ {{readelf -lW pr22393-2a.rd} \
264-+ {readelf -lW pr22393-2b.rd}} \
265-+ "pr22393-2" \
266-+ ] \
267-+ [list \
268-+ "Build pr22393-2 (PIE)" \
269-+ "-pie -Wl,-z,textonly,--no-as-needed tmpdir/pr22393-2a-now.so" \
270-+ "-fPIE" \
271-+ {pr22393-2b.c} \
272-+ {{readelf -lW pr22393-2a.rd} \
273-+ {readelf -lW pr22393-2b.rd}} \
274-+ "pr22393-2-pie" \
275-+ ] \
276-+ [list \
277-+ "Build pr22393-2 (static)" \
278-+ "-static -Wl,-z,textonly" \
279-+ "" \
280-+ {pr22393-2a.c pr22393-2b.c} \
281-+ {{readelf -lW pr22393-2a.rd} \
282-+ {readelf -lW pr22393-2b.rd}} \
283-+ "pr22393-2-static" \
284-+ ] \
285- ]
286- run_ld_link_exec_tests [list \
287- [list \
288-@@ -893,6 +938,32 @@ if { [istarget *-*-linux*]
289- "pass.out" \
290- "-fPIE" \
291- ] \
292-+ [list \
293-+ "Run pr22393-2" \
294-+ "$NOPIE_LDFLAGS -Wl,-z,textonly,--no-as-needed tmpdir/pr22393-2a.so" \
295-+ "" \
296-+ {pr22393-2b.c} \
297-+ "pr22393-2" \
298-+ "pass.out" \
299-+ "$NOPIE_CFLAGS" \
300-+ ] \
301-+ [list \
302-+ "Run pr22393-2 (PIE)" \
303-+ "-pie -Wl,-z,textonly,--no-as-needed tmpdir/pr22393-2a-now.so" \
304-+ "" \
305-+ {pr22393-2b.c} \
306-+ "pr22393-2-pie" \
307-+ "pass.out" \
308-+ "-fPIE" \
309-+ ] \
310-+ [list \
311-+ "Run pr22393-2 (static)" \
312-+ "-static -Wl,-z,textonly" \
313-+ "" \
314-+ {pr22393-2a.c pr22393-2b.c} \
315-+ "pr22393-2-static" \
316-+ "pass.out" \
317-+ ] \
318- ]
319- }
320-
321---
322-2.13.6
323-
--- a/patches/0006-x86-64-Add-tests-for-z-textonly-z-max-page-size-0x10.patch
+++ /dev/null
@@ -1,172 +0,0 @@
1-From 6a98c098b8284df539ca7d6ccf13e4e239ec65f7 Mon Sep 17 00:00:00 2001
2-From: "H.J. Lu" <hjl.tools@gmail.com>
3-Date: Mon, 13 Nov 2017 14:47:03 -0800
4-Subject: [PATCH 6/6] x86-64: Add tests for -z textonly -z max-page-size=0x1000
5-
6- PR ld/22393
7- * testsuite/ld-x86-64/pr22393-3a.c: New file.
8- * testsuite/ld-x86-64/pr22393-3a.rd: Likewise.
9- * testsuite/ld-x86-64/pr22393-3b.c: Likewise.
10- * testsuite/ld-x86-64/pr22393-3b.rd: Likewise.
11- * testsuite/ld-x86-64/x86-64.exp: Run tests for -z textonly
12- -z max-page-size=0x1000.
13----
14- ld/testsuite/ld-x86-64/pr22393-3a.c | 7 ++++
15- ld/testsuite/ld-x86-64/pr22393-3a.rd | 9 +++++
16- ld/testsuite/ld-x86-64/pr22393-3b.c | 7 ++++
17- ld/testsuite/ld-x86-64/pr22393-3b.rd | 9 +++++
18- ld/testsuite/ld-x86-64/x86-64.exp | 71 ++++++++++++++++++++++++++++++++++++
19- 5 files changed, 103 insertions(+)
20- create mode 100644 ld/testsuite/ld-x86-64/pr22393-3a.c
21- create mode 100644 ld/testsuite/ld-x86-64/pr22393-3a.rd
22- create mode 100644 ld/testsuite/ld-x86-64/pr22393-3b.c
23- create mode 100644 ld/testsuite/ld-x86-64/pr22393-3b.rd
24-
25-diff --git a/ld/testsuite/ld-x86-64/pr22393-3a.c b/ld/testsuite/ld-x86-64/pr22393-3a.c
26-new file mode 100644
27-index 0000000000..68fa4a0dd0
28---- /dev/null
29-+++ b/ld/testsuite/ld-x86-64/pr22393-3a.c
30-@@ -0,0 +1,7 @@
31-+#include <stdio.h>
32-+
33-+void
34-+test()
35-+{
36-+ printf ("PASS\n");
37-+}
38-diff --git a/ld/testsuite/ld-x86-64/pr22393-3a.rd b/ld/testsuite/ld-x86-64/pr22393-3a.rd
39-new file mode 100644
40-index 0000000000..b7ba110095
41---- /dev/null
42-+++ b/ld/testsuite/ld-x86-64/pr22393-3a.rd
43-@@ -0,0 +1,9 @@
44-+#source: pr22393-1.s
45-+#ld: -shared -z textonly
46-+#readelf: -l --wide
47-+#target: *-*-linux-gnu *-*-gnu* *-*-nacl*
48-+
49-+#failif
50-+#...
51-+ +[0-9]+ +.*(\.note|\.gnu|\.hash|\.dyn|\.rel).*\.text.*
52-+#...
53-diff --git a/ld/testsuite/ld-x86-64/pr22393-3b.c b/ld/testsuite/ld-x86-64/pr22393-3b.c
54-new file mode 100644
55-index 0000000000..3033809b02
56---- /dev/null
57-+++ b/ld/testsuite/ld-x86-64/pr22393-3b.c
58-@@ -0,0 +1,7 @@
59-+void test(void);
60-+
61-+int main()
62-+{
63-+ test();
64-+ return 0;
65-+}
66-diff --git a/ld/testsuite/ld-x86-64/pr22393-3b.rd b/ld/testsuite/ld-x86-64/pr22393-3b.rd
67-new file mode 100644
68-index 0000000000..b7ba110095
69---- /dev/null
70-+++ b/ld/testsuite/ld-x86-64/pr22393-3b.rd
71-@@ -0,0 +1,9 @@
72-+#source: pr22393-1.s
73-+#ld: -shared -z textonly
74-+#readelf: -l --wide
75-+#target: *-*-linux-gnu *-*-gnu* *-*-nacl*
76-+
77-+#failif
78-+#...
79-+ +[0-9]+ +.*(\.note|\.gnu|\.hash|\.dyn|\.rel).*\.text.*
80-+#...
81-diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
82-index ef2cb1551c..304128e165 100644
83---- a/ld/testsuite/ld-x86-64/x86-64.exp
84-+++ b/ld/testsuite/ld-x86-64/x86-64.exp
85-@@ -1104,6 +1104,51 @@ if { [isnative] && [which $CC] != 0 } {
86- {} \
87- "pr22064.so" \
88- ] \
89-+ [list \
90-+ "Build pr22393-3a.so" \
91-+ "-shared -Wl,-z,textonly,-z,max-page-size=0x1000" \
92-+ "-fPIC" \
93-+ {pr22393-3a.c} \
94-+ {{readelf -lW pr22393-3a.rd} \
95-+ {readelf -lW pr22393-3b.rd}} \
96-+ "pr22393-3a.so" \
97-+ ] \
98-+ [list \
99-+ "Build pr22393-3a-now.so" \
100-+ "-shared -Wl,-z,textonly,-z,now,-z,max-page-size=0x1000" \
101-+ "-fPIC" \
102-+ {pr22393-3a.c} \
103-+ {{readelf -lW pr22393-3a.rd} \
104-+ {readelf -lW pr22393-3b.rd}} \
105-+ "pr22393-3a-now.so" \
106-+ ] \
107-+ [list \
108-+ "Build pr22393-3" \
109-+ "$NOPIE_LDFLAGS -Wl,-z,textonly,-z,max-page-size=0x1000,--no-as-needed tmpdir/pr22393-2a.so" \
110-+ "$NOPIE_CFLAGS" \
111-+ {pr22393-3b.c} \
112-+ {{readelf -lW pr22393-3a.rd} \
113-+ {readelf -lW pr22393-3b.rd}} \
114-+ "pr22393-3" \
115-+ ] \
116-+ [list \
117-+ "Build pr22393-3 (PIE)" \
118-+ "-pie -Wl,-z,textonly,-z,max-page-size=0x1000,--no-as-needed tmpdir/pr22393-2a-now.so" \
119-+ "-fPIE" \
120-+ {pr22393-3b.c} \
121-+ {{readelf -lW pr22393-3a.rd} \
122-+ {readelf -lW pr22393-3b.rd}} \
123-+ "pr22393-3-pie" \
124-+ ] \
125-+ [list \
126-+ "Build pr22393-3 (static)" \
127-+ "-static -Wl,-z,textonly,-z,max-page-size=0x1000" \
128-+ "" \
129-+ {pr22393-3a.c pr22393-3b.c} \
130-+ {{readelf -lW pr22393-3a.rd} \
131-+ {readelf -lW pr22393-3b.rd}} \
132-+ "pr22393-3-static" \
133-+ ] \
134- ]
135-
136- if {[istarget "x86_64-*-linux*-gnux32"]} {
137-@@ -1403,6 +1448,32 @@ if { [isnative] && [which $CC] != 0 } {
138- "pass.out" \
139- "-fPIE" \
140- ] \
141-+ [list \
142-+ "Run pr22393-3" \
143-+ "$NOPIE_LDFLAGS -Wl,-z,textonly,-z,max-page-size=0x1000,--no-as-needed tmpdir/pr22393-3a.so" \
144-+ "" \
145-+ {pr22393-3b.c} \
146-+ "pr22393-3" \
147-+ "pass.out" \
148-+ "$NOPIE_CFLAGS" \
149-+ ] \
150-+ [list \
151-+ "Run pr22393-3 (PIE)" \
152-+ "-pie -Wl,-z,textonly,-z,max-page-size=0x1000,--no-as-needed tmpdir/pr22393-3a-now.so" \
153-+ "" \
154-+ {pr22393-3b.c} \
155-+ "pr22393-3-pie" \
156-+ "pass.out" \
157-+ "-fPIE" \
158-+ ] \
159-+ [list \
160-+ "Run pr22393-3 (static)" \
161-+ "-static -Wl,-z,textonly,-z,max-page-size=0x1000" \
162-+ "" \
163-+ {pr22393-3a.c pr22393-3b.c} \
164-+ "pr22393-3-static" \
165-+ "pass.out" \
166-+ ] \
167- ]
168-
169- # Run-time tests which require working ifunc attribute support.
170---
171-2.13.6
172-
--- a/patches/README
+++ b/patches/README
@@ -24,12 +24,6 @@ patches="
2424 binutils-pr21128.patch
2525 binutils-pr21129.patch
2626 binutils-x86-gpoff.patch
27-0001-ld-Add-z-textonly-option-to-ELF-linker.patch
28-0002-ld-Add-TEXT_SEGMENT_ALIGN-TEXT_SEGMENT_-RELRO_-END.patch
29-0003-ld-Create-a-new-LOAD-segment-for-text-only-LOAD-segm.patch
30-0004-ld-ppc-spu-Also-set-expld.textseg.phase-to-exp_seg_n.patch
31-0005-ld-Add-tests-for-z-textonly-and-z-notextonly.patch
32-0006-x86-64-Add-tests-for-z-textonly-z-max-page-size-0x10.patch
3327 "
3428
3529 for p in $patches