GNU Binutils with patches for OS216
修订版 | 5fd104addfddb68844fb8df67be832ee98ad9888 (tree) |
---|---|
时间 | 2020-06-19 09:20:20 |
作者 | Alan Modra <amodra@gmai...> |
Commiter | Alan Modra |
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".
@@ -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 | + | |
1 | 8 | 2020-06-11 Alan Modra <amodra@gmail.com> |
2 | 9 | |
3 | 10 | * readelf.c (process_mips_specific): Don't alloc memory for |
@@ -34,8 +34,6 @@ if ![info exists LD] then { | ||
34 | 34 | if ![info exists LDFLAGS] then { |
35 | 35 | set LDFLAGS "" |
36 | 36 | } |
37 | -set ld_elf_shared_opt "-z norelro" | |
38 | - | |
39 | 37 | if ![info exists NM] then { |
40 | 38 | set NM [findfile $base_dir/nm-new $base_dir/nm-new [transform nm]] |
41 | 39 | } |
@@ -308,6 +308,25 @@ proc check_pie_support { } { | ||
308 | 308 | return $pie_available_saved |
309 | 309 | } |
310 | 310 | |
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 | + | |
311 | 330 | # Compare two files line-by-line. FILE_1 is the actual output and FILE_2 |
312 | 331 | # is the expected output. Ignore blank lines in either file. |
313 | 332 | # |
@@ -729,7 +748,7 @@ proc run_dump_test { name {extra_options {}} } { | ||
729 | 748 | global ADDR2LINE ADDR2LINEFLAGS AS ASFLAGS ELFEDIT ELFEDITFLAGS LD LDFLAGS |
730 | 749 | global NM NMFLAGS OBJCOPY OBJCOPYFLAGS OBJDUMP OBJDUMPFLAGS |
731 | 750 | 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 | |
733 | 752 | |
734 | 753 | if [string match "*/*" $name] { |
735 | 754 | set file $name |
@@ -1119,9 +1138,9 @@ proc run_dump_test { name {extra_options {}} } { | ||
1119 | 1138 | set ld_extra_opt "" |
1120 | 1139 | global ld |
1121 | 1140 | 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 | + } | |
1125 | 1144 | |
1126 | 1145 | # Add -L$srcdir/$subdir so that the linker command can use |
1127 | 1146 | # linker scripts in the source directory. |
@@ -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 | + | |
1 | 19 | 2020-06-17 H.J. Lu <hongjiu.lu@intel.com> |
2 | 20 | |
3 | 21 | * testsuite/ld-elf/linux-x86.exp (check_pr25749a): Append "-w" |
@@ -47,7 +47,13 @@ gld${EMULATION_NAME}_before_parse (void) | ||
47 | 47 | config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`; |
48 | 48 | config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`; |
49 | 49 | link_info.check_relocs_after_open_input = TRUE; |
50 | +EOF | |
51 | +if test -n "$COMMONPAGESIZE"; then | |
52 | +fragment <<EOF | |
50 | 53 | link_info.relro = DEFAULT_LD_Z_RELRO; |
54 | +EOF | |
55 | +fi | |
56 | +fragment <<EOF | |
51 | 57 | } |
52 | 58 | |
53 | 59 | static void |
@@ -60,7 +60,13 @@ gld${EMULATION_NAME}_before_parse (void) | ||
60 | 60 | config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`; |
61 | 61 | config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`; |
62 | 62 | link_info.check_relocs_after_open_input = TRUE; |
63 | +EOF | |
64 | +if test -n "$COMMONPAGESIZE"; then | |
65 | +fragment <<EOF | |
63 | 66 | link_info.relro = DEFAULT_LD_Z_RELRO; |
67 | +EOF | |
68 | +fi | |
69 | +fragment <<EOF | |
64 | 70 | } |
65 | 71 | |
66 | 72 | static void |
@@ -82,7 +82,13 @@ gld${EMULATION_NAME}_before_parse (void) | ||
82 | 82 | config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`; |
83 | 83 | config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`; |
84 | 84 | link_info.check_relocs_after_open_input = TRUE; |
85 | +EOF | |
86 | +if test -n "$COMMONPAGESIZE"; then | |
87 | +fragment <<EOF | |
85 | 88 | link_info.relro = DEFAULT_LD_Z_RELRO; |
89 | +EOF | |
90 | +fi | |
91 | +fragment <<EOF | |
86 | 92 | link_info.separate_code = DEFAULT_LD_Z_SEPARATE_CODE; |
87 | 93 | } |
88 | 94 |
@@ -805,10 +811,16 @@ fragment <<EOF | ||
805 | 811 | link_info.combreloc = FALSE; |
806 | 812 | else if (strcmp (optarg, "nocopyreloc") == 0) |
807 | 813 | link_info.nocopyreloc = TRUE; |
814 | +EOF | |
815 | +if test -n "$COMMONPAGESIZE"; then | |
816 | +fragment <<EOF | |
808 | 817 | else if (strcmp (optarg, "relro") == 0) |
809 | 818 | link_info.relro = TRUE; |
810 | 819 | else if (strcmp (optarg, "norelro") == 0) |
811 | 820 | link_info.relro = FALSE; |
821 | +EOF | |
822 | +fi | |
823 | +fragment <<EOF | |
812 | 824 | else if (strcmp (optarg, "separate-code") == 0) |
813 | 825 | link_info.separate_code = TRUE; |
814 | 826 | else if (strcmp (optarg, "noseparate-code") == 0) |
@@ -52,7 +52,13 @@ gld${EMULATION_NAME}_before_parse (void) | ||
52 | 52 | input_flags.dynamic = TRUE; |
53 | 53 | config.has_shared = TRUE; |
54 | 54 | link_info.check_relocs_after_open_input = TRUE; |
55 | +EOF | |
56 | +if test -n "$COMMONPAGESIZE"; then | |
57 | +fragment <<EOF | |
55 | 58 | link_info.relro = DEFAULT_LD_Z_RELRO; |
59 | +EOF | |
60 | +fi | |
61 | +fragment <<EOF | |
56 | 62 | } |
57 | 63 | |
58 | 64 | /* Try to open a dynamic archive. This is where we know that Linux |
@@ -40,7 +40,13 @@ gld${EMULATION_NAME}_before_parse (void) | ||
40 | 40 | config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`; |
41 | 41 | config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`; |
42 | 42 | link_info.check_relocs_after_open_input = TRUE; |
43 | +EOF | |
44 | +if test -n "$COMMONPAGESIZE"; then | |
45 | +fragment <<EOF | |
43 | 46 | link_info.relro = DEFAULT_LD_Z_RELRO; |
47 | +EOF | |
48 | +fi | |
49 | +fragment <<EOF | |
44 | 50 | } |
45 | 51 | |
46 | 52 | static void |
@@ -76,9 +76,6 @@ if {[file exists tmpdir/libpath.exp]} { | ||
76 | 76 | } |
77 | 77 | } |
78 | 78 | |
79 | -# Many ELF testcases expect that "-z relro" is off. | |
80 | -set ld_elf_shared_opt "-z norelro" | |
81 | - | |
82 | 79 | # The "make check" target in the Makefile passes in |
83 | 80 | # "CC=$(CC_FOR_TARGET)". But, if the user invokes runtest directly |
84 | 81 | # (as when testing an installed linker), these flags may not be set. |
@@ -2,6 +2,7 @@ | ||
2 | 2 | #readelf: -l --wide |
3 | 3 | #target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi |
4 | 4 | #xfail: ![check_shared_lib_support] |
5 | +#xfail: ![check_relro_support] | |
5 | 6 | |
6 | 7 | #... |
7 | 8 | GNU_RELRO .* |
@@ -3,6 +3,7 @@ | ||
3 | 3 | #readelf: -l --wide |
4 | 4 | #target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi |
5 | 5 | #xfail: ![check_shared_lib_support] |
6 | +#xfail: ![check_relro_support] | |
6 | 7 | |
7 | 8 | #failif |
8 | 9 | #... |
@@ -3,6 +3,7 @@ | ||
3 | 3 | #readelf: -l --wide |
4 | 4 | #target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi |
5 | 5 | #xfail: ![check_shared_lib_support] |
6 | +#xfail: ![check_relro_support] | |
6 | 7 | |
7 | 8 | #failif |
8 | 9 | #... |
@@ -454,16 +454,6 @@ run_ld_link_tests [list \ | ||
454 | 454 | {pr20995b.s} {} "pr20995.so"] \ |
455 | 455 | ] |
456 | 456 | |
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 | - | |
467 | 457 | # These targets don't copy dynamic variables into .bss. |
468 | 458 | setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*" |
469 | 459 | # or don't have .data.rel.ro |
@@ -474,16 +464,22 @@ run_ld_link_tests [list \ | ||
474 | 464 | "$LFLAGS" "tmpdir/pr20995.so" "$AFLAGS_NONPIC" \ |
475 | 465 | {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995"]] |
476 | 466 | |
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-*-* | |
481 | 477 | run_ld_link_tests [list \ |
482 | 478 | [list \ |
483 | 479 | "pr20995-2" \ |
484 | 480 | "$LFLAGS" "tmpdir/pr20995-2.so" "$AFLAGS_NONPIC" \ |
485 | 481 | {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995-2"] |
486 | -] "*-*-lynxos*" "arm*-*-nto*" "i?86-*-nto*" "sh*-*-nto*" | |
482 | +] {![check_relro_support]} | |
487 | 483 | |
488 | 484 | run_ld_link_tests [list \ |
489 | 485 | [list "Build pr22374 shared library" \ |
@@ -463,12 +463,10 @@ proc run_ld_link_tests { ldtests args } { | ||
463 | 463 | global CFLAGS |
464 | 464 | global runtests |
465 | 465 | global exec_output |
466 | - global ld_elf_shared_opt | |
467 | 466 | |
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" | |
472 | 470 | } |
473 | 471 | |
474 | 472 | foreach testitem $ldtests { |