public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Fangrui Song <i@maskray.me>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: binutils@sourceware.org, nickc@redhat.com
Subject: Re: [PATCH] ld: Improve --fatal-warnings for unknown command-line options
Date: Wed, 24 Jan 2024 23:58:42 -0800	[thread overview]
Message-ID: <DS7PR12MB5765947AB56DB88B0440CFC1CB7A2@DS7PR12MB5765.namprd12.prod.outlook.com> (raw)
In-Reply-To: <20240124225103.219222-1-hjl.tools@gmail.com>

On Wed, Jan 24, 2024 at 2:51 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> There are 2 problems with --fatal-warnings for ignored command-line
> options:
>
> 1. --fatal-warnings doesn't trigger an error for an unknown command-line
> option when --fatal-warnings is the last command-line option.
> 2. When --fatal-warnings triggers an error for an unknown command-line
> option, the message says that the unknown command-line option is ignored.
>
> This patch queues unknown command-line option warnings and outputs queued
> command-line option warnings after all command-line options have been
> processed so that --fatal-warnings can work for unknown command-line
> options regardless of the order of --fatal-warnings.
>
> When --fatal-warnings is used, the linker message is changed from
>
> ld: warning: -z bad-option ignored
>
> to
>
> ld: error: unsupported option: -z bad-option
>
> The above also applies to "-z dynamic-undefined-weak" when the known
> "-z dynamic-undefined-weak" option is ignored.
>
>         PR ld/31289
>         * ldelf.c (ldelf_after_parse): Use queue_unknown_cmdline_warning
>         to warn the ignored -z dynamic-undefined-weak option.
>         * ldmain.c (main): Call output_unknown_cmdline_warnings after
>         calling ldemul_after_parse.
>         * ldmisc.c (CMDLINE_WARNING_SIZE): New.
>         (cmdline_warning_list): Likewise.
>         (cmdline_warning_head): Likewise.
>         (cmdline_warning_tail): Likewise.
>         (queue_unknown_cmdline_warning): Likewise.
>         (output_unknown_cmdline_warnings): Likewise.
>         * ldmisc.h (queue_unknown_cmdline_warning): Likewise.
>         (output_unknown_cmdline_warnings): Likewise.
>         * emultempl/elf.em (gld${EMULATION_NAME}_handle_option): Use
>         queue_unknown_cmdline_warning to warn unknown -z option.
>         * testsuite/ld-elf/pr31289-1a.d: New file.
>         * testsuite/ld-elf/pr31289-1b.d: Likewise.
>         * testsuite/ld-elf/pr31289-2a.d: Likewise.
>         * testsuite/ld-elf/pr31289-2b.d: Likewise.
>         * testsuite/ld-elf/pr31289-3a.d: Likewise.
>         * testsuite/ld-elf/pr31289-3b.d: Likewise.
>         * testsuite/ld-elf/pr31289-4a.d: Likewise.
>         * testsuite/ld-elf/pr31289-4b.d: Likewise.
> ---
>  ld/emultempl/elf.em              |  2 +-
>  ld/ldelf.c                       |  2 +-
>  ld/ldmain.c                      |  2 +
>  ld/ldmisc.c                      | 75 ++++++++++++++++++++++++++++++++
>  ld/ldmisc.h                      |  2 +
>  ld/testsuite/ld-elf/pr31289-1a.d |  5 +++
>  ld/testsuite/ld-elf/pr31289-1b.d |  5 +++
>  ld/testsuite/ld-elf/pr31289-2a.d |  5 +++
>  ld/testsuite/ld-elf/pr31289-2b.d |  5 +++
>  ld/testsuite/ld-elf/pr31289-3a.d |  5 +++
>  ld/testsuite/ld-elf/pr31289-3b.d |  5 +++
>  ld/testsuite/ld-elf/pr31289-4a.d |  5 +++
>  ld/testsuite/ld-elf/pr31289-4b.d |  5 +++
>  13 files changed, 121 insertions(+), 2 deletions(-)
>  create mode 100644 ld/testsuite/ld-elf/pr31289-1a.d
>  create mode 100644 ld/testsuite/ld-elf/pr31289-1b.d
>  create mode 100644 ld/testsuite/ld-elf/pr31289-2a.d
>  create mode 100644 ld/testsuite/ld-elf/pr31289-2b.d
>  create mode 100644 ld/testsuite/ld-elf/pr31289-3a.d
>  create mode 100644 ld/testsuite/ld-elf/pr31289-3b.d
>  create mode 100644 ld/testsuite/ld-elf/pr31289-4a.d
>  create mode 100644 ld/testsuite/ld-elf/pr31289-4b.d

Thanks for the patch. For newer tests, I wonder whether a descriptive
short name (in this case, fatal-warnings-*[ab].s) would be more
suitable than PR<number>.
A descriptive name helps future readers group related tests together.
A PR number is useful as well, but it can be noted down as a comment.

For most other warnings, with --fatal-warnings, "warning: " is still
emitted. `ld: error: unsupported option: -z bad-option` is a nice
improvement:)

  reply	other threads:[~2024-01-25  8:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-24 22:51 H.J. Lu
2024-01-25  7:58 ` Fangrui Song [this message]
2024-01-25  8:24   ` Jan Beulich
2024-01-25 11:32     ` Nick Clifton
2024-01-25 13:41       ` H.J. Lu
2024-01-25 15:45         ` H.J. Lu
2024-01-25 16:12           ` H.J. Lu
2024-01-26 10:24             ` Nick Clifton
2024-01-26 14:11               ` H.J. Lu

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=DS7PR12MB5765947AB56DB88B0440CFC1CB7A2@DS7PR12MB5765.namprd12.prod.outlook.com \
    --to=i@maskray.me \
    --cc=binutils@sourceware.org \
    --cc=hjl.tools@gmail.com \
    --cc=nickc@redhat.com \
    /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).