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)
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
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 \
44 /* We don't have GAS for the RS/6000 yet, so don't write out special
47 #define FASCIST_ASSEMBLER
49 /* We define this to prevent the name mangler from putting dollar signs into
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
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 \
75 read_only_data_section () \
77 if (in_section != read_only_data) \
79 fprintf (asm_out_file, "\t.csect %s[RO],3\n", \
80 xcoff_read_only_section_name); \
81 in_section = read_only_data; \
86 private_data_section () \
88 if (in_section != private_data) \
90 fprintf (asm_out_file, "\t.csect %s[RW],3\n", \
91 xcoff_private_data_section_name); \
92 in_section = private_data; \
97 read_only_private_data_section () \
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; \
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 \
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")); \
128 if (in_section != toc) \
129 fputs ("\t.toc\n", asm_out_file); \
134 /* Define the name of our readonly data section. */
136 #define READONLY_DATA_SECTION read_only_data_section
138 /* Select the section for an initialized data object.
140 On the RS/6000, we have a special section for all variables except those
143 #define SELECT_SECTION(EXP,RELOC,ALIGN) \
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))) \
154 if (TREE_PUBLIC (EXP)) \
155 read_only_data_section (); \
157 read_only_private_data_section (); \
161 if (TREE_PUBLIC (EXP)) \
164 private_data_section (); \
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
178 #define ASM_OUTPUT_SPECIAL_POOL_ENTRY_P(X, MODE) \
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)))))
192 /* Select section for constant in constant pool.
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
198 #define SELECT_RTX_SECTION(MODE, X, ALIGN) \
199 { if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (X, MODE)) \
202 read_only_private_data_section (); \
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. */
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;
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 ""
222 /* Function name to call to do profiling. */
224 #define RS6000_MCOUNT ".__mcount"
226 /* Function names to call to do floating point truncation. */
229 #define RS6000_ITRUNC "__itrunc"
230 #undef RS6000_UITRUNC
231 #define RS6000_UITRUNC "__uitrunc"
233 /* This outputs NAME to FILE up to the first null or '['. */
235 #define RS6000_OUTPUT_BASENAME(FILE, NAME) \
239 STRIP_NAME_ENCODING (_p, (NAME)); \
240 assemble_name ((FILE), _p); \
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. */
246 #define ASM_OUTPUT_LABEL(FILE,NAME) \
247 do { RS6000_OUTPUT_BASENAME (FILE, NAME); fputs (":\n", FILE); } while (0)
249 /* This is how to output a command to make the user-level label named NAME
250 defined for reference from other files. */
252 #define ASM_GLOBALIZE_LABEL(FILE,NAME) \
253 do { fputs ("\t.globl ", FILE); \
254 RS6000_OUTPUT_BASENAME (FILE, NAME); putc ('\n', FILE);} while (0)
256 /* Remove any trailing [DS] or the like from the symbol name. */
258 #define STRIP_NAME_ENCODING(VAR,NAME) \
261 const char *_name = (NAME); \
265 _len = strlen (_name); \
266 if (_name[_len - 1] != ']') \
270 char *_new_name = (char *) alloca (_len + 1); \
271 strcpy (_new_name, _name); \
272 _new_name[_len - 4] = '\0'; \
278 /* Output at beginning of assembler file.
280 Initialize the section names for the RS/6000 at this point.
282 Specify filename, including full path, to assembler.
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.
288 Finally, declare mcount when profiling to make the assembler happy. */
290 #define ASM_FILE_START(FILE) \
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_"); \
299 fprintf (FILE, "\t.file\t\"%s\"\n", main_input_filename); \
301 fputs ("\t.machine\t\"ppc64\"\n", FILE); \
303 if (write_symbols != NO_DEBUG) \
304 private_data_section (); \
307 fprintf (FILE, "\t.extern %s\n", RS6000_MCOUNT); \
308 rs6000_file_start (FILE, TARGET_CPU_DEFAULT); \
311 /* Output at end of assembler file.
313 On the RS/6000, referencing data should automatically pull in text. */
315 #define ASM_FILE_END(FILE) \
318 fputs ("_section_.text:\n", FILE); \
320 fputs (TARGET_32BIT \
321 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n", FILE); \
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.
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
332 We also record that the function exists in the current compilation
333 unit, reachable by short branch, by setting SYMBOL_REF_FLAG.
335 The third and fourth parameters to the .function pseudo-op (16 and 044)
336 are placeholders which no longer have any use. */
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)) \
344 if (!RS6000_WEAK || !DECL_WEAK (decl)) \
346 fputs ("\t.globl .", FILE); \
347 RS6000_OUTPUT_BASENAME (FILE, NAME); \
353 fputs ("\t.lglobl .", FILE); \
354 RS6000_OUTPUT_BASENAME (FILE, NAME); \
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); \
368 RS6000_OUTPUT_BASENAME (FILE, NAME); \
369 fputs (":\n", FILE); \
370 if (write_symbols == XCOFF_DEBUG) \
371 xcoffout_declare_function (FILE, DECL, NAME); \
374 /* Output a reference to SYM on FILE. */
376 #define ASM_OUTPUT_SYMBOL_REF(FILE, SYM) \
377 rs6000_output_symbol_ref (FILE, SYM)
379 /* This says how to output an external. */
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] != ']') \
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; \
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. */
398 #define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM) \
399 fprintf (FILE, "%s..%u:\n", (PREFIX), (unsigned) (NUM))
401 /* This is how to output an internal label prefix. rs6000.c uses this
402 when generating traceback tables. */
404 #define ASM_OUTPUT_INTERNAL_LABEL_PREFIX(FILE,PREFIX) \
405 fprintf (FILE, "%s..", PREFIX)
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
411 #define ASM_OUTPUT_CASE_LABEL(FILE,PREFIX,NUM,TABLEINSN) \
412 { ASM_OUTPUT_ALIGN (FILE, 2); ASM_OUTPUT_INTERNAL_LABEL (FILE, PREFIX, NUM); }
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'. */
419 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \
420 sprintf (LABEL, "*%s..%u", (PREFIX), (unsigned) (NUM))
422 /* This is how to output an assembler line to define N characters starting
425 #define ASM_OUTPUT_ASCII(FILE, P, N) output_ascii ((FILE), (P), (N))
427 /* This is how to advance the location counter by SIZE bytes. */
429 #define ASM_OUTPUT_SKIP(FILE,SIZE) \
430 fprintf (FILE, "\t.space %d\n", (SIZE))
432 /* This says how to output an assembler line
433 to define a global common symbol. */
435 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGNMENT) \
436 do { fputs ("\t.comm ", (FILE)); \
437 RS6000_OUTPUT_BASENAME ((FILE), (NAME)); \
439 fprintf ((FILE), ",%d,3\n", (SIZE)); \
441 fprintf ((FILE), ",%d\n", (SIZE)); \
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
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); \
457 /* This is how we tell the assembler that two symbols have the same value. */
458 #define SET_ASM_OP "\t.set "
460 /* Used by rs6000_assemble_integer, among others. */
461 #define DOUBLE_INT_ASM_OP "\t.llong\t"
463 /* Output before instructions. */
464 #define TEXT_SECTION_ASM_OP "\t.csect .text[PR]"
466 /* Output before writable data.
467 Align entire section to BIGGEST_ALIGNMENT. */
468 #define DATA_SECTION_ASM_OP "\t.csect .data[RW],3"
470 /* Define unique section name -- functions only. */
471 #define UNIQUE_SECTION(DECL,RELOC) \
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); \
486 /* Switch into a generic section. */
487 #define TARGET_ASM_NAMED_SECTION xcoff_asm_named_section
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
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