public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug preprocessor/109183] New: [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files
@ 2023-03-18 10:36 yann at droneaud dot fr
  2023-03-20  9:19 ` [Bug preprocessor/109183] " rguenth at gcc dot gnu.org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: yann at droneaud dot fr @ 2023-03-18 10:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109183

            Bug ID: 109183
           Summary: [regression?] since GCC 11.1, -MM -MMD generates "a-"
                    prefixed dependency files
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yann at droneaud dot fr
  Target Milestone: ---

I've found a rather surprising behavior change when using GCC >= 11.1 to build
some project using custom build environment.

How to reproduce:

    : > test.c
    gcc -MM -MMD test.c
    test -e a-test.d && echo "unexpected dependency file name"

I've git-bisect-ed between GCC 11.1 and GCC 10.1 and the behavior change did
happen as the result of this commit:

    commit 1dedc12d186a110854537e1279b4e6c29f2df35a
    Author: Alexandre Oliva <oliva@adacore.com>
    Date:   Tue May 26 04:30:15 2020 -0300

        revamp dump and aux output names

   
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=1dedc12d186a110854537e1279b4e6c29f2df35a

I didn't find an explanation there for this behavior change.

It's not noted in the documentation either
https://gcc.gnu.org/onlinedocs/gcc-11.3.0/gcc/Preprocessor-Options.html

So this make me believe it's some kind of regression for a corner case.

I understand the correct usage of -MMD is to be associated with some
processing, -E, -S, -c, etc, while -MM imply -E, so perhaps -MM and -MMD are
mutually exclusive and should not be allowed together. I dunno.

But generating "a-" prefixed dependency files is rather unexpected.

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

* [Bug preprocessor/109183] [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files
  2023-03-18 10:36 [Bug preprocessor/109183] New: [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files yann at droneaud dot fr
@ 2023-03-20  9:19 ` rguenth at gcc dot gnu.org
  2023-03-21 18:46 ` yann at droneaud dot fr
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-03-20  9:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109183

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aoliva at gcc dot gnu.org

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
It's expected, there might be a way to get back the old behavior.  Alex can
probably explain.

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

* [Bug preprocessor/109183] [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files
  2023-03-18 10:36 [Bug preprocessor/109183] New: [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files yann at droneaud dot fr
  2023-03-20  9:19 ` [Bug preprocessor/109183] " rguenth at gcc dot gnu.org
@ 2023-03-21 18:46 ` yann at droneaud dot fr
  2023-03-26 19:29 ` aoliva at gcc dot gnu.org
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: yann at droneaud dot fr @ 2023-03-21 18:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109183

Yann Droneaud <yann at droneaud dot fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yann at droneaud dot fr

--- Comment #2 from Yann Droneaud <yann at droneaud dot fr> ---
gcc -MM -MMD seems to behave like

  gcc -dumpbase a -MM -MMD test.c

or

  gcc -dumpdir a- -MM -MMD test.c

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

* [Bug preprocessor/109183] [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files
  2023-03-18 10:36 [Bug preprocessor/109183] New: [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files yann at droneaud dot fr
  2023-03-20  9:19 ` [Bug preprocessor/109183] " rguenth at gcc dot gnu.org
  2023-03-21 18:46 ` yann at droneaud dot fr
@ 2023-03-26 19:29 ` aoliva at gcc dot gnu.org
  2023-03-27 17:23 ` yann at droneaud dot fr
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: aoliva at gcc dot gnu.org @ 2023-03-26 19:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109183

--- Comment #3 from Alexandre Oliva <aoliva at gcc dot gnu.org> ---
dump files now consistently take the base name from the output name, when not
overridden

since in this case gcc is called for (compiling and) linking, and the final
output name is a.* (.out or .exe, depending on the platform), the prefix for
dump files is taken to be 'a'.  since there could be multiple source files, the
source file name is then appended to the prefix to form each compilation's dump
file base name.  using the randomized temporary output names for each
compilation wouldn't make for predictable dump file names, which was a primary
motivator for this implementation.  enabling separate dump files from multiple
compilations of the same source file was another.

change can be surprising, but the previous behaviors (they changed over time)
were very often undesirable, now (because we have tons of tests for the current
behavior) it will hopefully settle down, and will eventually feel intuitive and
just "right" :-)

thanks for bearing with us,

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

* [Bug preprocessor/109183] [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files
  2023-03-18 10:36 [Bug preprocessor/109183] New: [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files yann at droneaud dot fr
                   ` (2 preceding siblings ...)
  2023-03-26 19:29 ` aoliva at gcc dot gnu.org
@ 2023-03-27 17:23 ` yann at droneaud dot fr
  2023-04-13 16:09 ` allan.w.macdonald at gmail dot com
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: yann at droneaud dot fr @ 2023-03-27 17:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109183

--- Comment #4 from Yann Droneaud <yann at droneaud dot fr> ---
(In reply to Alexandre Oliva from comment #3)
> dump files now consistently take the base name from the output name, when
> not overridden
> 
> since in this case gcc is called for (compiling and) linking, and the final
> output name is a.* (.out or .exe, depending on the platform),

That the issue at hand, `gcc -MM -MMD test.c` does not compile nor link
anything: it preprocess and extract dependencies, nothing more. Thus using
"a.out" as the output is not expected.

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

* [Bug preprocessor/109183] [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files
  2023-03-18 10:36 [Bug preprocessor/109183] New: [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files yann at droneaud dot fr
                   ` (3 preceding siblings ...)
  2023-03-27 17:23 ` yann at droneaud dot fr
@ 2023-04-13 16:09 ` allan.w.macdonald at gmail dot com
  2023-04-13 16:12 ` allan.w.macdonald at gmail dot com
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: allan.w.macdonald at gmail dot com @ 2023-04-13 16:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109183

Allan W. Macdonald <allan.w.macdonald at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |allan.w.macdonald at gmail dot com

--- Comment #5 from Allan W. Macdonald <allan.w.macdonald at gmail dot com> ---
This is annoying as it breaks all my existing makefiles.

Here is a workaround:

$ gcc-11 -E -MMD test.c > /dev/null

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

* [Bug preprocessor/109183] [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files
  2023-03-18 10:36 [Bug preprocessor/109183] New: [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files yann at droneaud dot fr
                   ` (4 preceding siblings ...)
  2023-04-13 16:09 ` allan.w.macdonald at gmail dot com
@ 2023-04-13 16:12 ` allan.w.macdonald at gmail dot com
  2023-04-13 16:12 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: allan.w.macdonald at gmail dot com @ 2023-04-13 16:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109183

--- Comment #6 from Allan W. Macdonald <allan.w.macdonald at gmail dot com> ---
(In reply to Allan W. Macdonald from comment #5)
> Here is a workaround:

or just 

gcc -E -MMD test.c > /dev/null

if gcc-11 is default gcc.

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

* [Bug preprocessor/109183] [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files
  2023-03-18 10:36 [Bug preprocessor/109183] New: [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files yann at droneaud dot fr
                   ` (5 preceding siblings ...)
  2023-04-13 16:12 ` allan.w.macdonald at gmail dot com
@ 2023-04-13 16:12 ` pinskia at gcc dot gnu.org
  2023-04-13 16:21 ` allan.w.macdonald at gmail dot com
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-13 16:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109183

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Does using -c instead help?

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

* [Bug preprocessor/109183] [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files
  2023-03-18 10:36 [Bug preprocessor/109183] New: [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files yann at droneaud dot fr
                   ` (6 preceding siblings ...)
  2023-04-13 16:12 ` pinskia at gcc dot gnu.org
@ 2023-04-13 16:21 ` allan.w.macdonald at gmail dot com
  2023-04-13 16:31 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: allan.w.macdonald at gmail dot com @ 2023-04-13 16:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109183

--- Comment #8 from Allan W. Macdonald <allan.w.macdonald at gmail dot com> ---
(In reply to Andrew Pinski from comment #7)
> Does using -c instead help?

Why would we want to compile the file without FIRST checking for dependencies?  

The .d file needs to be up to date so that an included makefile rule can check
for any changes in the files listed in each .d file before the target file is
compiled.

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

* [Bug preprocessor/109183] [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files
  2023-03-18 10:36 [Bug preprocessor/109183] New: [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files yann at droneaud dot fr
                   ` (7 preceding siblings ...)
  2023-04-13 16:21 ` allan.w.macdonald at gmail dot com
@ 2023-04-13 16:31 ` jakub at gcc dot gnu.org
  2023-04-13 16:40 ` schwab@linux-m68k.org
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-04-13 16:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109183

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
And why would you want to preprocess it when not needed?  That is the same
thing.
Normally the dependencies are generated when a source file is being compiled.
And, that compilation happens when either the corresponding file with
dependencies doesn't exist or the object file is older than at least one of its
dependencies.

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

* [Bug preprocessor/109183] [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files
  2023-03-18 10:36 [Bug preprocessor/109183] New: [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files yann at droneaud dot fr
                   ` (8 preceding siblings ...)
  2023-04-13 16:31 ` jakub at gcc dot gnu.org
@ 2023-04-13 16:40 ` schwab@linux-m68k.org
  2023-04-13 19:27 ` allan.w.macdonald at gmail dot com
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: schwab@linux-m68k.org @ 2023-04-13 16:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109183

--- Comment #10 from Andreas Schwab <schwab@linux-m68k.org> ---
If you want to generate only dependencies, use -M or -MM.  -MD and -MMD are
primarily used to generate dependencies as side effect of compilation.

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

* [Bug preprocessor/109183] [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files
  2023-03-18 10:36 [Bug preprocessor/109183] New: [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files yann at droneaud dot fr
                   ` (9 preceding siblings ...)
  2023-04-13 16:40 ` schwab@linux-m68k.org
@ 2023-04-13 19:27 ` allan.w.macdonald at gmail dot com
  2023-04-13 21:05 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: allan.w.macdonald at gmail dot com @ 2023-04-13 19:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109183

--- Comment #11 from Allan W. Macdonald <allan.w.macdonald at gmail dot com> ---
The makefiles I've been maintaining contain a mechanism to make sure that any
change in a locally-included file will cause the c file that includes it to be
compiled again, like so:

### Extract of makefile:
%.d: %.c
        gcc -MM -MD $<

-include $(OBJECTS:.o=.d)
###

So, if I understand this correctly (tell me if I'm wrong), preprocessing is
performed to generate the .d files before any file is compiled to an object in
this situation.  These .d files are then included and turned into rules using a
substitution reference.

The 'a-' prefix breaks this mechanism.

The workaround I mentioned,

        gcc -E -MMD $< > /dev/null

seems to achieve the same behaviour but there's probably a better way to do it.

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

* [Bug preprocessor/109183] [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files
  2023-03-18 10:36 [Bug preprocessor/109183] New: [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files yann at droneaud dot fr
                   ` (10 preceding siblings ...)
  2023-04-13 19:27 ` allan.w.macdonald at gmail dot com
@ 2023-04-13 21:05 ` pinskia at gcc dot gnu.org
  2023-04-14 12:52 ` allan.w.macdonald at gmail dot com
  2023-04-14 13:45 ` schwab@linux-m68k.org
  13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-13 21:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109183

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unknown                     |11.1.0

--- Comment #12 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This what the gcc.cc includes:
 %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\
 %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\


+ %b     substitute the basename for outputs related with the input file
+       being processed.  This is often a substring of the input file name,
+       up to (and not including) the last period but, unless %w is active,
+       it is affected by the directory selected by -save-temps=*, by
+       -dumpdir, and, in case of multiple compilations, even by -dumpbase
+       and -dumpbase-ext and, in case of linking, by the linker output
+       name.  When %w is active, it derives the main output name only from
+       the input file base name; when it is not, it names aux/dump output
+       file.

Anyways this changed with r11-627-g1dedc12d186a11 .

I think it is the correct behavior though.

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

* [Bug preprocessor/109183] [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files
  2023-03-18 10:36 [Bug preprocessor/109183] New: [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files yann at droneaud dot fr
                   ` (11 preceding siblings ...)
  2023-04-13 21:05 ` pinskia at gcc dot gnu.org
@ 2023-04-14 12:52 ` allan.w.macdonald at gmail dot com
  2023-04-14 13:45 ` schwab@linux-m68k.org
  13 siblings, 0 replies; 15+ messages in thread
From: allan.w.macdonald at gmail dot com @ 2023-04-14 12:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109183

--- Comment #13 from Allan W. Macdonald <allan.w.macdonald at gmail dot com> ---
Ahhh, so, "to get back the old behaviour" (as @ Richard Biener put it), this
seems to work (at least with my project):

%.d: %.c
        gcc -MM -MD -dumpbase '' $<

Not obvious in the gcc 11.3.0 manual.

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

* [Bug preprocessor/109183] [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files
  2023-03-18 10:36 [Bug preprocessor/109183] New: [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files yann at droneaud dot fr
                   ` (12 preceding siblings ...)
  2023-04-14 12:52 ` allan.w.macdonald at gmail dot com
@ 2023-04-14 13:45 ` schwab@linux-m68k.org
  13 siblings, 0 replies; 15+ messages in thread
From: schwab@linux-m68k.org @ 2023-04-14 13:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109183

--- Comment #14 from Andreas Schwab <schwab@linux-m68k.org> ---
It doesn't make sense to use both -MM and -MD.  Either you want to generate
only dependencies, then use -M or -MM (and -MF to redirect to a file).  Or you
want to generate dependencies as side effect of compilation, then use -MD or
-MMD.

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

end of thread, other threads:[~2023-04-14 13:45 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-18 10:36 [Bug preprocessor/109183] New: [regression?] since GCC 11.1, -MM -MMD generates "a-" prefixed dependency files yann at droneaud dot fr
2023-03-20  9:19 ` [Bug preprocessor/109183] " rguenth at gcc dot gnu.org
2023-03-21 18:46 ` yann at droneaud dot fr
2023-03-26 19:29 ` aoliva at gcc dot gnu.org
2023-03-27 17:23 ` yann at droneaud dot fr
2023-04-13 16:09 ` allan.w.macdonald at gmail dot com
2023-04-13 16:12 ` allan.w.macdonald at gmail dot com
2023-04-13 16:12 ` pinskia at gcc dot gnu.org
2023-04-13 16:21 ` allan.w.macdonald at gmail dot com
2023-04-13 16:31 ` jakub at gcc dot gnu.org
2023-04-13 16:40 ` schwab@linux-m68k.org
2023-04-13 19:27 ` allan.w.macdonald at gmail dot com
2023-04-13 21:05 ` pinskia at gcc dot gnu.org
2023-04-14 12:52 ` allan.w.macdonald at gmail dot com
2023-04-14 13:45 ` schwab@linux-m68k.org

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