diff --git a/ares/m4/cares-compilers.m4 b/ares/m4/cares-compilers.m4
index 2b00dffc52407434fa175ae8b261b51b234c4101..156ff632fbd5b559df2bf2e7833601e4bfd68f1f 100644
--- a/ares/m4/cares-compilers.m4
+++ b/ares/m4/cares-compilers.m4
@@ -916,10 +916,20 @@ AC_DEFUN([CARES_SET_COMPILER_WARNING_OPTS], [
         if test "$want_warnings" = "yes"; then
           if test "$compiler_num" -gt "600"; then
             dnl Show errors, warnings, and remarks
-            tmp_CPPFLAGS="$tmp_CPPFLAGS -Wall"
+            tmp_CPPFLAGS="$tmp_CPPFLAGS -Wall -w2"
             dnl Perform extra compile-time code checking
             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wcheck"
           fi
+          dnl Disable using EBP register in optimizations
+          tmp_CFLAGS="$tmp_CFLAGS -fno-omit-frame-pointer"
+          dnl Disable inline expansion of intrinsic functions
+          tmp_CFLAGS="$tmp_CFLAGS -fno-builtin"
+          dnl Disable inlining of functions
+          tmp_CFLAGS="$tmp_CFLAGS -fno-inline"
+          dnl Enable floating-point stack integrity checks
+          tmp_CFLAGS="$tmp_CFLAGS -fpstkchk"
+          dnl Enable run-time detection of buffer overruns.
+          tmp_CFLAGS="$tmp_CFLAGS -fstack-security-check"
         fi
         ;;
         #
diff --git a/m4/curl-compilers.m4 b/m4/curl-compilers.m4
index 860db52001466b952e498a2e20d1de4feb69154b..0ccba96a16ba10b2369135917bf73cd04d1de385 100644
--- a/m4/curl-compilers.m4
+++ b/m4/curl-compilers.m4
@@ -922,10 +922,20 @@ AC_DEFUN([CURL_SET_COMPILER_WARNING_OPTS], [
         if test "$want_warnings" = "yes"; then
           if test "$compiler_num" -gt "600"; then
             dnl Show errors, warnings, and remarks
-            tmp_CPPFLAGS="$tmp_CPPFLAGS -Wall"
+            tmp_CPPFLAGS="$tmp_CPPFLAGS -Wall -w2"
             dnl Perform extra compile-time code checking
             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wcheck"
           fi
+          dnl Disable using EBP register in optimizations
+          tmp_CFLAGS="$tmp_CFLAGS -fno-omit-frame-pointer"
+          dnl Disable inline expansion of intrinsic functions
+          tmp_CFLAGS="$tmp_CFLAGS -fno-builtin"
+          dnl Disable inlining of functions
+          tmp_CFLAGS="$tmp_CFLAGS -fno-inline"
+          dnl Enable floating-point stack integrity checks
+          tmp_CFLAGS="$tmp_CFLAGS -fpstkchk"
+          dnl Enable run-time detection of buffer overruns.
+          tmp_CFLAGS="$tmp_CFLAGS -fstack-security-check"
         fi
         ;;
         #