https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104871

            Bug ID: 104871
           Summary: macosx-version-min wrong for macOS >= Big Sur
                    (darwin20)
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: simon at pushface dot org
  Target Milestone: ---

Created attachment 52603
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52603&action=edit
Patch, discards minor version

This is the same sort of problem as in PR80204: at present, GCC 11 &
12 assume that if the OS version is >= 20, the compiler should see
--mmacosx-version-min={major - 9}.{minor -1}.0, e.g. for OS version
21.3.0 that would be 12.2.0 (the linker sees -macosx-version-min, same
arguments).

However, the native compiler clang treats 21.3.0 as 12.0.0: the
compiler sees
   -triple x86_64-apple-macosx12.0.0
and the linker sees
   -platform_version macos 12.0.0
the result of which is that linking a main object file built with clang
and one built with gcc results in

  ld: warning: object file (null.o) was built for newer macOS version (12.2)
  than being linked (12.0)

I propose the following patch, which works fine for me (darwin 21.3.0).

diff --git a/gcc/config/darwin-driver.cc b/gcc/config/darwin-driver.cc
index 30e0e64f280..ca2a1ca1a60 100644
--- a/gcc/config/darwin-driver.cc
+++ b/gcc/config/darwin-driver.cc
@@ -164,15 +164,9 @@ darwin_find_version_from_kernel (void)
      version - 1 (at least for the initial releases).  */
   if (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, "%d.%02d.00", major_vers - 9, minor_vers);
+      /* clang doesn't include the minor version in the object file,
+         nor does it pass it to ld  */
+      asprintf (&new_flag, "%d.00.00", major_vers - 9);
     }
   else if (major_vers - 4 <= 4)
     /* On 10.4 and earlier, the old linker is used which does not

Reply via email to