public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH]: PR target/80204 (Darwin macosx-version-min problem)
Date: Fri, 01 Sep 2017 13:18:00 -0000	[thread overview]
Message-ID: <F2C9560C-3384-4A97-BB5B-450C8A0F549F@pushface.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 1166 bytes --]

In gcc/config/darwin-driver.c, darwin_find_version_from_kernel() assumes
that the minor version in the Darwin kernel version (16.7.0, => minor
version 7) is equal to the bugfix component of the macOS version, so that
the compiler receives -mmacosx-version-min=10.12.7 and the linker receives
-macosx_version_min 10.12.7.

Unfortunately, Apple don’t apply this algorithm; the macOS version is
actually 10.12.6.

Getting this wrong means that it’s impossible to run an executable from 
within a bundle: Sierra complains "You have macOS 10.12.6. The application
requires macOS 10.12.7 or later".

A workround would perhaps be to link the executable with
-Wl,-macosx_version_min,`sw_vers -productVersion` (I assume that it’s only
the linker phase that matters?)

I see that Apple’s gcc (Apple LLVM version 8.0.0
(clang-800.0.42.1)) specifies - only at link time -
  -macosx_version_min 10.12.0

This patch does the same.

gcc/Changelog:

	2017-09-01 Simon Wright <simon@pushface.org>

	PR target/80204
	* config/darwin-driver.c (darwin_find_version_from_kernel): eliminate calculation of the
	  minor version, always output as 0.


[-- Attachment #2: 80204-darwin-driver.c.diff --]
[-- Type: application/octet-stream, Size: 1832 bytes --]

diff --git a/gcc/config/darwin-driver.c b/gcc/config/darwin-driver.c
index e3ed79d..144f9d2 100644
--- a/gcc/config/darwin-driver.c
+++ b/gcc/config/darwin-driver.c
@@ -37,9 +37,7 @@ darwin_find_version_from_kernel (void)
   size_t osversion_len = sizeof (osversion) - 1;
   static int osversion_name[2] = { CTL_KERN, KERN_OSRELEASE };
   int major_vers;
-  char minor_vers[6];
   char * version_p;
-  char * version_pend;
   char * new_flag;
 
   /* Determine the version of the running OS.  If we can't, warn user,
@@ -61,13 +59,6 @@ darwin_find_version_from_kernel (void)
     major_vers = major_vers * 10 + (*version_p++ - '0');
   if (*version_p++ != '.')
     goto parse_failed;
-  version_pend = strchr(version_p, '.');
-  if (!version_pend)
-    goto parse_failed;
-  if (! ISDIGIT (*version_p))
-    goto parse_failed;
-  strncpy(minor_vers, version_p, version_pend - version_p);
-  minor_vers[version_pend - version_p] = '\0';
 
   /* The major kernel version number is 4 plus the second OS version
      component.  */
@@ -77,7 +68,11 @@ darwin_find_version_from_kernel (void)
        FIXME: we should not assume this - a newer linker could be used.  */
     asprintf (&new_flag, "10.%d", major_vers - 4);
   else
-    asprintf (&new_flag, "10.%d.%s", major_vers - 4, minor_vers);
+    /* Although the newer linker supports three-component system
+       versions, there's no guarantee that the minor version component
+       of the kernel and the system are the same. Apple's clang always
+       uses 0 as the minor version: do the same.  */
+    asprintf (&new_flag, "10.%d.0", major_vers - 4);
 
   return new_flag;
 
@@ -86,7 +81,6 @@ darwin_find_version_from_kernel (void)
 	   (int) osversion_len, osversion);
   return NULL;
 }
-
 #endif
 
 /* When running on a Darwin system and using that system's headers and

             reply	other threads:[~2017-09-01 13:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-01 13:18 Simon Wright [this message]
2017-09-01 22:05 Simon Wright
2017-09-04  6:09 ` Jeff Law
2017-09-04 18:57   ` Simon Wright
2017-09-04 19:05     ` Jakub Jelinek
2017-09-04 19:47 ` Simon Wright
2017-09-04 19:48   ` Jakub Jelinek
2017-09-11 12:32     ` Iain Sandoe
2017-09-12 15:29     ` Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=F2C9560C-3384-4A97-BB5B-450C8A0F549F@pushface.org \
    --to=simon@pushface.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).