diff options
author | Marcin KoĆcielnicki <koriakin@0x04.net> | 2016-06-03 16:39:42 +0200 |
---|---|---|
committer | Marcin KoĆcielnicki <koriakin@0x04.net> | 2016-06-22 13:06:44 +0200 |
commit | cbbdd101141a3c855b20c902f4fd33172fbae227 (patch) | |
tree | 75d6ab0ec0462995b9c0982c7cd0f5ac9d24c066 | |
parent | 6edaf4d75b45ff08d7296095506904663b8f0576 (diff) | |
download | gdb-cbbdd101141a3c855b20c902f4fd33172fbae227.zip gdb-cbbdd101141a3c855b20c902f4fd33172fbae227.tar.gz gdb-cbbdd101141a3c855b20c902f4fd33172fbae227.tar.bz2 |
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.
-rw-r--r-- | ld/emultempl/elf32.em | 44 | ||||
-rwxr-xr-x | ld/genscripts.sh | 42 |
2 files changed, 86 insertions, 0 deletions
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em index c2ad202..b221cda 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 <<EOF && link_info.relro && (link_info.flags & DF_BIND_NOW)) 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) + return "ldscripts/${EMULATION_NAME}.xdo"; +EOF +fi +fragment <<EOF else if (bfd_link_pie (&link_info) && link_info.combreloc) return "ldscripts/${EMULATION_NAME}.xdc"; @@ -2149,6 +2176,15 @@ 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"; +EOF +if test -n "$GENERATE_RELRO_SCRIPT" ; then +fragment <<EOF + else if (bfd_link_dll (&link_info) && link_info.combreloc + && link_info.relro) + return "ldscripts/${EMULATION_NAME}.xso"; +EOF +fi +fragment <<EOF else if (bfd_link_dll (&link_info) && link_info.combreloc) return "ldscripts/${EMULATION_NAME}.xsc"; EOF @@ -2163,6 +2199,14 @@ fragment <<EOF else if (link_info.combreloc && link_info.relro && (link_info.flags & DF_BIND_NOW)) return "ldscripts/${EMULATION_NAME}.xw"; +EOF +if test -n "$GENERATE_RELRO_SCRIPT" ; then +fragment <<EOF + else if (link_info.combreloc && link_info.relro) + return "ldscripts/${EMULATION_NAME}.xo"; +EOF +fi +fragment <<EOF else if (link_info.combreloc) return "ldscripts/${EMULATION_NAME}.xc"; EOF diff --git a/ld/genscripts.sh b/ld/genscripts.sh index eb262e7..0f27679 100755 --- a/ld/genscripts.sh +++ b/ld/genscripts.sh @@ -321,6 +321,20 @@ if test -n "$GENERATE_COMBRELOC_SCRIPT"; then . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > 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 |