[1/1] Fix canadian compile for mingw-w64 copies the wrong dlls for mingw-w64 multilibs [PR100427]

Message ID DM6PR05MB4697C9EE0E2625C498692206D64C9@DM6PR05MB4697.namprd05.prod.outlook.com
State New
Headers
Series [1/1] Fix canadian compile for mingw-w64 copies the wrong dlls for mingw-w64 multilibs [PR100427] |

Commit Message

cqwrteur Jan. 6, 2022, 11:30 p.m. UTC
  When building GCC hosted on windows with Canadian/native compilation (host==target), the build scripts in GCC would override DLLs with each other. For example, for MinGW-w64, 32-bit DLLs would override 64 bits because build scripts copy them both to /bin.

This patch fixes the issue by avoiding copying DLLs with multilibs. However, it would still copy when we do not build multilibs, usually the native build for GCC on windows.
---
 gcc/configure                  | 26 ++++++++++++++++++++++++++
 libatomic/configure            | 13 +++++++++++++
 libbacktrace/configure         | 13 +++++++++++++
 libcc1/configure               | 26 ++++++++++++++++++++++++++
 libffi/configure               | 26 ++++++++++++++++++++++++++
 libgfortran/configure          | 26 ++++++++++++++++++++++++++
 libgo/config/libtool.m4        | 13 +++++++++++++
 libgo/configure                | 13 +++++++++++++
 libgomp/configure              | 26 ++++++++++++++++++++++++++
 libitm/configure               | 26 ++++++++++++++++++++++++++
 libobjc/configure              | 13 +++++++++++++
 liboffloadmic/configure        | 26 ++++++++++++++++++++++++++
 liboffloadmic/plugin/configure | 26 ++++++++++++++++++++++++++
 libphobos/configure            | 13 +++++++++++++
 libquadmath/configure          | 13 +++++++++++++
 libsanitizer/configure         | 26 ++++++++++++++++++++++++++
 libssp/configure               | 13 +++++++++++++
 libstdc++-v3/configure         | 26 ++++++++++++++++++++++++++
 libtool.m4                     | 13 +++++++++++++
 libvtv/configure               | 26 ++++++++++++++++++++++++++
 lto-plugin/configure           | 13 +++++++++++++
 zlib/configure                 | 13 +++++++++++++
 22 files changed, 429 insertions(+)
  

Comments

NightStrike Jan. 8, 2022, 9:04 a.m. UTC | #1
On Thu, Jan 6, 2022, 18:31 cqwrteur via Gcc-patches <gcc-patches@gcc.gnu.org>
wrote:

> When building GCC hosted on windows with Canadian/native compilation
> (host==target), the build scripts in GCC would override DLLs with each
> other. For example, for MinGW-w64, 32-bit DLLs would override 64 bits
> because build scripts copy them both to /bin.
>
> This patch fixes the issue by avoiding copying DLLs with multilibs.
> However, it would still copy when we do not build multilibs, usually the
> native build for GCC on windows.
> ---
>  gcc/configure                  | 26 ++++++++++++++++++++++++++
>

You should probably not be modifying configure directly.

>
  
Jeff Law Jan. 8, 2022, 4:34 p.m. UTC | #2
On 1/8/2022 2:04 AM, NightStrike via Gcc-patches wrote:
> On Thu, Jan 6, 2022, 18:31 cqwrteur via Gcc-patches <gcc-patches@gcc.gnu.org>
> wrote:
>
>> When building GCC hosted on windows with Canadian/native compilation
>> (host==target), the build scripts in GCC would override DLLs with each
>> other. For example, for MinGW-w64, 32-bit DLLs would override 64 bits
>> because build scripts copy them both to /bin.
>>
>> This patch fixes the issue by avoiding copying DLLs with multilibs.
>> However, it would still copy when we do not build multilibs, usually the
>> native build for GCC on windows.
>> ---
>>   gcc/configure                  | 26 ++++++++++++++++++++++++++
>>
> You should probably not be modifying configure directly.
Umm, the patch modifies libtool.m4 (two instances) and presumably the 
configure changes are just rebuilds with the autotools.

jeff
  

Patch

diff --git a/gcc/configure b/gcc/configure
index 992a9d70092..d66ccc2a7f4 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -18642,6 +18642,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -18651,6 +18663,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
@@ -22299,6 +22312,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -22308,6 +22333,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/libatomic/configure b/libatomic/configure
index 5867e69ac14..4fd8cb34cd4 100755
--- a/libatomic/configure
+++ b/libatomic/configure
@@ -10461,6 +10461,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -10470,6 +10482,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/libbacktrace/configure b/libbacktrace/configure
index a2f33c0f35d..85bd1fff042 100755
--- a/libbacktrace/configure
+++ b/libbacktrace/configure
@@ -10590,6 +10590,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -10599,6 +10611,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/libcc1/configure b/libcc1/configure
index 01cfb2806da..8b2e6d851e4 100755
--- a/libcc1/configure
+++ b/libcc1/configure
@@ -9858,6 +9858,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -9867,6 +9879,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
@@ -13921,6 +13934,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -13930,6 +13955,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/libffi/configure b/libffi/configure
index 575641cca1d..6b57c4f65da 100755
--- a/libffi/configure
+++ b/libffi/configure
@@ -10653,6 +10653,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -10662,6 +10674,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
@@ -14310,6 +14323,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -14319,6 +14344,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/libgfortran/configure b/libgfortran/configure
index 4810b9b032e..faf5f0fa538 100755
--- a/libgfortran/configure
+++ b/libgfortran/configure
@@ -11791,6 +11791,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -11800,6 +11812,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
@@ -15563,6 +15576,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -15572,6 +15597,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/libgo/config/libtool.m4 b/libgo/config/libtool.m4
index 4ca90ee71bc..25436f1187c 100644
--- a/libgo/config/libtool.m4
+++ b/libgo/config/libtool.m4
@@ -2219,6 +2219,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -2228,6 +2240,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/libgo/configure b/libgo/configure
index 57ceeb2baa7..f51e5aed8d6 100755
--- a/libgo/configure
+++ b/libgo/configure
@@ -10630,6 +10630,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -10639,6 +10651,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/libgomp/configure b/libgomp/configure
index 4bc9b381c5c..5fc19cee246 100755
--- a/libgomp/configure
+++ b/libgomp/configure
@@ -10502,6 +10502,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -10511,6 +10523,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
@@ -14144,6 +14157,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -14153,6 +14178,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/libitm/configure b/libitm/configure
index b8f1e2360d0..37a0c4f1d19 100755
--- a/libitm/configure
+++ b/libitm/configure
@@ -11137,6 +11137,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -11146,6 +11158,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
@@ -14794,6 +14807,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -14803,6 +14828,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/libobjc/configure b/libobjc/configure
index 5d1b424a66d..63451d2b6c8 100755
--- a/libobjc/configure
+++ b/libobjc/configure
@@ -9834,6 +9834,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -9843,6 +9855,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/liboffloadmic/configure b/liboffloadmic/configure
index dfa8287fd75..e1c8226eeb0 100755
--- a/liboffloadmic/configure
+++ b/liboffloadmic/configure
@@ -10501,6 +10501,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -10510,6 +10522,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
@@ -14158,6 +14171,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -14167,6 +14192,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/liboffloadmic/plugin/configure b/liboffloadmic/plugin/configure
index 0b21d7d4eed..0ec1ebd453f 100755
--- a/liboffloadmic/plugin/configure
+++ b/liboffloadmic/plugin/configure
@@ -10148,6 +10148,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -10157,6 +10169,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
@@ -13805,6 +13818,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -13814,6 +13839,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/libphobos/configure b/libphobos/configure
index 17b26565505..ff957aee565 100755
--- a/libphobos/configure
+++ b/libphobos/configure
@@ -10831,6 +10831,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -10840,6 +10852,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/libquadmath/configure b/libquadmath/configure
index 31918507f62..2e1b565ecbe 100755
--- a/libquadmath/configure
+++ b/libquadmath/configure
@@ -9869,6 +9869,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -9878,6 +9890,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/libsanitizer/configure b/libsanitizer/configure
index 08bdbc68841..3fc32b7a4d6 100755
--- a/libsanitizer/configure
+++ b/libsanitizer/configure
@@ -11437,6 +11437,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -11446,6 +11458,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
@@ -15094,6 +15107,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -15103,6 +15128,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/libssp/configure b/libssp/configure
index 10ba209bde8..6e0f7ebe02e 100755
--- a/libssp/configure
+++ b/libssp/configure
@@ -10055,6 +10055,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -10064,6 +10076,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index b1a0157d0b9..79bc0ef3ecd 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -11239,6 +11239,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -11248,6 +11260,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
@@ -14920,6 +14933,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -14929,6 +14954,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/libtool.m4 b/libtool.m4
index 17f8e5f3074..9e5a9fde0de 100644
--- a/libtool.m4
+++ b/libtool.m4
@@ -2216,6 +2216,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -2225,6 +2237,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/libvtv/configure b/libvtv/configure
index d64b4af5c6b..29b7359da36 100755
--- a/libvtv/configure
+++ b/libvtv/configure
@@ -11335,6 +11335,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -11344,6 +11356,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
@@ -14992,6 +15005,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -15001,6 +15026,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/lto-plugin/configure b/lto-plugin/configure
index 26aad9dd699..caf752ed3fb 100755
--- a/lto-plugin/configure
+++ b/lto-plugin/configure
@@ -11062,6 +11062,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -11071,6 +11083,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'
diff --git a/zlib/configure b/zlib/configure
index f489f31bc70..35717a9fa50 100755
--- a/zlib/configure
+++ b/zlib/configure
@@ -9798,6 +9798,18 @@  cygwin* | mingw* | pw32* | cegcc*)
   yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
     library_names_spec='$libname.dll.a'
     # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    # If user builds GCC with mulitlibs enabled, it should just install on $(libdir)
+    # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones.
+    if test ${multilib} = yes; then
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      $install_prog $dir/$dlname $destdir/$dlname~
+      chmod a+x $destdir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib $destdir/$dlname'\'' || exit \$?;
+      fi'
+    else
     postinstall_cmds='base_file=`basename \${file}`~
       dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
       dldir=$destdir/`dirname \$dlpath`~
@@ -9807,6 +9819,7 @@  cygwin* | mingw* | pw32* | cegcc*)
       if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
         eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
       fi'
+    fi
     postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
       dlpath=$dir/\$dldll~
        $RM \$dlpath'