public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH]: PR target/80204 (Darwin macosx-version-min problem)
@ 2017-09-01 13:18 Simon Wright
  0 siblings, 0 replies; 9+ messages in thread
From: Simon Wright @ 2017-09-01 13:18 UTC (permalink / raw)
  To: gcc-patches

[-- 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH]: PR target/80204 (Darwin macosx-version-min problem)
  2017-09-04 19:48   ` Jakub Jelinek
  2017-09-11 12:32     ` Iain Sandoe
@ 2017-09-12 15:29     ` Jeff Law
  1 sibling, 0 replies; 9+ messages in thread
From: Jeff Law @ 2017-09-12 15:29 UTC (permalink / raw)
  To: Jakub Jelinek, Simon Wright; +Cc: gcc-patches

On 09/04/2017 01:48 PM, Jakub Jelinek wrote:
> On Mon, Sep 04, 2017 at 08:47:07PM +0100, Simon Wright wrote:
>> On 1 Sep 2017, at 23:05, Simon Wright <simon@pushface.org> wrote:
>>>
>>> 	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.
>>
>> Like this?
>>
>> Do you need the patch to be resubmitted as well?
>>
>> 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.
> 
> Better
> 
> 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.
Committed with Jakub's ChangeLog fixes.

jeff

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH]: PR target/80204 (Darwin macosx-version-min problem)
  2017-09-04 19:48   ` Jakub Jelinek
@ 2017-09-11 12:32     ` Iain Sandoe
  2017-09-12 15:29     ` Jeff Law
  1 sibling, 0 replies; 9+ messages in thread
From: Iain Sandoe @ 2017-09-11 12:32 UTC (permalink / raw)
  To: Simon Wright; +Cc: GCC Patches, Jeff Law, Jakub Jelinek


> On 4 Sep 2017, at 21:48, Jakub Jelinek <jakub@redhat.com> wrote:
> 
> On Mon, Sep 04, 2017 at 08:47:07PM +0100, Simon Wright wrote:
>> On 1 Sep 2017, at 23:05, Simon Wright <simon@pushface.org> wrote:
>>> 
>>> 	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.
>> 
>> Like this?
>> 
>> Do you need the patch to be resubmitted as well?
>> 
>> 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.
> 
> Better
> 
> 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.
> 
> 	Jakub

Very sorry that no-one from the Darwin folks has reviewed this to date, and thanks for the patch (and to Jakub and Jeff for taking care of it).

In general, I would prefer that a change like this would be made to apply to only versions of Darwin >= to the ones affected (so that the behaviour for earlier versions is unchanged).  As I read your patch, it alters things for all versions.

Having said that, the risk of bad effects is fairly low, and we can deal with them if they occur, so it’s a reasonable patch (as has been OK’d).

Please CC me directly on Darwin patches; in case I miss them in other list traffic.   Whilst I cannot approve them - at least I will try to review and make suggestions.

Iain Sandoe
CodeSourcery / Mentor Embedded / Siemens

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH]: PR target/80204 (Darwin macosx-version-min problem)
  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
  0 siblings, 2 replies; 9+ messages in thread
From: Jakub Jelinek @ 2017-09-04 19:48 UTC (permalink / raw)
  To: Simon Wright; +Cc: gcc-patches

On Mon, Sep 04, 2017 at 08:47:07PM +0100, Simon Wright wrote:
> On 1 Sep 2017, at 23:05, Simon Wright <simon@pushface.org> wrote:
> > 
> > 	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.
> 
> Like this?
> 
> Do you need the patch to be resubmitted as well?
> 
> 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.

Better

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.

	Jakub

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH]: PR target/80204 (Darwin macosx-version-min problem)
  2017-09-01 22:05 Simon Wright
  2017-09-04  6:09 ` Jeff Law
@ 2017-09-04 19:47 ` Simon Wright
  2017-09-04 19:48   ` Jakub Jelinek
  1 sibling, 1 reply; 9+ messages in thread
From: Simon Wright @ 2017-09-04 19:47 UTC (permalink / raw)
  To: gcc-patches

On 1 Sep 2017, at 23:05, Simon Wright <simon@pushface.org> wrote:
> 
> 	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.

Like this?

Do you need the patch to be resubmitted as well?

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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH]: PR target/80204 (Darwin macosx-version-min problem)
  2017-09-04 18:57   ` Simon Wright
@ 2017-09-04 19:05     ` Jakub Jelinek
  0 siblings, 0 replies; 9+ messages in thread
From: Jakub Jelinek @ 2017-09-04 19:05 UTC (permalink / raw)
  To: Simon Wright; +Cc: Jeff Law, gcc-patches

On Mon, Sep 04, 2017 at 07:56:58PM +0100, Simon Wright wrote:
> >> 	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.
> >> 
> > OK
> > jeff
> 
> Great! Can it be applied, please, when convenient

Note the ChangeLog entry has bad format, it should start with capital letter
(Eliminate) and the line is way too long, so should be wrapped differently.

	Jakub

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH]: PR target/80204 (Darwin macosx-version-min problem)
  2017-09-04  6:09 ` Jeff Law
@ 2017-09-04 18:57   ` Simon Wright
  2017-09-04 19:05     ` Jakub Jelinek
  0 siblings, 1 reply; 9+ messages in thread
From: Simon Wright @ 2017-09-04 18:57 UTC (permalink / raw)
  To: Jeff Law; +Cc: gcc-patches

(Apologies if this is a duplicate: Mac Mail vs the list's requirement for plain text)

On 4 Sep 2017, at 07:09, Jeff Law <law@redhat.com> wrote:
> 
> On 09/01/2017 04:05 PM, Simon Wright wrote:
>> 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.
>> 
> OK
> jeff

Great! Can it be applied, please, when convenient

--S

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH]: PR target/80204 (Darwin macosx-version-min problem)
  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:47 ` Simon Wright
  1 sibling, 1 reply; 9+ messages in thread
From: Jeff Law @ 2017-09-04  6:09 UTC (permalink / raw)
  To: Simon Wright, gcc-patches

On 09/01/2017 04:05 PM, Simon Wright wrote:
> 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.
> 
OK
jeff

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH]: PR target/80204 (Darwin macosx-version-min problem)
@ 2017-09-01 22:05 Simon Wright
  2017-09-04  6:09 ` Jeff Law
  2017-09-04 19:47 ` Simon Wright
  0 siblings, 2 replies; 9+ messages in thread
From: Simon Wright @ 2017-09-01 22:05 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1165 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-09-12 15:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-01 13:18 [PATCH]: PR target/80204 (Darwin macosx-version-min problem) Simon Wright
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

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).