summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Koƛcielnicki <koriakin@0x04.net>2016-06-03 16:39:42 +0200
committerMarcin Koƛcielnicki <koriakin@0x04.net>2016-06-08 14:07:29 +0200
commit85dd6069e6baac2596d6e9f200d4761eea2169de (patch)
tree1fb149c5332fee84c0874905b28606e8585afcb8
parent07905aad27a7cff907887c796ad5dbdd670aba84 (diff)
downloadbinutils-gdb-85dd6069e6baac2596d6e9f200d4761eea2169de.tar.gz
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.em44
-rwxr-xr-xld/genscripts.sh42
2 files changed, 86 insertions, 0 deletions
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 <<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 eb262e7ef61..0f27679e397 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