FSF GCC merge 02/23/03
[official-gcc.git] / gcc / config / rs6000 / xcoff.h
blob890e30d7da3d279c2fd98093479502c3d2f8a329
1 /* Definitions of target machine for GNU compiler,
2 for some generic XCOFF file format
3 Copyright (C) 2001, 2002 Free Software Foundation, Inc.
5 This file is part of GNU CC.
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.
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.
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. */
23 #define TARGET_OBJECT_FORMAT OBJECT_XCOFF
25 /* The RS/6000 uses the XCOFF format. */
26 #define XCOFF_DEBUGGING_INFO 1
28 /* Define if the object format being used is COFF or a superset. */
29 #define OBJECT_FORMAT_COFF
31 /* Define the magic numbers that we recognize as COFF.
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.
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)
44 /* We don't have GAS for the RS/6000 yet, so don't write out special
45 .stabs in cc1plus. */
47 #define FASCIST_ASSEMBLER
49 /* We define this to prevent the name mangler from putting dollar signs into
50 function names. */
52 #define NO_DOLLAR_IN_LABEL
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. */
58 #define DOLLARS_IN_IDENTIFIERS 0
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. */
66 #define EXTRA_SECTIONS \
67 read_only_data, private_data, read_only_private_data, toc, bss
69 /* Define the routines to implement these extra sections.
70 BIGGEST_ALIGNMENT is 64, so align the sections that much. */
72 #define EXTRA_SECTION_FUNCTIONS \
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 } \
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 } \
96 void \
97 read_only_private_data_section () \
98 { \
99 if (in_section != read_only_private_data) \
101 fprintf (asm_out_file, "\t.csect %s[RO],3\n", \
102 xcoff_private_data_section_name); \
103 in_section = read_only_private_data; \
107 void \
108 toc_section () \
110 if (TARGET_MINIMAL_TOC) \
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) \
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; \
122 if (in_section != toc) \
123 fprintf (asm_out_file, "\t.csect toc_table[RW]%s\n", \
124 (TARGET_32BIT ? "" : ",3")); \
126 else \
128 if (in_section != toc) \
129 fputs ("\t.toc\n", asm_out_file); \
131 in_section = toc; \
134 /* Define the name of our readonly data section. */
136 #define READONLY_DATA_SECTION read_only_data_section
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. */
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)))))
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
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 ""
177 /* Function name to call to do profiling. */
178 #undef RS6000_MCOUNT
179 #define RS6000_MCOUNT ".__mcount"
181 /* Function names to call to do floating point truncation. */
183 #undef RS6000_ITRUNC
184 #define RS6000_ITRUNC "__itrunc"
185 #undef RS6000_UITRUNC
186 #define RS6000_UITRUNC "__uitrunc"
188 /* This outputs NAME to FILE up to the first null or '['. */
190 #define RS6000_OUTPUT_BASENAME(FILE, NAME) \
191 assemble_name ((FILE), (*targetm.strip_name_encoding) (NAME))
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. */
196 #define ASM_OUTPUT_LABEL(FILE,NAME) \
197 do { RS6000_OUTPUT_BASENAME (FILE, NAME); fputs (":\n", FILE); } while (0)
199 /* This is how to output a command to make the user-level label named NAME
200 defined for reference from other files. */
202 /* Globalizing directive for a label. */
203 #define GLOBAL_ASM_OP "\t.globl "
205 /* Output at beginning of assembler file.
207 Initialize the section names for the RS/6000 at this point.
209 Specify filename, including full path, to assembler.
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.
215 Finally, declare mcount when profiling to make the assembler happy. */
217 #define ASM_FILE_START(FILE) \
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_"); \
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); \
240 /* Output at end of assembler file.
242 On the RS/6000, referencing data should automatically pull in text. */
244 #define ASM_FILE_END(FILE) \
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); \
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.
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.
261 We also record that the function exists in the current compilation
262 unit, reachable by short branch, by setting SYMBOL_REF_FLAG.
264 The third and fourth parameters to the .function pseudo-op (16 and 044)
265 are placeholders which no longer have any use. */
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)) \
273 if (!RS6000_WEAK || !DECL_WEAK (decl)) \
275 fputs ("\t.globl .", FILE); \
276 RS6000_OUTPUT_BASENAME (FILE, NAME); \
277 putc ('\n', FILE); \
280 else \
282 fputs ("\t.lglobl .", FILE); \
283 RS6000_OUTPUT_BASENAME (FILE, NAME); \
284 putc ('\n', FILE); \
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 != NO_DEBUG) \
300 xcoffout_declare_function (FILE, DECL, NAME); \
303 /* Output a reference to SYM on FILE. */
305 #define ASM_OUTPUT_SYMBOL_REF(FILE, SYM) \
306 rs6000_output_symbol_ref (FILE, SYM)
308 /* This says how to output an external. */
310 #undef ASM_OUTPUT_EXTERNAL
311 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \
312 { rtx _symref = XEXP (DECL_RTL (DECL), 0); \
313 if ((TREE_CODE (DECL) == VAR_DECL \
314 || TREE_CODE (DECL) == FUNCTION_DECL) \
315 && (NAME)[strlen (NAME) - 1] != ']') \
317 XSTR (_symref, 0) = concat (XSTR (_symref, 0), \
318 (TREE_CODE (DECL) == FUNCTION_DECL \
319 ? "[DS]" : "[RW]"), \
320 NULL); \
324 /* This is how to output an internal label prefix. rs6000.c uses this
325 when generating traceback tables. */
327 #define ASM_OUTPUT_INTERNAL_LABEL_PREFIX(FILE,PREFIX) \
328 fprintf (FILE, "%s..", PREFIX)
330 /* This is how to output a label for a jump table. Arguments are the same as
331 for (*targetm.asm_out.internal_label), except the insn for the jump table is
332 passed. */
334 #define ASM_OUTPUT_CASE_LABEL(FILE,PREFIX,NUM,TABLEINSN) \
335 { ASM_OUTPUT_ALIGN (FILE, 2); (*targetm.asm_out.internal_label) (FILE, PREFIX, NUM); }
337 /* This is how to store into the string LABEL
338 the symbol_ref name of an internal numbered label where
339 PREFIX is the class of label and NUM is the number within the class.
340 This is suitable for output with `assemble_name'. */
342 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \
343 sprintf (LABEL, "*%s..%u", (PREFIX), (unsigned) (NUM))
345 /* This is how to output an assembler line to define N characters starting
346 at P to FILE. */
348 #define ASM_OUTPUT_ASCII(FILE, P, N) output_ascii ((FILE), (P), (N))
350 /* This is how to advance the location counter by SIZE bytes. */
352 #define SKIP_ASM_OP "\t.space "
354 #define ASM_OUTPUT_SKIP(FILE,SIZE) \
355 fprintf (FILE, "%s%u\n", SKIP_ASM_OP, (SIZE))
357 /* This says how to output an assembler line
358 to define a global common symbol. */
360 #define COMMON_ASM_OP "\t.comm "
362 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \
363 do { fputs (COMMON_ASM_OP, (FILE)); \
364 RS6000_OUTPUT_BASENAME ((FILE), (NAME)); \
365 if ((ALIGN) > 32) \
366 fprintf ((FILE), ",%u,%u\n", (SIZE), \
367 exact_log2 ((ALIGN) / BITS_PER_UNIT)); \
368 else if ((SIZE) > 4) \
369 fprintf ((FILE), ",%u,3\n", (SIZE)); \
370 else \
371 fprintf ((FILE), ",%u\n", (SIZE)); \
372 } while (0)
374 /* This says how to output an assembler line
375 to define a local common symbol.
376 Alignment cannot be specified, but we can try to maintain
377 alignment after preceding TOC section if it was aligned
378 for 64-bit mode. */
380 #define LOCAL_COMMON_ASM_OP "\t.lcomm "
382 #define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED) \
383 do { fputs (LOCAL_COMMON_ASM_OP, (FILE)); \
384 RS6000_OUTPUT_BASENAME ((FILE), (NAME)); \
385 fprintf ((FILE), ",%u,%s\n", (TARGET_32BIT ? (SIZE) : (ROUNDED)), \
386 xcoff_bss_section_name); \
387 } while (0)
389 /* This is how we tell the assembler that two symbols have the same value. */
390 #define SET_ASM_OP "\t.set "
392 /* This is how we tell the assembler to equate two values. */
393 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \
394 do { fprintf ((FILE), "%s", SET_ASM_OP); \
395 RS6000_OUTPUT_BASENAME (FILE, LABEL1); \
396 fprintf (FILE, ","); \
397 RS6000_OUTPUT_BASENAME (FILE, LABEL2); \
398 fprintf (FILE, "\n"); \
399 } while (0)
401 /* Used by rs6000_assemble_integer, among others. */
402 #define DOUBLE_INT_ASM_OP "\t.llong\t"
404 /* Output before instructions. */
405 #define TEXT_SECTION_ASM_OP "\t.csect .text[PR]"
407 /* Output before writable data.
408 Align entire section to BIGGEST_ALIGNMENT. */
409 #define DATA_SECTION_ASM_OP "\t.csect .data[RW],3"
411 /* Define the name of the section to use for the EH language specific
412 data areas (.gcc_except_table on most other systems). */
413 #define TARGET_ASM_EXCEPTION_SECTION data_section
415 /* Define to prevent DWARF2 unwind info in the data section rather
416 than in the .eh_frame section. We do this because the AIX linker
417 would otherwise garbage collect these sections. */
418 #define EH_FRAME_IN_DATA_SECTION 1