mingw32.h (OUTPUT_QUOTED_STRING): Properly output quoted strings.
[platform/upstream/gcc.git] / gcc / config / rs6000 / xcoff.h
1 /* Definitions of target machine for GNU compiler,
2    for some generic XCOFF file format
3    Copyright (C) 2001, 2002 Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
7 GNU CC 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 2, or (at your option)
10 any later version.
11
12 GNU CC 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 GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22
23 #define TARGET_OBJECT_FORMAT OBJECT_XCOFF
24
25 /* The RS/6000 uses the XCOFF format.  */
26 #define XCOFF_DEBUGGING_INFO
27
28 /* Define if the object format being used is COFF or a superset.  */
29 #define OBJECT_FORMAT_COFF
30
31 /* Define the magic numbers that we recognize as COFF.
32  
33     AIX 4.3 adds U803XTOCMAGIC (0757) for 64-bit objects and AIX V5 adds
34     U64_TOCMAGIC (0767), but collect2.c does not include files in the
35     correct order to conditionally define the symbolic name in this macro.
36  
37     The AIX linker accepts import/export files as object files,
38     so accept "#!" (0x2321) magic number.  */
39 #define MY_ISCOFF(magic) \
40   ((magic) == U802WRMAGIC || (magic) == U802ROMAGIC \
41    || (magic) == U802TOCMAGIC || (magic) == 0757 || (magic) == 0767 \
42    || (magic) == 0x2321)
43
44 /* We don't have GAS for the RS/6000 yet, so don't write out special
45     .stabs in cc1plus.  */
46
47 #define FASCIST_ASSEMBLER
48
49 /* We define this to prevent the name mangler from putting dollar signs into
50    function names.  */
51
52 #define NO_DOLLAR_IN_LABEL
53
54 /* We define this to 0 so that gcc will never accept a dollar sign in a
55    variable name.  This is needed because the AIX assembler will not accept
56    dollar signs.  */
57
58 #define DOLLARS_IN_IDENTIFIERS 0
59
60 /* Define the extra sections we need.  We define three: one is the read-only
61    data section which is used for constants.  This is a csect whose name is
62    derived from the name of the input file.  The second is for initialized
63    global variables.  This is a csect whose name is that of the variable.
64    The third is the TOC.  */
65
66 #define EXTRA_SECTIONS \
67    read_only_data, private_data, read_only_private_data, toc, bss
68
69 /* Define the routines to implement these extra sections.
70    BIGGEST_ALIGNMENT is 64, so align the sections that much.  */
71
72 #define EXTRA_SECTION_FUNCTIONS                         \
73                                                         \
74 void                                                    \
75 read_only_data_section ()                               \
76 {                                                       \
77   if (in_section != read_only_data)                     \
78     {                                                   \
79       fprintf (asm_out_file, "\t.csect %s[RO],3\n",     \
80                xcoff_read_only_section_name);           \
81       in_section = read_only_data;                      \
82     }                                                   \
83 }                                                       \
84                                                         \
85 void                                                    \
86 private_data_section ()                                 \
87 {                                                       \
88   if (in_section != private_data)                       \
89     {                                                   \
90       fprintf (asm_out_file, "\t.csect %s[RW],3\n",     \
91                xcoff_private_data_section_name);        \
92       in_section = private_data;                        \
93     }                                                   \
94 }                                                       \
95                                                         \
96 void                                                    \
97 read_only_private_data_section ()                       \
98 {                                                       \
99   if (in_section != read_only_private_data)             \
100     {                                                   \
101       fprintf (asm_out_file, "\t.csect %s[RO],3\n",     \
102                xcoff_private_data_section_name);        \
103       in_section = read_only_private_data;              \
104     }                                                   \
105 }                                                       \
106                                                         \
107 void                                                    \
108 toc_section ()                                          \
109 {                                                       \
110   if (TARGET_MINIMAL_TOC)                               \
111     {                                                   \
112       /* toc_section is always called at least once from ASM_FILE_START, \
113          so this is guaranteed to always be defined once and only once   \
114          in each file.  */                                               \
115       if (! toc_initialized)                            \
116         {                                               \
117           fputs ("\t.toc\nLCTOC..1:\n", asm_out_file);  \
118           fputs ("\t.tc toc_table[TC],toc_table[RW]\n", asm_out_file); \
119           toc_initialized = 1;                          \
120         }                                               \
121                                                         \
122       if (in_section != toc)                            \
123         fprintf (asm_out_file, "\t.csect toc_table[RW]%s\n",    \
124                  (TARGET_32BIT ? "" : ",3"));           \
125     }                                                   \
126   else                                                  \
127     {                                                   \
128       if (in_section != toc)                            \
129         fputs ("\t.toc\n", asm_out_file);               \
130     }                                                   \
131   in_section = toc;                                     \
132 }
133
134 /* Define the name of our readonly data section.  */
135
136 #define READONLY_DATA_SECTION read_only_data_section
137
138 #define TARGET_ASM_SELECT_SECTION  rs6000_xcoff_select_section
139
140 /* Return non-zero if this entry is to be written into the constant
141    pool in a special way.  We do so if this is a SYMBOL_REF, LABEL_REF
142    or a CONST containing one of them.  If -mfp-in-toc (the default),
143    we also do this for floating-point constants.  We actually can only
144    do this if the FP formats of the target and host machines are the
145    same, but we can't check that since not every file that uses
146    GO_IF_LEGITIMATE_ADDRESS_P includes real.h.  We also do this when
147    we can write the entry into the TOC and the entry is not larger
148    than a TOC entry.  */
149
150 #define ASM_OUTPUT_SPECIAL_POOL_ENTRY_P(X, MODE)                        \
151   (TARGET_TOC                                                           \
152    && (GET_CODE (X) == SYMBOL_REF                                       \
153        || (GET_CODE (X) == CONST && GET_CODE (XEXP (X, 0)) == PLUS      \
154            && GET_CODE (XEXP (XEXP (X, 0), 0)) == SYMBOL_REF)           \
155        || GET_CODE (X) == LABEL_REF                                     \
156        || (GET_CODE (X) == CONST_INT                                    \
157            && GET_MODE_BITSIZE (MODE) <= GET_MODE_BITSIZE (Pmode))      \
158        || (GET_CODE (X) == CONST_DOUBLE                                 \
159            && (TARGET_POWERPC64                                         \
160                || TARGET_MINIMAL_TOC                                    \
161                || (GET_MODE_CLASS (GET_MODE (X)) == MODE_FLOAT          \
162                    && ! TARGET_NO_FP_IN_TOC)))))
163
164 #define TARGET_ASM_SELECT_RTX_SECTION  rs6000_xcoff_select_rtx_section
165 #define TARGET_ENCODE_SECTION_INFO rs6000_xcoff_encode_section_info
166 #define TARGET_STRIP_NAME_ENCODING rs6000_xcoff_strip_name_encoding
167
168 /* FP save and restore routines.  */
169 #define SAVE_FP_PREFIX "._savef"
170 #define SAVE_FP_SUFFIX ""
171 #define RESTORE_FP_PREFIX "._restf"
172 #define RESTORE_FP_SUFFIX ""
173
174 /* Function name to call to do profiling.  */
175 #undef RS6000_MCOUNT
176 #define RS6000_MCOUNT ".__mcount"
177
178 /* Function names to call to do floating point truncation.  */
179
180 #undef RS6000_ITRUNC
181 #define RS6000_ITRUNC "__itrunc"
182 #undef RS6000_UITRUNC
183 #define RS6000_UITRUNC "__uitrunc"
184
185 /* This outputs NAME to FILE up to the first null or '['.  */
186
187 #define RS6000_OUTPUT_BASENAME(FILE, NAME) \
188   assemble_name ((FILE), (*targetm.strip_name_encoding) (NAME))
189
190 /* This is how to output the definition of a user-level label named NAME,
191    such as the label on a static function or variable NAME.  */
192
193 #define ASM_OUTPUT_LABEL(FILE,NAME)     \
194   do { RS6000_OUTPUT_BASENAME (FILE, NAME); fputs (":\n", FILE); } while (0)
195
196 /* This is how to output a command to make the user-level label named NAME
197    defined for reference from other files.  */
198
199 #define ASM_GLOBALIZE_LABEL(FILE,NAME)  \
200   do { fputs ("\t.globl ", FILE);       \
201        RS6000_OUTPUT_BASENAME (FILE, NAME); putc ('\n', FILE);} while (0)
202
203 /* Output at beginning of assembler file.
204
205    Initialize the section names for the RS/6000 at this point.
206
207    Specify filename, including full path, to assembler.
208
209    We want to go into the TOC section so at least one .toc will be emitted.
210    Also, in order to output proper .bs/.es pairs, we need at least one static
211    [RW] section emitted.
212
213    Finally, declare mcount when profiling to make the assembler happy.  */
214
215 #define ASM_FILE_START(FILE)                                    \
216 {                                                               \
217   rs6000_gen_section_name (&xcoff_bss_section_name,             \
218                            main_input_filename, ".bss_");       \
219   rs6000_gen_section_name (&xcoff_private_data_section_name,    \
220                            main_input_filename, ".rw_");        \
221   rs6000_gen_section_name (&xcoff_read_only_section_name,       \
222                            main_input_filename, ".ro_");        \
223                                                                 \
224   fputs ("\t.file\t", FILE);                                    \
225   output_quoted_string (FILE, main_input_filename);             \
226   fputc ('\n', FILE);                                           \
227   if (TARGET_64BIT)                                             \
228     fputs ("\t.machine\t\"ppc64\"\n", FILE);                    \
229   toc_section ();                                               \
230   if (write_symbols != NO_DEBUG)                                \
231     private_data_section ();                                    \
232   text_section ();                                              \
233   if (profile_flag)                                             \
234     fprintf (FILE, "\t.extern %s\n", RS6000_MCOUNT);            \
235   rs6000_file_start (FILE, TARGET_CPU_DEFAULT);                 \
236 }
237
238 /* Output at end of assembler file.
239
240    On the RS/6000, referencing data should automatically pull in text.  */
241
242 #define ASM_FILE_END(FILE)                                      \
243 {                                                               \
244   text_section ();                                              \
245   fputs ("_section_.text:\n", FILE);                            \
246   data_section ();                                              \
247   fputs (TARGET_32BIT                                           \
248          ? "\t.long _section_.text\n" : "\t.llong _section_.text\n", FILE); \
249 }
250
251 /* This macro produces the initial definition of a function name.
252    On the RS/6000, we need to place an extra '.' in the function name and
253    output the function descriptor.
254
255    The csect for the function will have already been created by the
256    `text_section' call previously done.  We do have to go back to that
257    csect, however.
258
259    We also record that the function exists in the current compilation
260    unit, reachable by short branch, by setting SYMBOL_REF_FLAG.
261
262    The third and fourth parameters to the .function pseudo-op (16 and 044)
263    are placeholders which no longer have any use.  */
264
265 #define ASM_DECLARE_FUNCTION_NAME(FILE,NAME,DECL)               \
266 { rtx sym_ref = XEXP (DECL_RTL (DECL), 0);                      \
267   if (!DECL_WEAK (DECL))                                        \
268     SYMBOL_REF_FLAG (sym_ref) = 1;                              \
269   if (TREE_PUBLIC (DECL))                                       \
270     {                                                           \
271       if (!RS6000_WEAK || !DECL_WEAK (decl))                    \
272         {                                                       \
273           fputs ("\t.globl .", FILE);                           \
274           RS6000_OUTPUT_BASENAME (FILE, NAME);                  \
275           putc ('\n', FILE);                                    \
276         }                                                       \
277     }                                                           \
278   else                                                          \
279     {                                                           \
280       fputs ("\t.lglobl .", FILE);                              \
281       RS6000_OUTPUT_BASENAME (FILE, NAME);                      \
282       putc ('\n', FILE);                                        \
283     }                                                           \
284   fputs ("\t.csect ", FILE);                                    \
285   RS6000_OUTPUT_BASENAME (FILE, NAME);                          \
286   fputs (TARGET_32BIT ? "[DS]\n" : "[DS],3\n", FILE);           \
287   RS6000_OUTPUT_BASENAME (FILE, NAME);                          \
288   fputs (":\n", FILE);                                          \
289   fputs (TARGET_32BIT ? "\t.long ." : "\t.llong .", FILE);      \
290   RS6000_OUTPUT_BASENAME (FILE, NAME);                          \
291   fputs (", TOC[tc0], 0\n", FILE);                              \
292   in_section = no_section;                                      \
293   function_section(DECL);                                       \
294   putc ('.', FILE);                                             \
295   RS6000_OUTPUT_BASENAME (FILE, NAME);                          \
296   fputs (":\n", FILE);                                          \
297   if (write_symbols == XCOFF_DEBUG)                             \
298     xcoffout_declare_function (FILE, DECL, NAME);               \
299 }
300
301 /* Output a reference to SYM on FILE.  */
302
303 #define ASM_OUTPUT_SYMBOL_REF(FILE, SYM) \
304   rs6000_output_symbol_ref (FILE, SYM)
305
306 /* This says how to output an external.  */
307
308 #undef ASM_OUTPUT_EXTERNAL
309 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME)   \
310 { rtx _symref = XEXP (DECL_RTL (DECL), 0);      \
311   if ((TREE_CODE (DECL) == VAR_DECL             \
312        || TREE_CODE (DECL) == FUNCTION_DECL)    \
313       && (NAME)[strlen (NAME) - 1] != ']')      \
314     {                                           \
315       char *_name = (char *) permalloc (strlen (XSTR (_symref, 0)) + 5); \
316       strcpy (_name, XSTR (_symref, 0));        \
317       strcat (_name, TREE_CODE (DECL) == FUNCTION_DECL ? "[DS]" : "[RW]"); \
318       XSTR (_symref, 0) = _name;                \
319     }                                           \
320 }
321
322 /* This is how to output an internal numbered label where
323    PREFIX is the class of label and NUM is the number within the class.  */
324
325 #define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM)      \
326   fprintf (FILE, "%s..%u:\n", (PREFIX), (unsigned) (NUM))
327
328 /* This is how to output an internal label prefix.  rs6000.c uses this
329    when generating traceback tables.  */
330
331 #define ASM_OUTPUT_INTERNAL_LABEL_PREFIX(FILE,PREFIX)   \
332   fprintf (FILE, "%s..", PREFIX)
333
334 /* This is how to output a label for a jump table.  Arguments are the same as
335    for ASM_OUTPUT_INTERNAL_LABEL, except the insn for the jump table is
336    passed.  */
337
338 #define ASM_OUTPUT_CASE_LABEL(FILE,PREFIX,NUM,TABLEINSN)        \
339 { ASM_OUTPUT_ALIGN (FILE, 2); ASM_OUTPUT_INTERNAL_LABEL (FILE, PREFIX, NUM); }
340
341 /* This is how to store into the string LABEL
342    the symbol_ref name of an internal numbered label where
343    PREFIX is the class of label and NUM is the number within the class.
344    This is suitable for output with `assemble_name'.  */
345
346 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM)   \
347   sprintf (LABEL, "*%s..%u", (PREFIX), (unsigned) (NUM))
348
349 /* This is how to output an assembler line to define N characters starting
350    at P to FILE.  */
351
352 #define ASM_OUTPUT_ASCII(FILE, P, N)  output_ascii ((FILE), (P), (N))
353
354 /* This is how to advance the location counter by SIZE bytes.  */
355
356 #define ASM_OUTPUT_SKIP(FILE,SIZE)  \
357   fprintf (FILE, "\t.space %d\n", (SIZE))
358
359 /* This says how to output an assembler line
360    to define a global common symbol.  */
361
362 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGNMENT)  \
363   do { fputs ("\t.comm ", (FILE));                      \
364        RS6000_OUTPUT_BASENAME ((FILE), (NAME));         \
365        if ( (SIZE) > 4)                                 \
366          fprintf ((FILE), ",%d,3\n", (SIZE));           \
367        else                                             \
368          fprintf ((FILE), ",%d\n", (SIZE));             \
369   } while (0)
370
371 /* This says how to output an assembler line
372    to define a local common symbol.
373    Alignment cannot be specified, but we can try to maintain
374    alignment after preceding TOC section if it was aligned
375    for 64-bit mode.  */
376
377 #define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED)     \
378   do { fputs ("\t.lcomm ", (FILE));                     \
379        RS6000_OUTPUT_BASENAME ((FILE), (NAME));         \
380        fprintf ((FILE), ",%d,%s\n", (TARGET_32BIT ? (SIZE) : (ROUNDED)), \
381                 xcoff_bss_section_name);                \
382      } while (0)
383
384 /* This is how we tell the assembler that two symbols have the same value.  */
385 #define SET_ASM_OP "\t.set "
386
387 /* This is how we tell the assembler to equate two values.  */
388 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2)                              \
389  do {   fprintf ((FILE), "%s", SET_ASM_OP);                             \
390         RS6000_OUTPUT_BASENAME (FILE, LABEL1);                          \
391         fprintf (FILE, ",");                                            \
392         RS6000_OUTPUT_BASENAME (FILE, LABEL2);                          \
393         fprintf (FILE, "\n");                                           \
394   } while (0)
395
396 /* Used by rs6000_assemble_integer, among others.  */
397 #define DOUBLE_INT_ASM_OP "\t.llong\t"
398
399 /* Output before instructions.  */
400 #define TEXT_SECTION_ASM_OP "\t.csect .text[PR]"
401
402 /* Output before writable data.
403    Align entire section to BIGGEST_ALIGNMENT.  */
404 #define DATA_SECTION_ASM_OP "\t.csect .data[RW],3"
405
406 /* Define unique section name -- functions only.  */
407 #define TARGET_ASM_UNIQUE_SECTION  rs6000_xcoff_unique_section
408
409 /* Switch into a generic section.  */
410 #define TARGET_ASM_NAMED_SECTION  xcoff_asm_named_section
411
412 /* Define the name of the section to use for the EH language specific
413    data areas (.gcc_except_table on most other systems).  */
414 #define TARGET_ASM_EXCEPTION_SECTION data_section
415
416 /* Define to prevent DWARF2 unwind info in the data section rather
417    than in the .eh_frame section.  We do this because the AIX linker
418    would otherwise garbage collect these sections.  */
419 #define EH_FRAME_IN_DATA_SECTION 1