diff options
author | Alan Modra <amodra@gmail.com> | 2020-06-19 09:17:20 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2020-06-19 09:50:20 +0930 |
commit | 5fd104addfddb68844fb8df67be832ee98ad9888 (patch) | |
tree | c8a0805ad47e7cdce9e7a8d3aff24eb4a158d335 /ld | |
parent | 753d1583f7e61ae4b6a016accaa65ab2ea776e41 (diff) | |
download | gdb-5fd104addfddb68844fb8df67be832ee98ad9888.zip gdb-5fd104addfddb68844fb8df67be832ee98ad9888.tar.gz 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')
-rw-r--r-- | ld/ChangeLog | 18 | ||||
-rw-r--r-- | ld/emultempl/aarch64elf.em | 6 | ||||
-rw-r--r-- | ld/emultempl/armelf.em | 6 | ||||
-rw-r--r-- | ld/emultempl/elf.em | 12 | ||||
-rw-r--r-- | ld/emultempl/linux.em | 6 | ||||
-rw-r--r-- | ld/emultempl/scoreelf.em | 6 | ||||
-rw-r--r-- | ld/testsuite/config/default.exp | 3 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr16322.d | 1 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr22393-1a.d | 1 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr22393-1b.d | 1 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/shared.exp | 26 | ||||
-rw-r--r-- | ld/testsuite/lib/ld-lib.exp | 8 |
12 files changed, 71 insertions, 23 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog index 45cf948..7a6caa9 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,21 @@ +2020-06-19 Alan Modra <amodra@gmail.com> + + * 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". + 2020-06-17 H.J. Lu <hongjiu.lu@intel.com> * testsuite/ld-elf/linux-x86.exp (check_pr25749a): Append "-w" 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 diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp index b2097ce..9e89ca1 100644 --- a/ld/testsuite/config/default.exp +++ b/ld/testsuite/config/default.exp @@ -76,9 +76,6 @@ if {[file exists tmpdir/libpath.exp]} { } } -# Many ELF testcases expect that "-z relro" is off. -set ld_elf_shared_opt "-z norelro" - # The "make check" target in the Makefile passes in # "CC=$(CC_FOR_TARGET)". But, if the user invokes runtest directly # (as when testing an installed linker), these flags may not be set. diff --git a/ld/testsuite/ld-elf/pr16322.d b/ld/testsuite/ld-elf/pr16322.d index 7bd1a6f..1e9175c 100644 --- a/ld/testsuite/ld-elf/pr16322.d +++ b/ld/testsuite/ld-elf/pr16322.d @@ -2,6 +2,7 @@ #readelf: -l --wide #target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi #xfail: ![check_shared_lib_support] +#xfail: ![check_relro_support] #... GNU_RELRO .* diff --git a/ld/testsuite/ld-elf/pr22393-1a.d b/ld/testsuite/ld-elf/pr22393-1a.d index c08ecaa..2bfa403 100644 --- a/ld/testsuite/ld-elf/pr22393-1a.d +++ b/ld/testsuite/ld-elf/pr22393-1a.d @@ -3,6 +3,7 @@ #readelf: -l --wide #target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi #xfail: ![check_shared_lib_support] +#xfail: ![check_relro_support] #failif #... diff --git a/ld/testsuite/ld-elf/pr22393-1b.d b/ld/testsuite/ld-elf/pr22393-1b.d index b0020a1..96d8bc0 100644 --- a/ld/testsuite/ld-elf/pr22393-1b.d +++ b/ld/testsuite/ld-elf/pr22393-1b.d @@ -3,6 +3,7 @@ #readelf: -l --wide #target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi #xfail: ![check_shared_lib_support] +#xfail: ![check_relro_support] #failif #... diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp index 9d72cad..8f4ed71 100644 --- a/ld/testsuite/ld-elf/shared.exp +++ b/ld/testsuite/ld-elf/shared.exp @@ -454,16 +454,6 @@ run_ld_link_tests [list \ {pr20995b.s} {} "pr20995.so"] \ ] -# xfail on arm*-*-eabi*. The list can be enlarged to those targets that -# don't support GNU_RELRO. For more details, please see discussions at: -# https://sourceware.org/ml/binutils/2017-01/msg00441.html -run_ld_link_tests [list \ - [list "Build pr20995-2.so" \ - "-shared -z relro" "" "$AFLAGS_PIC" \ - {pr20995c.s} {{readelf {-l --wide} pr20995-2so.r}} "pr20995-2.so"] \ -] "tic6x-*-*" "arm*-*-eabi*" "hppa*64*-*-hpux*" "aarch64*-*-elf*" \ - "*-*-lynxos*" "arm*-*-nto*" "i?86-*-nto*" "sh*-*-nto*" - # These targets don't copy dynamic variables into .bss. setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*" # or don't have .data.rel.ro @@ -474,16 +464,22 @@ run_ld_link_tests [list \ "$LFLAGS" "tmpdir/pr20995.so" "$AFLAGS_NONPIC" \ {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995"]] -# xfail on arm*-*-eabi* is particularly because of no support of GNU_RELRO. -# Please see the link above for details. -setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*" "arm*-*-eabi*" -setup_xfail "hppa*64*-*-hpux*" "aarch64*-*-elf*" "tic6x-*-*" +# xfail on targets that don't support GNU_RELRO. +# For more details, please see discussions at: +# https://sourceware.org/ml/binutils/2017-01/msg00441.html +run_ld_link_tests [list \ + [list "Build pr20995-2.so" \ + "-shared -z relro" "" "$AFLAGS_PIC" \ + {pr20995c.s} {{readelf {-l --wide} pr20995-2so.r}} "pr20995-2.so"] \ +] {![check_relro_support]} + +setup_xfail alpha-*-* xtensa-*-* run_ld_link_tests [list \ [list \ "pr20995-2" \ "$LFLAGS" "tmpdir/pr20995-2.so" "$AFLAGS_NONPIC" \ {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995-2"] -] "*-*-lynxos*" "arm*-*-nto*" "i?86-*-nto*" "sh*-*-nto*" +] {![check_relro_support]} run_ld_link_tests [list \ [list "Build pr22374 shared library" \ diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp index a949437..0a256c2 100644 --- a/ld/testsuite/lib/ld-lib.exp +++ b/ld/testsuite/lib/ld-lib.exp @@ -463,12 +463,10 @@ proc run_ld_link_tests { ldtests args } { global CFLAGS global runtests global exec_output - global ld_elf_shared_opt - if { [is_elf_format] && [check_shared_lib_support] } { - set ld_extra_opt "$ld_elf_shared_opt" - } else { - set ld_extra_opt "" + set ld_extra_opt "" + if [check_relro_support] { + set ld_extra_opt "-z norelro" } foreach testitem $ldtests { |