Bug 84391 - External specs file misinterpreted, unless read twice
Summary: External specs file misinterpreted, unless read twice
Alias: None
Product: gcc
Classification: Unclassified
Component: driver (show other bugs)
Version: 6.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2018-02-14 20:43 UTC by Keith Marshall
Modified: 2018-02-15 00:49 UTC (History)
0 users

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Keith Marshall 2018-02-14 20:43:01 UTC
I'm experimenting with a customised GCC specs file, to enable selection of alternative runtime libraries for MinGW.  I started by extracting the default (built-in) specs:

  $ mingw32-gcc -dumpspecs > lib/gcc/mingw32/6.3.0/specs

This causes mingw32-gcc to read its default specs from this file, ignoring the built-in specs.  So far, so good; all behaves as expected, (and as documented).  Adding the '-v' option confirms that the specs are now read from the external file, and built-in specs are not used.

Next, I defined new specs strings, within my external specs file:


  ${msvcr*:$(msvcrt_id)%*0} $<msvcr*

and I prepended:

  %(msvcrt_version) ...original cpp spec-string unchanged...

in place, to the original cpp spec-string, within the same specs file.

The intent is to interpret a custom '-msvcr90' option (say), to set the MinGW specific '__MSVCRT_VERSION__' feature macro as appropriate for using MSVCR90.DLL, rather than the MSVCRT.DLL default.  However, if I specify it, using natural invocation syntax, I see:

  $ mingw32-gcc -E -dM -msvcr90 -xc /dev/null | grep MSVCRT
  mingw32-gcc: error: unrecognized command line option '-msvcr90'

Conversely, if I adopt this alternative (unnatural) invocation syntax:

  $ mingw32-gcc -specs=specs -E -dM -msvcr90 -xc /dev/null | grep MSVCRT
  #define __MSVCRT_VERSION__ 0x0900
  #define __MSVCRT__ 1

I see exactly the effect I am trying to achieve.

If I add the '-v' option to the former (failing) command, I see that my external specs file is read once, (before any other output is produced); if I add '-v' to the latter (successful) command, I see that my external specs file is read twice, (again, before any other output is produced).

FWIW, I also see the expected behaviour if I augment the built-in specs, by placing my customisations in an alternatively named auxiliary specs file, (say mingw.specs), and invoke:

  $ mingw32-gcc -specs=mingw.specs -E -dM -msvcr90 -xc /dev/null | grep MSVCRT
  #define __MSVCRT_VERSION__ 0x0900
  #define __MSVCRT__ 1

Unless I'm overlooking something, I guess this is a bug in the way GCC processes an external specs file explicitly named as 'specs', when reading it implicitly; it seems that it may be worked around by loading it explicitly, (although this is certainly much less convenient).
Comment 1 Andrew Pinski 2018-02-15 00:49:04 UTC
This is the correct behavior; the driver itself has option checking.  If you want a custom option, you need to either use directly the -specs option which disables option checking or add the .opt file inside GCC to say the option is a driver only option.

GCC will either use its internal specs or use the file called specs for the specs but that does not disable option checking.