gcc-patches@gcc.gnu.org
[Top] [All Lists]

Re: fixes for Darwin/x86, take 2

Subject: Re: fixes for Darwin/x86, take 2
From: Stuart Hastings
Date: Mon, 12 Dec 2005 16:31:26 -0800
On Nov 30, 2005, at 5:35 PM, Richard Henderson wrote:


On Wed, Nov 30, 2005 at 02:37:34PM -0800, Stuart Hastings wrote:

AFAICT, Darwin/x86 must be the only GCC port where the default stack
alignment can be /lowered/ from the commandline ("-mpreferred-stack-
boundary=2").  Darwin requires a 16-byte (SSE) stack alignment, yet
the Darwin/x86 GCC is obliged to support a few projects
(cough*kernel*cough) that require 4-byte alignment.  It's trivial to
make the STACK_BOUNDARY macro expand to a variable, but that won't
bootstrap, as the middle-end uses STACK_BOUNDARY in signed and
unsigned comparisons.


How is this different in practice from Linux?  Yes, you're touching
STACK_BOUNDARY, but I wanna know why.  As far as I know, you needn't
be touching *anything* to get your 16-byte stack alignment.


Hm. You're right. This was necessary to get a consistent 16-byte alignment for Darwin/x86 when it was done (three-plus years ago?), and it hasn't been examined since. I'll try it your way.

You were right; no STACK_BOUNDARY hackery was necessary. This patch is entirely confined to config/* and config/i386/*.

-  emit_insn (gen_set_got (pic_offset_table_rtx));
+  if (TARGET_MACHO)
+    {
+      rtx picreg = gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM);
+      rtx tmplabrtx;
+      char tmplab[20];
+
+      ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
+                                 CODE_LABEL_NUMBER (operands[0]));
+      tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
+
+      emit_insn (gen_load_macho_picbase_si (picreg));
+    }
+  else
+    emit_insn (gen_set_got (pic_offset_table_rtx));


Any reason this isn't going into output_set_got, wherein we
already have macho hackery?


Trying to avoid re-inventing the wheel, copying from GeoffKs version in Darwin/PPC. I'd be happy to move everything to output_set_got; discussion below.

Actually, a combination of builtin_setjmp_receiver and output_set_got. Done; more discussion below.

[snip]

-  if (USE_HIDDEN_LINKONCE)
+  if (USE_HIDDEN_LINKONCE || TARGET_MACHO)


Adjust the definition of USE_HIDDEN_LINKONCE instead.  I'm surprised
it isn't automatically happening...

USE_HIDDEN_LINKONCE is forced on, as requested, but the support in ix86_file_end() is ... unsubtle.

On Dec 1, 2005, at 4:18 PM, Richard Henderson wrote:

O.K., but the Darwin assembler doesn't like the ".hidden" stuff
generated in ix86_file_end().  I'll need to hack up ix86_file_end()
to say  "if (USE_HIDDEN_LINKONCE && !TARGET_MACHO)".  :-P

So, how does the hidden support work in MACHO? I know you've got it...

Well, Darwin has "private_extern"; AFAICT, it means, roughly, "this symbol disappears on the first pass through the linker." See ix86_file_end().

+#if TARGET_MACHO
+  if (1)
+    {
+ /* If this isn't the 'first_time', recompute the original Mach-O pic-base. */
+      if (!first_time)
+ output_asm_insn ("lea{l}\t{%P1-%P2(%0), %0|%0, %P1-%P2(%0)}", xops);
+    }
+  else
+#endif


What are you doing?  This looks suspiciously like a gross hack.

It /is/ a gross hack. (And if you're offended by this, there are a few functions in config/darwin.c that you should avoid looking at. :-)

[snip]

I don't care where this stuff goes, but it has to go somewhere; it's
needed to fix a bunch of DejaGnu failures.  Would you prefer

A) pushing the LEA cruft into the builtin_setjmp_receiver pattern, or

This sounds best to me.

O.K., I've moved the LEA into builtin_setjmp_receiver. However, it turned into a SUB because i386.c(darwin_local_data_pic) assumes that SYMBOL_REFs only occur on the right. :-P AFAICT, modern x86s won't care (I /assume/ that ADD, LEA, and SUB run equally fast), but I'm willing to revise this if others prefer.

Since Darwin has a different GOT for every function, and we must define it only once per function, I've added a label parameter to output_set_got(). This allows us to control when it gets generated (e.g. not duplicate it when outputting a builtin_setjmp_receiver). This avoids adding ugly state information into output_set_got(). Better ideas are welcome.

With these changes, C and ObjC improve on Darwin/x86, passing an additional 685 and 164 tests respectively. Darwin/x86 is still failing 170 C tests, so we're not done.

Bootstrapped, no regressions, on Darwin/x86 and Linux/x86.

2005-12-12  Stuart Hastings  <stuart@xxxxxxxxx>

        * config/darwin.c (machopic_legitimize_pic_address): Set
        regs_ever_live[].
        * config/i386/i386.c (ix86_preferred_stack_boundary): Always
        128bits for Darwin/x86. (USE_HIDDEN_LINKONCE): On for
        Darwin/x86. (ix86_file_end): Add Mach-O support.
        (darwin_x86_file_end): New.
        (output_set_got): Add label parmeter.
        (x86_output_mi_thunk): Ditto.
        * config/i386/i386-protos.h (output_set_got): Ditto.
        * config/i386/i386.md (set_got): Ditto.
        (UNSPEC_LD_MPIC, set_got_labelled): New.
        (builtin_setjmp_receiver): Mach-O support.
        * config/i386/darwin.h (SUBTARGET_OVERRIDE_OPTIONS): Define.
        (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN): Disable.
        (darwin_x86_file_end, TARGET_ASM_FILE_END): New.
        (TARGET_DEEP_BRANCH_PREDICTION): Remove.
        (GOT_SYMBOL_NAME): Define for Darwin/x86.

Attachment: gcc.fsf.bugs2.diffs.txt
Description: Text document


O.K. to commit?

stuart hastings
Apple Computer
<Prev in Thread] Current Thread [Next in Thread>