OSDN Git Service

* config/rs6000/darwin.h (SUBTARGET_OPTIONS): Move from here, to...
[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, 2003, 2004 Free Software Foundation, Inc.
4
5    This file is part of GCC.
6
7    GCC is free software; you can redistribute it and/or modify it
8    under the terms of the GNU General Public License as published
9    by the Free Software Foundation; either version 2, or (at your
10    option) any later version.
11
12    GCC is distributed in the hope that it will be useful, but WITHOUT
13    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15    License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GCC; see the file COPYING.  If not, write to the
19    Free Software Foundation, 59 Temple Place - Suite 330, Boston,
20    MA 02111-1307, USA.  */
21
22 #define TARGET_OBJECT_FORMAT OBJECT_XCOFF
23
24 /* The RS/6000 uses the XCOFF format.  */
25 #define XCOFF_DEBUGGING_INFO 1
26
27 /* Define if the object format being used is COFF or a superset.  */
28 #define OBJECT_FORMAT_COFF
29
30 /* Define the magic numbers that we recognize as COFF.
31  
32     AIX 4.3 adds U803XTOCMAGIC (0757) for 64-bit objects and AIX V5 adds
33     U64_TOCMAGIC (0767), but collect2.c does not include files in the
34     correct order to conditionally define the symbolic name in this macro.
35  
36     The AIX linker accepts import/export files as object files,
37     so accept "#!" (0x2321) magic number.  */
38 #define MY_ISCOFF(magic) \
39   ((magic) == U802WRMAGIC || (magic) == U802ROMAGIC \
40    || (magic) == U802TOCMAGIC || (magic) == 0757 || (magic) == 0767 \
41    || (magic) == 0x2321)
42
43 /* We don't have GAS for the RS/6000 yet, so don't write out special
44     .stabs in cc1plus.  */
45
46 #define FASCIST_ASSEMBLER
47
48 /* We define this to prevent the name mangler from putting dollar signs into
49    function names.  */
50
51 #define NO_DOLLAR_IN_LABEL
52
53 /* We define this to 0 so that gcc will never accept a dollar sign in a
54    variable name.  This is needed because the AIX assembler will not accept
55    dollar signs.  */
56
57 #define DOLLARS_IN_IDENTIFIERS 0
58
59 /* Define the extra sections we need.  We define three: one is the read-only
60    data section which is used for constants.  This is a csect whose name is
61    derived from the name of the input file.  The second is for initialized
62    global variables.  This is a csect whose name is that of the variable.
63    The third is the TOC.  */
64
65 #define EXTRA_SECTIONS \
66    read_only_data, private_data, read_only_private_data, toc, bss
67
68 /* Define the routines to implement these extra sections.
69    BIGGEST_ALIGNMENT is 64, so align the sections that much.  */
70
71 #define EXTRA_SECTION_FUNCTIONS                         \
72   READ_ONLY_DATA_SECTION_FUNCTION                       \
73   PRIVATE_DATA_SECTION_FUNCTION                         \
74   READ_ONLY_PRIVATE_DATA_SECTION_FUNCTION               \
75   TOC_SECTION_FUNCTION
76
77 #define READ_ONLY_DATA_SECTION_FUNCTION                 \
78 void                                                    \
79 read_only_data_section (void)                           \
80 {                                                       \
81   if (in_section != read_only_data)                     \
82     {                                                   \
83       fprintf (asm_out_file, "\t.csect %s[RO],3\n",     \
84                xcoff_read_only_section_name);           \
85       in_section = read_only_data;                      \
86     }                                                   \
87 }
88
89 #define PRIVATE_DATA_SECTION_FUNCTION                   \
90 void                                                    \
91 private_data_section (void)                             \
92 {                                                       \
93   if (in_section != private_data)                       \
94     {                                                   \
95       fprintf (asm_out_file, "\t.csect %s[RW],3\n",     \
96                xcoff_private_data_section_name);        \
97       in_section = private_data;                        \
98     }                                                   \
99 }
100
101 #define READ_ONLY_PRIVATE_DATA_SECTION_FUNCTION         \
102 void                                                    \
103 read_only_private_data_section (void)                   \
104 {                                                       \
105   if (in_section != read_only_private_data)             \
106     {                                                   \
107       fprintf (asm_out_file, "\t.csect %s[RO],3\n",     \
108                xcoff_private_data_section_name);        \
109       in_section = read_only_private_data;              \
110     }                                                   \
111 }
112
113 #define TOC_SECTION_FUNCTION                            \
114 void                                                    \
115 toc_section (void)                                      \
116 {                                                       \
117   if (TARGET_MINIMAL_TOC)                               \
118     {                                                   \
119       /* toc_section is always called at least once     \
120          from rs6000_xcoff_file_start, so this is       \
121          guaranteed to always be defined once and       \
122          only once in each file.  */                    \
123       if (! toc_initialized)                            \
124         {                                               \
125           fputs ("\t.toc\nLCTOC..1:\n", asm_out_file);  \
126           fputs ("\t.tc toc_table[TC],toc_table[RW]\n", asm_out_file); \
127           toc_initialized = 1;                          \
128         }                                               \
129                                                         \
130       if (in_section != toc)                            \
131         fprintf (asm_out_file, "\t.csect toc_table[RW]%s\n",    \
132                  (TARGET_32BIT ? "" : ",3"));           \
133     }                                                   \
134   else                                                  \
135     {                                                   \
136       if (in_section != toc)                            \
137         fputs ("\t.toc\n", asm_out_file);               \
138     }                                                   \
139   in_section = toc;                                     \
140 }
141
142 /* Define the name of our readonly data section.  */
143
144 #define READONLY_DATA_SECTION read_only_data_section
145
146 /* Return nonzero if this entry is to be written into the constant
147    pool in a special way.  We do so if this is a SYMBOL_REF, LABEL_REF
148    or a CONST containing one of them.  If -mfp-in-toc (the default),
149    we also do this for floating-point constants.  We actually can only
150    do this if the FP formats of the target and host machines are the
151    same, but we can't check that since not every file that uses
152    GO_IF_LEGITIMATE_ADDRESS_P includes real.h.  We also do this when
153    we can write the entry into the TOC and the entry is not larger
154    than a TOC entry.  */
155
156 #define ASM_OUTPUT_SPECIAL_POOL_ENTRY_P(X, MODE)                        \
157   (TARGET_TOC                                                           \
158    && (GET_CODE (X) == SYMBOL_REF                                       \
159        || (GET_CODE (X) == CONST && GET_CODE (XEXP (X, 0)) == PLUS      \
160            && GET_CODE (XEXP (XEXP (X, 0), 0)) == SYMBOL_REF)           \
161        || GET_CODE (X) == LABEL_REF                                     \
162        || (GET_CODE (X) == CONST_INT                                    \
163            && GET_MODE_BITSIZE (MODE) <= GET_MODE_BITSIZE (Pmode))      \
164        || (GET_CODE (X) == CONST_DOUBLE                                 \
165            && (TARGET_POWERPC64                                         \
166                || TARGET_MINIMAL_TOC                                    \
167                || (GET_MODE_CLASS (GET_MODE (X)) == MODE_FLOAT          \
168                    && ! TARGET_NO_FP_IN_TOC)))))
169
170 #define TARGET_ASM_GLOBALIZE_LABEL  rs6000_xcoff_asm_globalize_label
171 #define TARGET_ASM_NAMED_SECTION  rs6000_xcoff_asm_named_section
172 #define TARGET_ASM_SELECT_SECTION  rs6000_xcoff_select_section
173 #define TARGET_ASM_SELECT_RTX_SECTION  rs6000_xcoff_select_rtx_section
174 #define TARGET_ASM_UNIQUE_SECTION  rs6000_xcoff_unique_section
175 #define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
176 #define TARGET_STRIP_NAME_ENCODING  rs6000_xcoff_strip_name_encoding
177 #define TARGET_SECTION_TYPE_FLAGS  rs6000_xcoff_section_type_flags
178
179 /* FP save and restore routines.  */
180 #define SAVE_FP_PREFIX "._savef"
181 #define SAVE_FP_SUFFIX ""
182 #define RESTORE_FP_PREFIX "._restf"
183 #define RESTORE_FP_SUFFIX ""
184
185 /* Function name to call to do profiling.  */
186 #undef  RS6000_MCOUNT
187 #define RS6000_MCOUNT ".__mcount"
188
189 /* This outputs NAME to FILE up to the first null or '['.  */
190
191 #define RS6000_OUTPUT_BASENAME(FILE, NAME) \
192   assemble_name ((FILE), (*targetm.strip_name_encoding) (NAME))
193
194 /* This is how to output the definition of a user-level label named NAME,
195    such as the label on a static function or variable NAME.  */
196
197 #define ASM_OUTPUT_LABEL(FILE,NAME)     \
198   do { RS6000_OUTPUT_BASENAME (FILE, NAME); fputs (":\n", FILE); } while (0)
199
200 /* This is how to output a command to make the user-level label named NAME
201    defined for reference from other files.  */
202
203 /* Globalizing directive for a label.  */
204 #define GLOBAL_ASM_OP "\t.globl "
205
206 #undef TARGET_ASM_FILE_START
207 #define TARGET_ASM_FILE_START rs6000_xcoff_file_start
208 #define TARGET_ASM_FILE_END rs6000_xcoff_file_end
209 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
210 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE false
211
212 /* This macro produces the initial definition of a function name.
213    On the RS/6000, we need to place an extra '.' in the function name and
214    output the function descriptor.
215
216    The csect for the function will have already been created by the
217    `text_section' call previously done.  We do have to go back to that
218    csect, however.
219
220    The third and fourth parameters to the .function pseudo-op (16 and 044)
221    are placeholders which no longer have any use.  */
222
223 #define ASM_DECLARE_FUNCTION_NAME(FILE,NAME,DECL)               \
224 { if (TREE_PUBLIC (DECL))                                       \
225     {                                                           \
226       if (!RS6000_WEAK || !DECL_WEAK (decl))                    \
227         {                                                       \
228           fputs ("\t.globl .", FILE);                           \
229           RS6000_OUTPUT_BASENAME (FILE, NAME);                  \
230           putc ('\n', FILE);                                    \
231         }                                                       \
232     }                                                           \
233   else                                                          \
234     {                                                           \
235       fputs ("\t.lglobl .", FILE);                              \
236       RS6000_OUTPUT_BASENAME (FILE, NAME);                      \
237       putc ('\n', FILE);                                        \
238     }                                                           \
239   fputs ("\t.csect ", FILE);                                    \
240   RS6000_OUTPUT_BASENAME (FILE, NAME);                          \
241   fputs (TARGET_32BIT ? "[DS]\n" : "[DS],3\n", FILE);           \
242   RS6000_OUTPUT_BASENAME (FILE, NAME);                          \
243   fputs (":\n", FILE);                                          \
244   fputs (TARGET_32BIT ? "\t.long ." : "\t.llong .", FILE);      \
245   RS6000_OUTPUT_BASENAME (FILE, NAME);                          \
246   fputs (", TOC[tc0], 0\n", FILE);                              \
247   in_section = no_section;                                      \
248   function_section(DECL);                                       \
249   putc ('.', FILE);                                             \
250   RS6000_OUTPUT_BASENAME (FILE, NAME);                          \
251   fputs (":\n", FILE);                                          \
252   if (write_symbols != NO_DEBUG)                                \
253     xcoffout_declare_function (FILE, DECL, NAME);               \
254 }
255
256 /* Output a reference to SYM on FILE.  */
257
258 #define ASM_OUTPUT_SYMBOL_REF(FILE, SYM) \
259   rs6000_output_symbol_ref (FILE, SYM)
260
261 /* This says how to output an external.  */
262
263 #undef  ASM_OUTPUT_EXTERNAL
264 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME)                           \
265 { rtx _symref = XEXP (DECL_RTL (DECL), 0);                              \
266   if ((TREE_CODE (DECL) == VAR_DECL                                     \
267        || TREE_CODE (DECL) == FUNCTION_DECL)                            \
268       && (NAME)[strlen (NAME) - 1] != ']')                              \
269     {                                                                   \
270       XSTR (_symref, 0) = concat (XSTR (_symref, 0),                    \
271                                   (TREE_CODE (DECL) == FUNCTION_DECL    \
272                                    ? "[DS]" : "[RW]"),                  \
273                                   NULL);                                \
274     }                                                                   \
275 }
276
277 /* This is how to output an internal label prefix.  rs6000.c uses this
278    when generating traceback tables.  */
279
280 #define ASM_OUTPUT_INTERNAL_LABEL_PREFIX(FILE,PREFIX)   \
281   fprintf (FILE, "%s..", PREFIX)
282
283 /* This is how to output a label for a jump table.  Arguments are the same as
284    for (*targetm.asm_out.internal_label), except the insn for the jump table is
285    passed.  */
286
287 #define ASM_OUTPUT_CASE_LABEL(FILE,PREFIX,NUM,TABLEINSN)        \
288 { ASM_OUTPUT_ALIGN (FILE, 2); (*targetm.asm_out.internal_label) (FILE, PREFIX, NUM); }
289
290 /* This is how to store into the string LABEL
291    the symbol_ref name of an internal numbered label where
292    PREFIX is the class of label and NUM is the number within the class.
293    This is suitable for output with `assemble_name'.  */
294
295 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM)   \
296   sprintf (LABEL, "*%s..%u", (PREFIX), (unsigned) (NUM))
297
298 /* This is how to output an assembler line to define N characters starting
299    at P to FILE.  */
300
301 #define ASM_OUTPUT_ASCII(FILE, P, N)  output_ascii ((FILE), (P), (N))
302
303 /* This is how to advance the location counter by SIZE bytes.  */
304
305 #define SKIP_ASM_OP "\t.space "
306
307 #define ASM_OUTPUT_SKIP(FILE,SIZE)  \
308   fprintf (FILE, "%s"HOST_WIDE_INT_PRINT_UNSIGNED"\n", SKIP_ASM_OP, (SIZE))
309
310 /* This says how to output an assembler line
311    to define a global common symbol.  */
312
313 #define COMMON_ASM_OP "\t.comm "
314
315 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN)      \
316   do { fputs (COMMON_ASM_OP, (FILE));                   \
317        RS6000_OUTPUT_BASENAME ((FILE), (NAME));         \
318        if ((ALIGN) > 32)                                \
319          fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n", (SIZE), \
320                   exact_log2 ((ALIGN) / BITS_PER_UNIT)); \
321        else if ((SIZE) > 4)                             \
322          fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",3\n", (SIZE)); \
323        else                                             \
324          fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED"\n", (SIZE)); \
325   } while (0)
326
327 /* This says how to output an assembler line
328    to define a local common symbol.
329    Alignment cannot be specified, but we can try to maintain
330    alignment after preceding TOC section if it was aligned
331    for 64-bit mode.  */
332
333 #define LOCAL_COMMON_ASM_OP "\t.lcomm "
334
335 #define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED)     \
336   do { fputs (LOCAL_COMMON_ASM_OP, (FILE));             \
337        RS6000_OUTPUT_BASENAME ((FILE), (NAME));         \
338        fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%s\n", \
339                 (TARGET_32BIT ? (SIZE) : (ROUNDED)),    \
340                 xcoff_bss_section_name);                \
341      } while (0)
342
343 /* This is how we tell the assembler that two symbols have the same value.  */
344 #define SET_ASM_OP "\t.set "
345
346 /* This is how we tell the assembler to equate two values.  */
347 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2)                              \
348  do {   fprintf ((FILE), "%s", SET_ASM_OP);                             \
349         RS6000_OUTPUT_BASENAME (FILE, LABEL1);                          \
350         fprintf (FILE, ",");                                            \
351         RS6000_OUTPUT_BASENAME (FILE, LABEL2);                          \
352         fprintf (FILE, "\n");                                           \
353   } while (0)
354
355 /* Used by rs6000_assemble_integer, among others.  */
356 #define DOUBLE_INT_ASM_OP "\t.llong\t"
357
358 /* Output before instructions.  */
359 #define TEXT_SECTION_ASM_OP "\t.csect .text[PR]"
360
361 /* Output before writable data.
362    Align entire section to BIGGEST_ALIGNMENT.  */
363 #define DATA_SECTION_ASM_OP "\t.csect .data[RW],3"
364
365 /* Define the name of the section to use for the EH language specific
366    data areas (.gcc_except_table on most other systems).  */
367 #define TARGET_ASM_EXCEPTION_SECTION data_section
368
369 /* Define to prevent DWARF2 unwind info in the data section rather
370    than in the .eh_frame section.  We do this because the AIX linker
371    would otherwise garbage collect these sections.  */
372 #define EH_FRAME_IN_DATA_SECTION 1