Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH] gdb: fix MS_WIN64 redefinition error with Python >= 3.12 on MinGW
Date: Tue, 13 Oct 2026 10:08:56 -0400	[thread overview]
Message-ID: <20261013140907.1346231-1-simon.marchi@efficios.com> (raw)

When trying to cross-build GDB for x86_64-w64-mingw32 on Arch Linux
against Python 3.14 [1], I see:

      CXX    python/py-arch.o
    In file included from /usr/x86_64-w64-mingw32/include/python314/Python.h:14,
                     from /home/smarchi/src/binutils-gdb/gdb/python/python-internal.h:59,
                     from /home/smarchi/src/binutils-gdb/gdb/python/py-arch.c:23:
    /usr/x86_64-w64-mingw32/include/python314/pyconfig.h:253:9: error: ‘MS_WIN64’ redefined [-Werror]
      253 | #define MS_WIN64
          |         ^~~~~~~~
    <command-line>: note: this is the location of the previous definition

Our configure.ac defines MS_WIN64 because of this:

    # On x64 Windows, Python's include headers, and pyconfig.h in
    # particular, rely on MS_WIN64 macro to detect that it's a 64bit
    # version of Windows.  Unfortunately, MS_WIN64 is only defined if
    # _MSC_VER, a Microsoft-specific macro, is defined.  So, when
    # building on x64 Windows with GCC, we define MS_WIN64 ourselves.
    # The issue was reported to the Python community, but still isn't
    # solved as of 2012-10-02 (http://bugs.python.org/issue4709).

Actually, since CPython commit 158b8a07212c ("gh-79218: Define
`MS_WIN64` macro for Mingw-w64 64bit on Windows (GH-100137)",
2022-12-12), which is in Python 3.12, pyconfig.h does define this macro
when building with MinGW.  However, it defines it empty, whereas our
`-DMS_WIN64` defines it to 1, causing the macro redefinition error.
Change it to `-DMS_WIN64=`, which defines an empty macro, and avoids the
redefinition warning on Python >= 3.12.  Older Python versions still get
the macro they need.

Regenerate configure.

[1] https://aur.archlinux.org/packages/mingw-w64-python314-bin

Change-Id: I67d9b6cb22d66812b4230d0cd5a51cfdc96dc379
---
 gdb/configure    | 15 +++++++++------
 gdb/configure.ac | 15 +++++++++------
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/gdb/configure b/gdb/configure
index 810e9ed7a378..90a8ea0b7ebd 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -28677,16 +28677,19 @@ $as_echo "${PYTHON_CFLAGS}" >&6; }
 
   # On x64 Windows, Python's include headers, and pyconfig.h in
   # particular, rely on MS_WIN64 macro to detect that it's a 64bit
-  # version of Windows.  Unfortunately, MS_WIN64 is only defined if
-  # _MSC_VER, a Microsoft-specific macro, is defined.  So, when
-  # building on x64 Windows with GCC, we define MS_WIN64 ourselves.
-  # The issue was reported to the Python community, but still isn't
-  # solved as of 2012-10-02 (http://bugs.python.org/issue4709).
+  # version of Windows.  Before Python 3.12, MS_WIN64 is only defined
+  # if _MSC_VER, a Microsoft-specific macro, is defined.  So, when
+  # building on x64 Windows with GCC, we define MS_WIN64 ourselves
+  # (http://bugs.python.org/issue4709).  Python 3.12 and later define
+  # it as empty for MinGW too, so define it as empty as well here too.
+  #
+  # This can be removed when support for Python 3.12 and below is
+  # dropped.
 
   case "$gdb_host" in
     mingw64)
 	   if test "${GCC}" = yes; then
-	     CPPFLAGS="$CPPFLAGS -DMS_WIN64"
+	     CPPFLAGS="$CPPFLAGS -DMS_WIN64="
 	   fi
 	   ;;
   esac
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 0d88a280b163..3c526c9c108e 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1080,16 +1080,19 @@ if test "${have_libpython}" != no; then
 
   # On x64 Windows, Python's include headers, and pyconfig.h in
   # particular, rely on MS_WIN64 macro to detect that it's a 64bit
-  # version of Windows.  Unfortunately, MS_WIN64 is only defined if
-  # _MSC_VER, a Microsoft-specific macro, is defined.  So, when
-  # building on x64 Windows with GCC, we define MS_WIN64 ourselves.
-  # The issue was reported to the Python community, but still isn't
-  # solved as of 2012-10-02 (http://bugs.python.org/issue4709).
+  # version of Windows.  Before Python 3.12, MS_WIN64 is only defined
+  # if _MSC_VER, a Microsoft-specific macro, is defined.  So, when
+  # building on x64 Windows with GCC, we define MS_WIN64 ourselves
+  # (http://bugs.python.org/issue4709).  Python 3.12 and later define
+  # it as empty for MinGW too, so define it as empty as well here too.
+  #
+  # This can be removed when support for Python 3.12 and below is
+  # dropped.
 
   case "$gdb_host" in
     mingw64)
 	   if test "${GCC}" = yes; then
-	     CPPFLAGS="$CPPFLAGS -DMS_WIN64"
+	     CPPFLAGS="$CPPFLAGS -DMS_WIN64="
 	   fi
 	   ;;
   esac

base-commit: 80b91cb32b083868945f8da8fdeb2c20b5c9f099
-- 
2.56.0


             reply	other threads:[~2026-10-13 14:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 14:08 Simon Marchi [this message]
2026-10-14 11:57 ` Tom Tromey
2026-10-14 12:52   ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261013140907.1346231-1-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox