Bug 29654 - ld: add -w to suppress warnings
Summary: ld: add -w to suppress warnings
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.40
: P2 normal
Target Milestone: ---
Assignee: Nick Clifton
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-10-05 22:51 UTC by Fangrui Song
Modified: 2022-10-21 11:27 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Proposed patch (1.50 KB, patch)
2022-10-18 15:50 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2022-10-05 22:51:58 UTC
Apple ld64 and llvm-project ld64.lld support -w to suppress warnings. -w was picked likely because compiler drivers use -w to suppress warnings.
I think -w mildly benefits GNU ld/gold as well.

With --noinhibit-exec, we downgrade errors to warnings. When analyzing a large executable with relocation overflow issues, we may use --noinhibit-exec --emit-relocs
to get relocations and an output file despite relocation overflow issues.
Since we know the output otherwise does not link, the warnings are not useful. If we have -w, we can add -w to not see the unuseful warnings.
Comment 1 Nick Clifton 2022-10-18 15:50:29 UTC
Created attachment 14403 [details]
Proposed patch

Hi Fanguri,

  Is this patch the kind of thing that you had in mind ?

Cheers
  Nick
Comment 2 Fangrui Song 2022-10-18 20:45:29 UTC
(In reply to Nick Clifton from comment #1)
> Created attachment 14403 [details]
> Proposed patch
> 
> Hi Fanguri,
> 
>   Is this patch the kind of thing that you had in mind ?
> 
> Cheers
>   Nick

Hi Nick, thanks for sending a patch! This looks good with just one thought:

`config.fatal_warnings = false;` makes me wonder how -w interacts with --fatal-warnings. It seems that -w --fatal-warnings and --fatal-warnings -w have the same effect (-w wins, which makes sense IMO), so I guess `config.fatal_warnings = false;` can be omitted.
Comment 3 Sourceware Commits 2022-10-21 11:20:42 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4b2e7a577c2f7311a8c381ff791d46e654c41fcc

commit 4b2e7a577c2f7311a8c381ff791d46e654c41fcc
Author: Nick Clifton <nickc@redhat.com>
Date:   Fri Oct 21 12:20:09 2022 +0100

    Add a -w option to the linker to suppress warning and error messages.
    
            PR 29654
            * ld.h (struct ld_config_type): Add no_warnings field.
            * ldlex.h (enum option_values): Add OPTION_NO_WARNINGS.
            * lexsup.c (ld_options): Add --no-warnings.
            (parse_args): Add support for -w and --no-warnings.
            * ldmisc.c (vfinfo): Return early if the message is a warning and
            -w has been enabled.
            * ld.texi (options): Document new command line option.
            * NEWS: Mention the new feature.
Comment 4 Nick Clifton 2022-10-21 11:27:11 UTC
Hi Fangrui,
  
> `config.fatal_warnings = false;` makes me wonder how -w interacts with
> --fatal-warnings. It seems that -w --fatal-warnings and --fatal-warnings -w
> have the same effect (-w wins, which makes sense IMO), so I guess
> `config.fatal_warnings = false;` can be omitted.

It could, but I feel that it helps to emphasize that -w takes precedence over --fatal-warnings, so I have left it in.

Cheers
  Nick