public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* RFC: Document unexpected behaviour of --fatal-warnings
@ 2024-01-23 12:28 Nick Clifton
  2024-01-23 12:38 ` Jan Beulich
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Nick Clifton @ 2024-01-23 12:28 UTC (permalink / raw)
  To: binutils; +Cc: serge.guelton

Hi Guys,

  It was recently pointed out to me that the bfd linker's
  --fatal-warnings option can behave in an unexpected manner.  For
  example:

    $ ld.bfd -z bad-option --fatal-warnings -e 0/dev/null
    ld.bfd: warning: -z bad-option ignored
    $ echo $?
    0

  ie the warning about the ignored option is not being treated as an
  error.  This happens because the --fatal-warnings option only takes
  affect after it has been processed, and we process the options in a
  linear order.  So the following works:

    $ ld.bfd --fatal-warnings -z bad-option -e 0 /dev/null
    ld.bfd: warning: -z bad-option ignored
    $ echo $?
    1

  This behaviour differs from gold and lld, both of which honour
  --fatal-warnings no matter where it occurs on the command line.

  So we could fix the linker, create a two pass argument scan and the
  problem would be solved.  But a) I am lazy and b) we already have a
  precedent for options on the command line only affecting options that
  come after it.  (I am thinking of the -L option here, although there
  are probably several others).  So instead I am considering documenting
  the current behaviour as expected.  (See the patch below).

  What do people think ?

Cheers
  Nick

diff --git a/ld/ld.texi b/ld/ld.texi
index 4fda259a552..16ab08e03f2 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -1993,7 +1993,20 @@ in filename invoked by -R or --just-symbols
 @item --fatal-warnings
 @itemx --no-fatal-warnings
 Treat all warnings as errors.  The default behaviour can be restored
-with the option @option{--no-fatal-warnings}.
+with the option @option{--no-fatal-warnings}.  Note: this option does
+not affects warnings generated by other command line options that are
+placed before it on the command line.  So for example:
+
+@smallexample
+$ ld -z bad-option --fatal-warnings -e 0/dev/null
+ld: warning: -z bad-option ignored
+$ echo $?
+0
+$ ld --fatal-warnings -z bad-option -e 0 /dev/null
+ld: warning: -z bad-option ignored
+$ echo $?
+1
+@end smallexample
 
 @kindex -w
 @kindex --no-warnings


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-01-24 22:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-23 12:28 RFC: Document unexpected behaviour of --fatal-warnings Nick Clifton
2024-01-23 12:38 ` Jan Beulich
2024-01-23 12:50   ` H.J. Lu
2024-01-23 13:15     ` H.J. Lu
2024-01-24 15:07 ` Serge Guelton
2024-01-24 15:13 ` Sam James
2024-01-24 16:06   ` H.J. Lu
2024-01-24 22:52     ` H.J. Lu

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).