http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45233

--- Comment #5 from Iain Sandoe <iains at gcc dot gnu.org> 2011-11-07 08:24:54 
UTC ---
(In reply to comment #4)
> (In reply to comment #3)

FWIW gcc-4.2.1 (Apple local) fails and clang passes the test (although clang's
asm at version 2.9 is a bit long-winded c.f. GCC's ... but that's quite an old
version).

> > or not properly restoring the UNSPEC during reload (it's its duty, not 
> > IRAs).
> 
> I'll check this too.

Thanks Richi, this seems to be the problem - it appears that the reload
legitimizer does not consider that the item might be 'undefined' (in the
mach-o, local-to-the-file sense) - and, therefore, there was no mechanism to
recreate the necessary indirection.

so, this is a fix - which bootstraps and regtests:

I'd very much like an opinion as to whether it's the _right_ fix ... this is an
area with which I am not familiar and therefore could have missed some other
guard that's needed.

It's clearly a very infrequent (perhaps even non-existent) occurrence outside
the particular asm test-case (which makes me wonder still if combine came to
the right decision to remove the refs in the first place).

Index: gcc/config/rs6000/rs6000.c
===================================================================
--- gcc/config/rs6000/rs6000.c  (revision 181027)
+++ gcc/config/rs6000/rs6000.c  (working copy)
@@ -6185,7 +6185,21 @@ rs6000_legitimize_reload_address (rtx x, enum mach
 #if TARGET_MACHO
       if (flag_pic)
        {
-         rtx offset = machopic_gen_offset (x);
+         rtx offset;
+
+         /* Reload might present us with a case where there is a reference to
+            an undefined entity.  */
+         if (!machopic_symbol_defined_p (x) && !MACHO_DYNAMIC_NO_PIC_P)
+           {
+             offset = gen_rtx_SYMBOL_REF (Pmode, 
+                                          machopic_indirection_name (x, 
+                                                                     false));
+             SYMBOL_REF_DATA (offset) = SYMBOL_REF_DATA (x);
+             machopic_define_symbol (gen_const_mem (Pmode,offset));
+             x = offset;
+           }
+
+         offset = machopic_gen_offset (x);
          x = gen_rtx_LO_SUM (GET_MODE (x),
                gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
                  gen_rtx_HIGH (Pmode, offset)), offset);

Reply via email to