diff mbox

[i386,windows] : Fix for PR/56975

Message ID CAEwic4Z7tnYuOXEB1H=wDBtdQCxJ0UVZb4MSdAk8hMWJyuXm_g@mail.gmail.com
State New
Headers show

Commit Message

Kai Tietz May 8, 2013, 6:41 p.m. UTC
Hi,

initial patch for supporting x64 add some checks for MS_ABI.  That
caused for 32-bit cygwin to some regression due cygwin-32 uses
SYSV_ABI as default ABI.  So I introduce in this patch the define
TARGET_PECOFF to indicate if targets use pe-coff or ELF-object/image
sematics.
This approach has also the advantage that ELF/PE-COFF specific code is
just used for these targets.

ChangeLog

2013-05-08  Kai Tietz  <ktietz@redhat.com>

    PR target/56975
    * config/i386/cygming.h (TARGET_PECOFF): Define as true.
    * config/i386/i386.h (TARGET_PECOFF): Define by default
    as false.
    (PIC_OFFSET_TABLE_REGNUM): Use TARGET_PECOFF.
    * config/i386/i386.c (ix86_option_override_internal):
    Likewise.
    (ix86_expand_prologue): Likewise.
    (ix86_expand_split_stack_prologue): Likewise.
    (legitimate_pic_address_disp_p): Likewise.
    (legitimize_pic_address): Likewise.
    (legitimize_tls_address): Likewise.
    (legitimize_pe_coff_symbol): Likewise.
    (output_pic_addr_const): Likewise.
    (construct_plt_address): Likewise.
    (ix86_expand_call): Likewise.
    (x86_output_mi_thunk): Likewise.
    (x86_function_profiler): Likewise.

Tested for x86_64-w64-mingw32, x86_64-pc-cygwin, i686-pc-cygwin, and
i686-w64-mingw32.  Ok for apply?

Regards,
Kai

Comments

Richard Henderson May 9, 2013, 3:43 p.m. UTC | #1
On 05/08/2013 11:41 AM, Kai Tietz wrote:
> 2013-05-08  Kai Tietz  <ktietz@redhat.com>
> 
>     PR target/56975
>     * config/i386/cygming.h (TARGET_PECOFF): Define as true.
>     * config/i386/i386.h (TARGET_PECOFF): Define by default
>     as false.
>     (PIC_OFFSET_TABLE_REGNUM): Use TARGET_PECOFF.
>     * config/i386/i386.c (ix86_option_override_internal):
>     Likewise.
>     (ix86_expand_prologue): Likewise.
>     (ix86_expand_split_stack_prologue): Likewise.
>     (legitimate_pic_address_disp_p): Likewise.
>     (legitimize_pic_address): Likewise.
>     (legitimize_tls_address): Likewise.
>     (legitimize_pe_coff_symbol): Likewise.
>     (output_pic_addr_const): Likewise.
>     (construct_plt_address): Likewise.
>     (ix86_expand_call): Likewise.
>     (x86_output_mi_thunk): Likewise.
>     (x86_function_profiler): Likewise.
> 
> Tested for x86_64-w64-mingw32, x86_64-pc-cygwin, i686-pc-cygwin, and
> i686-w64-mingw32.  Ok for apply?

Ok.


r~
diff mbox

Patch

Index: cygming.h
===================================================================
--- cygming.h    (Revision 198060)
+++ cygming.h    (Arbeitskopie)
@@ -55,6 +55,9 @@  along with GCC; see the file COPYING3.  If not see
 #undef DEFAULT_ABI
 #define DEFAULT_ABI (TARGET_64BIT ? MS_ABI : SYSV_ABI)

+#undef TARGET_PECOFF
+#define TARGET_PECOFF 1
+
 #if ! defined (USE_MINGW64_LEADING_UNDERSCORES)
 #undef USER_LABEL_PREFIX
 #define USER_LABEL_PREFIX (TARGET_64BIT ? "" : "_")
Index: i386.c
===================================================================
--- i386.c    (Revision 198060)
+++ i386.c    (Arbeitskopie)
@@ -3235,7 +3235,7 @@  ix86_option_override_internal (bool main_args_p)
      use of rip-relative addressing.  This eliminates fixups that
      would otherwise be needed if this object is to be placed in a
      DLL, and is essentially just as efficient as direct addressing.  */
-      if (TARGET_64BIT && (TARGET_RDOS || DEFAULT_ABI == MS_ABI))
+      if (TARGET_64BIT && (TARGET_RDOS || TARGET_PECOFF))
     ix86_cmodel = CM_MEDIUM_PIC, flag_pic = 1;
       else if (TARGET_64BIT)
     ix86_cmodel = flag_pic ? CM_SMALL_PIC : CM_SMALL;
@@ -10581,7 +10595,7 @@  ix86_expand_prologue (void)
   pic_reg_used = false;
   /* We don't use pic-register for pe-coff target.  */
   if (pic_offset_table_rtx
-      && DEFAULT_ABI != MS_ABI
+      && !TARGET_PECOFF
       && (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
       || crtl->profile))
     {
@@ -11387,7 +11401,7 @@  ix86_expand_split_stack_prologue (void)
     }

       if ((ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
-          && DEFAULT_ABI != MS_ABI)
+          && !TARGET_PECOFF)
     {
       HOST_WIDE_INT argval;

@@ -12112,7 +12126,7 @@  legitimate_pic_address_disp_p (rtx disp)
           || (TARGET_DLLIMPORT_DECL_ATTRIBUTES &&
SYMBOL_REF_DLLIMPORT_P (op0)))
         return false;

-      if (DEFAULT_ABI == MS_ABI)
+      if (TARGET_PECOFF)
         {
           if (is_imported_p (op0))
         return true;
@@ -12199,7 +12213,7 @@  legitimate_pic_address_disp_p (rtx disp)
       if ((GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
        || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF)
       && !TARGET_64BIT)
-        return DEFAULT_ABI != MS_ABI && gotoff_operand (XVECEXP
(disp, 0, 0), Pmode);
+        return !TARGET_PECOFF && gotoff_operand (XVECEXP (disp, 0, 0), Pmode);
       return false;
     case UNSPEC_GOTTPOFF:
     case UNSPEC_GOTNTPOFF:
@@ -12543,7 +12557,7 @@  legitimize_pic_address (rtx orig, rtx reg)

   if (TARGET_64BIT && legitimate_pic_address_disp_p (addr))
     new_rtx = addr;
-  else if (TARGET_64BIT && DEFAULT_ABI != MS_ABI
+  else if (TARGET_64BIT && !TARGET_PECOFF
        && ix86_cmodel != CM_SMALL_PIC && gotoff_operand (addr, Pmode))
     {
       rtx tmpreg;
@@ -12578,7 +12592,7 @@  legitimize_pic_address (rtx orig, rtx reg)
       else
         new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, tmpreg);
     }
-  else if (!TARGET_64BIT && DEFAULT_ABI != MS_ABI && gotoff_operand
(addr, Pmode))
+  else if (!TARGET_64BIT && !TARGET_PECOFF && gotoff_operand (addr, Pmode))
     {
       /* This symbol may be referenced via a displacement from the PIC
      base address (@GOTOFF).  */
@@ -12615,7 +12629,7 @@  legitimize_pic_address (rtx orig, rtx reg)

       /* For x64 PE-COFF there is no GOT table.  So we use address
          directly.  */
-      if (TARGET_64BIT && DEFAULT_ABI == MS_ABI)
+      if (TARGET_64BIT && TARGET_PECOFF)
     {
       new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_PCREL);
       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
@@ -12693,7 +12707,7 @@  legitimize_pic_address (rtx orig, rtx reg)

       /* Check first to see if this is a constant offset from a @GOTOFF
          symbol reference.  */
-      if (DEFAULT_ABI != MS_ABI && gotoff_operand (op0, Pmode)
+      if (!TARGET_PECOFF && gotoff_operand (op0, Pmode)
           && CONST_INT_P (op1))
         {
           if (!TARGET_64BIT)
@@ -12837,7 +12851,7 @@  legitimize_tls_address (rtx x, enum tls_model mode

       if (!TARGET_64BIT)
     {
-      if (flag_pic && DEFAULT_ABI != MS_ABI)
+      if (flag_pic && !TARGET_PECOFF)
         pic = pic_offset_table_rtx;
       else
         {
@@ -13160,7 +13174,7 @@  legitimize_dllimport_symbol (rtx symbol, bool want
 static rtx
 legitimize_pe_coff_symbol (rtx addr, bool inreg)
 {
-  if (DEFAULT_ABI != MS_ABI)
+  if (!TARGET_PECOFF)
     return NULL_RTX;

   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
@@ -13442,7 +13456,7 @@  output_pic_addr_const (FILE *file, rtx x, int code
 #endif
       assemble_name (file, name);
     }
-      if (!TARGET_MACHO && !(TARGET_64BIT && DEFAULT_ABI == MS_ABI)
+      if (!TARGET_MACHO && !(TARGET_64BIT && TARGET_PECOFF)
       && code == 'P' && ! SYMBOL_REF_LOCAL_P (x))
     fputs ("@PLT", file);
       break;
@@ -23688,7 +23702,7 @@  construct_plt_address (rtx symbol)
   rtx tmp, unspec;

   gcc_assert (GET_CODE (symbol) == SYMBOL_REF);
-  gcc_assert (ix86_cmodel == CM_LARGE_PIC && DEFAULT_ABI != MS_ABI);
+  gcc_assert (ix86_cmodel == CM_LARGE_PIC && !TARGET_PECOFF);
   gcc_assert (Pmode == DImode);

   tmp = gen_reg_rtx (Pmode);
@@ -23731,7 +23745,7 @@  ix86_expand_call (rtx retval, rtx fnaddr, rtx call
     {
       /* Static functions and indirect calls don't need the pic register.  */
       if (flag_pic && (!TARGET_64BIT
-                       || (ix86_cmodel == CM_LARGE_PIC && DEFAULT_ABI
!= MS_ABI))
+                       || (ix86_cmodel == CM_LARGE_PIC && !TARGET_PECOFF))
       && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
       && ! SYMBOL_REF_LOCAL_P (XEXP (fnaddr, 0)))
     use_reg (&use, pic_offset_table_rtx);
@@ -23745,7 +23759,7 @@  ix86_expand_call (rtx retval, rtx fnaddr, rtx call
     }

   if (ix86_cmodel == CM_LARGE_PIC
-      && DEFAULT_ABI != MS_ABI
+      && !TARGET_PECOFF
       && MEM_P (fnaddr)
       && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
       && !local_symbolic_operand (XEXP (fnaddr, 0), VOIDmode))
@@ -35089,7 +35103,7 @@  x86_output_mi_thunk (FILE *file,
   if (TARGET_64BIT)
     {
       if (!flag_pic || targetm.binds_local_p (function)
-      || DEFAULT_ABI == MS_ABI)
+      || TARGET_PECOFF)
     ;
       else
     {
@@ -35202,7 +35216,7 @@  x86_function_profiler (FILE *file, int labelno ATT
       fprintf (file, "\tleaq\t%sP%d(%%rip),%%r11\n", LPREFIX, labelno);
 #endif

-      if (DEFAULT_ABI == SYSV_ABI && flag_pic)
+      if (!TARGET_PECOFF && flag_pic)
     fprintf (file, "\tcall\t*%s@GOTPCREL(%%rip)\n", mcount_name);
       else
     fprintf (file, "\tcall\t%s\n", mcount_name);
Index: i386.h
===================================================================
--- i386.h    (Revision 198060)
+++ i386.h    (Arbeitskopie)
@@ -533,6 +533,9 @@  extern tree x86_mfence;
 /* This is re-defined by cygming.h.  */
 #define TARGET_SEH 0

+/* This is re-defined by cygming.h.  */
+#define TARGET_PECOFF 0
+
 /* The default abi used by target.  */
 #define DEFAULT_ABI SYSV_ABI

@@ -1183,7 +1186,7 @@  enum target_cpu_default

 #define PIC_OFFSET_TABLE_REGNUM                \
   ((TARGET_64BIT && (ix86_cmodel == CM_SMALL_PIC    \
-                     || DEFAULT_ABI == MS_ABI))        \
+                     || TARGET_PECOFF))        \
    || !flag_pic ? INVALID_REGNUM            \
    : reload_completed ? REGNO (pic_offset_table_rtx)    \
    : REAL_PIC_OFFSET_TABLE_REGNUM)