diff --git a/gdb/configure b/gdb/configure
index 324eb50944..04ead07bc9 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -13642,6 +13642,63 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing __memcpy_chk" >&5
+$as_echo_n "checking for library containing __memcpy_chk... " >&6; }
+if ${ac_cv_search___memcpy_chk+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char __memcpy_chk ();
+int
+main ()
+{
+return __memcpy_chk ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' ssp; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search___memcpy_chk=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext
+  if ${ac_cv_search___memcpy_chk+:} false; then :
+  break
+fi
+done
+if ${ac_cv_search___memcpy_chk+:} false; then :
+
+else
+  ac_cv_search___memcpy_chk=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search___memcpy_chk" >&5
+$as_echo "$ac_cv_search___memcpy_chk" >&6; }
+ac_res=$ac_cv_search___memcpy_chk
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+
+
   # Check for std::thread.  This does not work on some platforms, like
   # mingw and DJGPP.
   ac_ext=cpp
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
index ccffde80ed..9f1cc70fda 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -7034,6 +7034,63 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing __memcpy_chk" >&5
+$as_echo_n "checking for library containing __memcpy_chk... " >&6; }
+if ${ac_cv_search___memcpy_chk+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char __memcpy_chk ();
+int
+main ()
+{
+return __memcpy_chk ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' ssp; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search___memcpy_chk=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext
+  if ${ac_cv_search___memcpy_chk+:} false; then :
+  break
+fi
+done
+if ${ac_cv_search___memcpy_chk+:} false; then :
+
+else
+  ac_cv_search___memcpy_chk=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search___memcpy_chk" >&5
+$as_echo "$ac_cv_search___memcpy_chk" >&6; }
+ac_res=$ac_cv_search___memcpy_chk
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+
+
   # Check for std::thread.  This does not work on some platforms, like
   # mingw and DJGPP.
   ac_ext=cpp
diff --git a/gdb/gdbsupport/common.m4 b/gdb/gdbsupport/common.m4
index c61753fb8e..eb66ec3731 100644
--- a/gdb/gdbsupport/common.m4
+++ b/gdb/gdbsupport/common.m4
@@ -37,6 +37,10 @@ AC_DEFUN([GDB_AC_COMMON], [
 
   AC_CHECK_DECLS([strstr])
 
+  dnl Recent mingw requires -lssp when using _FORTIFY_SOURCE, which we do
+  dnl (see gdbsupport/common-defs.h)
+  AC_SEARCH_LIBS(__memcpy_chk, ssp)
+
   # Check for std::thread.  This does not work on some platforms, like
   # mingw and DJGPP.
   AC_LANG_PUSH([C++])
