Fix gdbserver build with x86_64-w64-mingw32 -m32

Message ID 1420825778-8946-1-git-send-email-zwelch@codesourcery.com
State New, archived
Headers

Commit Message

Zachary T Welch Jan. 9, 2015, 5:49 p.m. UTC
  This patch allows a x86_64-w64-mingw32 toolchain to build a 32-bit
gdbserver.  Without it, gdbserver attempts to link to the 64-bit
register files, resulting in undefined references.

	* configure.ac: Add check for -m32 on x86_64-*-mingw*.
	* configure.srv: If using -m32 on x86_64-*-mingw*, use i386
	instead of amd64 registers.
	* configure: Regenerated.
	* aclocal.m4: Regenerated.

Signed-off-by: Zachary T Welch <zwelch@codesourcery.com>
---
 gdb/gdbserver/ChangeLog     |  8 ++++++++
 gdb/gdbserver/aclocal.m4    | 46 +++++++++++++++++++--------------------------
 gdb/gdbserver/configure     | 34 +++++++++++++++++++++++++++++++--
 gdb/gdbserver/configure.ac  | 12 ++++++++++++
 gdb/gdbserver/configure.srv |  3 +++
 5 files changed, 74 insertions(+), 29 deletions(-)
  

Comments

Sergio Durigan Junior Jan. 9, 2015, 8:05 p.m. UTC | #1
On Friday, January 09 2015, Zachary T. Welch wrote:

> This patch allows a x86_64-w64-mingw32 toolchain to build a 32-bit
> gdbserver.  Without it, gdbserver attempts to link to the 64-bit
> register files, resulting in undefined references.

Hey Zachary,

Thanks for the patch.  I noticed you used a newer version of aclocal to
regenerate the files, which generated a lot of hunks that do not relate
to the patch itself.

The right version to use is 1.11.1 (not 1.13.1).  Could you please
regenerate the files using the exact versions of autoconf, automake and
aclocal?  This page might help you:

  <https://sourceware.org/gdb/wiki/DeveloperTips#Editing_configure.ac>

To grab the exact versions of the packages, go to:

  <ftp://ftp.gnu.org/gnu/>

Thanks,

> 	* configure.ac: Add check for -m32 on x86_64-*-mingw*.
> 	* configure.srv: If using -m32 on x86_64-*-mingw*, use i386
> 	instead of amd64 registers.
> 	* configure: Regenerated.
> 	* aclocal.m4: Regenerated.
>
> Signed-off-by: Zachary T Welch <zwelch@codesourcery.com>
> ---
>  gdb/gdbserver/ChangeLog     |  8 ++++++++
>  gdb/gdbserver/aclocal.m4    | 46 +++++++++++++++++++--------------------------
>  gdb/gdbserver/configure     | 34 +++++++++++++++++++++++++++++++--
>  gdb/gdbserver/configure.ac  | 12 ++++++++++++
>  gdb/gdbserver/configure.srv |  3 +++
>  5 files changed, 74 insertions(+), 29 deletions(-)
>
> diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
> index 6937ec0..1e17544 100644
> --- a/gdb/gdbserver/ChangeLog
> +++ b/gdb/gdbserver/ChangeLog
> @@ -1,3 +1,11 @@
> +2015-01-05  Zachary T Welch  <zwelch@codesourcery.com>
> +
> +	* configure.ac: Add check for -m32 on x86_64-*-mingw*.
> +	* configure.srv: If using -m32 on x86_64-*-mingw*, use i386
> +	instead of amd64 registers.
> +	* configure: Regenerated.
> +	* aclocal.m4: Regenerated.
> +
>  2015-01-01  Joel Brobecker  <brobecker@adacore.com>
>  
>  	* gdbreplay.c (gdbreplay_version): Update copyright year to 2015.
> diff --git a/gdb/gdbserver/aclocal.m4 b/gdb/gdbserver/aclocal.m4
> index 7b546b7..0105e8e 100644
> --- a/gdb/gdbserver/aclocal.m4
> +++ b/gdb/gdbserver/aclocal.m4
> @@ -1,7 +1,7 @@
> -# generated automatically by aclocal 1.11.1 -*- Autoconf -*-
> +# generated automatically by aclocal 1.13.1 -*- Autoconf -*-
> +
> +# Copyright (C) 1996-2012 Free Software Foundation, Inc.
>  
> -# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
> -# 2005, 2006, 2007, 2008, 2009  Free Software Foundation, Inc.
>  # This file is free software; the Free Software Foundation
>  # gives unlimited permission to copy and/or distribute it,
>  # with or without modifications, as long as this notice is preserved.
> @@ -11,24 +11,22 @@
>  # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
>  # PARTICULAR PURPOSE.
>  
> +m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
>  # AM_CONDITIONAL                                            -*- Autoconf -*-
>  
> -# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006, 2008
> -# Free Software Foundation, Inc.
> +# Copyright (C) 1997-2013 Free Software Foundation, Inc.
>  #
>  # This file is free software; the Free Software Foundation
>  # gives unlimited permission to copy and/or distribute it,
>  # with or without modifications, as long as this notice is preserved.
>  
> -# serial 9
> -
>  # AM_CONDITIONAL(NAME, SHELL-CONDITION)
>  # -------------------------------------
>  # Define a conditional.
>  AC_DEFUN([AM_CONDITIONAL],
> -[AC_PREREQ(2.52)dnl
> - ifelse([$1], [TRUE],  [AC_FATAL([$0: invalid condition: $1])],
> -	[$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
> +[AC_PREREQ([2.52])dnl
> + m4_if([$1], [TRUE],  [AC_FATAL([$0: invalid condition: $1])],
> +       [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
>  AC_SUBST([$1_TRUE])dnl
>  AC_SUBST([$1_FALSE])dnl
>  _AM_SUBST_NOTMAKE([$1_TRUE])dnl
> @@ -50,20 +48,17 @@ fi])])
>  # Add --enable-maintainer-mode option to configure.         -*- Autoconf -*-
>  # From Jim Meyering
>  
> -# Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2008
> -# Free Software Foundation, Inc.
> +# Copyright (C) 1996-2013 Free Software Foundation, Inc.
>  #
>  # This file is free software; the Free Software Foundation
>  # gives unlimited permission to copy and/or distribute it,
>  # with or without modifications, as long as this notice is preserved.
>  
> -# serial 5
> -
>  # AM_MAINTAINER_MODE([DEFAULT-MODE])
>  # ----------------------------------
>  # Control maintainer-specific portions of Makefiles.
> -# Default is to disable them, unless `enable' is passed literally.
> -# For symmetry, `disable' may be passed as well.  Anyway, the user
> +# Default is to disable them, unless 'enable' is passed literally.
> +# For symmetry, 'disable' may be passed as well.  Anyway, the user
>  # can override the default with the --enable/--disable switch.
>  AC_DEFUN([AM_MAINTAINER_MODE],
>  [m4_case(m4_default([$1], [disable]),
> @@ -71,13 +66,14 @@ AC_DEFUN([AM_MAINTAINER_MODE],
>         [disable], [m4_define([am_maintainer_other], [enable])],
>         [m4_define([am_maintainer_other], [enable])
>          m4_warn([syntax], [unexpected argument to AM@&t@_MAINTAINER_MODE: $1])])
> -AC_MSG_CHECKING([whether to am_maintainer_other maintainer-specific portions of Makefiles])
> +AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles])
>    dnl maintainer-mode's default is 'disable' unless 'enable' is passed
>    AC_ARG_ENABLE([maintainer-mode],
> -[  --][am_maintainer_other][-maintainer-mode  am_maintainer_other make rules and dependencies not useful
> -			  (and sometimes confusing) to the casual installer],
> -      [USE_MAINTAINER_MODE=$enableval],
> -      [USE_MAINTAINER_MODE=]m4_if(am_maintainer_other, [enable], [no], [yes]))
> +    [AS_HELP_STRING([--]am_maintainer_other[-maintainer-mode],
> +      am_maintainer_other[ make rules and dependencies not useful
> +      (and sometimes confusing) to the casual installer])],
> +    [USE_MAINTAINER_MODE=$enableval],
> +    [USE_MAINTAINER_MODE=]m4_if(am_maintainer_other, [enable], [no], [yes]))
>    AC_MSG_RESULT([$USE_MAINTAINER_MODE])
>    AM_CONDITIONAL([MAINTAINER_MODE], [test $USE_MAINTAINER_MODE = yes])
>    MAINT=$MAINTAINER_MODE_TRUE
> @@ -85,16 +81,12 @@ AC_MSG_CHECKING([whether to am_maintainer_other maintainer-specific portions of
>  ]
>  )
>  
> -AU_DEFUN([jm_MAINTAINER_MODE], [AM_MAINTAINER_MODE])
> -
> -# Copyright (C) 2006, 2008  Free Software Foundation, Inc.
> +# Copyright (C) 2006-2013 Free Software Foundation, Inc.
>  #
>  # This file is free software; the Free Software Foundation
>  # gives unlimited permission to copy and/or distribute it,
>  # with or without modifications, as long as this notice is preserved.
>  
> -# serial 2
> -
>  # _AM_SUBST_NOTMAKE(VARIABLE)
>  # ---------------------------
>  # Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in.
> @@ -102,7 +94,7 @@ AU_DEFUN([jm_MAINTAINER_MODE], [AM_MAINTAINER_MODE])
>  AC_DEFUN([_AM_SUBST_NOTMAKE])
>  
>  # AM_SUBST_NOTMAKE(VARIABLE)
> -# ---------------------------
> +# --------------------------
>  # Public sister of _AM_SUBST_NOTMAKE.
>  AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
>  
> diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
> index 45efc51..8776a6f 100755
> --- a/gdb/gdbserver/configure
> +++ b/gdb/gdbserver/configure
> @@ -1325,8 +1325,9 @@ Optional Features:
>    --disable-option-checking  ignore unrecognized --enable/--with options
>    --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
>    --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
> -  --enable-maintainer-mode  enable make rules and dependencies not useful
> -			  (and sometimes confusing) to the casual installer
> +  --enable-maintainer-mode
> +                          enable make rules and dependencies not useful (and
> +                          sometimes confusing) to the casual installer
>    --disable-largefile     omit support for large files
>    --enable-libmcheck      Try linking with -lmcheck if available
>    --enable-werror         treat compile warnings as errors
> @@ -5535,6 +5536,35 @@ fi
>  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gdb_cv_m68k_is_coldfire" >&5
>  $as_echo "$gdb_cv_m68k_is_coldfire" >&6; }
>      ;;
> +  x86_64-*-mingw*)
> +    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if building with -m32" >&5
> +$as_echo_n "checking if building with -m32... " >&6; }
> +if test "${gdb_cv_x86_64_is_i386+set}" = set; then :
> +  $as_echo_n "(cached) " >&6
> +else
> +  save_CPPFLAGS="$CPPFLAGS"
> +		    CPPFLAGS="$CPPFLAGS $CFLAGS"
> +                    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
> +/* end confdefs.h.  */
> +
> +#if ! __x86_64__
> +got it
> +#endif
> +
> +_ACEOF
> +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
> +  $EGREP "got it" >/dev/null 2>&1; then :
> +  gdb_cv_w64_x86_64_is_i386=yes
> +else
> +  gdb_cv_w64_x86_64_is_i386=no
> +fi
> +rm -f conftest*
> +
> +                    CPPFLAGS="$save_CPPFLAGS"
> +fi
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gdb_cv_x86_64_is_i386" >&5
> +$as_echo "$gdb_cv_x86_64_is_i386" >&6; }
> +    ;;
>  esac
>  
>  . ${srcdir}/configure.srv
> diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac
> index 02082cc..ff9e272 100644
> --- a/gdb/gdbserver/configure.ac
> +++ b/gdb/gdbserver/configure.ac
> @@ -238,6 +238,18 @@ got it
>                      [gdb_cv_m68k_is_coldfire=no])
>                      CPPFLAGS="$save_CPPFLAGS"])
>      ;;
> +  x86_64-*-mingw*)
> +    AC_CACHE_CHECK([if building with -m32], [gdb_cv_x86_64_is_i386],
> +		   [save_CPPFLAGS="$CPPFLAGS"
> +		    CPPFLAGS="$CPPFLAGS $CFLAGS"
> +                    AC_EGREP_CPP([got it], [
> +#if ! __x86_64__
> +got it
> +#endif
> +                 ], [gdb_cv_w64_x86_64_is_i386=yes],
> +                    [gdb_cv_w64_x86_64_is_i386=no])
> +                    CPPFLAGS="$save_CPPFLAGS"])
> +    ;;
>  esac
>  
>  . ${srcdir}/configure.srv
> diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
> index 679fc9f..e0d5413 100644
> --- a/gdb/gdbserver/configure.srv
> +++ b/gdb/gdbserver/configure.srv
> @@ -325,6 +325,9 @@ case "${target}" in
>  			ipa_obj="${ipa_amd64_linux_regobj} linux-amd64-ipa.o"
>  			;;
>    x86_64-*-mingw*)	srv_regobj="$srv_amd64_regobj"
> +			if test "$gdb_cv_w64_x86_64_is_i386" = yes ; then
> +			  srv_regobj="$srv_i386_regobj"
> +			fi
>  			srv_tgtobj="x86-low.o x86-dregs.o i387-fp.o win32-low.o win32-i386-low.o"
>  			srv_xmlfiles="$srv_i386_xmlfiles $srv_amd64_xmlfiles"
>  			srv_mingw=yes
> -- 
> 1.8.1.1
  
Joel Brobecker Jan. 10, 2015, 4:17 a.m. UTC | #2
> This patch allows a x86_64-w64-mingw32 toolchain to build a 32-bit
> gdbserver.  Without it, gdbserver attempts to link to the 64-bit
> register files, resulting in undefined references.
> 
> 	* configure.ac: Add check for -m32 on x86_64-*-mingw*.
> 	* configure.srv: If using -m32 on x86_64-*-mingw*, use i386
> 	instead of amd64 registers.
> 	* configure: Regenerated.
> 	* aclocal.m4: Regenerated.

Intuitively, I would say that the proper way to achive a 32bit
gdbserver is by configuring it using a 32bit triplet, no?
What happens if you do:

    ./configure --build=i686-pc-mingw32 CFLAGS='-m32'

?
  
Zachary T Welch Jan. 12, 2015, 5:54 p.m. UTC | #3
On 01/09/2015 08:17 PM, Joel Brobecker wrote:
>> This patch allows a x86_64-w64-mingw32 toolchain to build a 32-bit
>> gdbserver.  Without it, gdbserver attempts to link to the 64-bit
>> register files, resulting in undefined references.
>>
>> 	* configure.ac: Add check for -m32 on x86_64-*-mingw*.
>> 	* configure.srv: If using -m32 on x86_64-*-mingw*, use i386
>> 	instead of amd64 registers.
>> 	* configure: Regenerated.
>> 	* aclocal.m4: Regenerated.
> 
> Intuitively, I would say that the proper way to achive a 32bit
> gdbserver is by configuring it using a 32bit triplet, no?
> What happens if you do:
> 
>     ./configure --build=i686-pc-mingw32 CFLAGS='-m32'

Actually, I am using i686-pc-linux-gnu as $build.  I think you meant to
ask for --host.  I am using --host=x86_64-w64-mingw32 CFLAGS=-m32, which
is distinctly different than i686-pc-mingw32.  For example, they use
completely different runtime libraries.  I think it would be an error to
conflate the two toolchains.  Thus, I stand by my patch as the correct
solution for this issue.
  
Joel Brobecker Jan. 13, 2015, 9:17 a.m. UTC | #4
> > Intuitively, I would say that the proper way to achive a 32bit
> > gdbserver is by configuring it using a 32bit triplet, no?
> > What happens if you do:
> > 
> >     ./configure --build=i686-pc-mingw32 CFLAGS='-m32'
> 
> Actually, I am using i686-pc-linux-gnu as $build.  I think you meant to
> ask for --host.  I am using --host=x86_64-w64-mingw32 CFLAGS=-m32, which
> is distinctly different than i686-pc-mingw32.  For example, they use
> completely different runtime libraries.  I think it would be an error to
> conflate the two toolchains.  Thus, I stand by my patch as the correct
> solution for this issue.

Actually, I did mean --build=. This option is meant to override
what the config.guess script would normally guess as being your
operating system. On Windows, at least in my case, config.guess
guesses i686-pc-mingw32, which is not what you want, because it's
cygwin. That's why you need --build=i686-pc-mingw32.

Unless I misunderstood you, I suspect you're gettting confused by
the meaning of the --host, --build and --target.

BTW, if you configure with just --host, you should get the following
warning at the very beginning.

configure: WARNING: If you wanted to set the --build type, don't use --host.
    If a cross compiler is detected then cross compile mode will be used.
  
Zachary T Welch Jan. 13, 2015, 4:59 p.m. UTC | #5
On 01/13/2015 01:17 AM, Joel Brobecker wrote:
>>> Intuitively, I would say that the proper way to achive a 32bit
>>> gdbserver is by configuring it using a 32bit triplet, no?
>>> What happens if you do:
>>>
>>>     ./configure --build=i686-pc-mingw32 CFLAGS='-m32'
>>
>> Actually, I am using i686-pc-linux-gnu as $build.  I think you meant to
>> ask for --host.  I am using --host=x86_64-w64-mingw32 CFLAGS=-m32, which
>> is distinctly different than i686-pc-mingw32.  For example, they use
>> completely different runtime libraries.  I think it would be an error to
>> conflate the two toolchains.  Thus, I stand by my patch as the correct
>> solution for this issue.
> 
> Actually, I did mean --build=. This option is meant to override
> what the config.guess script would normally guess as being your
> operating system. On Windows, at least in my case, config.guess
> guesses i686-pc-mingw32, which is not what you want, because it's
> cygwin. That's why you need --build=i686-pc-mingw32.
> 
> Unless I misunderstood you, I suspect you're gettting confused by
> the meaning of the --host, --build and --target.

I believe that you have misunderstood my scenario.

The build server's host OS is x86_64-linux-gnu; however, I am using a
i686-pc-linux-gnu toolchain (thus, --build=i686-pc-linux-gnu) to produce
32-bit binaries (for maximum portability).  I am using that toolchain to
build a complete cross toolchain for x86_64-w64-mingw32 (--target).

Thus, the primary host for which I am building gdbserver is
x86_64-w64-mingw32 (--host=x86_64-w64-mingw32), but I am also using the
x86_64-w64-mingw32 toolchain to build a multilib for 32-bit windows
(--host=x86_64-w64-mingw32 CFLAGS="-m32") as a secondary host. gdbserver
runs on the target (and is not itself a cross compiler), so --host ==
--target in both cases.

The primary host gdbserver build (--host=x86_64-w64-mingw32) works, but
the secondary host build (--host=x86_64-w64-mingw32 CFLAGS="-m32") fails
without my provided patch.

In conclusion, I feel fairly confident that I am using the correct
configure options.  The i686-pc-mingw32 triplet should not enter into
the equation at all in my situation.
  
Pedro Alves Jan. 13, 2015, 5:41 p.m. UTC | #6
On 01/12/2015 05:54 PM, Zach Welch wrote:
> On 01/09/2015 08:17 PM, Joel Brobecker wrote:
>>> This patch allows a x86_64-w64-mingw32 toolchain to build a 32-bit
>>> gdbserver.  Without it, gdbserver attempts to link to the 64-bit
>>> register files, resulting in undefined references.
>>>
>>> 	* configure.ac: Add check for -m32 on x86_64-*-mingw*.
>>> 	* configure.srv: If using -m32 on x86_64-*-mingw*, use i386
>>> 	instead of amd64 registers.
>>> 	* configure: Regenerated.
>>> 	* aclocal.m4: Regenerated.
>>
>> Intuitively, I would say that the proper way to achive a 32bit
>> gdbserver is by configuring it using a 32bit triplet, no?
>> What happens if you do:
>>
>>     ./configure --build=i686-pc-mingw32 CFLAGS='-m32'
> 
> Actually, I am using i686-pc-linux-gnu as $build.  I think you meant to
> ask for --host.  I am using --host=x86_64-w64-mingw32 CFLAGS=-m32, which
> is distinctly different than i686-pc-mingw32.  For example, they use
> completely different runtime libraries.  I think it would be an error to
> conflate the two toolchains.  

Not offhand objecting to the patch, but the right triplet would
be i686-w64-mingw32.  It's what Fedora uses, for example.  In practice,
it'd be the same as i686-pc-mingw32 though.  AFAIK, nowhere do we need
to distinguish them.

> Thus, I stand by my patch as the correct solution for this issue.

Thanks,
Pedro Alves
  
Joel Brobecker Jan. 15, 2015, 4:46 a.m. UTC | #7
> Thus, the primary host for which I am building gdbserver is
> x86_64-w64-mingw32 (--host=x86_64-w64-mingw32), but I am also using the
> x86_64-w64-mingw32 toolchain to build a multilib for 32-bit windows
> (--host=x86_64-w64-mingw32 CFLAGS="-m32") as a secondary host. gdbserver
> runs on the target (and is not itself a cross compiler), so --host ==
> --target in both cases.
> 
> The primary host gdbserver build (--host=x86_64-w64-mingw32) works, but
> the secondary host build (--host=x86_64-w64-mingw32 CFLAGS="-m32") fails
> without my provided patch.

OK, IIUC, I think you want to use a 32bit mingw32 --host triplet
in this case.  The fact that the OS you'll be running gdbserver on
is 64bit does matter, your gdbserver still going to be a 32bit executable,
and therefore should be configured as such.
  

Patch

diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index 6937ec0..1e17544 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,3 +1,11 @@ 
+2015-01-05  Zachary T Welch  <zwelch@codesourcery.com>
+
+	* configure.ac: Add check for -m32 on x86_64-*-mingw*.
+	* configure.srv: If using -m32 on x86_64-*-mingw*, use i386
+	instead of amd64 registers.
+	* configure: Regenerated.
+	* aclocal.m4: Regenerated.
+
 2015-01-01  Joel Brobecker  <brobecker@adacore.com>
 
 	* gdbreplay.c (gdbreplay_version): Update copyright year to 2015.
diff --git a/gdb/gdbserver/aclocal.m4 b/gdb/gdbserver/aclocal.m4
index 7b546b7..0105e8e 100644
--- a/gdb/gdbserver/aclocal.m4
+++ b/gdb/gdbserver/aclocal.m4
@@ -1,7 +1,7 @@ 
-# generated automatically by aclocal 1.11.1 -*- Autoconf -*-
+# generated automatically by aclocal 1.13.1 -*- Autoconf -*-
+
+# Copyright (C) 1996-2012 Free Software Foundation, Inc.
 
-# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-# 2005, 2006, 2007, 2008, 2009  Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -11,24 +11,22 @@ 
 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 # PARTICULAR PURPOSE.
 
+m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
 # AM_CONDITIONAL                                            -*- Autoconf -*-
 
-# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006, 2008
-# Free Software Foundation, Inc.
+# Copyright (C) 1997-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
-# serial 9
-
 # AM_CONDITIONAL(NAME, SHELL-CONDITION)
 # -------------------------------------
 # Define a conditional.
 AC_DEFUN([AM_CONDITIONAL],
-[AC_PREREQ(2.52)dnl
- ifelse([$1], [TRUE],  [AC_FATAL([$0: invalid condition: $1])],
-	[$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
+[AC_PREREQ([2.52])dnl
+ m4_if([$1], [TRUE],  [AC_FATAL([$0: invalid condition: $1])],
+       [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
 AC_SUBST([$1_TRUE])dnl
 AC_SUBST([$1_FALSE])dnl
 _AM_SUBST_NOTMAKE([$1_TRUE])dnl
@@ -50,20 +48,17 @@  fi])])
 # Add --enable-maintainer-mode option to configure.         -*- Autoconf -*-
 # From Jim Meyering
 
-# Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2008
-# Free Software Foundation, Inc.
+# Copyright (C) 1996-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
-# serial 5
-
 # AM_MAINTAINER_MODE([DEFAULT-MODE])
 # ----------------------------------
 # Control maintainer-specific portions of Makefiles.
-# Default is to disable them, unless `enable' is passed literally.
-# For symmetry, `disable' may be passed as well.  Anyway, the user
+# Default is to disable them, unless 'enable' is passed literally.
+# For symmetry, 'disable' may be passed as well.  Anyway, the user
 # can override the default with the --enable/--disable switch.
 AC_DEFUN([AM_MAINTAINER_MODE],
 [m4_case(m4_default([$1], [disable]),
@@ -71,13 +66,14 @@  AC_DEFUN([AM_MAINTAINER_MODE],
        [disable], [m4_define([am_maintainer_other], [enable])],
        [m4_define([am_maintainer_other], [enable])
         m4_warn([syntax], [unexpected argument to AM@&t@_MAINTAINER_MODE: $1])])
-AC_MSG_CHECKING([whether to am_maintainer_other maintainer-specific portions of Makefiles])
+AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles])
   dnl maintainer-mode's default is 'disable' unless 'enable' is passed
   AC_ARG_ENABLE([maintainer-mode],
-[  --][am_maintainer_other][-maintainer-mode  am_maintainer_other make rules and dependencies not useful
-			  (and sometimes confusing) to the casual installer],
-      [USE_MAINTAINER_MODE=$enableval],
-      [USE_MAINTAINER_MODE=]m4_if(am_maintainer_other, [enable], [no], [yes]))
+    [AS_HELP_STRING([--]am_maintainer_other[-maintainer-mode],
+      am_maintainer_other[ make rules and dependencies not useful
+      (and sometimes confusing) to the casual installer])],
+    [USE_MAINTAINER_MODE=$enableval],
+    [USE_MAINTAINER_MODE=]m4_if(am_maintainer_other, [enable], [no], [yes]))
   AC_MSG_RESULT([$USE_MAINTAINER_MODE])
   AM_CONDITIONAL([MAINTAINER_MODE], [test $USE_MAINTAINER_MODE = yes])
   MAINT=$MAINTAINER_MODE_TRUE
@@ -85,16 +81,12 @@  AC_MSG_CHECKING([whether to am_maintainer_other maintainer-specific portions of
 ]
 )
 
-AU_DEFUN([jm_MAINTAINER_MODE], [AM_MAINTAINER_MODE])
-
-# Copyright (C) 2006, 2008  Free Software Foundation, Inc.
+# Copyright (C) 2006-2013 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
-# serial 2
-
 # _AM_SUBST_NOTMAKE(VARIABLE)
 # ---------------------------
 # Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in.
@@ -102,7 +94,7 @@  AU_DEFUN([jm_MAINTAINER_MODE], [AM_MAINTAINER_MODE])
 AC_DEFUN([_AM_SUBST_NOTMAKE])
 
 # AM_SUBST_NOTMAKE(VARIABLE)
-# ---------------------------
+# --------------------------
 # Public sister of _AM_SUBST_NOTMAKE.
 AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
 
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
index 45efc51..8776a6f 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -1325,8 +1325,9 @@  Optional Features:
   --disable-option-checking  ignore unrecognized --enable/--with options
   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
-  --enable-maintainer-mode  enable make rules and dependencies not useful
-			  (and sometimes confusing) to the casual installer
+  --enable-maintainer-mode
+                          enable make rules and dependencies not useful (and
+                          sometimes confusing) to the casual installer
   --disable-largefile     omit support for large files
   --enable-libmcheck      Try linking with -lmcheck if available
   --enable-werror         treat compile warnings as errors
@@ -5535,6 +5536,35 @@  fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gdb_cv_m68k_is_coldfire" >&5
 $as_echo "$gdb_cv_m68k_is_coldfire" >&6; }
     ;;
+  x86_64-*-mingw*)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if building with -m32" >&5
+$as_echo_n "checking if building with -m32... " >&6; }
+if test "${gdb_cv_x86_64_is_i386+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  save_CPPFLAGS="$CPPFLAGS"
+		    CPPFLAGS="$CPPFLAGS $CFLAGS"
+                    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#if ! __x86_64__
+got it
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "got it" >/dev/null 2>&1; then :
+  gdb_cv_w64_x86_64_is_i386=yes
+else
+  gdb_cv_w64_x86_64_is_i386=no
+fi
+rm -f conftest*
+
+                    CPPFLAGS="$save_CPPFLAGS"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gdb_cv_x86_64_is_i386" >&5
+$as_echo "$gdb_cv_x86_64_is_i386" >&6; }
+    ;;
 esac
 
 . ${srcdir}/configure.srv
diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac
index 02082cc..ff9e272 100644
--- a/gdb/gdbserver/configure.ac
+++ b/gdb/gdbserver/configure.ac
@@ -238,6 +238,18 @@  got it
                     [gdb_cv_m68k_is_coldfire=no])
                     CPPFLAGS="$save_CPPFLAGS"])
     ;;
+  x86_64-*-mingw*)
+    AC_CACHE_CHECK([if building with -m32], [gdb_cv_x86_64_is_i386],
+		   [save_CPPFLAGS="$CPPFLAGS"
+		    CPPFLAGS="$CPPFLAGS $CFLAGS"
+                    AC_EGREP_CPP([got it], [
+#if ! __x86_64__
+got it
+#endif
+                 ], [gdb_cv_w64_x86_64_is_i386=yes],
+                    [gdb_cv_w64_x86_64_is_i386=no])
+                    CPPFLAGS="$save_CPPFLAGS"])
+    ;;
 esac
 
 . ${srcdir}/configure.srv
diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
index 679fc9f..e0d5413 100644
--- a/gdb/gdbserver/configure.srv
+++ b/gdb/gdbserver/configure.srv
@@ -325,6 +325,9 @@  case "${target}" in
 			ipa_obj="${ipa_amd64_linux_regobj} linux-amd64-ipa.o"
 			;;
   x86_64-*-mingw*)	srv_regobj="$srv_amd64_regobj"
+			if test "$gdb_cv_w64_x86_64_is_i386" = yes ; then
+			  srv_regobj="$srv_i386_regobj"
+			fi
 			srv_tgtobj="x86-low.o x86-dregs.o i387-fp.o win32-low.o win32-i386-low.o"
 			srv_xmlfiles="$srv_i386_xmlfiles $srv_amd64_xmlfiles"
 			srv_mingw=yes