From cbbdd101141a3c855b20c902f4fd33172fbae227 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marcin=20Ko=C5=9Bcielnicki?= Date: Fri, 3 Jun 2016 16:39:42 +0200 Subject: [PATCH] ld: Enable using separate linker script for -z relro This will be used for s390 relro got support. ld/ChangeLog: * emultempl/elf32.em: Use .xo, .xso, .xdo scripts if GENERATE_RELRO_SCRIPT is set. * genscripts.sh: Create .xo, .xso, .xdo scripts if GENERATE_RELRO_SCRIPT is set. --- ld/emultempl/elf32.em | 44 +++++++++++++++++++++++++++++++++++++++++++ ld/genscripts.sh | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em index c2ad2022cee..b221cda9b18 100644 --- a/ld/emultempl/elf32.em +++ b/ld/emultempl/elf32.em @@ -2074,6 +2074,12 @@ 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.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)' >> e${EMULATION_NAME}.c echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c @@ -2087,6 +2093,12 @@ echo ' ; else if (bfd_link_dll (&link_info) && link_info.combreloc' >> e${EMULA 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.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) && link_info.combreloc) return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c fi @@ -2097,6 +2109,11 @@ if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then echo ' ; else if (link_info.combreloc && 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.relro) return' >> e${EMULATION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xo >> 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 @@ -2133,6 +2150,16 @@ fragment < ldscripts/${EMULATION_NAME}.xc rm -f ${COMBRELOC} + + if test -n "$GENERATE_RELRO_SCRIPT"; then + LD_FLAG=o + RELRO=" " + COMBRELOC=ldscripts/${EMULATION_NAME}.xo.tmp + ( echo "/* Script for -z combreloc -z relro: combine and sort reloc sections */" + . ${CUSTOMIZER_SCRIPT} + . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc + ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xo + rm -f ${COMBRELOC} + COMBRELOC= + unset RELRO + fi + LD_FLAG=w RELRO_NOW=" " COMBRELOC=ldscripts/${EMULATION_NAME}.xw.tmp @@ -351,6 +365,20 @@ if test -n "$GENERATE_SHLIB_SCRIPT"; then . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc rm -f ${COMBRELOC} + + if test -n "$GENERATE_RELRO_SCRIPT"; then + LD_FLAG=oshared + RELRO=" " + COMBRELOC=ldscripts/${EMULATION_NAME}.xso.tmp + ( echo "/* Script for --shared -z combreloc -z relro: shared library, combine & sort relocs */" + . ${CUSTOMIZER_SCRIPT} + . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc + ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xso + rm -f ${COMBRELOC} + COMBRELOC= + unset RELRO + fi + LD_FLAG=wshared RELRO_NOW=" " COMBRELOC=ldscripts/${EMULATION_NAME}.xsw.tmp @@ -383,6 +411,20 @@ if test -n "$GENERATE_PIE_SCRIPT"; then . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdc rm -f ${COMBRELOC} + + if test -n "$GENERATE_RELRO_SCRIPT"; then + LD_FLAG=opie + RELRO=" " + COMBRELOC=ldscripts/${EMULATION_NAME}.xdo.tmp + ( echo "/* Script for -pie -z combreloc -z relro: position independent executable, combine & sort relocs */" + . ${CUSTOMIZER_SCRIPT} + . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc + ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdo + rm -f ${COMBRELOC} + COMBRELOC= + unset RELRO + fi + LD_FLAG=wpie RELRO_NOW=" " COMBRELOC=ldscripts/${EMULATION_NAME}.xdw.tmp -- 2.47.2