gcc -E -MD -o behaves differently in 3.0.4 than in 2.95.2.

Sergei Organov osv@javad.ru
Fri Feb 15 06:11:00 GMT 2002


Neil Booth <neil@daikokuya.demon.co.uk> writes:
> Sergei Organov wrote:-
> 
> > used to send preprocessor output to 'file.out'.  With gcc 3.0.4 (from
> > anon-cvs) the former command (incorrectly) sends preprocessor output to
> > stdout instead (while the latter command still behaves as before). It
> > seems that gcc just doesn't pass "-o file.out" to the cpp when both -E and
> > -MD are present. I observe the same (presumably incorrect) behavior with
> > gcc 3.0.3 release.
> 
> The fundamental problem here is that the meaning of "-o" is overloaded;
> it is used for both preprocessor output and object file output.  We changed
> -MD to be more clever about the specified output object file, and
> as a result the driver now interprets the "-o" as indicating compiler
> output.
> 
> I get a headache thinking about these things; I'm really not sure what
> the best thing to do is.  We spent a lot of time before 3.0 trying to
> get it to do what people wanted, but we have only partly succeeded.
> I'm not sure what to do; and so until someone who really wants to get
> this done right steps forward to fix it, I suspect it will remain as it
> is.  Note that the current code can do everything (and a lot more) it
> could do before, it's just that we lost backwards compatibility more
> than we intended too.  You can control dependency output finely with
> -MF, -MQ, -MT and -MP with 3.x; all these options are new.

Yes, I've noticed these new fine features. The only problem is indeed the lack
of backwards compatibility, but fortunately there is a simple workaround:

gcc -E -MD file.c > file.out

works the same for both 2.95 and 3.0 and the same as 

gcc -E -MD file.c -o file.out

works in 2.95.

> 
> >  /home/osv/try/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/cpp0 -lang-c -v -M -MF file.d -MQ file.out -D__GNUC__=3 -D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=4 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ file.c
> 
> Here you see the driver has passed "-MQ file.out" to the preprocessor,
> which tells it to interpret it as the (quoted) target of the dependency.
> You can also see "-MF file.d" which is the file that contains the
> dependency output.
> 
> Now that we have a released version with the new semantics, I think it's
> simplest if we retain them, in that -MD is understood to be added to the
> normal compiler "-c" command line, so that any "-o" options indicate the
> output object file.  If you want to change the dependency output file,
> you can additionally -MF on the command line (note that this option was
> new to 3.x), which will override the default output file.

Do you see any problem if 'gcc' will pass "-o" to preprocessor if there are
both "-E" and "-MD" ("-c" and "-E" are mutually exclusive, right)?

> 
> Neil.

Sergei.



More information about the Gcc-bugs mailing list