OSDN Git Service

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