[pushed] Darwin : Update the kernel version to macOS version mapping.

Message ID B72AB7C9-3924-4366-8FF8-AB6F7895FBD0@sandoe.co.uk
State New
Headers show
Series
  • [pushed] Darwin : Update the kernel version to macOS version mapping.
Related show

Commit Message

Iain Sandoe Dec. 21, 2020, 8:27 p.m.
Hi

We are currently computing the wrong macOS version information for
Darwin kernel editions >= 20.1 (because the computation rules have
changed).  This fixes the computation as far as it’s currently defined.

The patch is an addendum to “Darwin20 is macOS 11” and is needed
on the open [and closed!] branches to support those on Darwin20.

----

tested on x86_64-darwin20.2, x86_64-darwin16 and i686-darwin9.8.
pushed to master,
thanks
Iain

—— commit log

With the change to macOS 11 and Darwin20, the algorithm for mapping
kernel version to macOS version has changed.

We now have darwin 20.X.Y => macOS 11.(X > 0 ? X - 1 : 0).??.
It currently unclear if the Y will be mapped to macOS patch version
and, if so, whether it will be one-based or 0-based.
Likewise, it's unknown if Darwin 21 will map to macOS 12, so these
entries are unchanged for the present.

gcc/ChangeLog:

	* config/darwin-driver.c (darwin_find_version_from_kernel):
	Compute the minor OS version from the minor kernel version.
---
 gcc/config/darwin-driver.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

-- 
2.24.1

Patch

diff --git a/gcc/config/darwin-driver.c b/gcc/config/darwin-driver.c
index 8ae300057fd..4a9426ef273 100644
--- a/gcc/config/darwin-driver.c
+++ b/gcc/config/darwin-driver.c
@@ -149,9 +149,22 @@  darwin_find_version_from_kernel (void)
   if (*version_p++ != '.')
     goto parse_failed;
 
-  /* Darwin20 sees a transition to macOS 11.  */
+  /* Darwin20 sees a transition to macOS 11.  In this, it seems that the
+     mapping to macOS minor version is now shifted to the kernel minor
+     version - 1 (at least for the initial releases).  At this stage, we
+     don't know what macOS version will correspond to Darwin21.  */
   if (major_vers >= 20)
-    asprintf (&new_flag, "11.%02d.00", major_vers - 20);
+    {
+      int minor_vers = *version_p++ - '0';
+      if (ISDIGIT (*version_p))
+	minor_vers = minor_vers * 10 + (*version_p++ - '0');
+      if (*version_p++ != '.')
+	goto parse_failed;
+      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);
+    }
   else if (major_vers - 4 <= 4)
     /* On 10.4 and earlier, the old linker is used which does not
        support three-component system versions.