[PATCH] Fix build issues with mingw toolchain

Pedro Alves pedro@palves.net
Tue May 14 14:20:18 GMT 2024


On 2024-05-13 19:45, Tom Tromey wrote:
> Pedro> I don't plan on proposing bumping the minimal supported version currently,
> Pedro> as I don't recall it blocking anything, but I would like to understand that
> Pedro> constraint better, for if/when the time comes.
> 
> The problem is that libstdc++ puts gdb in a bind.
> 
> On the one hand, gdb tries to support XP.
> On the other hand, <thread> requires a newer version; and use of threads
> is desirable.

That is for the win32 threading model, right?

I just tried cross building a win32 mingw gdb using the posix thread model:

/home/pedro/gdb/src/configure \
    --disable-ld \
    --disable-binutils \
    --disable-gas \
    --disable-gold \
    --disable-nls \
    --build=x86_64-pc-linux-gnu \
    --host=i686-w64-mingw32 \
    --target=i686-w64-mingw32 \
    --disable-source-highlight \
    --with-static-standard-libraries \
    --with-gmp=/home/pedro/src/gmp/install-win32 \
    --with-mpfr=/home/pedro/src/mpfr/install-win32 \
    --with-expat=yes --with-libexpat-prefix=/home/pedro/src/expat/install-win32/ \
    --enable-threading \
    CC=i686-w64-mingw32-gcc-posix \
    CXX=i686-w64-mingw32-g++-posix \
    CFLAGS="-g3 -O0" \
    CXXFLAGS="-g3 -O0"

and I got:

 $ wine ./gdb -ex "maintenance show worker-threads" -q --batch
 The number of worker threads GDB can use is the default (currently 8).

I think this binary would work on WinXP, and it supports threads.

The 64-bit mingw gcc with win32 threading model that comes with Ubuntu 22.04 seems to
be too old to support threading OOTB even if I configure with -D_WIN32_WINNT=0x600
in CFLAGS/CXXFLAGS.  It's GCC 10 based.  I think I'd need at least GCC 14.

But I think you should be able to configure with 

    --enable-threading CFLAGS="-D_WIN32_WINNT=0x600" CXXFLAGS="-D_WIN32_WINNT=0x600"

and then threads will be enabled.  If this doesn't work (with GCC >= 14), then it seems
like a bug to me.

Also, "--enable-threading=yes" silently ends up with threading disabled if std::thread
doesn't work.  I think that's a bug.  If I explicitly request threading, and then
configure detects std::thread doesn't work, it should error out.  Other options work
that way, like e.g., the TUI checks for curses:

# Check whether we should enable the TUI, but only do so if we really
# can.
if test x"$enable_tui" != xno; then
  if test "$curses_found" != no; then
    CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_TUI_OBS)"
    CONFIG_DEPS="$CONFIG_DEPS \$(SUBDIR_TUI_DEPS)"
    CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_TUI_SRCS)"
    ENABLE_CFLAGS="$ENABLE_CFLAGS \$(SUBDIR_TUI_CFLAGS)"
  else
    if test x"$enable_tui" = xyes; then
      AC_MSG_ERROR([no enhanced curses library found; disable TUI])
    else
      AC_MSG_WARN([no enhanced curses library found; disabling TUI])
    fi
  fi
fi


More information about the Gdb-patches mailing list