From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.hosts.co.uk (smtp.hosts.co.uk [85.233.160.19]) by sourceware.org (Postfix) with ESMTPS id B877F396D804 for ; Wed, 8 Jun 2022 11:18:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B877F396D804 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=pushface.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=pushface.org Received: from host-78-148-8-241.as13285.net ([78.148.8.241] helo=smtpclient.apple) by smtp.hosts.co.uk with esmtpsa (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim) (envelope-from ) id 1nythv-0001Wv-BI; Wed, 08 Jun 2022 12:18:39 +0100 From: Simon Wright Content-Type: multipart/mixed; boundary="Apple-Mail=_452A7ABF-3464-4CAE-BD84-0E6D4A86EBFA" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.100.31\)) Subject: [PATCH] Fix PR target/104871 (macosx-version-min wrong for macOS >= Big Sur (darwin20)) Message-Id: Date: Wed, 8 Jun 2022 12:18:38 +0100 Cc: iain@codesourcery.com To: gcc-patches@gcc.gnu.org X-Mailer: Apple Mail (2.3696.100.31) X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jun 2022 11:18:42 -0000 --Apple-Mail=_452A7ABF-3464-4CAE-BD84-0E6D4A86EBFA Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 (resent with commit message format update) This is the same sort of problem as in PR80204: at present, GCC 11 & 12 = assume that if the=20 OS version is >=3D 20, the compiler should see = --mmacosx-version-min=3D{major - 9}.{minor -1}.0,=20 e.g. for OS version 21.3.0 that would be 12.2.0 (the linker sees = -macosx-version-min, same=20 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=20 the result of which is that linking an object file built with clang and = one built with gcc gives e.g. 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). gcc/ChangeLog: =09 2022-06-02 Simon Wright =09 PR target/104871 * config/darwin-driver.cc (darwin_find_version_from_kernel): If = the OS version is 20 (macOS 11) or greater, report the minor version and the = patch level as 0 to match Apple clang=E2=80=99s behaviour. --Apple-Mail=_452A7ABF-3464-4CAE-BD84-0E6D4A86EBFA Content-Disposition: attachment; filename=pr104871.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="pr104871.diff" Content-Transfer-Encoding: 7bit diff --git a/gcc/config/darwin-driver.cc b/gcc/config/darwin-driver.cc index 30e0e64f280..c47599e3fcb 100644 --- a/gcc/config/darwin-driver.cc +++ b/gcc/config/darwin-driver.cc @@ -160,19 +160,13 @@ darwin_find_version_from_kernel (void) goto parse_failed; /* 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). */ + mapping to macOS minor version and patch level is now always 0, 0 + (at least for macOS 11 and 12). */ 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); + /* Apple clang doesn't include the minor version or the patch level + 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 --Apple-Mail=_452A7ABF-3464-4CAE-BD84-0E6D4A86EBFA--