View | Details | Return to bug 63810 | Differences between
and this patch

Collapse All | Expand All

(-)a/gcc/config/darwin-c.c (-14 / +152 lines)
Lines 570-598 find_subframework_header (cpp_reader *pfile, const char *header, cpp_dir **dirp) Link Here
570
  return 0;
570
  return 0;
571
}
571
}
572
572
573
/* Return the value of darwin_macosx_version_min suitable for the
573
/*  Given a version string, return the version as a statically-allocated
574
   __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro,
574
    array of three non-negative integers.  If the version string is
575
   so '10.4.2' becomes 1040.  The lowest digit is always zero.
575
    invalid, return null.
576
   Print a warning if the version number can't be understood.  */
576
577
    Version strings must consist of one, two, or three tokens, each
578
    separated by a single period.  Each token must contain only the
579
    characters '0' through '9' and is converted to an equivalent
580
    integer.  Omitted tokens are treated as zeros.  For example:
581
582
        "10"              becomes   {10,0,0}
583
        "10.10"           becomes   {10,10,0}
584
        "10.10.1"         becomes   {10,10,1}
585
        "10.000010.1"     becomes   {10,10,1}
586
        "10.010.001"      becomes   {10,10,1}
587
        "000010.10.00001" becomes   {10,10,1}  */
588
589
enum version_components { MAJOR, MINOR, TINY };
590
591
static const unsigned long *
592
parse_version (const char *version_str)
593
{
594
  size_t version_len;
595
  char *end;
596
  static unsigned long version_array[3];
597
598
  if (! version_str)
599
    return NULL;
600
601
  version_len = strlen (version_str);
602
  if (version_len < 1)
603
    return NULL;
604
605
  /* Version string must consist of digits and periods only.  */
606
  if (strspn (version_str, "0123456789.") != version_len)
607
    return NULL;
608
609
  if (! ISDIGIT (version_str[0]) || ! ISDIGIT (version_str[version_len - 1]))
610
    return NULL;
611
612
  version_array[MAJOR] = strtoul (version_str, &end, 10);
613
  version_str = end + ((*end == '.') ? 1 : 0);
614
615
  /* Version string must not contain adjacent periods.  */
616
  if (*version_str == '.')
617
    return NULL;
618
619
  version_array[MINOR] = strtoul (version_str, &end, 10);
620
  version_str = end + ((*end == '.') ? 1 : 0);
621
622
  version_array[TINY] = strtoul (version_str, &end, 10);
623
624
  /* Version string must contain no more than three tokens.  */
625
  if (*end != '\0')
626
    return NULL;
627
628
  return version_array;
629
}
630
631
/*  Given a three-component version represented as an array of
632
    non-negative integers, return a statically-allocated string suitable
633
    for the legacy __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro.
634
    If the version is invalid and cannot be coerced into a valid form,
635
    return null.
636
637
    The legacy format is a four-character string -- two chars for the
638
    major number and one each for the minor and tiny numbers.  Major
639
    numbers are zero-padded if necessary.  Minor and tiny numbers from
640
    10 through 99 are permitted but are clamped to 9 (for example,
641
    {10,9,10} produces "1099").  Versions containing numbers greater
642
    than 99 are rejected.  */
643
644
static const char *
645
version_as_legacy_macro (const unsigned long *version)
646
{
647
  unsigned long major = version[MAJOR];
648
  unsigned long minor = version[MINOR];
649
  unsigned long tiny = version[TINY];
650
  static char result[sizeof "9999"];
651
652
  if (major > 99 || minor > 99 || tiny > 99)
653
    return NULL;
654
655
  minor = ((minor > 9) ? 9 : minor);
656
  tiny = ((tiny > 9) ? 9 : tiny);
657
658
  /* NOTE: Cast result of sizeof so that result of sprintf is not
659
     converted to an unsigned type.  */
660
  if (sprintf (result, "%02lu%lu%lu", major, minor, tiny)
661
      != (int) sizeof "9999" - 1)
662
    return NULL;
663
664
  return result;
665
}
666
667
/*  Given a three-component version represented as an array of
668
    non-negative integers, return a statically-allocated string suitable
669
    for the modern __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro
670
    or the __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ macro.  If the
671
    version is invalid, return null.
672
673
    The modern format is a five- or six-character string -- one or two
674
    chars for the major number and two each for the minor and tiny
675
    numbers, which are zero-padded if necessary (for example, {8,1,0}
676
    produces "80100", and {10,10,1} produces "101001").  Versions
677
    containing numbers greater than 99 are rejected.  */
678
577
static const char *
679
static const char *
578
version_as_macro (void)
680
version_as_modern_macro (const unsigned long *version)
579
{
681
{
580
  static char result[] = "1000";
682
  unsigned long major = version[MAJOR];
683
  unsigned long minor = version[MINOR];
684
  unsigned long tiny = version[TINY];
685
  static char result[sizeof "999999"];
686
687
  if (major > 99 || minor > 99 || tiny > 99)
688
    return NULL;
689
690
  /* NOTE: 'sizeof "foo"' returns size of char array, but
691
     'sizeof ((x > y) ? "foo" : "bar")' returns size of char pointer.  */
692
  /* NOTE: Cast result of sizeof so that result of sprintf is not
693
     converted to an unsigned type.  */
694
  if (sprintf (result, "%lu%02lu%02lu", major, minor, tiny)
695
      != (int) ((major > 9) ? sizeof "999999" : sizeof "99999") - 1)
696
    return NULL;
697
698
  return result;
699
}
581
700
582
  if (strncmp (darwin_macosx_version_min, "10.", 3) != 0)
701
/*  Return the value of darwin_macosx_version_min, suitably formatted
702
    for the __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro.  (For
703
    example, "10.9" produces "1090", and "10.10.1" produces "101001".)
704
    If its value is invalid and cannot be coerced into a valid form,
705
    print a warning and return "1000".  */
706
707
static const char *
708
macosx_version_as_macro (void)
709
{
710
  const unsigned long *version_array;
711
  const char *version_macro;
712
713
  version_array = parse_version (darwin_macosx_version_min);
714
  if (! version_array)
583
    goto fail;
715
    goto fail;
584
  if (! ISDIGIT (darwin_macosx_version_min[3]))
716
717
  /* Do not assume that the major number will always be exactly 10.  */
718
  if (version_array[MAJOR] < 10 || version_array[MAJOR] > 10)
585
    goto fail;
719
    goto fail;
586
  result[2] = darwin_macosx_version_min[3];
720
587
  if (darwin_macosx_version_min[4] != '\0'
721
  if (version_array[MAJOR] == 10 && version_array[MINOR] < 10)
588
      && darwin_macosx_version_min[4] != '.')
722
    version_macro = version_as_legacy_macro (version_array);
723
  else
724
    version_macro = version_as_modern_macro (version_array);
725
726
  if (! version_macro)
589
    goto fail;
727
    goto fail;
590
728
591
  return result;
729
  return version_macro;
592
730
593
 fail:
731
 fail:
594
  error ("unknown value %qs of -mmacosx-version-min",
732
  error ("unknown value %qs of -mmacosx-version-min",
595
	 darwin_macosx_version_min);
733
         darwin_macosx_version_min);
596
  return "1000";
734
  return "1000";
597
}
735
}
598
736
Lines 614-620 darwin_cpp_builtins (cpp_reader *pfile) Link Here
614
    builtin_define ("__CONSTANT_CFSTRINGS__");
752
    builtin_define ("__CONSTANT_CFSTRINGS__");
615
753
616
  builtin_define_with_value ("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__",
754
  builtin_define_with_value ("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__",
617
			     version_as_macro(), false);
755
			     macosx_version_as_macro(), false);
618
756
619
  /* Since we do not (at 4.6) support ObjC gc for the NeXT runtime, the
757
  /* Since we do not (at 4.6) support ObjC gc for the NeXT runtime, the
620
     following will cause a syntax error if one tries to compile gc attributed
758
     following will cause a syntax error if one tries to compile gc attributed
(-)a/gcc/config/darwin-driver.c (-19 / +16 lines)
Lines 29-36 along with GCC; see the file COPYING3. If not see Link Here
29
#include <sys/sysctl.h>
29
#include <sys/sysctl.h>
30
#include "xregex.h"
30
#include "xregex.h"
31
31
32
static bool
32
static char *
33
darwin_find_version_from_kernel (char *new_flag)
33
darwin_find_version_from_kernel (void)
34
{
34
{
35
  char osversion[32];
35
  char osversion[32];
36
  size_t osversion_len = sizeof (osversion) - 1;
36
  size_t osversion_len = sizeof (osversion) - 1;
Lines 39-44 darwin_find_version_from_kernel (char *new_flag) Link Here
39
  char minor_vers[6];
39
  char minor_vers[6];
40
  char * version_p;
40
  char * version_p;
41
  char * version_pend;
41
  char * version_pend;
42
  char * new_flag;
42
43
43
  /* Determine the version of the running OS.  If we can't, warn user,
44
  /* Determine the version of the running OS.  If we can't, warn user,
44
     and do nothing.  */
45
     and do nothing.  */
Lines 46-52 darwin_find_version_from_kernel (char *new_flag) Link Here
46
	      &osversion_len, NULL, 0) == -1)
47
	      &osversion_len, NULL, 0) == -1)
47
    {
48
    {
48
      warning (0, "sysctl for kern.osversion failed: %m");
49
      warning (0, "sysctl for kern.osversion failed: %m");
49
      return false;
50
      return NULL;
50
    }
51
    }
51
52
52
  /* Try to parse the first two parts of the OS version number.  Warn
53
  /* Try to parse the first two parts of the OS version number.  Warn
Lines 57-64 darwin_find_version_from_kernel (char *new_flag) Link Here
57
  version_p = osversion + 1;
58
  version_p = osversion + 1;
58
  if (ISDIGIT (*version_p))
59
  if (ISDIGIT (*version_p))
59
    major_vers = major_vers * 10 + (*version_p++ - '0');
60
    major_vers = major_vers * 10 + (*version_p++ - '0');
60
  if (major_vers > 4 + 9)
61
    goto parse_failed;
62
  if (*version_p++ != '.')
61
  if (*version_p++ != '.')
63
    goto parse_failed;
62
    goto parse_failed;
64
  version_pend = strchr(version_p, '.');
63
  version_pend = strchr(version_p, '.');
Lines 74-90 darwin_find_version_from_kernel (char *new_flag) Link Here
74
  if (major_vers - 4 <= 4)
73
  if (major_vers - 4 <= 4)
75
    /* On 10.4 and earlier, the old linker is used which does not
74
    /* On 10.4 and earlier, the old linker is used which does not
76
       support three-component system versions.  */
75
       support three-component system versions.  */
77
    sprintf (new_flag, "10.%d", major_vers - 4);
76
    asprintf (&new_flag, "10.%d", major_vers - 4);
78
  else
77
  else
79
    sprintf (new_flag, "10.%d.%s", major_vers - 4,
78
    asprintf (&new_flag, "10.%d.%s", major_vers - 4, minor_vers);
80
	     minor_vers);
81
79
82
  return true;
80
  return new_flag;
83
81
84
 parse_failed:
82
 parse_failed:
85
  warning (0, "couldn%'t understand kern.osversion %q.*s",
83
  warning (0, "couldn%'t understand kern.osversion %q.*s",
86
	   (int) osversion_len, osversion);
84
	   (int) osversion_len, osversion);
87
  return false;
85
  return NULL;
88
}
86
}
89
87
90
#endif
88
#endif
Lines 105-111 darwin_default_min_version (unsigned int *decoded_options_count, Link Here
105
  const unsigned int argc = *decoded_options_count;
103
  const unsigned int argc = *decoded_options_count;
106
  struct cl_decoded_option *const argv = *decoded_options;
104
  struct cl_decoded_option *const argv = *decoded_options;
107
  unsigned int i;
105
  unsigned int i;
108
  static char new_flag[sizeof ("10.0.0") + 6];
106
  const char *new_flag;
109
107
110
  /* If the command-line is empty, just return.  */
108
  /* If the command-line is empty, just return.  */
111
  if (argc <= 1)
109
  if (argc <= 1)
Lines 142-157 darwin_default_min_version (unsigned int *decoded_options_count, Link Here
142
140
143
#ifndef CROSS_DIRECTORY_STRUCTURE
141
#ifndef CROSS_DIRECTORY_STRUCTURE
144
142
145
 /* Try to find the version from the kernel, if we fail - we print a message 
143
  /* Try to find the version from the kernel, if we fail - we print a message
146
    and give up.  */
144
     and give up.  */
147
 if (!darwin_find_version_from_kernel (new_flag))
145
  new_flag = darwin_find_version_from_kernel ();
148
   return;
146
  if (!new_flag)
147
    return;
149
148
150
#else
149
#else
151
150
152
 /* For cross-compilers, default to the target OS version. */
151
  /* For cross-compilers, default to the target OS version. */
153
152
  new_flag = DEF_MIN_OSX_VERSION;
154
 strncpy (new_flag, DEF_MIN_OSX_VERSION, sizeof (new_flag));
155
153
156
#endif /* CROSS_DIRECTORY_STRUCTURE */
154
#endif /* CROSS_DIRECTORY_STRUCTURE */
157
155
Lines 165-171 darwin_default_min_version (unsigned int *decoded_options_count, Link Here
165
  memcpy (*decoded_options + 2, argv + 1,
163
  memcpy (*decoded_options + 2, argv + 1,
166
	  (argc - 1) * sizeof (struct cl_decoded_option));
164
	  (argc - 1) * sizeof (struct cl_decoded_option));
167
  return;
165
  return;
168
  
169
}
166
}
170
167
171
/* Translate -filelist and -framework options in *DECODED_OPTIONS
168
/* Translate -filelist and -framework options in *DECODED_OPTIONS
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-1.c (-1 / +2 lines)
Lines 2-8 Link Here
2
/* { dg-options "-mmacosx-version-min=10.1" } */
2
/* { dg-options "-mmacosx-version-min=10.1" } */
3
/* { dg-do run { target *-*-darwin* } } */
3
/* { dg-do run { target *-*-darwin* } } */
4
4
5
int main(void)
5
int
6
main ()
6
{
7
{
7
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1010
8
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1010
8
  fail me;
9
  fail me;
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-10.c (+16 lines)
Line 0 Link Here
1
/* PR 63810: Test that a version with a zero-padded minor number < 10
2
   and a zero-padded tiny number < 10 produces the correct
3
   four-character macro.  */
4
/* Added by Lawrence Velázquez <larryv@macports.org>.  */
5
6
/* { dg-options "-mmacosx-version-min=10.07.02" } */
7
/* { dg-do compile { target *-*-darwin* } } */
8
9
int
10
main ()
11
{
12
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1072
13
  fail me;
14
#endif
15
  return 0;
16
}
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-11.c (+15 lines)
Line 0 Link Here
1
/* PR 63810: Test that a version with outrageous zero-padding and
2
   a minor number > 9 still produces a six-character macro.  */
3
/* Added by Lawrence Velázquez <larryv@macports.org>.  */
4
5
/* { dg-options "-mmacosx-version-min=00010.010.0000098" } */
6
/* { dg-do compile { target *-*-darwin* } } */
7
8
int
9
main ()
10
{
11
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 101098
12
  fail me;
13
#endif
14
  return 0;
15
}
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-12.c (+15 lines)
Line 0 Link Here
1
/* PR 63810: Test that a version with outrageous zero-padding and
2
   a minor number < 10 still produces a four-character macro.  */
3
/* Added by Lawrence Velázquez <larryv@macports.org>.  */
4
5
/* { dg-options "-mmacosx-version-min=010.008.000031" } */
6
/* { dg-do compile { target *-*-darwin* } } */
7
8
int
9
main ()
10
{
11
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1089
12
  fail me;
13
#endif
14
  return 0;
15
}
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-2.c (-1 / +2 lines)
Lines 2-8 Link Here
2
/* { dg-options "-mmacosx-version-min=10.1 -mmacosx-version-min=10.3" } */
2
/* { dg-options "-mmacosx-version-min=10.1 -mmacosx-version-min=10.3" } */
3
/* { dg-do run { target *-*-darwin* } } */
3
/* { dg-do run { target *-*-darwin* } } */
4
4
5
int main(void)
5
int
6
main ()
6
{
7
{
7
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1030
8
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1030
8
  fail me;
9
  fail me;
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-3.c (-4 / +5 lines)
Lines 1-10 Link Here
1
/* Test that most-minor versions greater than 9 work.  */
1
/* Test that most minor versions < 10 work.  */
2
/* { dg-options "-mmacosx-version-min=10.4.10" } */
2
/* { dg-options "-mmacosx-version-min=10.4.1" } */
3
/* { dg-do compile { target *-*-darwin* } } */
3
/* { dg-do compile { target *-*-darwin* } } */
4
4
5
int main(void)
5
int
6
main ()
6
{
7
{
7
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1040
8
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1041
8
  fail me;
9
  fail me;
9
#endif
10
#endif
10
  return 0;
11
  return 0;
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-4.c (+12 lines)
Line 0 Link Here
1
/* Test that minor versions > 9 produce a 6-digit macro.  */
2
/* { dg-options "-mmacosx-version-min=10.10.1" } */
3
/* { dg-do compile { target *-*-darwin* } } */
4
5
int
6
main ()
7
{
8
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 101001
9
  fail me;
10
#endif
11
  return 0;
12
}
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-5.c (+15 lines)
Line 0 Link Here
1
/* PR 63810: Test that a version with minor number < 10 and tiny number > 9
2
   produces a four-character macro with the tiny number clamped to 9.  */
3
/* Added by Lawrence Velázquez <larryv@macports.org>.  */
4
5
/* { dg-options "-mmacosx-version-min=10.9.10" } */
6
/* { dg-do compile { target *-*-darwin* } } */
7
8
int
9
main ()
10
{
11
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1099
12
  fail me;
13
#endif
14
  return 0;
15
}
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-6.c (+14 lines)
Line 0 Link Here
1
/* PR 63810: Test that tiny numbers are preserved in six-character macros.  */
2
/* Added by Lawrence Velázquez <larryv@macports.org>.  */
3
4
/* { dg-options "-mmacosx-version-min=10.10.11" } */
5
/* { dg-do compile { target *-*-darwin* } } */
6
7
int
8
main ()
9
{
10
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 101011
11
  fail me;
12
#endif
13
  return 0;
14
}
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-7.c (+15 lines)
Line 0 Link Here
1
/* PR 63810: Test that tiny numbers < 10 are preserved in four-character
2
   macros.  */
3
/* Added by Lawrence Velázquez <larryv@macports.org>.  */
4
5
/* { dg-options "-mmacosx-version-min=10.9.1" } */
6
/* { dg-do compile { target *-*-darwin* } } */
7
8
int
9
main ()
10
{
11
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1091
12
  fail me;
13
#endif
14
  return 0;
15
}
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-8.c (+16 lines)
Line 0 Link Here
1
/* PR 63810: Test that a version with minor number > 9 and no tiny
2
   number produces a six-character macro with "00" as the last two
3
   characters.  */
4
/* Added by Lawrence Velázquez <larryv@macports.org>.  */
5
6
/* { dg-options "-mmacosx-version-min=10.11" } */
7
/* { dg-do compile { target *-*-darwin* } } */
8
9
int
10
main ()
11
{
12
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 101100
13
  fail me;
14
#endif
15
  return 0;
16
}
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-9.c (+15 lines)
Line 0 Link Here
1
/* PR 63810: Test that a version with a zero-padded minor number < 10
2
   produces a four-character macro.  */
3
/* Added by Lawrence Velázquez <larryv@macports.org>.  */
4
5
/* { dg-options "-mmacosx-version-min=10.08.4" } */
6
/* { dg-do compile { target *-*-darwin* } } */
7
8
int
9
main ()
10
{
11
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1084
12
  fail me;
13
#endif
14
  return 0;
15
}

Return to bug 63810