ld: Turn on --error-execstack/--error-rwx-segments
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_binutils_build--master-arm |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_binutils_check--master-arm |
fail
|
Testing failed
|
Commit Message
Since --fatal-warnings always turns a warning to an error, turn on
--error-execstack for --warn-execstack and --error-rwx-segments for
--warn-rwx-segments if --fatal-warnings is used, overriding
--no-error-execstack and --no-error-rwx-segments.
PR ld/31299
* lexsup.c (parse_args): Turn on --error-execstack for
--warn-execstack and --error-rwx-segments for --warn-rwx-segments
if --fatal-warnings is used.
* testsuite/ld-elf/elf.exp: Run PR ld/31299 tests.
* testsuite/ld-elf/pr31299-1.error: New file.
* testsuite/ld-elf/pr31299-2.error: Likewise.
* testsuite/ld-elf/pr31299-3.error: Likewise.
---
ld/lexsup.c | 11 +++++++++++
ld/testsuite/ld-elf/elf.exp | 26 +++++++++++++++++++++++++-
ld/testsuite/ld-elf/pr31299-1.error | 2 ++
ld/testsuite/ld-elf/pr31299-2.error | 1 +
ld/testsuite/ld-elf/pr31299-3.error | 1 +
5 files changed, 40 insertions(+), 1 deletion(-)
create mode 100644 ld/testsuite/ld-elf/pr31299-1.error
create mode 100644 ld/testsuite/ld-elf/pr31299-2.error
create mode 100644 ld/testsuite/ld-elf/pr31299-3.error
@@ -1947,6 +1947,17 @@ parse_args (unsigned argc, char **argv)
&& command_line.check_section_addresses < 0)
command_line.check_section_addresses = 0;
+ /* Override --no-error-execstack and --no-warn-execstack and turn on
+ --error-execstack for --warn-execstack and --error-rwx-segments for
+ --warn-rwx-segments if --fatal-warnings is used. */
+ if (config.fatal_warnings)
+ {
+ if (link_info.warn_execstack)
+ link_info.error_execstack = 1;
+ if (!link_info.no_warn_rwx_segments)
+ link_info.warn_is_error_for_rwx_segments = 1;
+ }
+
if (export_list)
{
struct bfd_elf_version_expr *head = export_list->head.list;
@@ -305,7 +305,23 @@ if { [istarget *-*-*linux*]
{nobits-1.s} \
{} \
"rwx-segments-3.exe"] \
- ]
+ [list "Ensure that an error issued when creating a segment with RWX permissions" \
+ "-e 0 -Tnobits-1.t --warn-rwx-segments \
+ --fatal-warnings --no-error-rwx-segments" \
+ "" \
+ "" \
+ {nobits-1.s} \
+ {{ld pr31299-2.error}} \
+ "pr31299-2.exe"] \
+ [list "Ensure that an error issued when creating a TLS segment with execute permission" \
+ "-e 0 -T rwx-segments-2.t --warn-rwx-segments \
+ --fatal-warnings --no-error-rwx-segments" \
+ "" \
+ "" \
+ {size-2.s} \
+ {{ld pr31299-3.error}} \
+ "pr31299-3.exe"] \
+ ]
set LDFLAGS $curr_ldflags
@@ -318,6 +334,14 @@ if { [istarget *-*-*linux*]
{pr29072-b.s} \
{{ld pr29072.b.warn}} \
"pr29072-b.exe"] \
+ [list "PR ld/31299 (error about absent .note.GNU-stack)" \
+ "-e 0 -z stack-size=0x123400 --warn-execstack \
+ --fatal-warnings --no-error-execstack" \
+ "" \
+ "" \
+ {pr29072-b.s} \
+ {{ld pr31299-1.error}} \
+ "pr31299-1.exe"] \
]
} else {
run_ld_link_tests [list \
new file mode 100644
@@ -0,0 +1,2 @@
+.*: error: .*\.o: is triggering the generation of an executable stack because it does not have a \.note\.GNU-stack section
+.*: failed to set dynamic section sizes: file format not recognized
new file mode 100644
@@ -0,0 +1 @@
+.*: error: .* has a LOAD segment with RWX permissions
new file mode 100644
@@ -0,0 +1 @@
+.*: error: .* has a TLS segment with execute permission