diff --git a/gcc/config.gcc b/gcc/config.gcc
index efd1f42ac234d9c73aaf952e229027c36beb4f2f..b1082cdbab1359fd66bc96dc5cd2b4bf38f0064e 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -681,9 +681,9 @@ case ${target} in
       *-*-darwin[4-9]* | *-*-darwin1[0-9]*)
         macos_min=`expr $darwin_maj - 4`
         ;;
-      *-*-darwin20*)
-        # Darwin 20 corresponds to macOS 11.
-        macos_maj=11
+      *-*-darwin2*)
+        # Darwin 20 corresponds to macOS 11, Darwin 21 to macOS 12.
+        macos_maj=`expr $darwin_maj - 9`
         def_ld64=609.0
         ;;
       *-*-darwin)
diff --git a/gcc/config/darwin-c.c b/gcc/config/darwin-c.c
index 951a998775f83e16ed6c11963e6e9eb1286c51a7..62d28fcea501bbcb9eb403c74793af45eb91ca7f 100644
--- a/gcc/config/darwin-c.c
+++ b/gcc/config/darwin-c.c
@@ -691,7 +691,7 @@ macosx_version_as_macro (void)
   if (!version_array)
     goto fail;
 
-  if (version_array[MAJOR] < 10 || version_array[MAJOR] > 11)
+  if (version_array[MAJOR] < 10 || version_array[MAJOR] > 12)
     goto fail;
 
   if (version_array[MAJOR] == 10 && version_array[MINOR] < 10)
diff --git a/gcc/config/darwin-driver.c b/gcc/config/darwin-driver.c
index a036e091c48b02d072e22965953817f72d2fcfca..4f0c6bad61fdc739ff93ed967088ccee4b5290b5 100644
--- a/gcc/config/darwin-driver.c
+++ b/gcc/config/darwin-driver.c
@@ -64,17 +64,17 @@ validate_macosx_version_min (const char *version_str)
 
   major = strtoul (version_str, &end, 10);
 
-  if (major < 10 || major > 11 ) /* MacOS 10 and 11 are known. */
+  if (major < 10 || major > 12 ) /* macOS 10, 11, and 12 are known. */
     return NULL;
 
   /* Skip a separating period, if there's one.  */
   version_str = end + ((*end == '.') ? 1 : 0);
 
-  if (major == 11 && *end != '\0' && !ISDIGIT (version_str[0]))
-     /* For MacOS 11, we allow just the major number, but if the minor is
+  if (major > 10 && *end != '\0' && !ISDIGIT (version_str[0]))
+     /* For macOS 11+, we allow just the major number, but if the minor is
 	there it must be numeric.  */
     return NULL;
-  else if (major == 11 && *end == '\0')
+  else if (major > 10 && *end == '\0')
     /* We will rewrite 11 =>  11.0.0.  */
     need_rewrite = true;
   else if (major == 10 && (*end == '\0' || !ISDIGIT (version_str[0])))
@@ -172,7 +172,7 @@ darwin_find_version_from_kernel (void)
       if (minor_vers > 0)
 	minor_vers -= 1; /* Kernel 20.3 => macOS 11.2.  */
       /* It's not yet clear whether patch level will be considered.  */
-      asprintf (&new_flag, "11.%02d.00", minor_vers);
+      asprintf (&new_flag, "%d.%02d.00", major_vers - 9, minor_vers);
     }
   else if (major_vers - 4 <= 4)
     /* On 10.4 and earlier, the old linker is used which does not