]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Darwin: Handle the fPIE option specially.
authorIain Sandoe <iain@sandoe.co.uk>
Wed, 25 Oct 2023 14:28:52 +0000 (15:28 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Mon, 1 Apr 2024 13:31:44 +0000 (14:31 +0100)
For Darwin, PIE requires PIC codegen, but otherwise is only a link-time
change. For almost all Darwin, we do not report __PIE__; the exception is
32bit X86 and from Darwin12 to 17 only (32 bit is no longer supported
after Darwin17).

gcc/ChangeLog:

* config/darwin.cc (darwin_override_options): Handle fPIE.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit da9e72f80f3358bd9586e11aaf03341c1f867318)

gcc/config/darwin.cc

index 3f7fb4d9a6a03b7388f7f182cfdfe8e007d07c44..b4a7c4226c4bf455aa0b03793b975e75c7c06b37 100644 (file)
@@ -3286,6 +3286,8 @@ darwin_override_options (void)
     {
       if (strverscmp (darwin_macosx_version_min, "10.14") >= 0)
        generating_for_darwin_version = 18;
+      else if (strverscmp (darwin_macosx_version_min, "10.8") >= 0)
+       generating_for_darwin_version = 12;
       else if (strverscmp (darwin_macosx_version_min, "10.7") >= 0)
        generating_for_darwin_version = 11;
       else if (strverscmp (darwin_macosx_version_min, "10.6") >= 0)
@@ -3444,8 +3446,17 @@ darwin_override_options (void)
       && dwarf_debuginfo_p ())
     flag_var_tracking_uninit = flag_var_tracking;
 
-  /* Final check on PCI options; for Darwin these are not dependent on the PIE
-     ones, although PIE does require PIC to support it.  */
+  if (OPTION_SET_P (flag_pie) && flag_pie)
+    {
+      /* This is a little complicated, to match Xcode tools.
+        For Darwin, PIE requires PIC codegen, but otherwise is only a link-
+        time change.  For almost all Darwin, we do not report __PIE__; the
+        exception is Darwin12-17 and for 32b only.  */
+      flag_pie = generating_for_darwin_version >= 12 && !TARGET_64BIT ? 2 : 0;
+      flag_pic = 2; /* We always set this.  */
+    }
+
+  /* Final check on PIC options.  */
   if (MACHO_DYNAMIC_NO_PIC_P)
     {
       if (flag_pic)