(root)/
gcc-13.2.0/
gcc/
config/
i386/
cygming.h
       1  /* Operating system specific defines to be used when targeting GCC for
       2     hosting on Windows32, using a Unix style C library and tools.
       3     Copyright (C) 1995-2023 Free Software Foundation, Inc.
       4  
       5  This file is part of GCC.
       6  
       7  GCC is free software; you can redistribute it and/or modify
       8  it under the terms of the GNU General Public License as published by
       9  the Free Software Foundation; either version 3, or (at your option)
      10  any later version.
      11  
      12  GCC is distributed in the hope that it will be useful,
      13  but WITHOUT ANY WARRANTY; without even the implied warranty of
      14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15  GNU General Public License for more details.
      16  
      17  You should have received a copy of the GNU General Public License
      18  along with GCC; see the file COPYING3.  If not see
      19  <http://www.gnu.org/licenses/>.  */
      20  
      21  #define DWARF2_DEBUGGING_INFO 1
      22  
      23  #undef PREFERRED_DEBUGGING_TYPE
      24  #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
      25  
      26  #undef TARGET_SEH
      27  #define TARGET_SEH  (TARGET_64BIT_MS_ABI && flag_unwind_tables)
      28  
      29  /* Win64 with SEH cannot represent DRAP stack frames.  Disable its use.
      30     Force the use of different mechanisms to allocate aligned local data.  */
      31  #undef MAX_STACK_ALIGNMENT
      32  #define MAX_STACK_ALIGNMENT  (TARGET_SEH ? 128 : MAX_OFILE_ALIGNMENT)
      33  
      34  /* 32-bit Windows aligns the stack on a 4-byte boundary but SSE instructions
      35     may require 16-byte alignment.  */
      36  #undef STACK_REALIGN_DEFAULT
      37  #define STACK_REALIGN_DEFAULT TARGET_SSE
      38  
      39  /* Support hooks for SEH.  */
      40  #undef  TARGET_ASM_UNWIND_EMIT
      41  #define TARGET_ASM_UNWIND_EMIT  i386_pe_seh_unwind_emit
      42  #undef  TARGET_ASM_UNWIND_EMIT_BEFORE_INSN
      43  #define TARGET_ASM_UNWIND_EMIT_BEFORE_INSN  false
      44  #undef  TARGET_ASM_FUNCTION_END_PROLOGUE
      45  #define TARGET_ASM_FUNCTION_END_PROLOGUE  i386_pe_seh_end_prologue
      46  #undef  TARGET_ASM_EMIT_EXCEPT_PERSONALITY
      47  #define TARGET_ASM_EMIT_EXCEPT_PERSONALITY i386_pe_seh_emit_except_personality
      48  #undef  TARGET_ASM_INIT_SECTIONS
      49  #define TARGET_ASM_INIT_SECTIONS  i386_pe_seh_init_sections
      50  #define SUBTARGET_ASM_UNWIND_INIT  i386_pe_seh_init
      51  
      52  #undef DEFAULT_ABI
      53  #define DEFAULT_ABI (TARGET_64BIT ? MS_ABI : SYSV_ABI)
      54  
      55  #undef TARGET_PECOFF
      56  #define TARGET_PECOFF 1
      57  
      58  #if ! defined (USE_MINGW64_LEADING_UNDERSCORES)
      59  #undef USER_LABEL_PREFIX
      60  #define USER_LABEL_PREFIX (TARGET_64BIT ? "" : "_")
      61  
      62  #undef LOCAL_LABEL_PREFIX
      63  #define LOCAL_LABEL_PREFIX (TARGET_64BIT ? "." : "")
      64  
      65  #undef ASM_GENERATE_INTERNAL_LABEL
      66  #define ASM_GENERATE_INTERNAL_LABEL(BUF,PREFIX,NUMBER)  \
      67    sprintf ((BUF), "*%s%s%ld", LOCAL_LABEL_PREFIX, \
      68  	   (PREFIX), (long)(NUMBER))
      69  
      70  #undef LPREFIX
      71  #define LPREFIX (TARGET_64BIT ? ".L" : "L")
      72  
      73  #endif
      74  
      75  #undef DEBUGGER_REGNO
      76  #define DEBUGGER_REGNO(n)				\
      77    (TARGET_64BIT ? debugger64_register_map[n]			\
      78     : (dwarf_debuginfo_p ()				\
      79        ? svr4_debugger_register_map[n] : debugger_register_map[n]))
      80  
      81  /* Map gcc register number to DWARF 2 CFA column number. For 32 bit
      82     target, always use the svr4_debugger_register_map for DWARF .eh_frame
      83     even if we don't use DWARF .debug_frame. */
      84  #undef DWARF_FRAME_REGNUM
      85  #define DWARF_FRAME_REGNUM(n)				\
      86    (TARGET_64BIT ? debugger64_register_map[(n)]		\
      87  		: svr4_debugger_register_map[(n)])
      88  
      89  /* The 64-bit MS_ABI changes the set of call-used registers.  */
      90  #undef DWARF_FRAME_REGISTERS
      91  #define DWARF_FRAME_REGISTERS (TARGET_64BIT ? 33 : 17)
      92  
      93  /* Use section relative relocations for debugging offsets.  Unlike
      94     other targets that fake this by putting the section VMA at 0, PE
      95     won't allow it.  */
      96  #define ASM_OUTPUT_DWARF_OFFSET(FILE, SIZE, LABEL, OFFSET, SECTION) \
      97    do {								\
      98      switch (SIZE)						\
      99        {								\
     100        case 4:							\
     101  	fputs ("\t.secrel32\t", FILE);				\
     102  	assemble_name (FILE, LABEL);				\
     103  	if ((OFFSET) != 0)					\
     104  	  fprintf (FILE, "+" HOST_WIDE_INT_PRINT_DEC,		\
     105  		   (HOST_WIDE_INT) (OFFSET));			\
     106  	break;							\
     107        case 8:							\
     108  	/* This is a hack.  There is no 64-bit section relative	\
     109  	   relocation.  However, the COFF format also does not	\
     110  	   support 64-bit file offsets; 64-bit applications are	\
     111  	   limited to 32-bits of code+data in any one module.	\
     112  	   Fake the 64-bit offset by zero-extending it.  */	\
     113  	fputs ("\t.secrel32\t", FILE);				\
     114  	assemble_name (FILE, LABEL);				\
     115  	if ((OFFSET) != 0)					\
     116  	  fprintf (FILE, "+" HOST_WIDE_INT_PRINT_DEC,		\
     117  		   (HOST_WIDE_INT) (OFFSET));			\
     118  	fputs ("\n\t.long\t0", FILE);				\
     119  	break;							\
     120        default:							\
     121  	gcc_unreachable ();					\
     122        }								\
     123    } while (0)
     124  
     125  #define TARGET_EXECUTABLE_SUFFIX ".exe"
     126  
     127  #define TARGET_OS_CPP_BUILTINS()					\
     128    do									\
     129      {									\
     130  	if (!TARGET_64BIT)						\
     131  	  builtin_define ("_X86_=1");					\
     132  	if (TARGET_SEH)							\
     133  	  builtin_define ("__SEH__");				\
     134  	builtin_assert ("system=winnt");				\
     135  	builtin_define ("__stdcall=__attribute__((__stdcall__))");	\
     136  	builtin_define ("__fastcall=__attribute__((__fastcall__))");	\
     137  	builtin_define ("__thiscall=__attribute__((__thiscall__))");	\
     138  	builtin_define ("__cdecl=__attribute__((__cdecl__))");		\
     139  	if (!flag_iso)							\
     140  	  {								\
     141  	    builtin_define ("_stdcall=__attribute__((__stdcall__))");	\
     142  	    builtin_define ("_fastcall=__attribute__((__fastcall__))");	\
     143  	    builtin_define ("_thiscall=__attribute__((__thiscall__))");	\
     144  	    builtin_define ("_cdecl=__attribute__((__cdecl__))");	\
     145  	  }								\
     146  	/* Even though linkonce works with static libs, this is needed 	\
     147  	    to compare typeinfo symbols across dll boundaries.  */	\
     148  	builtin_define ("__GXX_MERGED_TYPEINFO_NAMES=0");		\
     149  	builtin_define ("__GXX_TYPEINFO_EQUALITY_INLINE=0");		\
     150  	EXTRA_OS_CPP_BUILTINS ();					\
     151    }									\
     152    while (0)
     153  
     154  /* Get tree.cc to declare a target-specific specialization of
     155     merge_decl_attributes.  */
     156  #define TARGET_DLLIMPORT_DECL_ATTRIBUTES 1
     157  
     158  /* This macro defines names of additional specifications to put in the specs
     159     that can be used in various specifications like CC1_SPEC.  Its definition
     160     is an initializer with a subgrouping for each command option.
     161  
     162     Each subgrouping contains a string constant, that defines the
     163     specification name, and a string constant that used by the GCC driver
     164     program.
     165  
     166     Do not define this macro if it does not need to do anything.  */
     167  
     168  #undef  SUBTARGET_EXTRA_SPECS
     169  #define SUBTARGET_EXTRA_SPECS						\
     170    { "mingw_include_path", DEFAULT_TARGET_MACHINE }
     171  
     172  #undef MATH_LIBRARY
     173  #define MATH_LIBRARY ""
     174  
     175  #undef TARGET_LIBC_HAS_FUNCTION
     176  #define TARGET_LIBC_HAS_FUNCTION no_c99_libc_has_function
     177  
     178  #define SIZE_TYPE (TARGET_64BIT ? "long long unsigned int" : "unsigned int")
     179  #define PTRDIFF_TYPE (TARGET_64BIT ? "long long int" : "int")
     180  
     181  #define WCHAR_TYPE_SIZE 16
     182  #define WCHAR_TYPE "short unsigned int"
     183  
     184  /* Windows64 continues to use a 32-bit long type.  */
     185  #undef LONG_TYPE_SIZE
     186  #define LONG_TYPE_SIZE 32
     187  
     188  #define drectve_section() \
     189    (fprintf (asm_out_file, "\t.section .drectve\n"), \
     190     in_section = NULL)
     191  
     192  /* Older versions of gas don't handle 'r' as data.
     193     Explicitly set data flag with 'd'.  */  
     194  #define READONLY_DATA_SECTION_ASM_OP "\t.section .rdata,\"dr\""
     195  
     196  /* Don't allow flag_pic to propagate since gas may produce invalid code
     197     otherwise.  */
     198  
     199  #undef  SUBTARGET_OVERRIDE_OPTIONS
     200  #define SUBTARGET_OVERRIDE_OPTIONS					\
     201  do {									\
     202    flag_pic = TARGET_64BIT ? 1 : 0;                                      \
     203  } while (0)
     204  
     205  /* Define this macro if references to a symbol must be treated
     206     differently depending on something about the variable or
     207     function named by the symbol (such as what section it is in).
     208  
     209     On i386 running Windows NT, modify the assembler name with a suffix
     210     consisting of an atsign (@) followed by string of digits that represents
     211     the number of bytes of arguments passed to the function, if it has the
     212     attribute STDCALL.
     213  
     214     In addition, we must mark dll symbols specially. Definitions of
     215     dllexport'd objects install some info in the .drectve section.
     216     References to dllimport'd objects are fetched indirectly via
     217     _imp__.  If both are declared, dllexport overrides.  This is also
     218     needed to implement one-only vtables: they go into their own
     219     section and we need to set DECL_SECTION_NAME so we do that here.
     220     Note that we can be called twice on the same decl.  */
     221  
     222  #define SUBTARGET_ENCODE_SECTION_INFO  i386_pe_encode_section_info
     223  
     224  /* Local and global relocs can be placed always into readonly memory
     225     for PE-COFF targets.  */
     226  #undef TARGET_ASM_RELOC_RW_MASK
     227  #define TARGET_ASM_RELOC_RW_MASK i386_pe_reloc_rw_mask
     228  
     229  /* Output a common block.  */
     230  #undef ASM_OUTPUT_ALIGNED_DECL_COMMON
     231  #define ASM_OUTPUT_ALIGNED_DECL_COMMON \
     232    i386_pe_asm_output_aligned_decl_common
     233  
     234  /* Output the label for an initialized variable.  */
     235  #undef ASM_DECLARE_OBJECT_NAME
     236  #define ASM_DECLARE_OBJECT_NAME(STREAM, NAME, DECL)	\
     237  do {							\
     238    i386_pe_maybe_record_exported_symbol (DECL, NAME, 1);	\
     239    ASM_OUTPUT_LABEL ((STREAM), (NAME));			\
     240  } while (0)
     241  
     242  /* Output a reference to a label. Fastcall function symbols
     243     keep their '@' prefix, while other symbols are prefixed
     244     with user_label_prefix.  */
     245  #undef ASM_OUTPUT_LABELREF
     246  #define  ASM_OUTPUT_LABELREF(STREAM, NAME)	\
     247  do {						\
     248    if ((NAME)[0] != FASTCALL_PREFIX)		\
     249      fputs (user_label_prefix, (STREAM));	\
     250    fputs ((NAME), (STREAM));			\
     251  } while (0)
     252  
     253  /* This does much the same in memory rather than to a stream.  */
     254  #undef TARGET_MANGLE_ASSEMBLER_NAME
     255  #define TARGET_MANGLE_ASSEMBLER_NAME i386_pe_mangle_assembler_name
     256  
     257  
     258  /* Emit code to check the stack when allocating more than 4000
     259     bytes in one go.  */
     260  #define CHECK_STACK_LIMIT 4000
     261  
     262  /* By default, target has a 80387, uses IEEE compatible arithmetic,
     263     returns float values in the 387 and needs stack probes.
     264     We also align doubles to 64-bits for MSVC default compatibility.  */
     265  
     266  #undef TARGET_SUBTARGET_DEFAULT
     267  #define TARGET_SUBTARGET_DEFAULT \
     268  	(MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS \
     269  	 | MASK_STACK_PROBE | MASK_ALIGN_DOUBLE)
     270  
     271  #undef TARGET_SUBTARGET64_DEFAULT
     272  #define TARGET_SUBTARGET64_DEFAULT \
     273  	MASK_128BIT_LONG_DOUBLE
     274  
     275  /* This is how to output an assembler line
     276     that says to advance the location counter
     277     to a multiple of 2**LOG bytes.  */
     278  
     279  #undef ASM_OUTPUT_ALIGN
     280  #define ASM_OUTPUT_ALIGN(FILE,LOG)	\
     281      if ((LOG) != 0) fprintf ((FILE), "\t.align %d\n", 1 << (LOG))
     282  
     283  /* Windows uses explicit import from shared libraries.  */
     284  #define MULTIPLE_SYMBOL_SPACES 1
     285  
     286  #define TARGET_ASM_UNIQUE_SECTION i386_pe_unique_section
     287  #define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
     288  
     289  #define SUPPORTS_ONE_ONLY 1
     290  
     291  /* Switch into a generic section.  */
     292  #define TARGET_ASM_NAMED_SECTION  i386_pe_asm_named_section
     293  
     294  /* Select attributes for named sections.  */
     295  #define TARGET_SECTION_TYPE_FLAGS  i386_pe_section_type_flags
     296  
     297  /* Write the extra assembler code needed to declare a function
     298     properly.  */
     299  #undef ASM_DECLARE_FUNCTION_NAME
     300  #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
     301    i386_pe_start_function (FILE, NAME, DECL)
     302  
     303  /* Write the extra assembler code needed to declare the name of a
     304     cold function partition properly.  */
     305  
     306  #undef ASM_DECLARE_COLD_FUNCTION_NAME
     307  #define ASM_DECLARE_COLD_FUNCTION_NAME(FILE, NAME, DECL)	\
     308    do								\
     309      {								\
     310        i386_pe_declare_function_type (FILE, NAME, 0);		\
     311        i386_pe_seh_cold_init (FILE, NAME);			\
     312        ASM_OUTPUT_LABEL (FILE, NAME);				\
     313      }								\
     314    while (0)
     315  
     316  #undef ASM_DECLARE_FUNCTION_SIZE
     317  #define ASM_DECLARE_FUNCTION_SIZE(FILE,NAME,DECL) \
     318    i386_pe_end_function (FILE, NAME, DECL)
     319  
     320  #undef ASM_DECLARE_COLD_FUNCTION_SIZE
     321  #define ASM_DECLARE_COLD_FUNCTION_SIZE(FILE,NAME,DECL) \
     322    i386_pe_end_cold_function (FILE, NAME, DECL)
     323  
     324  /* Add an external function to the list of functions to be declared at
     325     the end of the file.  */
     326  #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME)				\
     327    do									\
     328      {									\
     329        if (TREE_CODE (DECL) == FUNCTION_DECL)				\
     330  	i386_pe_record_external_function ((DECL), (NAME));		\
     331      }									\
     332    while (0)
     333  
     334  /* Declare the type properly for any external libcall.  */
     335  #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
     336    i386_pe_declare_function_type (FILE, XSTR (FUN, 0), 1)
     337  
     338  /* This says out to put a global symbol in the BSS section.  */
     339  #undef ASM_OUTPUT_ALIGNED_BSS
     340  #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
     341    asm_output_aligned_bss ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
     342  
     343  /* Output function declarations at the end of the file.  */
     344  #undef TARGET_ASM_FILE_END
     345  #define TARGET_ASM_FILE_END i386_pe_file_end
     346  
     347  /* Kludge because of missing PE-COFF support for early LTO debug.  */
     348  #undef  TARGET_ASM_LTO_START
     349  #define TARGET_ASM_LTO_START i386_pe_asm_lto_start
     350  #undef  TARGET_ASM_LTO_END
     351  #define TARGET_ASM_LTO_END i386_pe_asm_lto_end
     352  
     353  #undef ASM_COMMENT_START
     354  #define ASM_COMMENT_START " #"
     355  
     356  #ifndef DWARF2_UNWIND_INFO
     357  /* If configured with --disable-sjlj-exceptions, use DWARF2 for 32-bit
     358     mode else default to SJLJ.  64-bit code uses SEH unless you request
     359     SJLJ.  */
     360  #if  (defined (CONFIG_SJLJ_EXCEPTIONS) && !CONFIG_SJLJ_EXCEPTIONS)
     361  /* The logic of this #if must be kept synchronised with the logic
     362     for selecting the tmake_eh_file fragment in libgcc/config.host.  */
     363  #define DWARF2_UNWIND_INFO 1
     364  #else
     365  #define DWARF2_UNWIND_INFO 0
     366  #endif
     367  #endif
     368  
     369  #undef PROFILE_HOOK
     370  #define PROFILE_HOOK(LABEL)						\
     371    if (MAIN_NAME_P (DECL_NAME (current_function_decl)))			\
     372      {									\
     373        emit_call_insn (gen_rtx_CALL (VOIDmode,				\
     374  	gen_rtx_MEM (FUNCTION_MODE,					\
     375  		     gen_rtx_SYMBOL_REF (Pmode, "_monstartup")),	\
     376  	const0_rtx));							\
     377      }
     378  
     379  /* For Win32 ABI compatibility */
     380  #undef DEFAULT_PCC_STRUCT_RETURN
     381  #define DEFAULT_PCC_STRUCT_RETURN 0
     382  
     383  /* MSVC returns aggregate types of up to 8 bytes via registers.
     384     See i386.cc:ix86_return_in_memory.  */
     385  #undef MS_AGGREGATE_RETURN
     386  #define MS_AGGREGATE_RETURN 1
     387  
     388  /* Biggest alignment supported by the object file format of this
     389     machine.  Use this macro to limit the alignment which can be
     390     specified using the `__attribute__ ((aligned (N)))' construct.  If
     391     not defined, the default value is `BIGGEST_ALIGNMENT'.  */
     392  /* IMAGE_SCN_ALIGN_8192BYTES is the largest section alignment flag
     393     specified in the PECOFF60 spec.  Native MS compiler also limits
     394     user-specified alignment to 8192 bytes.  */
     395  #undef MAX_OFILE_ALIGNMENT
     396  #define MAX_OFILE_ALIGNMENT (8192 * 8)
     397  
     398  /* BIGGEST_FIELD_ALIGNMENT macro is used directly by libobjc, There, we
     399     align internal doubles in structures on dword boundaries. Otherwise,
     400     support vector modes using ADJUST_FIELD_ALIGN, defined in i386.h.  */
     401  #ifdef IN_TARGET_LIBS
     402  #undef	BIGGEST_FIELD_ALIGNMENT
     403  #define BIGGEST_FIELD_ALIGNMENT 64
     404  #endif
     405  
     406  /* Enable alias attribute support.  */
     407  #ifndef SET_ASM_OP
     408  #define SET_ASM_OP "\t.set\t"
     409  #endif
     410  
     411  /* This implements the `alias' attribute, keeping any stdcall or
     412     fastcall decoration.  */
     413  #undef	ASM_OUTPUT_DEF_FROM_DECLS
     414  #define	ASM_OUTPUT_DEF_FROM_DECLS(STREAM, DECL, TARGET)			\
     415    do									\
     416      {									\
     417        const char *alias							\
     418  	= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL));		\
     419        i386_pe_maybe_record_exported_symbol (DECL, alias, 0);		\
     420        if (TREE_CODE (DECL) == FUNCTION_DECL)				\
     421  	i386_pe_declare_function_type (STREAM, alias,			\
     422  				       TREE_PUBLIC (DECL));		\
     423        ASM_OUTPUT_DEF (STREAM, alias, IDENTIFIER_POINTER (TARGET));	\
     424      } while (0)
     425  
     426  /* GNU as supports weak symbols on PECOFF. */
     427  #ifdef HAVE_GAS_WEAK
     428  #define ASM_WEAKEN_LABEL(FILE, NAME)  \
     429    do                                  \
     430      {                                 \
     431        fputs ("\t.weak\t", (FILE));    \
     432        assemble_name ((FILE), (NAME)); \
     433        fputc ('\n', (FILE));           \
     434      }                                 \
     435    while (0)
     436  
     437  #endif /* HAVE_GAS_WEAK */
     438  
     439  /* Decide whether it is safe to use a local alias for a virtual function
     440     when constructing thunks.  */
     441  #undef TARGET_USE_LOCAL_THUNK_ALIAS_P
     442  #define TARGET_USE_LOCAL_THUNK_ALIAS_P(DECL) (!DECL_ONE_ONLY (DECL))
     443  
     444  #define SUBTARGET_ATTRIBUTE_TABLE \
     445    { "selectany", 0, 0, true, false, false, false, \
     446      ix86_handle_selectany_attribute, NULL }
     447    /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
     448         affects_type_identity, handler, exclude } */
     449  
     450  /*  mcount() does not need a counter variable.  */
     451  #undef NO_PROFILE_COUNTERS
     452  #define NO_PROFILE_COUNTERS 1
     453  
     454  #define TARGET_VALID_DLLIMPORT_ATTRIBUTE_P i386_pe_valid_dllimport_attribute_p
     455  #define TARGET_CXX_ADJUST_CLASS_AT_DEFINITION i386_pe_adjust_class_at_definition
     456  #define SUBTARGET_MANGLE_DECL_ASSEMBLER_NAME i386_pe_mangle_decl_assembler_name
     457  
     458  #undef TARGET_ASM_ASSEMBLE_VISIBILITY
     459  #define TARGET_ASM_ASSEMBLE_VISIBILITY i386_pe_assemble_visibility
     460  
     461  #undef SUB_TARGET_RECORD_STUB
     462  #define SUB_TARGET_RECORD_STUB i386_pe_record_stub
     463  
     464  /* Static stack checking is supported by means of probes.  */
     465  #define STACK_CHECK_STATIC_BUILTIN 1
     466  
     467  #ifndef HAVE_GAS_ALIGNED_COMM
     468  # define HAVE_GAS_ALIGNED_COMM 0
     469  #endif