https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118636
Bug ID: 118636
Summary: `-Werror` and `-w` do not affect linker warnings, but
the docs say they should [docs bug?]
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: driver
Assignee: unassigned at gcc dot gnu.org
Reporter: evaned at gmail dot com
Target Milestone: ---
[Detailed information, including the input file, are at the end of the report.]
This could be considered either a behavior bug or a documentation bug. There
wasn't a Docs component to select and the bug writing guidelines don't provide
info on filing documentation bugs, so please excuse if this isn't quite the
format you want for that.
I discovered during an online discussion that `-Werror` does not affect linker
warnings:
/tmp$ gcc -Werror linker-warning.c -o linker-warning
/usr/bin/ld: warning: /tmp/cciBYjrB.o: requires executable stack (because
the .note.GNU-stack section is executable)
/tmp$ echo $?
0
/tmp$ ./linker-warning
/tmp$
Should it? According to the documentation, yes.
There's a corresponding problem where `-w` does not suppress linker warnings,
even though the documentation says it should.
I'll argue that the docs do in fact say that `-Werror` should fail a
compilation when the linker warns, discuss if this is a behavior that should be
changed, propose doc changes, and then provide the detailed info about my
environment.
THE DOCS SAY IT SHOULD WORK
===
Here's what the docs say the flags should do:
-w
Inhibit all warning messages.
-Werror
Make all warnings into errors.
Emphasis on the word "all", and lack of any mention that linker warnings are
not included.
Maybe the section they are in has that qualification? Let's see:
3.9 Options to Request or Suppress Warnings
Warnings are diagnostic messages that report constructions that
are not inherently erroneous but that are risky or suggest there
may have been an error.
The following language-independent options do not enable specific
warnings but control the kinds of diagnostics produced by GCC.
I would say not really.
"Produced by GCC" is moving in that direction, but at best it's ambiguous. You
could read it as appling to just the compiler proper, but this has two
problems. First, I feel that this interpretation is one of those things where a
prerequisite to understanding something is to already understand it. Second,
and worse, is that the very first sentence of the "description" of GCC in the
manpage is "When you invoke GCC, it normally does preprocessing, compilation,
assembly and linking." But if "GCC" is supposed to refer to the compiler
proper, clearly the description of what GCC *is* is incorrect.
Further, even if the section intro had such a clarification, I think the
documentation would still be quite poor on this point, and not reflective of
how people most use reference docs like manpages, which is to search for the
specific thing of interest.
Ironically enough, I *was* going to say the following:
The closest thing to an unambiguous statement that `-Werror`
refers to just compiler warnings is if you note that it is part of
the output of `--help=warnings`, the behavior of which is
described as "Display all of the options controlling warning
messages produced by the compiler," with emphasis on "by the
compiler."
... but THAT IS WRONG! `-Werror` is actually NOT included in that output!
(Another bug?)
I feel quite confident in claiming that the documentation says that `-Werror`
should affect linker warnings.
DOC OR BEHAVIOR BUG?
This bug could be viewed in a couple of ways.
The first is a behavior bug, where the GCC driver should pass
`--fatal-warnings` to the linker. I think there are some obvious attractions to
this change, and it should be considered.
That said, I don't know how universal that flag is. I checked ld.bfd, ld.gold,
lld, and mold and all support that flag, so maybe it's universal enough (or any
remaining problems can be papered over in the linker script), but I don't say
that with confidence.
Potentially a bigger problem is that while `-Werror` would be improved, it
introduces a gulf with some other warning flags. I mentioned how `-w` doesn't
suppress linker warnings, but I don't see an analogue to `-w` for the linker
that the driver could pass; just a bunch of individual no-warning flags that
vary by linker and linker version. And of course the GCC driver allows
controlling compiler warnings with `-Wnonnull` or whatever, and I have
layperson concerns about if GCC could similarly control linker warnings; and
assuming those concerns are wel