aboutsummaryrefslogtreecommitdiff
path: root/ld/emultempl
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/emultempl
parent6181e9c2c5ba252ac016f51903dc35d7bfbbca71 (diff)
downloadgdb-47acac12c83f173481debc64618626b50ecf7498.zip
gdb-47acac12c83f173481debc64618626b50ecf7498.tar.gz
gdb-47acac12c83f173481debc64618626b50ecf7498.tar.bz2
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/emultempl')
-rw-r--r--ld/emultempl/elf32.em100
1 files changed, 91 insertions, 9 deletions
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index a12aefa..8ff19bf 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -2367,13 +2367,25 @@ if test -n "$GENERATE_PIE_SCRIPT" ; then
if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
+echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
+echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xdwe >> e${EMULATION_NAME}.c
+echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
+echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
echo ' && link_info.relro' >> e${EMULATION_NAME}.c
echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c
echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
+echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
+echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xdce >> e${EMULATION_NAME}.c
+echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c
fi
+echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
+echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xde >> e${EMULATION_NAME}.c
echo ' ; else if (bfd_link_pie (&link_info)) return' >> e${EMULATION_NAME}.c
sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c
fi
@@ -2381,24 +2393,45 @@ if test -n "$GENERATE_SHLIB_SCRIPT" ; then
if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
+echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
+echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xswe >> e${EMULATION_NAME}.c
+echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
+echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
echo ' && link_info.relro' >> e${EMULATION_NAME}.c
echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c
echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
+echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
+echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xsce >> e${EMULATION_NAME}.c
+echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c
fi
+echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
+echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xse >> e${EMULATION_NAME}.c
echo ' ; else if (bfd_link_dll (&link_info)) return' >> e${EMULATION_NAME}.c
sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
fi
if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
+echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
+echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xwe >> e${EMULATION_NAME}.c
+echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
echo ' && link_info.relro' >> e${EMULATION_NAME}.c
echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
sed $sc ldscripts/${EMULATION_NAME}.xw >> e${EMULATION_NAME}.c
+echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
+echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xce >> e${EMULATION_NAME}.c
echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c
sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c
fi
+echo ' ; else if (link_info.separate_code) return' >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xe >> e${EMULATION_NAME}.c
echo ' ; else return' >> e${EMULATION_NAME}.c
sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
echo '; }' >> e${EMULATION_NAME}.c
@@ -2431,15 +2464,30 @@ fragment <<EOF
&& link_info.combreloc
&& link_info.relro
&& (link_info.flags & DF_BIND_NOW))
- return "ldscripts/${EMULATION_NAME}.xdw";
+ {
+ if (link_info.separate_code)
+ return "ldscripts/${EMULATION_NAME}.xdwe";
+ else
+ return "ldscripts/${EMULATION_NAME}.xdw";
+ }
else if (bfd_link_pie (&link_info)
&& link_info.combreloc)
- return "ldscripts/${EMULATION_NAME}.xdc";
+ {
+ if (link_info.separate_code)
+ return "ldscripts/${EMULATION_NAME}.xdce";
+ else
+ return "ldscripts/${EMULATION_NAME}.xdc";
+ }
EOF
fi
fragment <<EOF
else if (bfd_link_pie (&link_info))
- return "ldscripts/${EMULATION_NAME}.xd";
+ {
+ if (link_info.separate_code)
+ return "ldscripts/${EMULATION_NAME}.xde";
+ else
+ return "ldscripts/${EMULATION_NAME}.xd";
+ }
EOF
fi
if test -n "$GENERATE_SHLIB_SCRIPT" ; then
@@ -2447,28 +2495,58 @@ if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
fragment <<EOF
else if (bfd_link_dll (&link_info) && link_info.combreloc
&& link_info.relro && (link_info.flags & DF_BIND_NOW))
- return "ldscripts/${EMULATION_NAME}.xsw";
+ {
+ if (link_info.separate_code)
+ return "ldscripts/${EMULATION_NAME}.xswe";
+ else
+ return "ldscripts/${EMULATION_NAME}.xsw";
+ }
else if (bfd_link_dll (&link_info) && link_info.combreloc)
- return "ldscripts/${EMULATION_NAME}.xsc";
+ {
+ if (link_info.separate_code)
+ return "ldscripts/${EMULATION_NAME}.xsce";
+ else
+ return "ldscripts/${EMULATION_NAME}.xsc";
+ }
EOF
fi
fragment <<EOF
else if (bfd_link_dll (&link_info))
- return "ldscripts/${EMULATION_NAME}.xs";
+ {
+ if (link_info.separate_code)
+ return "ldscripts/${EMULATION_NAME}.xse";
+ else
+ return "ldscripts/${EMULATION_NAME}.xs";
+ }
EOF
fi
if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
fragment <<EOF
else if (link_info.combreloc && link_info.relro
&& (link_info.flags & DF_BIND_NOW))
- return "ldscripts/${EMULATION_NAME}.xw";
+ {
+ if (link_info.separate_code)
+ return "ldscripts/${EMULATION_NAME}.xwe";
+ else
+ return "ldscripts/${EMULATION_NAME}.xw";
+ }
else if (link_info.combreloc)
- return "ldscripts/${EMULATION_NAME}.xc";
+ {
+ if (link_info.separate_code)
+ return "ldscripts/${EMULATION_NAME}.xce";
+ else
+ return "ldscripts/${EMULATION_NAME}.xc";
+ }
EOF
fi
fragment <<EOF
else
- return "ldscripts/${EMULATION_NAME}.x";
+ {
+ if (link_info.separate_code)
+ return "ldscripts/${EMULATION_NAME}.xe";
+ else
+ return "ldscripts/${EMULATION_NAME}.x";
+ }
}
EOF
@@ -2738,6 +2816,10 @@ fragment <<EOF
link_info.relro = TRUE;
else if (strcmp (optarg, "norelro") == 0)
link_info.relro = FALSE;
+ else if (strcmp (optarg, "separate-code") == 0)
+ link_info.separate_code = TRUE;
+ else if (strcmp (optarg, "noseparate-code") == 0)
+ link_info.separate_code = FALSE;
else if (strcmp (optarg, "common") == 0)
link_info.elf_stt_common = elf_stt_common;
else if (strcmp (optarg, "nocommon") == 0)