OSDN Git Service

64a0dcd45db07a5405d784749a1e74a7c6330a57
[pf3gnuchains/gcc-fork.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 1
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 /* Return nonzero if this entry is to be written into the constant
139    pool in a special way.  We do so if this is a SYMBOL_REF, LABEL_REF
140    or a CONST containing one of them.  If -mfp-in-toc (the default),
141    we also do this for floating-point constants.  We actually can only
142    do this if the FP formats of the target and host machines are the
143    same, but we can't check that since not every file that uses
144    GO_IF_LEGITIMATE_ADDRESS_P includes real.h.  We also do this when
145    we can write the entry into the TOC and the entry is not larger
146    than a TOC entry.  */
147
148 #define ASM_OUTPUT_SPECIAL_POOL_ENTRY_P(X, MODE)                        \
149   (TARGET_TOC                                                           \
150    && (GET_CODE (X) == SYMBOL_REF                                       \
151        || (GET_CODE (X) == CONST && GET_CODE (XEXP (X, 0)) == PLUS      \
152            && GET_CODE (XEXP (XEXP (X, 0), 0)) == SYMBOL_REF)           \
153        || GET_CODE (X) == LABEL_REF                                     \
154        || (GET_CODE (X) == CONST_INT                                    \
155            && GET_MODE_BITSIZE (MODE) <= GET_MODE_BITSIZE (Pmode))      \
156        || (GET_CODE (X) == CONST_DOUBLE                                 \
157            && (TARGET_POWERPC64                                         \
158                || TARGET_MINIMAL_TOC                                    \
159                || (GET_MODE_CLASS (GET_MODE (X)) == MODE_FLOAT          \
160                    && ! TARGET_NO_FP_IN_TOC)))))
161
162 #define TARGET_ASM_GLOBALIZE_LABEL  rs6000_xcoff_asm_globalize_label
163 #define TARGET_ASM_NAMED_SECTION  rs6000_xcoff_asm_named_section
164 #define TARGET_ASM_SELECT_SECTION  rs6000_xcoff_select_section
165 #define TARGET_ASM_SELECT_RTX_SECTION  rs6000_xcoff_select_rtx_section
166 #define TARGET_ASM_UNIQUE_SECTION  rs6000_xcoff_unique_section
167 #define TARGET_ENCODE_SECTION_INFO  rs6000_xcoff_encode_section_info
168 #define TARGET_STRIP_NAME_ENCODING  rs6000_xcoff_strip_name_encoding
169 #define TARGET_SECTION_TYPE_FLAGS  rs6000_xcoff_section_type_flags
170
171 /* FP save and restore routines.  */
172 #define SAVE_FP_PREFIX "._savef"
173 #define SAVE_FP_SUFFIX ""
174 #define RESTORE_FP_PREFIX "._restf"
175 #define RESTORE_FP_SUFFIX ""
176
177 /* Function name to call to do profiling.  */
178 #undef RS6000_MCOUNT
179 #define RS6000_MCOUNT ".__mcount"
180
181 /* Function names to call to do floating point truncation.  */
182
183 #undef RS6000_ITRUNC
184 #define RS6000_ITRUNC "__itrunc"
185 #undef RS6000_UITRUNC
186 #define RS6000_UITRUNC "__uitrunc"
187
188 /* This outputs NAME to FILE up to the first null or '['.  */
189
190 #define RS6000_OUTPUT_BASENAME(FILE, NAME) \
191   assemble_name ((FILE), (*targetm.strip_name_encoding) (NAME))
192
193 /* This is how to output the definition of a user-level label named NAME,
194    such as the label on a static function or variable NAME.  */
195
196 #define ASM_OUTPUT_LABEL(FILE,NAME)     \
197   do { RS6000_OUTPUT_BASENAME (FILE, NAME); fputs (":\n", FILE); } while (0)
198
199 /* This is how to output a command to make the user-level label named NAME
200    defined for reference from other files.  */
201
202 /* Globalizing directive for a label.  */
203 #define GLOBAL_ASM_OP "\t.globl "
204
205 /* Output at beginning of assembler file.
206
207    Initialize the section names for the RS/6000 at this point.
208
209    Specify filename, including full path, to assembler.
210
211    We want to go into the TOC section so at least one .toc will be emitted.
212    Also, in order to output proper .bs/.es pairs, we need at least one static
213    [RW] section emitted.
214
215    Finally, declare mcount when profiling to make the assembler happy.  */
216
217 #define ASM_FILE_START(FILE)                                    \
218 {                                                               \
219   rs6000_gen_section_name (&xcoff_bss_section_name,             \
220                            main_input_filename, ".bss_");       \
221   rs6000_gen_section_name (&xcoff_private_data_section_name,    \
222                            main_input_filename, ".rw_");        \
223   rs6000_gen_section_name (&xcoff_read_only_section_name,       \
224                            main_input_filename, ".ro_");        \
225                                                                 \
226   fputs ("\t.file\t", FILE);                                    \
227   output_quoted_string (FILE, main_input_filename);             \
228   fputc ('\n', FILE);                                           \
229   if (TARGET_64BIT)                                             \
230     fputs ("\t.machine\t\"ppc64\"\n", FILE);                    \
231   toc_section ();                                               \
232   if (write_symbols != NO_DEBUG)                                \
233     private_data_section ();                                    \
234   text_section ();                                              \
235   if (profile_flag)                                             \
236     fprintf (FILE, "\t.extern %s\n", RS6000_MCOUNT);            \
237   rs6000_file_start (FILE, TARGET_CPU_DEFAULT);                 \
238 }
239
240 /* Output at end of assembler file.
241
242    On the RS/6000, referencing data should automatically pull in text.  */
243
244 #define ASM_FILE_END(FILE)                                      \
245 {                                                               \
246   text_section ();                                              \
247   fputs ("_section_.text:\n", FILE);                            \
248   data_section ();                                              \
249   fputs (TARGET_32BIT                                           \
250          ? "\t.long _section_.text\n" : "\t.llong _section_.text\n", FILE); \
251 }
252
253 /* This macro produces the initial definition of a function name.
254    On the RS/6000, we need to place an extra '.' in the function name and
255    output the function descriptor.
256
257    The csect for the function will have already been created by the
258    `text_section' call previously done.  We do have to go back to that
259    csect, however.
260
261    We also record that the function exists in the current compilation
262    unit, reachable by short branch, by setting SYMBOL_REF_FLAG.
263
264    The third and fourth parameters to the .function pseudo-op (16 and 044)
265    are placeholders which no longer have any use.  */
266
267 #define ASM_DECLARE_FUNCTION_NAME(FILE,NAME,DECL)               \
268 { rtx sym_ref = XEXP (DECL_RTL (DECL), 0);                      \
269   if ((*targetm.binds_local_p) (DECL))                          \
270     SYMBOL_REF_FLAG (sym_ref) = 1;                              \
271   if (TREE_PUBLIC (DECL))                                       \
272     {                                                           \
273       if (!RS6000_WEAK || !DECL_WEAK (decl))                    \
274         {                                                       \
275           fputs ("\t.globl .", FILE);                           \
276           RS6000_OUTPUT_BASENAME (FILE, NAME);                  \
277           putc ('\n', FILE);                                    \
278         }                                                       \
279     }                                                           \
280   else                                                          \
281     {                                                           \
282       fputs ("\t.lglobl .", FILE);                              \
283       RS6000_OUTPUT_BASENAME (FILE, NAME);                      \
284       putc ('\n', FILE);                                        \
285     }                                                           \
286   fputs ("\t.csect ", FILE);                                    \
287   RS6000_OUTPUT_BASENAME (FILE, NAME);                          \
288   fputs (TARGET_32BIT ? "[DS]\n" : "[DS],3\n", FILE);           \
289   RS6000_OUTPUT_BASENAME (FILE, NAME);                          \
290   fputs (":\n", FILE);                                          \
291   fputs (TARGET_32BIT ? "\t.long ." : "\t.llong .", FILE);      \
292   RS6000_OUTPUT_BASENAME (FILE, NAME);                          \
293   fputs (", TOC[tc0], 0\n", FILE);                              \
294   in_section = no_section;                                      \
295   function_section(DECL);                                       \
296   putc ('.', FILE);                                             \
297   RS6000_OUTPUT_BASENAME (FILE, NAME);                          \
298   fputs (":\n", FILE);                                          \
299   if (write_symbols == XCOFF_DEBUG                              \
300       /* When called before targetm.asm_out.output_mi_thunk,    \
301          we won't be emitting the rest of the debug info that   \
302          goes along with this, leading to assembler errors.  */ \
303       && !(current_function_is_thunk && !no_new_pseudos))       \
304     xcoffout_declare_function (FILE, DECL, NAME);               \
305 }
306
307 /* Output a reference to SYM on FILE.  */
308
309 #define ASM_OUTPUT_SYMBOL_REF(FILE, SYM) \
310   rs6000_output_symbol_ref (FILE, SYM)
311
312 /* This says how to output an external.  */
313
314 #undef ASM_OUTPUT_EXTERNAL
315 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME)                           \
316 { rtx _symref = XEXP (DECL_RTL (DECL), 0);                              \
317   if ((TREE_CODE (DECL) == VAR_DECL                                     \
318        || TREE_CODE (DECL) == FUNCTION_DECL)                            \
319       && (NAME)[strlen (NAME) - 1] != ']')                              \
320     {                                                                   \
321       XSTR (_symref, 0) = concat (XSTR (_symref, 0),                    \
322                                   (TREE_CODE (DECL) == FUNCTION_DECL    \
323                                    ? "[DS]" : "[RW]"),                  \
324                                   NULL);                                \
325     }                                                                   \
326 }
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 (*targetm.asm_out.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); (*targetm.asm_out.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 SKIP_ASM_OP "\t.space "
357
358 #define ASM_OUTPUT_SKIP(FILE,SIZE)  \
359   fprintf (FILE, "%s%u\n", SKIP_ASM_OP, (SIZE))
360
361 /* This says how to output an assembler line
362    to define a global common symbol.  */
363
364 #define COMMON_ASM_OP "\t.comm "
365
366 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN)      \
367   do { fputs (COMMON_ASM_OP, (FILE));                   \
368        RS6000_OUTPUT_BASENAME ((FILE), (NAME));         \
369        if ((ALIGN) > 32)                                \
370          fprintf ((FILE), ",%u,%u\n", (SIZE),           \
371                   exact_log2 ((ALIGN) / BITS_PER_UNIT)); \
372        else if ((SIZE) > 4)                             \
373          fprintf ((FILE), ",%u,3\n", (SIZE));           \
374        else                                             \
375          fprintf ((FILE), ",%u\n", (SIZE));             \
376   } while (0)
377
378 /* This says how to output an assembler line
379    to define a local common symbol.
380    Alignment cannot be specified, but we can try to maintain
381    alignment after preceding TOC section if it was aligned
382    for 64-bit mode.  */
383
384 #define LOCAL_COMMON_ASM_OP "\t.lcomm "
385
386 #define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED)     \
387   do { fputs (LOCAL_COMMON_ASM_OP, (FILE));             \
388        RS6000_OUTPUT_BASENAME ((FILE), (NAME));         \
389        fprintf ((FILE), ",%u,%s\n", (TARGET_32BIT ? (SIZE) : (ROUNDED)), \
390                 xcoff_bss_section_name);                \
391      } while (0)
392
393 /* This is how we tell the assembler that two symbols have the same value.  */
394 #define SET_ASM_OP "\t.set "
395
396 /* This is how we tell the assembler to equate two values.  */
397 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2)                              \
398  do {   fprintf ((FILE), "%s", SET_ASM_OP);                             \
399         RS6000_OUTPUT_BASENAME (FILE, LABEL1);                          \
400         fprintf (FILE, ",");                                            \
401         RS6000_OUTPUT_BASENAME (FILE, LABEL2);                          \
402         fprintf (FILE, "\n");                                           \
403   } while (0)
404
405 /* Used by rs6000_assemble_integer, among others.  */
406 #define DOUBLE_INT_ASM_OP "\t.llong\t"
407
408 /* Output before instructions.  */
409 #define TEXT_SECTION_ASM_OP "\t.csect .text[PR]"
410
411 /* Output before writable data.
412    Align entire section to BIGGEST_ALIGNMENT.  */
413 #define DATA_SECTION_ASM_OP "\t.csect .data[RW],3"
414
415 /* Define the name of the section to use for the EH language specific
416    data areas (.gcc_except_table on most other systems).  */
417 #define TARGET_ASM_EXCEPTION_SECTION data_section
418
419 /* Define to prevent DWARF2 unwind info in the data section rather
420    than in the .eh_frame section.  We do this because the AIX linker
421    would otherwise garbage collect these sections.  */
422 #define EH_FRAME_IN_DATA_SECTION 1