Patchwork [darwin] do not generate branch islands when the linker can do it.

login
register
mail settings
Submitter IainS
Date July 15, 2010, 6:27 p.m.
Message ID <8987CD7A-53F6-45B1-9A88-E27107B1AAFB@sandoe-acoustics.co.uk>
Download mbox | patch
Permalink /patch/59003/
State New
Headers show

Comments

IainS - July 15, 2010, 6:27 p.m.
On 15 Jul 2010, at 18:38, Richard Henderson wrote:

> On 07/15/2010 10:10 AM, IainS wrote:
>> -      if (! TARGET_MACHO || TARGET_64BIT)
>> +      if (! TARGET_MACHO ||
>> +#if TARGET_MACHO
>> +          ! darwin_emit_branch_islands ||
>> +#endif
>> +      TARGET_64BIT)
>
> I'd really like to avoid the #if mid if.  Perhaps
>
>  if (TARGET_64BIT || !TARGET_MACHO_BRANCH_ISLANDS)
>
> with
>
> #if TARGET_MACHO
> #define TARGET_MACHO_BRANCH_ISLANDS  darwin_emit_branch_islands
> #else
> #define TARGET_MACHO_BRANCH_ISLANDS  0
> #endif
>
> or similar via #undef

(I almost did that anyway .. not quite sure why I didn't now.. )

Iain

----

amendment (changes since first patch only);


@@ -11510,7 +11514,7 @@ output_pic_addr_const (FILE *file, rtx x, int  
code
        break;

      case SYMBOL_REF:
-      if (! TARGET_MACHO || TARGET_64BIT)
+      if (! TARGET_MACHO || ! TARGET_MACHO_BRANCH_ISLANDS ||  
TARGET_64BIT)
  	output_addr_const (file, x);
        else
  	{
@@ -27230,10 +27234,11 @@ x86_output_mi_thunk (FILE *file,
  	if (TARGET_MACHO)
  	  {
  	    rtx sym_ref = XEXP (DECL_RTL (function), 0);
-	    tmp = (gen_rtx_SYMBOL_REF
+	    if (TARGET_MACHO_BRANCH_ISLANDS)
+	      sym_ref = (gen_rtx_SYMBOL_REF
  		   (Pmode,
  		    machopic_indirection_name (sym_ref, /*stub_p=*/true)));
-	    tmp = gen_rtx_MEM (QImode, tmp);
+	    tmp = gen_rtx_MEM (QImode, sym_ref);
  	    xops[0] = tmp;
  	    output_asm_insn ("jmp\t%0", xops);
  	  }
Richard Henderson - July 15, 2010, 6:44 p.m.
On 07/15/2010 11:27 AM, IainS wrote:
> +#ifndef TARGET_MACHO_BRANCH_ISLANDS
> +#  define TARGET_MACHO_BRANCH_ISLANDS 0
> +#endif

This could go next to the TARGET_MACHO definition in i386.h, for consistency.

From a i386 maintainer perspective, I think this is ok.  I'll defer
for ppc and darwin knowledge.


r~
IainS - July 15, 2010, 7:34 p.m.
On 15 Jul 2010, at 19:44, Richard Henderson wrote:

> On 07/15/2010 11:27 AM, IainS wrote:
>> +#ifndef TARGET_MACHO_BRANCH_ISLANDS
>> +#  define TARGET_MACHO_BRANCH_ISLANDS 0
>> +#endif
>
> This could go next to the TARGET_MACHO definition in i386.h, for  
> consistency.
>
> From a i386 maintainer perspective, I think this is ok.  I'll defer
> for ppc and darwin knowledge.

FWIW: At your suggestion,
since then I've built powerpc-unknown-linux-gnu (crossed from i6868- 
darwin9) and proved it can compile a trivial source file.

(of course, the patch was already tested on powerpc-apple-darwin9  as  
well)

Iain

Patch

Index: gcc/config/i386/darwin.h
===================================================================
--- gcc/config/i386/darwin.h	(revision 162209)
+++ gcc/config/i386/darwin.h	(working copy)
@@ -60,6 +60,9 @@  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 MAX_BITS_PER_WORD
  #define MAX_BITS_PER_WORD 64

@@ -225,7 +228,7 @@  along with GCC; see the file COPYING3.  If not see
  #undef FUNCTION_PROFILER
  #define FUNCTION_PROFILER(FILE, LABELNO)				\
      do {								\
-      if (MACHOPIC_INDIRECT && !TARGET_64BIT)				\
+      if (darwin_emit_branch_islands && MACHOPIC_INDIRECT && ! 
TARGET_64BIT)		\
  	{								\
  	  const char *name = machopic_mcount_stub_name ();		\
  	  fprintf (FILE, "\tcall %s\n", name+1);  /*  skip '&'  */	\
@@ -300,3 +303,7 @@  along with GCC; see the file COPYING3.  If not see
  #define MACHO_SYMBOL_FLAG_VARIABLE ((SYMBOL_FLAG_MACH_DEP) << 3)

  #define SUBTARGET32_DEFAULT_CPU "i686"
+
+#undef TARGET_MACHO_BRANCH_ISLANDS
+#define TARGET_MACHO_BRANCH_ISLANDS darwin_emit_branch_islands
+
Index: gcc/config/i386/i386.c
===================================================================
--- gcc/config/i386/i386.c	(revision 162209)
+++ gcc/config/i386/i386.c	(working copy)
@@ -2206,6 +2206,10 @@  static const char *const  
cpu_names[TARGET_CPU_DEFA
    "amdfam10",
    "bdver1"
  };
+
+#ifndef TARGET_MACHO_BRANCH_ISLANDS
+#  define TARGET_MACHO_BRANCH_ISLANDS 0
+#endif
  
  /* Implement TARGET_HANDLE_OPTION.  */