public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug bootstrap/108300] New: `abort()` macro cause bootstrap failure on *-w64-mingw32
@ 2023-01-05 11:09 lh_mouse at 126 dot com
  2023-01-05 11:16 ` [Bug bootstrap/108300] " redi at gcc dot gnu.org
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: lh_mouse at 126 dot com @ 2023-01-05 11:09 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108300
           Summary: `abort()` macro cause bootstrap failure on
                    *-w64-mingw32
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: bootstrap
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lh_mouse at 126 dot com
  Target Milestone: ---

Recently, mingw-w64 has got updated <msxml.h> from Wine. GCC then ceases to
build:

```
../../gcc/gcc/system.h:791:30: error: expected identifier before string
constant
  791 | #define abort() fancy_abort (__FILE__, __LINE__, __FUNCTION__)
      |                              ^~~~~~~~
```

The reason is elaborated in this piece of log of #gcc on OFTC:

```
[16:51:28] <lh_ideapad> on Windows hosts, <windows.h> now involves <msxml.h>,
which brings a struct that has `abort()` as a member function, so if the macro
above is expanded there it will become nonsense.
[16:52:34] <lh_ideapad> if GCC does not use that struct (and a plenty more) the
standard way to prevent them from being included is to define
`WIN32_LEAN_AND_MEAN` before inclusion of <windows.h>.  unfortunately, not all
GCC source files do so.
[16:53:31] <lh_ideapad> there are about thirty to forty files that include
<windows.h> without defining `WIN32_LEAN_AND_MEAN`.  do you think it is a good
idea to patch them all?
[16:54:11] <lh_ideapad> this can be generated by an sed command, but it's gonna
be a large patch, touching files that I am not familiar with.
[16:55:03] <lh_ideapad> or, we can patch mingw-w64 msxml.h to `#undef abort`.
[16:57:22] <iains> can you fixincludes windows.h to add a wrapperr that defines
WIN32_LEAN_AND_MEAN and then include_next windows.h?
[16:58:11] <iains> (that means you do not have to patch the original file ..
you could also use fixincludes to do that too - but it seems maybe more
complicated than the wrapper)
[17:06:14] <iains> .. of course, that does not help if the files are sources
that need to be built by the bootstrap compiler - it’s only going to succeed if
they are all target-libs related.
[17:23:52] <iains> .. hmm but if they are sources in the gcc tree, I’d suppose
that windows.h should not be included directly - but via system.h where you
could place the #define before the inclusion.
[17:34:14] <Arsen> ugh, the wonders of macros
[17:34:25] <Arsen> maybe that can be a static inline fn instead?
[17:34:41] <Arsen> (or even just regular ol inline)
[18:08:19] <jwakely> yeah, GCC should not #define abort like that, it's
disgusting
[18:08:40] <jwakely> "but we've always done it like that" - time to stop
```

I create this PR for the record. In my opinion, including <windows.h> without
`WIN32_LEAN_AND_MEAN` pulls in tons of unnecessary stuff and is almost never
desired. This can be fixed by

```
sed -Ei 's,^( *)#( *)include <windows\.h>,\1#\2define WIN32_LEAN_AND_MEAN
1\n&,'  \
  $(grep --inc "*.[hc]" --inc "*.cc" -Flr "<windows.h>")
```

(Some source files already have it.)

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

end of thread, other threads:[~2023-01-19  9:08 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-05 11:09 [Bug bootstrap/108300] New: `abort()` macro cause bootstrap failure on *-w64-mingw32 lh_mouse at 126 dot com
2023-01-05 11:16 ` [Bug bootstrap/108300] " redi at gcc dot gnu.org
2023-01-05 12:45 ` lh_mouse at 126 dot com
2023-01-06  6:39 ` [Bug middle-end/108300] " pinskia at gcc dot gnu.org
2023-01-06  9:42 ` pinskia at gcc dot gnu.org
2023-01-06 11:54 ` lh_mouse at 126 dot com
2023-01-07  6:51 ` cvs-commit at gcc dot gnu.org
2023-01-07 10:58 ` i.nixman at autistici dot org
2023-01-07 12:38 ` lh_mouse at 126 dot com
2023-01-07 12:40 ` arsen at aarsen dot me
2023-01-07 14:38 ` lh_mouse at 126 dot com
2023-01-07 20:32 ` arsen at aarsen dot me
2023-01-08 15:32 ` i.nixman at autistici dot org
2023-01-08 15:47 ` i.nixman at autistici dot org
2023-01-09  9:57 ` redi at gcc dot gnu.org
2023-01-14 14:12 ` nightstrike at gmail dot com
2023-01-19  9:08 ` i.nixman at autistici dot 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).