pe.h revision 117395
190075Sobrien/* Definitions of target machine for GNU compiler, for ARM with PE obj format.
2117395Skan   Copyright (C) 1995, 1996, 1999, 2000, 2002 Free Software Foundation, Inc.
390075Sobrien   Contributed by Doug Evans (dje@cygnus.com).
490075Sobrien
590075SobrienThis file is part of GNU CC.
690075Sobrien
790075SobrienGNU CC is free software; you can redistribute it and/or modify
890075Sobrienit under the terms of the GNU General Public License as published by
990075Sobrienthe Free Software Foundation; either version 2, or (at your option)
1090075Sobrienany later version.
1190075Sobrien
1290075SobrienGNU CC is distributed in the hope that it will be useful,
1390075Sobrienbut WITHOUT ANY WARRANTY; without even the implied warranty of
1490075SobrienMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1590075SobrienGNU General Public License for more details.
1690075Sobrien
1790075SobrienYou should have received a copy of the GNU General Public License
1890075Sobrienalong with GNU CC; see the file COPYING.  If not, write to
1990075Sobrienthe Free Software Foundation, 59 Temple Place - Suite 330,
2090075SobrienBoston, MA 02111-1307, USA.  */
2190075Sobrien
2290075Sobrien/* Enable PE specific code.  */
2390075Sobrien#define ARM_PE		1
2490075Sobrien
2590075Sobrien#define ARM_PE_FLAG_CHAR '@'
2690075Sobrien
2790075Sobrien/* Ensure that @x. will be stripped from the function name.  */
2890075Sobrien#undef SUBTARGET_NAME_ENCODING_LENGTHS
2990075Sobrien#define SUBTARGET_NAME_ENCODING_LENGTHS  \
3090075Sobrien  case ARM_PE_FLAG_CHAR: return 3;
3190075Sobrien
3290075Sobrien#undef  USER_LABEL_PREFIX
3390075Sobrien#define USER_LABEL_PREFIX "_"
3490075Sobrien
3590075Sobrien
3690075Sobrien/* Run-time Target Specification.  */
3790075Sobrien#undef  TARGET_VERSION
3890075Sobrien#define TARGET_VERSION fputs (" (ARM/pe)", stderr)
3990075Sobrien
4090075Sobrien/* Get tree.c to declare a target-specific specialization of
4190075Sobrien   merge_decl_attributes.  */
4290075Sobrien#define TARGET_DLLIMPORT_DECL_ATTRIBUTES
4390075Sobrien
4490075Sobrien/* Support the __declspec keyword by turning them into attributes.
4590075Sobrien   We currently only support: naked, dllimport, and dllexport.
4690075Sobrien   Note that the current way we do this may result in a collision with
4790075Sobrien   predefined attributes later on.  This can be solved by using one attribute,
4890075Sobrien   say __declspec__, and passing args to it.  The problem with that approach
4990075Sobrien   is that args are not accumulated: each new appearance would clobber any
5090075Sobrien   existing args.  */
5190075Sobrien#undef  SUBTARGET_CPP_SPEC
5290075Sobrien#define SUBTARGET_CPP_SPEC "-D__pe__ -D__declspec(x)=__attribute__((x))"
5390075Sobrien
5490075Sobrien
5590075Sobrien/* Experimental addition for pr 7885.
5690075Sobrien   Ignore dllimport for functions.  */
5790075Sobrien#define TARGET_FLAG_NOP_FUN	(1 << 24)
5890075Sobrien
5990075Sobrien#undef  TARGET_NOP_FUN_DLLIMPORT
6090075Sobrien#define TARGET_NOP_FUN_DLLIMPORT (target_flags & TARGET_FLAG_NOP_FUN)
6190075Sobrien
6290075Sobrien#undef  SUBTARGET_SWITCHES
6390075Sobrien#define SUBTARGET_SWITCHES					\
6490075Sobrien{ "nop-fun-dllimport",		  TARGET_FLAG_NOP_FUN,		\
6590075Sobrien  N_("Ignore dllimport attribute for functions") },		\
6690075Sobrien{ "no-nop-fun-dllimport",	- TARGET_FLAG_NOP_FUN, "" },
6790075Sobrien
6890075Sobrien#undef  TARGET_DEFAULT
6990075Sobrien#define TARGET_DEFAULT	(ARM_FLAG_SOFT_FLOAT | TARGET_FLAG_NOP_FUN)
7090075Sobrien
7190075Sobrien
7290075Sobrien#undef  WCHAR_TYPE
7390075Sobrien#define WCHAR_TYPE 	"short unsigned int"
7490075Sobrien#undef  WCHAR_TYPE_SIZE
7590075Sobrien#define WCHAR_TYPE_SIZE 16
7690075Sobrien
7790075Sobrien/* Same as arm.h except r10 is call-saved, not fixed.  */
7890075Sobrien#undef  FIXED_REGISTERS
7990075Sobrien#define FIXED_REGISTERS \
8090075Sobrien{			\
8190075Sobrien  0,0,0,0,0,0,0,0,	\
8290075Sobrien  0,0,0,1,0,1,0,1,	\
8390075Sobrien  0,0,0,0,0,0,0,0,	\
8490075Sobrien  1,1,1			\
8590075Sobrien}
8690075Sobrien
8790075Sobrien/* Same as arm.h except r10 is call-saved, not fixed.  */
8890075Sobrien#undef  CALL_USED_REGISTERS
8990075Sobrien#define CALL_USED_REGISTERS \
9090075Sobrien{			\
9190075Sobrien  1,1,1,1,0,0,0,0,	\
9290075Sobrien  0,0,0,1,1,1,1,1,	\
9390075Sobrien  1,1,1,1,0,0,0,0,	\
9490075Sobrien  1,1,1			\
9590075Sobrien}
9690075Sobrien
9790075Sobrien/* Define this macro if in some cases global symbols from one translation
9890075Sobrien   unit may not be bound to undefined symbols in another translation unit
9990075Sobrien   without user intervention.  For instance, under Microsoft Windows
10090075Sobrien   symbols must be explicitly imported from shared libraries (DLLs).  */
10190075Sobrien#define MULTIPLE_SYMBOL_SPACES
10290075Sobrien
103117395Skan#define TARGET_ASM_UNIQUE_SECTION arm_pe_unique_section
10490075Sobrien
10590075Sobrien#define SUPPORTS_ONE_ONLY 1
10690075Sobrien
10790075Sobrien/* Switch into a generic section.  */
10890075Sobrien#undef TARGET_ASM_NAMED_SECTION
10990075Sobrien#define TARGET_ASM_NAMED_SECTION  default_pe_asm_named_section
11090075Sobrien
11190075Sobrien/* This outputs a lot of .req's to define alias for various registers.
11290075Sobrien   Let's try to avoid this.  */
11390075Sobrien#undef  ASM_FILE_START
11490075Sobrien#define ASM_FILE_START(STREAM)					\
11590075Sobrien  do								\
11690075Sobrien    {								\
11790075Sobrien      asm_fprintf (STREAM, "%@ Generated by gcc %s for ARM/pe\n",\
11890075Sobrien	   version_string);					\
11990075Sobrien      output_file_directive ((STREAM), main_input_filename);	\
12090075Sobrien    }								\
12190075Sobrien  while (0)
12290075Sobrien
12390075Sobrien/* Output a reference to a label.  */
12490075Sobrien#undef  ASM_OUTPUT_LABELREF
12590075Sobrien#define ASM_OUTPUT_LABELREF(STREAM, NAME)  \
12690075Sobrien  asm_fprintf (STREAM, "%U%s", arm_strip_name_encoding (NAME))
12790075Sobrien
12890075Sobrien/* Output a function definition label.  */
12990075Sobrien#undef  ASM_DECLARE_FUNCTION_NAME
13090075Sobrien#define ASM_DECLARE_FUNCTION_NAME(STREAM, NAME, DECL)   	\
13190075Sobrien  do								\
13290075Sobrien    {								\
13390075Sobrien      if (arm_dllexport_name_p (NAME))				\
13490075Sobrien	{							\
13590075Sobrien	  drectve_section ();					\
13690075Sobrien	  fprintf (STREAM, "\t.ascii \" -export:%s\"\n",	\
13790075Sobrien		   arm_strip_name_encoding (NAME));		\
13890075Sobrien	  function_section (DECL);				\
13990075Sobrien	}							\
14090075Sobrien      ARM_DECLARE_FUNCTION_NAME (STREAM, NAME, DECL);		\
14190075Sobrien      if (TARGET_THUMB)						\
14290075Sobrien	fprintf (STREAM, "\t.code 16\n");			\
14390075Sobrien      ASM_OUTPUT_LABEL (STREAM, NAME);				\
14490075Sobrien    }								\
14590075Sobrien  while (0)
14690075Sobrien
14790075Sobrien/* Output a common block.  */
14890075Sobrien#undef  ASM_OUTPUT_COMMON
14990075Sobrien#define ASM_OUTPUT_COMMON(STREAM, NAME, SIZE, ROUNDED)	\
15090075Sobrien  do							\
15190075Sobrien    {							\
15290075Sobrien      if (arm_dllexport_name_p (NAME))			\
15390075Sobrien	{						\
15490075Sobrien	  drectve_section ();				\
15590075Sobrien	  fprintf ((STREAM), "\t.ascii \" -export:%s\"\n",\
15690075Sobrien		   arm_strip_name_encoding (NAME));	\
15790075Sobrien	}						\
15890075Sobrien      if (! arm_dllimport_name_p (NAME))		\
15990075Sobrien	{						\
16090075Sobrien	  fprintf ((STREAM), "\t.comm\t"); 		\
16190075Sobrien	  assemble_name ((STREAM), (NAME));		\
16290075Sobrien	  asm_fprintf ((STREAM), ", %d\t%@ %d\n",	\
16390075Sobrien		   (ROUNDED), (SIZE));			\
16490075Sobrien	}						\
16590075Sobrien    }							\
16690075Sobrien  while (0)
16790075Sobrien
16890075Sobrien/* Output the label for an initialized variable.  */
16990075Sobrien#undef  ASM_DECLARE_OBJECT_NAME
17090075Sobrien#define ASM_DECLARE_OBJECT_NAME(STREAM, NAME, DECL) 	\
17190075Sobrien  do							\
17290075Sobrien    {							\
17390075Sobrien      if (arm_dllexport_name_p (NAME))			\
17490075Sobrien	{						\
17590075Sobrien	  enum in_section save_section = in_section;	\
17690075Sobrien	  drectve_section ();				\
17790075Sobrien	  fprintf (STREAM, "\t.ascii \" -export:%s\"\n",\
17890075Sobrien		   arm_strip_name_encoding (NAME));	\
17990075Sobrien	  switch_to_section (save_section, (DECL));	\
18090075Sobrien	}						\
18190075Sobrien      ASM_OUTPUT_LABEL ((STREAM), (NAME));		\
18290075Sobrien    }							\
18390075Sobrien  while (0)
18490075Sobrien
18590075Sobrien/* Support the ctors/dtors and other sections.  */
18690075Sobrien
18790075Sobrien#define DRECTVE_SECTION_ASM_OP	"\t.section .drectve"
18890075Sobrien
18990075Sobrien/* A list of other sections which the compiler might be "in" at any
19090075Sobrien   given time.  */
19190075Sobrien
192117395Skan#undef  EXTRA_SECTIONS
193117395Skan#define EXTRA_SECTIONS in_drectve
19490075Sobrien
19590075Sobrien/* A list of extra section function definitions.  */
19690075Sobrien
197117395Skan#undef  EXTRA_SECTION_FUNCTIONS
198117395Skan#define EXTRA_SECTION_FUNCTIONS \
19990075Sobrien  DRECTVE_SECTION_FUNCTION	\
20090075Sobrien  SWITCH_TO_SECTION_FUNCTION
20190075Sobrien
20290075Sobrien#define DRECTVE_SECTION_FUNCTION \
20390075Sobrienvoid									\
20490075Sobriendrectve_section ()							\
20590075Sobrien{									\
20690075Sobrien  if (in_section != in_drectve)						\
20790075Sobrien    {									\
20890075Sobrien      fprintf (asm_out_file, "%s\n", DRECTVE_SECTION_ASM_OP);		\
20990075Sobrien      in_section = in_drectve;						\
21090075Sobrien    }									\
21190075Sobrien}
21290075Sobrien
21390075Sobrien/* Switch to SECTION (an `enum in_section').
21490075Sobrien
21590075Sobrien   ??? This facility should be provided by GCC proper.
21690075Sobrien   The problem is that we want to temporarily switch sections in
21790075Sobrien   ASM_DECLARE_OBJECT_NAME and then switch back to the original section
21890075Sobrien   afterwards.  */
21990075Sobrien#define SWITCH_TO_SECTION_FUNCTION				\
22090075Sobrienstatic void switch_to_section PARAMS ((enum in_section, tree)); \
22190075Sobrienstatic void							\
22290075Sobrienswitch_to_section (section, decl)				\
22390075Sobrien     enum in_section section;					\
22490075Sobrien     tree decl;							\
22590075Sobrien{								\
22690075Sobrien  switch (section)						\
22790075Sobrien    {								\
22890075Sobrien      case in_text: text_section (); break;			\
22990075Sobrien      case in_data: data_section (); break;			\
23090075Sobrien      case in_named: named_section (decl, NULL, 0); break;	\
231117395Skan      case in_readonly_data: readonly_data_section (); break;	\
23290075Sobrien      case in_ctors: ctors_section (); break;			\
23390075Sobrien      case in_dtors: dtors_section (); break;			\
23490075Sobrien      case in_drectve: drectve_section (); break;		\
23590075Sobrien      default: abort (); break;					\
23690075Sobrien    }								\
23790075Sobrien}
238