• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

修订版5fd104addfddb68844fb8df67be832ee98ad9888 (tree)
时间2020-06-19 09:20:20
作者Alan Modra <amodra@gmai...>
CommiterAlan Modra

Log Message

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".

更改概述

差异

--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,10 @@
1+2020-06-19 Alan Modra <amodra@gmail.com>
2+
3+ * testsuite/config/default.exp (ld_elf_shared_opt): Don't set.
4+ * testsuite/lib/binutils-common.exp (check_relro_support): New proc.
5+ (run_dump_test): Use check_relro_support to decide whether to pass
6+ extra ld option "-z norelro".
7+
18 2020-06-11 Alan Modra <amodra@gmail.com>
29
310 * readelf.c (process_mips_specific): Don't alloc memory for
--- a/binutils/testsuite/config/default.exp
+++ b/binutils/testsuite/config/default.exp
@@ -34,8 +34,6 @@ if ![info exists LD] then {
3434 if ![info exists LDFLAGS] then {
3535 set LDFLAGS ""
3636 }
37-set ld_elf_shared_opt "-z norelro"
38-
3937 if ![info exists NM] then {
4038 set NM [findfile $base_dir/nm-new $base_dir/nm-new [transform nm]]
4139 }
--- a/binutils/testsuite/lib/binutils-common.exp
+++ b/binutils/testsuite/lib/binutils-common.exp
@@ -308,6 +308,25 @@ proc check_pie_support { } {
308308 return $pie_available_saved
309309 }
310310
311+proc check_relro_support { } {
312+ global relro_available_saved
313+ global ld
314+
315+ if {![info exists relro_available_saved]} {
316+ remote_file host delete norelro
317+ set ld_output [remote_exec host $ld "-z norelro"]
318+ if { [string first "not supported" $ld_output] >= 0
319+ || [string first "unrecognized option" $ld_output] >= 0
320+ || [string first "-z norelro ignored" $ld_output] >= 0
321+ || [string first "cannot find norelro" $ld_output] >= 0 } {
322+ set relro_available_saved 0
323+ } else {
324+ set relro_available_saved 1
325+ }
326+ }
327+ return $relro_available_saved
328+}
329+
311330 # Compare two files line-by-line. FILE_1 is the actual output and FILE_2
312331 # is the expected output. Ignore blank lines in either file.
313332 #
@@ -729,7 +748,7 @@ proc run_dump_test { name {extra_options {}} } {
729748 global ADDR2LINE ADDR2LINEFLAGS AS ASFLAGS ELFEDIT ELFEDITFLAGS LD LDFLAGS
730749 global NM NMFLAGS OBJCOPY OBJCOPYFLAGS OBJDUMP OBJDUMPFLAGS
731750 global READELF READELFFLAGS STRIP STRIPFLAGS
732- global copyfile env ld_elf_shared_opt runtests srcdir subdir verbose
751+ global copyfile env runtests srcdir subdir verbose
733752
734753 if [string match "*/*" $name] {
735754 set file $name
@@ -1119,9 +1138,9 @@ proc run_dump_test { name {extra_options {}} } {
11191138 set ld_extra_opt ""
11201139 global ld
11211140 set ld "$LD"
1122- if { [is_elf_format] && [check_shared_lib_support] } {
1123- set ld_extra_opt "$ld_elf_shared_opt"
1124- }
1141+ if [check_relro_support] {
1142+ set ld_extra_opt "-z norelro"
1143+ }
11251144
11261145 # Add -L$srcdir/$subdir so that the linker command can use
11271146 # linker scripts in the source directory.
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,21 @@
1+2020-06-19 Alan Modra <amodra@gmail.com>
2+
3+ * emultempl/elf.em (gld${EMULATION_NAME}_handle_option): Omit
4+ -z relro and -z norelro when target support for GNU_RELRO is lacking.
5+ (gld${EMULATION_NAME}_before_parse): Ignore RELRO default too.
6+ * emultempl/aarch64elf.em (gld${EMULATION_NAME}_before_parse): Ignore
7+ RELRO default when target support for GNU_RELRO is lacking.
8+ * emultempl/armelf.em (gld${EMULATION_NAME}_before_parse): Likewise.
9+ * emultempl/linux.em (gld${EMULATION_NAME}_before_parse): Likewise.
10+ * emultempl/scoreelf.em (gld${EMULATION_NAME}_before_parse): Likewise.
11+ * testsuite/config/default.exp (ld_elf_shared_opt): Don't set.
12+ * testsuite/ld-elf/pr16322.d: xfail when no relro support.
13+ * testsuite/ld-elf/pr22393-1a.d: Likewise.
14+ * testsuite/ld-elf/pr22393-1b.d: Likewise.
15+ * testsuite/ld-elf/shared.exp (pr20995-2.so, pr20995-2): Likewise.
16+ * testsuite/lib/ld-lib.exp (run_ld_link_tests): Use check_relro_support
17+ to decide whether to pass extra ld option "-z norelro".
18+
119 2020-06-17 H.J. Lu <hongjiu.lu@intel.com>
220
321 * testsuite/ld-elf/linux-x86.exp (check_pr25749a): Append "-w"
--- a/ld/emultempl/aarch64elf.em
+++ b/ld/emultempl/aarch64elf.em
@@ -47,7 +47,13 @@ gld${EMULATION_NAME}_before_parse (void)
4747 config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
4848 config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
4949 link_info.check_relocs_after_open_input = TRUE;
50+EOF
51+if test -n "$COMMONPAGESIZE"; then
52+fragment <<EOF
5053 link_info.relro = DEFAULT_LD_Z_RELRO;
54+EOF
55+fi
56+fragment <<EOF
5157 }
5258
5359 static void
--- a/ld/emultempl/armelf.em
+++ b/ld/emultempl/armelf.em
@@ -60,7 +60,13 @@ gld${EMULATION_NAME}_before_parse (void)
6060 config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
6161 config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
6262 link_info.check_relocs_after_open_input = TRUE;
63+EOF
64+if test -n "$COMMONPAGESIZE"; then
65+fragment <<EOF
6366 link_info.relro = DEFAULT_LD_Z_RELRO;
67+EOF
68+fi
69+fragment <<EOF
6470 }
6571
6672 static void
--- a/ld/emultempl/elf.em
+++ b/ld/emultempl/elf.em
@@ -82,7 +82,13 @@ gld${EMULATION_NAME}_before_parse (void)
8282 config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
8383 config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
8484 link_info.check_relocs_after_open_input = TRUE;
85+EOF
86+if test -n "$COMMONPAGESIZE"; then
87+fragment <<EOF
8588 link_info.relro = DEFAULT_LD_Z_RELRO;
89+EOF
90+fi
91+fragment <<EOF
8692 link_info.separate_code = DEFAULT_LD_Z_SEPARATE_CODE;
8793 }
8894
@@ -805,10 +811,16 @@ fragment <<EOF
805811 link_info.combreloc = FALSE;
806812 else if (strcmp (optarg, "nocopyreloc") == 0)
807813 link_info.nocopyreloc = TRUE;
814+EOF
815+if test -n "$COMMONPAGESIZE"; then
816+fragment <<EOF
808817 else if (strcmp (optarg, "relro") == 0)
809818 link_info.relro = TRUE;
810819 else if (strcmp (optarg, "norelro") == 0)
811820 link_info.relro = FALSE;
821+EOF
822+fi
823+fragment <<EOF
812824 else if (strcmp (optarg, "separate-code") == 0)
813825 link_info.separate_code = TRUE;
814826 else if (strcmp (optarg, "noseparate-code") == 0)
--- a/ld/emultempl/linux.em
+++ b/ld/emultempl/linux.em
@@ -52,7 +52,13 @@ gld${EMULATION_NAME}_before_parse (void)
5252 input_flags.dynamic = TRUE;
5353 config.has_shared = TRUE;
5454 link_info.check_relocs_after_open_input = TRUE;
55+EOF
56+if test -n "$COMMONPAGESIZE"; then
57+fragment <<EOF
5558 link_info.relro = DEFAULT_LD_Z_RELRO;
59+EOF
60+fi
61+fragment <<EOF
5662 }
5763
5864 /* Try to open a dynamic archive. This is where we know that Linux
--- a/ld/emultempl/scoreelf.em
+++ b/ld/emultempl/scoreelf.em
@@ -40,7 +40,13 @@ gld${EMULATION_NAME}_before_parse (void)
4040 config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
4141 config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
4242 link_info.check_relocs_after_open_input = TRUE;
43+EOF
44+if test -n "$COMMONPAGESIZE"; then
45+fragment <<EOF
4346 link_info.relro = DEFAULT_LD_Z_RELRO;
47+EOF
48+fi
49+fragment <<EOF
4450 }
4551
4652 static void
--- a/ld/testsuite/config/default.exp
+++ b/ld/testsuite/config/default.exp
@@ -76,9 +76,6 @@ if {[file exists tmpdir/libpath.exp]} {
7676 }
7777 }
7878
79-# Many ELF testcases expect that "-z relro" is off.
80-set ld_elf_shared_opt "-z norelro"
81-
8279 # The "make check" target in the Makefile passes in
8380 # "CC=$(CC_FOR_TARGET)". But, if the user invokes runtest directly
8481 # (as when testing an installed linker), these flags may not be set.
--- a/ld/testsuite/ld-elf/pr16322.d
+++ b/ld/testsuite/ld-elf/pr16322.d
@@ -2,6 +2,7 @@
22 #readelf: -l --wide
33 #target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi
44 #xfail: ![check_shared_lib_support]
5+#xfail: ![check_relro_support]
56
67 #...
78 GNU_RELRO .*
--- a/ld/testsuite/ld-elf/pr22393-1a.d
+++ b/ld/testsuite/ld-elf/pr22393-1a.d
@@ -3,6 +3,7 @@
33 #readelf: -l --wide
44 #target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi
55 #xfail: ![check_shared_lib_support]
6+#xfail: ![check_relro_support]
67
78 #failif
89 #...
--- a/ld/testsuite/ld-elf/pr22393-1b.d
+++ b/ld/testsuite/ld-elf/pr22393-1b.d
@@ -3,6 +3,7 @@
33 #readelf: -l --wide
44 #target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi
55 #xfail: ![check_shared_lib_support]
6+#xfail: ![check_relro_support]
67
78 #failif
89 #...
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -454,16 +454,6 @@ run_ld_link_tests [list \
454454 {pr20995b.s} {} "pr20995.so"] \
455455 ]
456456
457-# xfail on arm*-*-eabi*. The list can be enlarged to those targets that
458-# don't support GNU_RELRO. For more details, please see discussions at:
459-# https://sourceware.org/ml/binutils/2017-01/msg00441.html
460-run_ld_link_tests [list \
461- [list "Build pr20995-2.so" \
462- "-shared -z relro" "" "$AFLAGS_PIC" \
463- {pr20995c.s} {{readelf {-l --wide} pr20995-2so.r}} "pr20995-2.so"] \
464-] "tic6x-*-*" "arm*-*-eabi*" "hppa*64*-*-hpux*" "aarch64*-*-elf*" \
465- "*-*-lynxos*" "arm*-*-nto*" "i?86-*-nto*" "sh*-*-nto*"
466-
467457 # These targets don't copy dynamic variables into .bss.
468458 setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*"
469459 # or don't have .data.rel.ro
@@ -474,16 +464,22 @@ run_ld_link_tests [list \
474464 "$LFLAGS" "tmpdir/pr20995.so" "$AFLAGS_NONPIC" \
475465 {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995"]]
476466
477-# xfail on arm*-*-eabi* is particularly because of no support of GNU_RELRO.
478-# Please see the link above for details.
479-setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*" "arm*-*-eabi*"
480-setup_xfail "hppa*64*-*-hpux*" "aarch64*-*-elf*" "tic6x-*-*"
467+# xfail on targets that don't support GNU_RELRO.
468+# For more details, please see discussions at:
469+# https://sourceware.org/ml/binutils/2017-01/msg00441.html
470+run_ld_link_tests [list \
471+ [list "Build pr20995-2.so" \
472+ "-shared -z relro" "" "$AFLAGS_PIC" \
473+ {pr20995c.s} {{readelf {-l --wide} pr20995-2so.r}} "pr20995-2.so"] \
474+] {![check_relro_support]}
475+
476+setup_xfail alpha-*-* xtensa-*-*
481477 run_ld_link_tests [list \
482478 [list \
483479 "pr20995-2" \
484480 "$LFLAGS" "tmpdir/pr20995-2.so" "$AFLAGS_NONPIC" \
485481 {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995-2"]
486-] "*-*-lynxos*" "arm*-*-nto*" "i?86-*-nto*" "sh*-*-nto*"
482+] {![check_relro_support]}
487483
488484 run_ld_link_tests [list \
489485 [list "Build pr22374 shared library" \
--- 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 } {
463463 global CFLAGS
464464 global runtests
465465 global exec_output
466- global ld_elf_shared_opt
467466
468- if { [is_elf_format] && [check_shared_lib_support] } {
469- set ld_extra_opt "$ld_elf_shared_opt"
470- } else {
471- set ld_extra_opt ""
467+ set ld_extra_opt ""
468+ if [check_relro_support] {
469+ set ld_extra_opt "-z norelro"
472470 }
473471
474472 foreach testitem $ldtests {