aboutsummaryrefslogtreecommitdiff
path: root/ld/emultempl
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2020-06-19 09:17:20 +0930
committerAlan Modra <amodra@gmail.com>2020-06-19 09:50:20 +0930
commit5fd104addfddb68844fb8df67be832ee98ad9888 (patch)
treec8a0805ad47e7cdce9e7a8d3aff24eb4a158d335 /ld/emultempl
parent753d1583f7e61ae4b6a016accaa65ab2ea776e41 (diff)
downloadfsf-binutils-gdb-5fd104addfddb68844fb8df67be832ee98ad9888.zip
fsf-binutils-gdb-5fd104addfddb68844fb8df67be832ee98ad9888.tar.gz
fsf-binutils-gdb-5fd104addfddb68844fb8df67be832ee98ad9888.tar.bz2
Emit a warning when -z relro is unsupported
ld silently accepts -z relro and -z norelro for targets that lack the necessary GNU_RELRO support. This patch makes those targets emit a warning instead, and adds testsuite infrastructure to detect when relro is unsupported. binutils/ * testsuite/config/default.exp (ld_elf_shared_opt): Don't set. * testsuite/lib/binutils-common.exp (check_relro_support): New proc. (run_dump_test): Use check_relro_support to decide whether to pass extra ld option "-z norelro". ld/ * emultempl/elf.em (gld${EMULATION_NAME}_handle_option): Omit -z relro and -z norelro when target support for GNU_RELRO is lacking. (gld${EMULATION_NAME}_before_parse): Ignore RELRO default too. * emultempl/aarch64elf.em (gld${EMULATION_NAME}_before_parse): Ignore RELRO default when target support for GNU_RELRO is lacking. * emultempl/armelf.em (gld${EMULATION_NAME}_before_parse): Likewise. * emultempl/linux.em (gld${EMULATION_NAME}_before_parse): Likewise. * emultempl/scoreelf.em (gld${EMULATION_NAME}_before_parse): Likewise. * testsuite/config/default.exp (ld_elf_shared_opt): Don't set. * testsuite/ld-elf/pr16322.d: xfail when no relro support. * testsuite/ld-elf/pr22393-1a.d: Likewise. * testsuite/ld-elf/pr22393-1b.d: Likewise. * testsuite/ld-elf/shared.exp (pr20995-2.so, pr20995-2): Likewise. * testsuite/lib/ld-lib.exp (run_ld_link_tests): Use check_relro_support to decide whether to pass extra ld option "-z norelro".
Diffstat (limited to 'ld/emultempl')
-rw-r--r--ld/emultempl/aarch64elf.em6
-rw-r--r--ld/emultempl/armelf.em6
-rw-r--r--ld/emultempl/elf.em12
-rw-r--r--ld/emultempl/linux.em6
-rw-r--r--ld/emultempl/scoreelf.em6
5 files changed, 36 insertions, 0 deletions
diff --git a/ld/emultempl/aarch64elf.em b/ld/emultempl/aarch64elf.em
index d0519b3..a036da9 100644
--- a/ld/emultempl/aarch64elf.em
+++ b/ld/emultempl/aarch64elf.em
@@ -47,7 +47,13 @@ gld${EMULATION_NAME}_before_parse (void)
config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
link_info.check_relocs_after_open_input = TRUE;
+EOF
+if test -n "$COMMONPAGESIZE"; then
+fragment <<EOF
link_info.relro = DEFAULT_LD_Z_RELRO;
+EOF
+fi
+fragment <<EOF
}
static void
diff --git a/ld/emultempl/armelf.em b/ld/emultempl/armelf.em
index fb5bbf8..34372ba 100644
--- a/ld/emultempl/armelf.em
+++ b/ld/emultempl/armelf.em
@@ -60,7 +60,13 @@ gld${EMULATION_NAME}_before_parse (void)
config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
link_info.check_relocs_after_open_input = TRUE;
+EOF
+if test -n "$COMMONPAGESIZE"; then
+fragment <<EOF
link_info.relro = DEFAULT_LD_Z_RELRO;
+EOF
+fi
+fragment <<EOF
}
static void
diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
index c577e8b..356f345 100644
--- a/ld/emultempl/elf.em
+++ b/ld/emultempl/elf.em
@@ -82,7 +82,13 @@ gld${EMULATION_NAME}_before_parse (void)
config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
link_info.check_relocs_after_open_input = TRUE;
+EOF
+if test -n "$COMMONPAGESIZE"; then
+fragment <<EOF
link_info.relro = DEFAULT_LD_Z_RELRO;
+EOF
+fi
+fragment <<EOF
link_info.separate_code = DEFAULT_LD_Z_SEPARATE_CODE;
}
@@ -805,10 +811,16 @@ fragment <<EOF
link_info.combreloc = FALSE;
else if (strcmp (optarg, "nocopyreloc") == 0)
link_info.nocopyreloc = TRUE;
+EOF
+if test -n "$COMMONPAGESIZE"; then
+fragment <<EOF
else if (strcmp (optarg, "relro") == 0)
link_info.relro = TRUE;
else if (strcmp (optarg, "norelro") == 0)
link_info.relro = FALSE;
+EOF
+fi
+fragment <<EOF
else if (strcmp (optarg, "separate-code") == 0)
link_info.separate_code = TRUE;
else if (strcmp (optarg, "noseparate-code") == 0)
diff --git a/ld/emultempl/linux.em b/ld/emultempl/linux.em
index e9d802c..1444610 100644
--- a/ld/emultempl/linux.em
+++ b/ld/emultempl/linux.em
@@ -52,7 +52,13 @@ gld${EMULATION_NAME}_before_parse (void)
input_flags.dynamic = TRUE;
config.has_shared = TRUE;
link_info.check_relocs_after_open_input = TRUE;
+EOF
+if test -n "$COMMONPAGESIZE"; then
+fragment <<EOF
link_info.relro = DEFAULT_LD_Z_RELRO;
+EOF
+fi
+fragment <<EOF
}
/* Try to open a dynamic archive. This is where we know that Linux
diff --git a/ld/emultempl/scoreelf.em b/ld/emultempl/scoreelf.em
index 327ec6b..70b9a70 100644
--- a/ld/emultempl/scoreelf.em
+++ b/ld/emultempl/scoreelf.em
@@ -40,7 +40,13 @@ gld${EMULATION_NAME}_before_parse (void)
config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
link_info.check_relocs_after_open_input = TRUE;
+EOF
+if test -n "$COMMONPAGESIZE"; then
+fragment <<EOF
link_info.relro = DEFAULT_LD_Z_RELRO;
+EOF
+fi
+fragment <<EOF
}
static void