]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Darwin] Use of symbol stubs should depend on the linker in use.
authorIain Sandoe <iain@sandoe.co.uk>
Wed, 30 Oct 2019 19:56:41 +0000 (19:56 +0000)
committerIain Sandoe <iains@gcc.gnu.org>
Wed, 30 Oct 2019 19:56:41 +0000 (19:56 +0000)
This is a combination of two patches that prevents a bootstrap fail when
a modern assembler/linker pair are used that don't support the JBSR reloc
(but don't require it for long calls).

272356 The need for picsym stubs is dependent on linker used, not OS rev.

For very old toolchains, the compiler generated pic symbol stubs that
provide the necessary indirections. We no longer need this (since xcode
3 era) and it's more efficient for the linker to make one stub when it
knows a symbol is needed that for us to emit them speculatively in every
object.

Our current codegen is making the assumption that a specific OS version
uses a specific linker version - and therefore the presence of support
could be based on the target OS rev. Of course, that's way too simplistic
(most likely bogus for cross-toolchains) and we want to make things explict.

Since we have detection of the linker version, we can use that directly
(A config test for support for stub-less linking might also be feasible
but much more involved).

Finally, should the user wish to generate code that caters for export to
use in an environment with an older toolchain, the generation of stubs
can be forced from the command line.

In addition to the points above, branch islanding and a long branch opt
for PowerPC Darwin has become conflated with the emission of these stubs
(which is confusing, and will be rectified in a following patch).

274397 There is no need to distinguish PIC/non-PIC symbol stubs.

So we can use a single flag for both.

2019-10-30  Iain Sandoe  <iain@sandoe.co.uk>

Backport from mainline
2019-08-13 Iain Sandoe <iain@sandoe.co.uk>

* config/darwin.c (machopic_indirect_call_target): Rename symbol stub
flag.
(darwin_override_options): Likewise.
* config/darwin.h: Likewise.
* config/darwin.opt: Likewise.
* config/i386/i386.c (output_pic_addr_const): Likewise.
* config/rs6000/darwin.h: Likewise.
* config/rs6000/rs6000.c (rs6000_call_darwin_1): Likewise.
* config/i386/darwin.h (TARGET_MACHO_PICSYM_STUBS): Rename to ...
... this TARGET_MACHO_SYMBOL_STUBS.
(FUNCTION_PROFILER):Likewise.
* config/i386/i386.h: Likewise.

Backport from mainline
2019-06-16  Iain Sandoe  <iain@sandoe.co.uk>

* config/darwin.c (machopic_indirect_call_target): Use renamed
darwin_picsymbol_stubs to decide on output.
(darwin_override_options): Handle darwin_picsymbol_stubs.
* config/darwin.h (MIN_LD64_OMIT_STUBS): New.
(LD64_VERSION): Revise default.
* config/darwin.opt: (mpic-symbol-stubs): New option.
(darwin_picsymbol_stubs): New variable.
* config/i386/darwin.h (TARGET_MACHO_BRANCH_ISLANDS):
rename to TARGET_MACHO_PICSYM_STUBS.
* config/i386/i386.c (output_pic_addr_const): Likewise.
* config/i386/i386.h Likewise.
* config/rs6000/darwin.h: Likewise.
* config/rs6000/rs6000.c (rs6000_call_darwin_1): Use renamed
darwin_picsymbol_stubs.

From-SVN: r277638

14 files changed:
gcc/ChangeLog
gcc/config/darwin.c
gcc/config/darwin.h
gcc/config/darwin.opt
gcc/config/i386/darwin.h
gcc/config/i386/i386.c
gcc/config/i386/i386.h
gcc/config/rs6000/darwin.h
gcc/config/rs6000/rs6000.c
gcc/testsuite/ChangeLog
gcc/testsuite/obj-c++.dg/stubify-1.mm
gcc/testsuite/obj-c++.dg/stubify-2.mm
gcc/testsuite/objc.dg/stubify-1.m
gcc/testsuite/objc.dg/stubify-2.m

index 8cd677e55f7d34cc533733d96babd681568c907b..648034e2dc126b9ad6b133cd9e4a5b88d99f4a68 100644 (file)
@@ -1,3 +1,39 @@
+2019-10-30  Iain Sandoe  <iain@sandoe.co.uk>
+
+       Backport from mainline
+       2019-08-13 Iain Sandoe <iain@sandoe.co.uk>
+
+       * config/darwin.c (machopic_indirect_call_target): Rename symbol stub
+       flag.
+       (darwin_override_options): Likewise.
+       * config/darwin.h: Likewise.
+       * config/darwin.opt: Likewise.
+       * config/i386/i386.c (output_pic_addr_const): Likewise.
+       * config/rs6000/darwin.h: Likewise.
+       * config/rs6000/rs6000.c (rs6000_call_darwin_1): Likewise.
+       * config/i386/darwin.h (TARGET_MACHO_PICSYM_STUBS): Rename to ...
+       ... this TARGET_MACHO_SYMBOL_STUBS.
+       (FUNCTION_PROFILER):Likewise.
+       * config/i386/i386.h: Likewise.
+
+       Backport from mainline
+       2019-06-16  Iain Sandoe  <iain@sandoe.co.uk>
+
+       * config/darwin.c (machopic_indirect_call_target): Use renamed
+       darwin_picsymbol_stubs to decide on output.
+       (darwin_override_options): Handle darwin_picsymbol_stubs.
+       * config/darwin.h (MIN_LD64_OMIT_STUBS): New.
+       (LD64_VERSION): Revise default.
+       * config/darwin.opt: (mpic-symbol-stubs): New option.
+       (darwin_picsymbol_stubs): New variable.
+       * config/i386/darwin.h (TARGET_MACHO_BRANCH_ISLANDS):
+       rename to TARGET_MACHO_PICSYM_STUBS.
+       * config/i386/i386.c (output_pic_addr_const): Likewise.
+       * config/i386/i386.h Likewise.
+       * config/rs6000/darwin.h: Likewise.
+       * config/rs6000/rs6000.c (rs6000_call_darwin_1): Use renamed
+       darwin_picsymbol_stubs.
+
 2019-10-30  Dragan Mladjenovic  <dmladjenovic@wavecomp.com>
 
        Backport from mainline
index 0d21d86b98a4e6ac9c5ec4bccfd4b62af340d676..597f3c63440364eeac0a17dcf210501893f13b78 100644 (file)
@@ -78,12 +78,6 @@ along with GCC; see the file COPYING3.  If not see
    of MACHO_SYMBOL_FLAG_STATIC for the code that handles @code{static}
    symbol indirection.  */
 
-/* For darwin >= 9  (OSX 10.5) the linker is capable of making the necessary
-   branch islands and we no longer need to emit darwin stubs.
-   However, if we are generating code for earlier systems (or for use in the 
-   kernel) the stubs might still be required, and this will be set true.  */
-int darwin_emit_branch_islands = false;
-
 typedef struct GTY(()) cdtor_record {
   rtx symbol;
   int priority;                /* [con/de]structor priority */
@@ -810,7 +804,7 @@ machopic_indirect_data_reference (rtx orig, rtx reg)
 rtx
 machopic_indirect_call_target (rtx target)
 {
-  if (! darwin_emit_branch_islands)
+  if (! darwin_symbol_stubs)
     return target;
 
   if (GET_CODE (target) != MEM)
@@ -3345,11 +3339,31 @@ darwin_override_options (void)
       flag_pic = 2;
     }
 
-  /* It is assumed that branch island stubs are needed for earlier systems.  */
-  if (generating_for_darwin_version < 9)
-    darwin_emit_branch_islands = true;
-  else
-    emit_aligned_common = true; /* Later systems can support aligned common.  */
+  /* Linkers >= ld64-62.1 (at least) are capable of making the necessary PIC
+     indirections and we no longer need to emit pic symbol stubs.
+     However, if we are generating code for earlier ones (or for use in the
+     kernel) the stubs might still be required, and this will be set true.
+     If the user sets it on or off - then that takes precedence. */
+
+  if (!global_options_set.x_darwin_symbol_stubs)
+    {
+      if (darwin_target_linker) {
+       if (strverscmp (darwin_target_linker, MIN_LD64_OMIT_STUBS) < 0)
+         darwin_symbol_stubs = true;
+      } else if (generating_for_darwin_version < 9)
+       /* We know no better than to assume the use of an earlier linker.  */
+       darwin_symbol_stubs = true;
+    }
+  else if (DARWIN_X86 && darwin_symbol_stubs && TARGET_64BIT)
+    {
+      inform (input_location,
+             "%<-mpic-symbol-stubs%> is not required for 64b code (ignored)");
+      darwin_symbol_stubs = false;
+    }
+
+  if (generating_for_darwin_version >= 9)
+    /* Later systems can support aligned common.  */
+    emit_aligned_common = true;
 
   /* The c_dialect...() macros are not available to us here.  */
   darwin_running_cxx = (strstr (lang_hooks.name, "C++") != 0);
index 4f1268494b163557f8729617f9d59c2cced2635b..a8046d000e3ea2d8dd928f8a71c410c544115222 100644 (file)
@@ -1023,8 +1023,12 @@ extern void darwin_driver_init (unsigned int *,struct cl_decoded_option **);
    _tested_ version known to support this so far.  */
 #define MIN_LD64_NO_COAL_SECTS "236.4"
 
+/* From at least version 62.1, ld64 can build symbol indirection stubs as
+   needed, and there is no need for the compiler to emit them.  */
+#define MIN_LD64_OMIT_STUBS "85.2"
+
 #ifndef LD64_VERSION
-#define LD64_VERSION "85.2"
+#define LD64_VERSION "62.1"
 #else
 #define DEF_LD64 LD64_VERSION
 #endif
index 3f04375e6330a60e55a2610ac05f9e3bd33123ae..7f5616cbe078fe59d2daf08f26179063b24c0245 100644 (file)
@@ -75,6 +75,10 @@ mone-byte-bool
 Target RejectNegative Report Var(darwin_one_byte_bool)
 Set sizeof(bool) to 1.
 
+msymbol-stubs
+Target Report Var(darwin_symbol_stubs) Init(0)
+Force generation of external symbol indirection stubs.
+
 ; Some code-gen may be improved / adjusted if the linker is sufficiently modern.
 mtarget-linker=
 Target RejectNegative Joined Report Alias(mtarget-linker)
index 3284af2fb204e4e02533ef3476e930496bca88a7..bdb36f0095961a44672b8b9e3305e9629bca24f9 100644 (file)
@@ -90,14 +90,12 @@ along with GCC; see the file COPYING3.  If not see
 #undef WCHAR_TYPE_SIZE
 #define WCHAR_TYPE_SIZE 32
 
-/* Generate branch islands stubs if this is true.  */
-extern int darwin_emit_branch_islands;
-
-#undef TARGET_MACHO_BRANCH_ISLANDS
-#define TARGET_MACHO_BRANCH_ISLANDS darwin_emit_branch_islands
+/* Generate pic symbol indirection stubs if this is true.  */
+#undef TARGET_MACHO_SYMBOL_STUBS
+#define TARGET_MACHO_SYMBOL_STUBS (darwin_symbol_stubs)
 
 /* For compatibility with OSX system tools, use the new style of pic stub
-   if this is set.  */
+   if this is set (default).  */
 #undef  MACHOPIC_ATT_STUB
 #define MACHOPIC_ATT_STUB (darwin_macho_att_stub)
 
@@ -245,7 +243,7 @@ extern int darwin_emit_branch_islands;
 #undef FUNCTION_PROFILER
 #define FUNCTION_PROFILER(FILE, LABELNO)                               \
   do {                                                                 \
-    if (TARGET_MACHO_BRANCH_ISLANDS                                    \
+    if (TARGET_MACHO_SYMBOL_STUBS                                      \
        && MACHOPIC_INDIRECT && !TARGET_64BIT)                          \
       {                                                                        \
        const char *name = machopic_mcount_stub_name ();                \
index 2b37296e537e10fb43035eac6c208fc72c7d901d..73a3ef364b34a6e3cbc442e959b89b1493ac1ce3 100644 (file)
@@ -16960,7 +16960,7 @@ output_pic_addr_const (FILE *file, rtx x, int code)
       break;
 
     case SYMBOL_REF:
-      if (TARGET_64BIT || ! TARGET_MACHO_BRANCH_ISLANDS)
+      if (TARGET_64BIT || ! TARGET_MACHO_SYMBOL_STUBS)
        output_addr_const (file, x);
       else
        {
index 2cb16d9fbf60691eeaa2188c191053074466d955..170bbdd7fbfbaaf1fcd86d154d9acf472c1e900a 100644 (file)
@@ -640,7 +640,7 @@ extern tree x86_mfence;
 /* Replace MACH-O, ifdefs by in-line tests, where possible. 
    (a) Macros defined in config/i386/darwin.h  */
 #define TARGET_MACHO 0
-#define TARGET_MACHO_BRANCH_ISLANDS 0
+#define TARGET_MACHO_SYMBOL_STUBS 0
 #define MACHOPIC_ATT_STUB 0
 /* (b) Macros defined in config/darwin.h  */
 #define MACHO_DYNAMIC_NO_PIC_P 0
index 9fab84fd82e189f133e543dd1634618cf6aba47e..523ddb6900f65eab5c0668e46975593bc9e05aa0 100644 (file)
@@ -75,9 +75,6 @@
     }                                                  \
   while (0)
 
-/* Generate branch islands stubs if this is true.  */
-extern int darwin_emit_branch_islands;
-
 #define SUBTARGET_OVERRIDE_OPTIONS darwin_rs6000_override_options ()
 
 #define C_COMMON_OVERRIDE_OPTIONS do {                                 \
index 6523dd2dabc90faffbd231e0f17d298437104a3b..2a8932d80aaaba172d0bc98b8453c59654d800cc 100644 (file)
@@ -21434,7 +21434,7 @@ print_operand (FILE *file, rtx x, int code)
        {
          const char *name = XSTR (x, 0);
 #if TARGET_MACHO
-         if (darwin_emit_branch_islands
+         if (darwin_symbol_stubs
              && MACHOPIC_INDIRECT
              && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
            name = machopic_indirection_name (x, /*stub_p=*/true);
@@ -38383,7 +38383,8 @@ rs6000_call_darwin_1 (rtx value, rtx func_desc, rtx tlsarg,
   if ((cookie_val & CALL_LONG) != 0
       && GET_CODE (func_desc) == SYMBOL_REF)
     {
-      if (darwin_emit_branch_islands && TARGET_32BIT)
+      /* FIXME: the longcall opt should not hang off picsymbol stubs.  */
+      if (darwin_symbol_stubs && TARGET_32BIT)
        make_island = true; /* Do nothing yet, retain the CALL_LONG flag.  */
       else
        {
index 19272a43775ea26d69a1b8b2a21856f23b1b1af6..ab5a39fccc3b652bc797642fdab823e5cb880385 100644 (file)
@@ -1,3 +1,13 @@
+2019-10-30  Iain Sandoe  <iain@sandoe.co.uk>
+
+       Backport from mainline.
+       2019-08-13  Iain Sandoe  <iain@sandoe.co.uk>
+
+       * obj-c++.dg/stubify-1.mm: Rename symbol stub option.
+       * obj-c++.dg/stubify-2.mm: Likewise.
+       * objc.dg/stubify-1.m: Likewise.
+       * objc.dg/stubify-2.m: Likewise.
+
 2019-10-30  Dragan Mladjenovic  <dmladjenovic@wavecomp.com>
 
        Backport from mainline
index c2355437afc8051bdd472f34e689d6e3904f5b00..46ce3fb815856c10ea515d5d43abda02745abf60 100644 (file)
@@ -4,7 +4,7 @@
 /* { dg-do compile { target *-*-darwin* } } */
 /* { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } */
 /* { dg-require-effective-target ilp32 } */
-/* { dg-options "-Os -mdynamic-no-pic -fno-exceptions -mmacosx-version-min=10.4" } */
+/* { dg-options "-Os -mdynamic-no-pic -fno-exceptions -mmacosx-version-min=10.4 -msymbol-stubs" } */
 
 typedef struct objc_object { } *id ;
 int x = 41 ;
index a9f66cac5d26b72d4223edf05c7adab08b183d44..dd88974e2594427e2d3288beb0598c024f45429b 100644 (file)
@@ -4,7 +4,7 @@
 /* { dg-do compile { target *-*-darwin* } } */
 /* { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } */
 /* { dg-require-effective-target ilp32 } */
-/* { dg-options "-mdynamic-no-pic -fdump-rtl-jump -mmacosx-version-min=10.4" } */
+/* { dg-options "-mdynamic-no-pic -fdump-rtl-jump -mmacosx-version-min=10.4 -msymbol-stubs" } */
 
 typedef struct objc_object { } *id ;
 int x = 41 ;
index 91bf73a14f7afe24adac55b734eb2501acaaf1f9..97d5b598380e371152f7e240acc3c1cfe6b26b10 100644 (file)
@@ -4,7 +4,7 @@
 /* { dg-do compile { target *-*-darwin* } } */
 /* { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } */
 /* { dg-require-effective-target ilp32 } */
-/* { dg-options "-Os -mdynamic-no-pic -mmacosx-version-min=10.4" } */
+/* { dg-options "-Os -mdynamic-no-pic -mmacosx-version-min=10.4 -msymbol-stubs" } */
 
 typedef struct objc_object { } *id ;
 int x = 41 ;
index eaf4b964e4b313967a46321d3138fe2205ce75f5..a07992a5a9e4c64b5c44a4e6e7940bcd5c65fca3 100644 (file)
@@ -4,7 +4,7 @@
 /* { dg-do compile { target powerpc*-*-darwin* } } */
 /* { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } */
 /* { dg-require-effective-target ilp32 } */
-/* { dg-options "-mdynamic-no-pic -fdump-rtl-jump -mmacosx-version-min=10.4" } */
+/* { dg-options "-mdynamic-no-pic -fdump-rtl-jump -mmacosx-version-min=10.4 -msymbol-stubs" } */
 
 typedef struct objc_object { } *id ;
 int x = 41 ;