summaryrefslogtreecommitdiff
path: root/ld/genscripts.sh
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2018-01-11 19:01:39 -0800
committerH.J. Lu <hjl.tools@gmail.com>2018-01-11 19:01:52 -0800
commit47acac12c83f173481debc64618626b50ecf7498 (patch)
treee48aae92826c2b354a47ca3721c85cfa93b4194e /ld/genscripts.sh
parent6181e9c2c5ba252ac016f51903dc35d7bfbbca71 (diff)
downloadbinutils-gdb-47acac12c83f173481debc64618626b50ecf7498.tar.gz
ld: Add "-z separate-code" option to ELF linker
The new "-z separate-code" option will generate separate code LOAD segment which must be in wholly disjoint pages from any other data. include/ PR ld/22393 * bfdlink.h (bfd_link_info): Add separate_code. ld/ PR ld/22393 * NEWS: Mention "-z separate-code". * emultempl/elf32.em (gld${EMULATION_NAME}_get_script): Get builtin linker scripts and return linker scripts from disk for "-z separate-code". (gld${EMULATION_NAME}_handle_option): Handle "-z separate-code" and "-z noseparate-code". * genscripts.sh: Generate linker scripts for "-z separate-code". (LD_FLAG): Set to *textonly for "-z separate-code". * ld.texinfo: Document "-z separate-code". * lexsup.c (elf_shlib_list_options): Add linker help messsages for "-z separate-code" and "-z noseparate-code". * scripttempl/elf.sc (SEPARATE_TEXT): New (TEXT_SEGMENT_ALIGN): Likewise. Use ${TEXT_SEGMENT_ALIGN} to align and pad text segment to ${MAXPAGESIZE}.
Diffstat (limited to 'ld/genscripts.sh')
-rwxr-xr-xld/genscripts.sh76
1 files changed, 68 insertions, 8 deletions
diff --git a/ld/genscripts.sh b/ld/genscripts.sh
index 43ccf5eda4d..8732422b3a1 100755
--- a/ld/genscripts.sh
+++ b/ld/genscripts.sh
@@ -290,14 +290,20 @@ CONSTRUCTING=" "
. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xu
-LD_FLAG=
DATA_ALIGNMENT=${DATA_ALIGNMENT_}
RELOCATING=" "
+LD_FLAG=
( echo "/* Default linker script, for normal executables */"
. ${CUSTOMIZER_SCRIPT}
. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.x
+LD_FLAG=textonly
+( echo "/* Script for -z separate-code: generate normal executables with separate code segment */"
+ . ${CUSTOMIZER_SCRIPT}
+ . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
+) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xe
+
LD_FLAG=n
DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
( echo "/* Script for -n: mix text and data on same page */"
@@ -321,44 +327,78 @@ if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xc
rm -f ${COMBRELOC}
- LD_FLAG=w
+ LD_FLAG=ctextonly
+ COMBRELOC=ldscripts/${EMULATION_NAME}.xce.tmp
+ ( echo "/* Script for -z combreloc -z separate-code: combine and sort reloc sections with separate code segment */"
+ . ${CUSTOMIZER_SCRIPT}
+ . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
+ ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xce
+ rm -f ${COMBRELOC}
RELRO_NOW=" "
+ LD_FLAG=w
COMBRELOC=ldscripts/${EMULATION_NAME}.xw.tmp
( echo "/* Script for -z combreloc -z now -z relro: combine and sort reloc sections */"
. ${CUSTOMIZER_SCRIPT}
. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xw
rm -f ${COMBRELOC}
+ LD_FLAG=wtextonly
+ COMBRELOC=ldscripts/${EMULATION_NAME}.xwe.tmp
+ ( echo "/* Script for -z combreloc -z now -z relro -z separate-code: combine and sort reloc sections with separate code segment */"
+ . ${CUSTOMIZER_SCRIPT}
+ . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
+ ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xwe
+ rm -f ${COMBRELOC}
COMBRELOC=
unset RELRO_NOW
fi
if test -n "$GENERATE_SHLIB_SCRIPT"; then
- LD_FLAG=shared
DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
CREATE_SHLIB=" "
+ LD_FLAG=shared
(
echo "/* Script for ld --shared: link shared library */"
. ${CUSTOMIZER_SCRIPT}
. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xs
+ LD_FLAG=sharedtextonly
+ (
+ echo "/* Script for ld --shared -z separate-code: link shared library with separate code segment */"
+ . ${CUSTOMIZER_SCRIPT}
+ . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
+ ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xse
if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
- LD_FLAG=cshared
DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
+ LD_FLAG=cshared
COMBRELOC=ldscripts/${EMULATION_NAME}.xsc.tmp
( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */"
. ${CUSTOMIZER_SCRIPT}
. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc
rm -f ${COMBRELOC}
- LD_FLAG=wshared
+ LD_FLAG=csharedtextonly
+ COMBRELOC=ldscripts/${EMULATION_NAME}.xsce.tmp
+ ( echo "/* Script for --shared -z combreloc -z separate-code: shared library, combine & sort relocs with separate code segment */"
+ . ${CUSTOMIZER_SCRIPT}
+ . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
+ ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsce
+ rm -f ${COMBRELOC}
RELRO_NOW=" "
+ LD_FLAG=wshared
COMBRELOC=ldscripts/${EMULATION_NAME}.xsw.tmp
( echo "/* Script for --shared -z combreloc -z now -z relro: shared library, combine & sort relocs */"
. ${CUSTOMIZER_SCRIPT}
. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsw
rm -f ${COMBRELOC}
+ LD_FLAG=wsharedtextonly
+ COMBRELOC=ldscripts/${EMULATION_NAME}.xswe.tmp
+ ( echo "/* Script for --shared -z combreloc -z now -z relro -z separate-code: shared library, combine & sort relocs with separate code segment */"
+ . ${CUSTOMIZER_SCRIPT}
+ . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
+ ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xswe
+ rm -f ${COMBRELOC}
COMBRELOC=
unset RELRO_NOW
fi
@@ -366,31 +406,51 @@ if test -n "$GENERATE_SHLIB_SCRIPT"; then
fi
if test -n "$GENERATE_PIE_SCRIPT"; then
- LD_FLAG=pie
DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
CREATE_PIE=" "
+ LD_FLAG=pie
(
echo "/* Script for ld -pie: link position independent executable */"
. ${CUSTOMIZER_SCRIPT}
. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xd
+ LD_FLAG=pietextonly
+ (
+ echo "/* Script for ld -pie -z separate-code: link position independent executable with separate code segment */"
+ . ${CUSTOMIZER_SCRIPT}
+ . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
+ ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xde
if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
- LD_FLAG=cpie
DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
COMBRELOC=ldscripts/${EMULATION_NAME}.xdc.tmp
+ LD_FLAG=cpie
( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */"
. ${CUSTOMIZER_SCRIPT}
. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdc
rm -f ${COMBRELOC}
- LD_FLAG=wpie
+ LD_FLAG=cpietextonly
+ COMBRELOC=ldscripts/${EMULATION_NAME}.xdce.tmp
+ ( echo "/* Script for -pie -z combreloc -z separate-code: position independent executable, combine & sort relocs with separate code segment */"
+ . ${CUSTOMIZER_SCRIPT}
+ . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
+ ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdce
+ rm -f ${COMBRELOC}
RELRO_NOW=" "
+ LD_FLAG=wpie
COMBRELOC=ldscripts/${EMULATION_NAME}.xdw.tmp
( echo "/* Script for -pie -z combreloc -z now -z relro: position independent executable, combine & sort relocs */"
. ${CUSTOMIZER_SCRIPT}
. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdw
rm -f ${COMBRELOC}
+ LD_FLAG=wpietextonly
+ COMBRELOC=ldscripts/${EMULATION_NAME}.xdwe.tmp
+ ( echo "/* Script for -pie -z combreloc -z now -z relro -z separate-code: position independent executable, combine & sort relocs with separate code segment */"
+ . ${CUSTOMIZER_SCRIPT}
+ . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
+ ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdwe
+ rm -f ${COMBRELOC}
COMBRELOC=
unset RELRO_NOW
fi