OSDN Git Service

9fcedf8de5cda67690124d0d843668594cf11400
[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
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 /* Select the section for an initialized data object.
139
140    On the RS/6000, we have a special section for all variables except those
141    that are static.  */
142
143 #define SELECT_SECTION(EXP,RELOC,ALIGN)                 \
144 {                                                       \
145   if ((TREE_CODE (EXP) == STRING_CST                    \
146        && ! flag_writable_strings)                      \
147       || (TREE_CODE_CLASS (TREE_CODE (EXP)) == 'd'      \
148           && TREE_READONLY (EXP) && ! TREE_THIS_VOLATILE (EXP) \
149           && DECL_INITIAL (EXP)                         \
150           && (DECL_INITIAL (EXP) == error_mark_node     \
151               || TREE_CONSTANT (DECL_INITIAL (EXP)))    \
152           && ! (RELOC)))                                \
153     {                                                   \
154       if (TREE_PUBLIC (EXP))                            \
155         read_only_data_section ();                      \
156       else                                              \
157         read_only_private_data_section ();              \
158     }                                                   \
159   else                                                  \
160     {                                                   \
161       if (TREE_PUBLIC (EXP))                            \
162         data_section ();                                \
163       else                                              \
164         private_data_section ();                        \
165     }                                                   \
166 }
167
168 /* Return non-zero if this entry is to be written into the constant
169    pool in a special way.  We do so if this is a SYMBOL_REF, LABEL_REF
170    or a CONST containing one of them.  If -mfp-in-toc (the default),
171    we also do this for floating-point constants.  We actually can only
172    do this if the FP formats of the target and host machines are the
173    same, but we can't check that since not every file that uses
174    GO_IF_LEGITIMATE_ADDRESS_P includes real.h.  We also do this when
175    we can write the entry into the TOC and the entry is not larger
176    than a TOC entry.  */
177
178 #define ASM_OUTPUT_SPECIAL_POOL_ENTRY_P(X, MODE)                        \
179   (TARGET_TOC                                                           \
180    && (GET_CODE (X) == SYMBOL_REF                                       \
181        || (GET_CODE (X) == CONST && GET_CODE (XEXP (X, 0)) == PLUS      \
182            && GET_CODE (XEXP (XEXP (X, 0), 0)) == SYMBOL_REF)           \
183        || GET_CODE (X) == LABEL_REF                                     \
184        || (GET_CODE (X) == CONST_INT                                    \
185            && GET_MODE_BITSIZE (MODE) <= GET_MODE_BITSIZE (Pmode))      \
186        || (GET_CODE (X) == CONST_DOUBLE                                 \
187            && (TARGET_POWERPC64                                         \
188                || TARGET_MINIMAL_TOC                                    \
189                || (GET_MODE_CLASS (GET_MODE (X)) == MODE_FLOAT          \
190                    && ! TARGET_NO_FP_IN_TOC)))))
191
192 /* Select section for constant in constant pool.
193
194    On RS/6000, all constants are in the private read-only data area.
195    However, if this is being placed in the TOC it must be output as a
196    toc entry.  */
197
198 #define SELECT_RTX_SECTION(MODE, X, ALIGN)              \
199 { if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (X, MODE))        \
200     toc_section ();                                     \
201   else                                                  \
202     read_only_private_data_section ();                  \
203 }
204
205 /* If we are referencing a function that is static or is known to be
206    in this file, make the SYMBOL_REF special.  We can use this to indicate
207    that we can branch to this function without emitting a no-op after the
208    call.  Do not set this flag if the function is weakly defined.  */
209
210 #define ENCODE_SECTION_INFO(DECL, FIRST)                \
211   if (TREE_CODE (DECL) == FUNCTION_DECL                 \
212       && !TREE_PUBLIC (DECL)                            \
213       && !DECL_WEAK (DECL))                             \
214     SYMBOL_REF_FLAG (XEXP (DECL_RTL (DECL), 0)) = 1;
215
216 /* FP save and restore routines.  */
217 #define SAVE_FP_PREFIX "._savef"
218 #define SAVE_FP_SUFFIX ""
219 #define RESTORE_FP_PREFIX "._restf"
220 #define RESTORE_FP_SUFFIX ""
221
222 /* Function name to call to do profiling.  */
223 #undef RS6000_MCOUNT
224 #define RS6000_MCOUNT ".__mcount"
225
226 /* Function names to call to do floating point truncation.  */
227
228 #undef RS6000_ITRUNC
229 #define RS6000_ITRUNC "__itrunc"
230 #undef RS6000_UITRUNC
231 #define RS6000_UITRUNC "__uitrunc"
232
233 /* This outputs NAME to FILE up to the first null or '['.  */
234
235 #define RS6000_OUTPUT_BASENAME(FILE, NAME)      \
236   {                                             \
237     const char *_p;                             \
238                                                 \
239     STRIP_NAME_ENCODING (_p, (NAME));           \
240     assemble_name ((FILE), _p);                 \
241   }
242
243 /* This is how to output the definition of a user-level label named NAME,
244    such as the label on a static function or variable NAME.  */
245
246 #define ASM_OUTPUT_LABEL(FILE,NAME)     \
247   do { RS6000_OUTPUT_BASENAME (FILE, NAME); fputs (":\n", FILE); } while (0)
248
249 /* This is how to output a command to make the user-level label named NAME
250    defined for reference from other files.  */
251
252 #define ASM_GLOBALIZE_LABEL(FILE,NAME)  \
253   do { fputs ("\t.globl ", FILE);       \
254        RS6000_OUTPUT_BASENAME (FILE, NAME); putc ('\n', FILE);} while (0)
255
256 /* Remove any trailing [DS] or the like from the symbol name.  */
257
258 #define STRIP_NAME_ENCODING(VAR,NAME)                   \
259   do                                                    \
260     {                                                   \
261       const char *_name = (NAME);                       \
262       size_t _len;                                      \
263       if (*_name == '*')                                \
264         _name++;                                        \
265       _len = strlen (_name);                            \
266       if (_name[_len - 1] != ']')                       \
267         (VAR) = _name;                                  \
268       else                                              \
269         {                                               \
270           char *_new_name = (char *) alloca (_len + 1); \
271           strcpy (_new_name, _name);                    \
272           _new_name[_len - 4] = '\0';                   \
273           (VAR) = _new_name;                            \
274         }                                               \
275     }                                                   \
276   while (0)
277
278 /* Output at beginning of assembler file.
279
280    Initialize the section names for the RS/6000 at this point.
281
282    Specify filename, including full path, to assembler.
283
284    We want to go into the TOC section so at least one .toc will be emitted.
285    Also, in order to output proper .bs/.es pairs, we need at least one static
286    [RW] section emitted.
287
288    Finally, declare mcount when profiling to make the assembler happy.  */
289
290 #define ASM_FILE_START(FILE)                                    \
291 {                                                               \
292   rs6000_gen_section_name (&xcoff_bss_section_name,             \
293                            main_input_filename, ".bss_");       \
294   rs6000_gen_section_name (&xcoff_private_data_section_name,    \
295                            main_input_filename, ".rw_");        \
296   rs6000_gen_section_name (&xcoff_read_only_section_name,       \
297                            main_input_filename, ".ro_");        \
298                                                                 \
299   fprintf (FILE, "\t.file\t\"%s\"\n", main_input_filename);     \
300   if (TARGET_64BIT)                                             \
301     fputs ("\t.machine\t\"ppc64\"\n", FILE);                    \
302   toc_section ();                                               \
303   if (write_symbols != NO_DEBUG)                                \
304     private_data_section ();                                    \
305   text_section ();                                              \
306   if (profile_flag)                                             \
307     fprintf (FILE, "\t.extern %s\n", RS6000_MCOUNT);            \
308   rs6000_file_start (FILE, TARGET_CPU_DEFAULT);                 \
309 }
310
311 /* Output at end of assembler file.
312
313    On the RS/6000, referencing data should automatically pull in text.  */
314
315 #define ASM_FILE_END(FILE)                                      \
316 {                                                               \
317   text_section ();                                              \
318   fputs ("_section_.text:\n", FILE);                            \
319   data_section ();                                              \
320   fputs (TARGET_32BIT                                           \
321          ? "\t.long _section_.text\n" : "\t.llong _section_.text\n", FILE); \
322 }
323
324 /* This macro produces the initial definition of a function name.
325    On the RS/6000, we need to place an extra '.' in the function name and
326    output the function descriptor.
327
328    The csect for the function will have already been created by the
329    `text_section' call previously done.  We do have to go back to that
330    csect, however.
331
332    We also record that the function exists in the current compilation
333    unit, reachable by short branch, by setting SYMBOL_REF_FLAG.
334
335    The third and fourth parameters to the .function pseudo-op (16 and 044)
336    are placeholders which no longer have any use.  */
337
338 #define ASM_DECLARE_FUNCTION_NAME(FILE,NAME,DECL)               \
339 { rtx sym_ref = XEXP (DECL_RTL (DECL), 0);                      \
340   if (!DECL_WEAK (DECL))                                        \
341     SYMBOL_REF_FLAG (sym_ref) = 1;                              \
342   if (TREE_PUBLIC (DECL))                                       \
343     {                                                           \
344       if (!RS6000_WEAK || !DECL_WEAK (decl))                    \
345         {                                                       \
346           fputs ("\t.globl .", FILE);                           \
347           RS6000_OUTPUT_BASENAME (FILE, NAME);                  \
348           putc ('\n', FILE);                                    \
349         }                                                       \
350     }                                                           \
351   else                                                          \
352     {                                                           \
353       fputs ("\t.lglobl .", FILE);                              \
354       RS6000_OUTPUT_BASENAME (FILE, NAME);                      \
355       putc ('\n', FILE);                                        \
356     }                                                           \
357   fputs ("\t.csect ", FILE);                                    \
358   RS6000_OUTPUT_BASENAME (FILE, NAME);                          \
359   fputs (TARGET_32BIT ? "[DS]\n" : "[DS],3\n", FILE);           \
360   RS6000_OUTPUT_BASENAME (FILE, NAME);                          \
361   fputs (":\n", FILE);                                          \
362   fputs (TARGET_32BIT ? "\t.long ." : "\t.llong .", FILE);      \
363   RS6000_OUTPUT_BASENAME (FILE, NAME);                          \
364   fputs (", TOC[tc0], 0\n", FILE);                              \
365   in_section = no_section;                                      \
366   function_section(DECL);                                       \
367   putc ('.', FILE);                                             \
368   RS6000_OUTPUT_BASENAME (FILE, NAME);                          \
369   fputs (":\n", FILE);                                          \
370   if (write_symbols == XCOFF_DEBUG)                             \
371     xcoffout_declare_function (FILE, DECL, NAME);               \
372 }
373
374 /* Output a reference to SYM on FILE.  */
375
376 #define ASM_OUTPUT_SYMBOL_REF(FILE, SYM) \
377   rs6000_output_symbol_ref (FILE, SYM)
378
379 /* This says how to output an external.  */
380
381 #undef ASM_OUTPUT_EXTERNAL
382 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME)   \
383 { rtx _symref = XEXP (DECL_RTL (DECL), 0);      \
384   if ((TREE_CODE (DECL) == VAR_DECL             \
385        || TREE_CODE (DECL) == FUNCTION_DECL)    \
386       && (NAME)[strlen (NAME) - 1] != ']')      \
387     {                                           \
388       char *_name = (char *) permalloc (strlen (XSTR (_symref, 0)) + 5); \
389       strcpy (_name, XSTR (_symref, 0));        \
390       strcat (_name, TREE_CODE (DECL) == FUNCTION_DECL ? "[DS]" : "[RW]"); \
391       XSTR (_symref, 0) = _name;                \
392     }                                           \
393 }
394
395 /* This is how to output an internal numbered label where
396    PREFIX is the class of label and NUM is the number within the class.  */
397
398 #define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM)      \
399   fprintf (FILE, "%s..%u:\n", (PREFIX), (unsigned) (NUM))
400
401 /* This is how to output an internal label prefix.  rs6000.c uses this
402    when generating traceback tables.  */
403
404 #define ASM_OUTPUT_INTERNAL_LABEL_PREFIX(FILE,PREFIX)   \
405   fprintf (FILE, "%s..", PREFIX)
406
407 /* This is how to output a label for a jump table.  Arguments are the same as
408    for ASM_OUTPUT_INTERNAL_LABEL, except the insn for the jump table is
409    passed.  */
410
411 #define ASM_OUTPUT_CASE_LABEL(FILE,PREFIX,NUM,TABLEINSN)        \
412 { ASM_OUTPUT_ALIGN (FILE, 2); ASM_OUTPUT_INTERNAL_LABEL (FILE, PREFIX, NUM); }
413
414 /* This is how to store into the string LABEL
415    the symbol_ref name of an internal numbered label where
416    PREFIX is the class of label and NUM is the number within the class.
417    This is suitable for output with `assemble_name'.  */
418
419 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM)   \
420   sprintf (LABEL, "*%s..%u", (PREFIX), (unsigned) (NUM))
421
422 /* This is how to output an assembler line to define N characters starting
423    at P to FILE.  */
424
425 #define ASM_OUTPUT_ASCII(FILE, P, N)  output_ascii ((FILE), (P), (N))
426
427 /* This is how to advance the location counter by SIZE bytes.  */
428
429 #define ASM_OUTPUT_SKIP(FILE,SIZE)  \
430   fprintf (FILE, "\t.space %d\n", (SIZE))
431
432 /* This says how to output an assembler line
433    to define a global common symbol.  */
434
435 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGNMENT)  \
436   do { fputs ("\t.comm ", (FILE));                      \
437        RS6000_OUTPUT_BASENAME ((FILE), (NAME));         \
438        if ( (SIZE) > 4)                                 \
439          fprintf ((FILE), ",%d,3\n", (SIZE));           \
440        else                                             \
441          fprintf ((FILE), ",%d\n", (SIZE));             \
442   } while (0)
443
444 /* This says how to output an assembler line
445    to define a local common symbol.
446    Alignment cannot be specified, but we can try to maintain
447    alignment after preceding TOC section if it was aligned
448    for 64-bit mode.  */
449
450 #define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED)     \
451   do { fputs ("\t.lcomm ", (FILE));                     \
452        RS6000_OUTPUT_BASENAME ((FILE), (NAME));         \
453        fprintf ((FILE), ",%d,%s\n", (TARGET_32BIT ? (SIZE) : (ROUNDED)), \
454                 xcoff_bss_section_name);                \
455      } while (0)
456
457 /* This is how we tell the assembler that two symbols have the same value.  */
458 #define SET_ASM_OP "\t.set "
459
460 /* Used by rs6000_assemble_integer, among others.  */
461 #define DOUBLE_INT_ASM_OP "\t.llong\t"
462
463 /* Output before instructions.  */
464 #define TEXT_SECTION_ASM_OP "\t.csect .text[PR]"
465
466 /* Output before writable data.
467    Align entire section to BIGGEST_ALIGNMENT.  */
468 #define DATA_SECTION_ASM_OP "\t.csect .data[RW],3"
469
470 /* Define unique section name -- functions only.  */
471 #define UNIQUE_SECTION(DECL,RELOC)                      \
472   do {                                                  \
473     int len;                                            \
474     const char *name;                                   \
475     char *string;                                       \
476                                                         \
477     if (TREE_CODE (DECL) == FUNCTION_DECL) {            \
478       name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
479       len = strlen (name) + 5;                          \
480       string = alloca (len + 1);                        \
481       sprintf (string, ".%s[PR]", name);                \
482       DECL_SECTION_NAME (DECL) = build_string (len, string); \
483     }                                                   \
484   } while (0)
485
486 /* Switch into a generic section.  */
487 #define TARGET_ASM_NAMED_SECTION  xcoff_asm_named_section
488
489 /* Define the name of the section to use for the EH language specific
490    data areas (.gcc_except_table on most other systems).  */
491 #define TARGET_ASM_EXCEPTION_SECTION data_section
492
493 /* Define to prevent DWARF2 unwind info in the data section rather
494    than in the .eh_frame section.  We do this because the AIX linker
495    would otherwise garbage collect these sections.  */
496 #define EH_FRAME_IN_DATA_SECTION 1