]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ld: Enable using separate linker script for -z relro
authorMarcin Kościelnicki <koriakin@0x04.net>
Fri, 3 Jun 2016 14:39:42 +0000 (16:39 +0200)
committerMarcin Kościelnicki <koriakin@0x04.net>
Wed, 22 Jun 2016 11:06:44 +0000 (13:06 +0200)
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
ld/genscripts.sh

index c2ad2022ceed804dda1caa17ca64c03f2ad08ba0..b221cda9b18338623560c397aa0518e32010d523 100644 (file)
@@ -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
index eb262e7ef6168c8a88fbae12ec47207d451e6ee3..0f27679e397a7babc485b2668cff0ca2bc3d884b 100755 (executable)
@@ -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