public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: binutils@sourceware.org
Subject: [PATCH] ld: Turn on --error-execstack for --warn-execstack --fatal-warnings
Date: Fri, 26 Jan 2024 09:28:15 -0800	[thread overview]
Message-ID: <20240126172815.3007950-1-hjl.tools@gmail.com> (raw)

Since --fatal-warnings always turns a warning to an error, turn on
--error-execstack for --warn-execstack --fatal-warnings and override
--no-error-execstack.

	PR ld/31299
	* lexsup.c (parse_args): Override --no-error-execstack and turn
	on --error-execstack for --warn-execstack --fatal-warnings.
	* testsuite/ld-elf/elf.exp: Run PR ld/31299 test.
	* testsuite/ld-elf/pr31299.error: New file.
---
 ld/lexsup.c                       | 5 +++++
 ld/testsuite/ld-elf/elf.exp       | 8 ++++++++
 ld/testsuite/ld-elf/pr31299.error | 2 ++
 3 files changed, 15 insertions(+)
 create mode 100644 ld/testsuite/ld-elf/pr31299.error

diff --git a/ld/lexsup.c b/ld/lexsup.c
index 099dff8ecde..e81059d53ba 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -1947,6 +1947,11 @@ parse_args (unsigned argc, char **argv)
       && command_line.check_section_addresses < 0)
     command_line.check_section_addresses = 0;
 
+  /* Override --no-error-execstack and turn on --error-execstack for
+    --warn-execstack --fatal-warnings.  */
+  if (link_info.warn_execstack && config.fatal_warnings)
+    link_info.error_execstack = 1;
+
   if (export_list)
     {
       struct bfd_elf_version_expr *head = export_list->head.list;
diff --git a/ld/testsuite/ld-elf/elf.exp b/ld/testsuite/ld-elf/elf.exp
index 685b87588e7..511ca569ffd 100644
--- a/ld/testsuite/ld-elf/elf.exp
+++ b/ld/testsuite/ld-elf/elf.exp
@@ -318,6 +318,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.error}} \
+	    "pr31299.exe"] \
 	]
     } else {
 	run_ld_link_tests [list \
diff --git a/ld/testsuite/ld-elf/pr31299.error b/ld/testsuite/ld-elf/pr31299.error
new file mode 100644
index 00000000000..d1a9569a374
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr31299.error
@@ -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
-- 
2.43.0


                 reply	other threads:[~2024-01-26 17:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240126172815.3007950-1-hjl.tools@gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).