Hi,

The attached patch allows SH target to use local and global dynamic
tls models without -fpic/-fpie.  Tested on sh4-unknown-linux-gnu
with no new failures.  Applied on trunk.

Regards,
        kaz
--
2011-06-08  Kaz Kojima  <kkoj...@gcc.gnu.org>

        * config/sh/sh.c (prepare_move_operands): Set pic register
        appropriately for global and local dynamic tls models even
        if flag_pic is unset.

--- ORIG/trunk/gcc/config/sh/sh.c       2011-06-02 09:41:16.000000000 +0900
+++ trunk/gcc/config/sh/sh.c    2011-06-07 22:32:02.000000000 +0900
@@ -1844,12 +1844,30 @@ prepare_move_operands (rtx operands[], e
        {
          rtx tga_op1, tga_ret, tmp, tmp2;
 
+         if (! flag_pic
+             && (tls_kind == TLS_MODEL_GLOBAL_DYNAMIC
+                 || tls_kind == TLS_MODEL_LOCAL_DYNAMIC
+                 || tls_kind == TLS_MODEL_INITIAL_EXEC))
+           {
+             /* Don't schedule insns for getting GOT address when
+                the first scheduling is enabled, to avoid spill
+                failures for R0.  */
+             if (flag_schedule_insns)
+               emit_insn (gen_blockage ());
+             emit_insn (gen_GOTaddr2picreg ());
+             emit_use (gen_rtx_REG (SImode, PIC_REG));
+             if (flag_schedule_insns)
+               emit_insn (gen_blockage ());
+       }
+
          switch (tls_kind)
            {
            case TLS_MODEL_GLOBAL_DYNAMIC:
              tga_ret = gen_rtx_REG (Pmode, R0_REG);
              emit_call_insn (gen_tls_global_dynamic (tga_ret, op1));
-             op1 = tga_ret;
+             tmp = gen_reg_rtx (Pmode);
+             emit_move_insn (tmp, tga_ret);
+             op1 = tmp;
              break;
 
            case TLS_MODEL_LOCAL_DYNAMIC:
@@ -1869,18 +1887,6 @@ prepare_move_operands (rtx operands[], e
              break;
 
            case TLS_MODEL_INITIAL_EXEC:
-             if (! flag_pic)
-               {
-                 /* Don't schedule insns for getting GOT address when
-                    the first scheduling is enabled, to avoid spill
-                    failures for R0.  */
-                 if (flag_schedule_insns)
-                   emit_insn (gen_blockage ());
-                 emit_insn (gen_GOTaddr2picreg ());
-                 emit_use (gen_rtx_REG (SImode, PIC_REG));
-                 if (flag_schedule_insns)
-                   emit_insn (gen_blockage ());
-               }
              tga_op1 = !can_create_pseudo_p () ? op0 : gen_reg_rtx (Pmode);
              tmp = gen_sym2GOTTPOFF (op1);
              emit_insn (gen_tls_initial_exec (tga_op1, tmp));

Reply via email to