diff options
author | 2018-06-11 13:23:00 +0200 | |
---|---|---|
committer | 2018-07-18 13:20:06 +0200 | |
commit | a38137289e91fd548fc27fb6566a439233b94d65 (patch) | |
tree | 6cfffbd27fb55feb22dc50b2c935cc047d0687a0 /ld/emultempl | |
parent | Updated French translation for gold and Spanish translation for ld. (diff) | |
download | binutils-gdb-a38137289e91fd548fc27fb6566a439233b94d65.tar.gz binutils-gdb-a38137289e91fd548fc27fb6566a439233b94d65.tar.bz2 binutils-gdb-a38137289e91fd548fc27fb6566a439233b94d65.zip |
ld: Enable using separate linker script for -z relro
With this patch dedicated linker scripts can be generated for partial
relro triggered by defining GENERATE_RELRO_SCRIPT in the target
specific scripts.
This is necessary for e.g. S/390 where usually the .got.plt comes
first and prevents the relro segment from being extended across the
non-plt GOT entries.
The patch started with the work from Marcin taken from the mwk user
branches. However, the patch needed substantial changes due to the
'separate code' feature which got committed in the meantime.
ld/ChangeLog:
2018-07-18 Andreas Krebbel <krebbel@linux.ibm.com>
Marcin Kościelnicki <koriakin@0x04.net>
* emultempl/elf32.em: Add code to pick dedicated linker scripts
for partial relro.
* genscripts.sh: Generate dedicated linker scripts for partial relro.
Diffstat (limited to 'ld/emultempl')
-rw-r--r-- | ld/emultempl/elf32.em | 149 |
1 files changed, 148 insertions, 1 deletions
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em index 1ad9d6b6fa8..5160e2449b9 100644 --- a/ld/emultempl/elf32.em +++ b/ld/emultempl/elf32.em @@ -2376,17 +2376,41 @@ 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 +if test -n "$GENERATE_RELRO_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.relro) return' >> e${EMULATION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xdceo >> e${EMULATION_NAME}.c +fi 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 +if test -n "$GENERATE_RELRO_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.relro) return' >> e${EMULATION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xdco >> e${EMULATION_NAME}.c +fi 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 +if test -n "$GENERATE_RELRO_SCRIPT" ; then +echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c +echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c +echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xdeo >> e${EMULATION_NAME}.c +fi 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 +if test -n "$GENERATE_RELRO_SCRIPT" ; then +echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c +echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xdo >> e${EMULATION_NAME}.c +fi echo ' ; else if (bfd_link_pie (&link_info)) return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c fi @@ -2402,17 +2426,41 @@ 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 +if test -n "$GENERATE_RELRO_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.relro) return' >> e${EMULATION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xsceo >> e${EMULATION_NAME}.c +fi 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 +if test -n "$GENERATE_RELRO_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.relro) return' >> e${EMULATION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xsco >> e${EMULATION_NAME}.c +fi 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 +if test -n "$GENERATE_RELRO_SCRIPT" ; then +echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c +echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c +echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xseo >> e${EMULATION_NAME}.c +fi 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 +if test -n "$GENERATE_RELRO_SCRIPT" ; then +echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c +echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xso >> e${EMULATION_NAME}.c +fi echo ' ; else if (bfd_link_dll (&link_info)) return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c fi @@ -2425,14 +2473,34 @@ 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 +if test -n "$GENERATE_RELRO_SCRIPT" ; then +echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c +echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c +echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xceo >> e${EMULATION_NAME}.c +fi 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 +if test -n "$GENERATE_RELRO_SCRIPT" ; then +echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c +echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xco >> e${EMULATION_NAME}.c +fi 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 +if test -n "$GENERATE_RELRO_SCRIPT" ; then +echo ' ; else if (link_info.separate_code' >> e${EMULATION_NAME}.c +echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xeo >> 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 +if test -n "$GENERATE_RELRO_SCRIPT" ; then +echo ' ; else if (link_info.relro) return' >> e${EMULATION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xo >> e${EMULATION_NAME}.c +fi echo ' ; else return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c echo '; }' >> e${EMULATION_NAME}.c @@ -2471,6 +2539,21 @@ fragment <<EOF else return "ldscripts/${EMULATION_NAME}.xdw"; } +EOF +if test -n "$GENERATE_RELRO_SCRIPT" ; then +fragment <<EOF + else if (bfd_link_pie (&link_info) + && link_info.combreloc + && link_info.relro) + { + if (link_info.separate_code) + return "ldscripts/${EMULATION_NAME}.xdceo"; + else + return "ldscripts/${EMULATION_NAME}.xdco"; + } +EOF +fi +fragment <<EOF else if (bfd_link_pie (&link_info) && link_info.combreloc) { @@ -2481,6 +2564,18 @@ fragment <<EOF } EOF fi +if test -n "$GENERATE_RELRO_SCRIPT" ; then +fragment <<EOF + else if (bfd_link_pie (&link_info) + && link_info.relro) + { + if (link_info.separate_code) + return "ldscripts/${EMULATION_NAME}.xdeo"; + else + return "ldscripts/${EMULATION_NAME}.xdo"; + } +EOF +fi fragment <<EOF else if (bfd_link_pie (&link_info)) { @@ -2502,6 +2597,21 @@ fragment <<EOF else return "ldscripts/${EMULATION_NAME}.xsw"; } +EOF +if test -n "$GENERATE_RELRO_SCRIPT" ; then +fragment <<EOF + else if (bfd_link_dll (&link_info) + && link_info.combreloc + && link_info.relro) + { + if (link_info.separate_code) + return "ldscripts/${EMULATION_NAME}.xsceo"; + else + return "ldscripts/${EMULATION_NAME}.xsco"; + } +EOF +fi +fragment <<EOF else if (bfd_link_dll (&link_info) && link_info.combreloc) { if (link_info.separate_code) @@ -2511,6 +2621,18 @@ fragment <<EOF } EOF fi +if test -n "$GENERATE_RELRO_SCRIPT" ; then +fragment <<EOF + else if (bfd_link_dll (&link_info) + && link_info.relro) + { + if (link_info.separate_code) + return "ldscripts/${EMULATION_NAME}.xseo"; + else + return "ldscripts/${EMULATION_NAME}.xso"; + } +EOF +fi fragment <<EOF else if (bfd_link_dll (&link_info)) { @@ -2531,6 +2653,20 @@ fragment <<EOF else return "ldscripts/${EMULATION_NAME}.xw"; } +EOF +if test -n "$GENERATE_RELRO_SCRIPT" ; then +fragment <<EOF + else if (link_info.combreloc + && link_info.relro) + { + if (link_info.separate_code) + return "ldscripts/${EMULATION_NAME}.xceo"; + else + return "ldscripts/${EMULATION_NAME}.xco"; + } +EOF +fi +fragment <<EOF else if (link_info.combreloc) { if (link_info.separate_code) @@ -2540,6 +2676,17 @@ fragment <<EOF } EOF fi +if test -n "$GENERATE_RELRO_SCRIPT" ; then +fragment <<EOF + else if (link_info.relro) + { + if (link_info.separate_code) + return "ldscripts/${EMULATION_NAME}.xeo"; + else + return "ldscripts/${EMULATION_NAME}.xo"; + } +EOF +fi fragment <<EOF else { |