1 /* Definitions of target machine for GNU compiler,
2 for some generic XCOFF file format
3 Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
5 This file is part of GCC.
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.
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.
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. */
22 #define TARGET_OBJECT_FORMAT OBJECT_XCOFF
24 /* The RS/6000 uses the XCOFF format. */
25 #define XCOFF_DEBUGGING_INFO 1
27 /* Define if the object format being used is COFF or a superset. */
28 #define OBJECT_FORMAT_COFF
30 /* Define the magic numbers that we recognize as COFF.
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.
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 \
43 /* We don't have GAS for the RS/6000 yet, so don't write out special
46 #define FASCIST_ASSEMBLER
48 /* We define this to prevent the name mangler from putting dollar signs into
51 #define NO_DOLLAR_IN_LABEL
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
57 #define DOLLARS_IN_IDENTIFIERS 0
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. */
65 #define EXTRA_SECTIONS \
66 read_only_data, private_data, read_only_private_data, toc, bss
68 /* Define the routines to implement these extra sections.
69 BIGGEST_ALIGNMENT is 64, so align the sections that much. */
71 #define EXTRA_SECTION_FUNCTIONS \
74 read_only_data_section () \
76 if (in_section != read_only_data) \
78 fprintf (asm_out_file, "\t.csect %s[RO],3\n", \
79 xcoff_read_only_section_name); \
80 in_section = read_only_data; \
85 private_data_section () \
87 if (in_section != private_data) \
89 fprintf (asm_out_file, "\t.csect %s[RW],3\n", \
90 xcoff_private_data_section_name); \
91 in_section = private_data; \
96 read_only_private_data_section () \
98 if (in_section != read_only_private_data) \
100 fprintf (asm_out_file, "\t.csect %s[RO],3\n", \
101 xcoff_private_data_section_name); \
102 in_section = read_only_private_data; \
109 if (TARGET_MINIMAL_TOC) \
111 /* toc_section is always called at least once from ASM_FILE_START, \
112 so this is guaranteed to always be defined once and only once \
114 if (! toc_initialized) \
116 fputs ("\t.toc\nLCTOC..1:\n", asm_out_file); \
117 fputs ("\t.tc toc_table[TC],toc_table[RW]\n", asm_out_file); \
118 toc_initialized = 1; \
121 if (in_section != toc) \
122 fprintf (asm_out_file, "\t.csect toc_table[RW]%s\n", \
123 (TARGET_32BIT ? "" : ",3")); \
127 if (in_section != toc) \
128 fputs ("\t.toc\n", asm_out_file); \
133 /* Define the name of our readonly data section. */
135 #define READONLY_DATA_SECTION read_only_data_section
137 /* Return nonzero if this entry is to be written into the constant
138 pool in a special way. We do so if this is a SYMBOL_REF, LABEL_REF
139 or a CONST containing one of them. If -mfp-in-toc (the default),
140 we also do this for floating-point constants. We actually can only
141 do this if the FP formats of the target and host machines are the
142 same, but we can't check that since not every file that uses
143 GO_IF_LEGITIMATE_ADDRESS_P includes real.h. We also do this when
144 we can write the entry into the TOC and the entry is not larger
147 #define ASM_OUTPUT_SPECIAL_POOL_ENTRY_P(X, MODE) \
149 && (GET_CODE (X) == SYMBOL_REF \
150 || (GET_CODE (X) == CONST && GET_CODE (XEXP (X, 0)) == PLUS \
151 && GET_CODE (XEXP (XEXP (X, 0), 0)) == SYMBOL_REF) \
152 || GET_CODE (X) == LABEL_REF \
153 || (GET_CODE (X) == CONST_INT \
154 && GET_MODE_BITSIZE (MODE) <= GET_MODE_BITSIZE (Pmode)) \
155 || (GET_CODE (X) == CONST_DOUBLE \
156 && (TARGET_POWERPC64 \
157 || TARGET_MINIMAL_TOC \
158 || (GET_MODE_CLASS (GET_MODE (X)) == MODE_FLOAT \
159 && ! TARGET_NO_FP_IN_TOC)))))
161 #define TARGET_ASM_GLOBALIZE_LABEL rs6000_xcoff_asm_globalize_label
162 #define TARGET_ASM_NAMED_SECTION rs6000_xcoff_asm_named_section
163 #define TARGET_ASM_SELECT_SECTION rs6000_xcoff_select_section
164 #define TARGET_ASM_SELECT_RTX_SECTION rs6000_xcoff_select_rtx_section
165 #define TARGET_ASM_UNIQUE_SECTION rs6000_xcoff_unique_section
166 #define TARGET_STRIP_NAME_ENCODING rs6000_xcoff_strip_name_encoding
167 #define TARGET_SECTION_TYPE_FLAGS rs6000_xcoff_section_type_flags
169 /* FP save and restore routines. */
170 #define SAVE_FP_PREFIX "._savef"
171 #define SAVE_FP_SUFFIX ""
172 #define RESTORE_FP_PREFIX "._restf"
173 #define RESTORE_FP_SUFFIX ""
175 /* Function name to call to do profiling. */
177 #define RS6000_MCOUNT ".__mcount"
179 /* Function names to call to do floating point truncation. */
182 #define RS6000_ITRUNC "__itrunc"
183 #undef RS6000_UITRUNC
184 #define RS6000_UITRUNC "__uitrunc"
186 /* This outputs NAME to FILE up to the first null or '['. */
188 #define RS6000_OUTPUT_BASENAME(FILE, NAME) \
189 assemble_name ((FILE), (*targetm.strip_name_encoding) (NAME))
191 /* This is how to output the definition of a user-level label named NAME,
192 such as the label on a static function or variable NAME. */
194 #define ASM_OUTPUT_LABEL(FILE,NAME) \
195 do { RS6000_OUTPUT_BASENAME (FILE, NAME); fputs (":\n", FILE); } while (0)
197 /* This is how to output a command to make the user-level label named NAME
198 defined for reference from other files. */
200 /* Globalizing directive for a label. */
201 #define GLOBAL_ASM_OP "\t.globl "
203 /* Output at beginning of assembler file.
205 Initialize the section names for the RS/6000 at this point.
207 Specify filename, including full path, to assembler.
209 We want to go into the TOC section so at least one .toc will be emitted.
210 Also, in order to output proper .bs/.es pairs, we need at least one static
211 [RW] section emitted.
213 Finally, declare mcount when profiling to make the assembler happy. */
215 #define ASM_FILE_START(FILE) \
217 rs6000_gen_section_name (&xcoff_bss_section_name, \
218 main_input_filename, ".bss_"); \
219 rs6000_gen_section_name (&xcoff_private_data_section_name, \
220 main_input_filename, ".rw_"); \
221 rs6000_gen_section_name (&xcoff_read_only_section_name, \
222 main_input_filename, ".ro_"); \
224 fputs ("\t.file\t", FILE); \
225 output_quoted_string (FILE, main_input_filename); \
226 fputc ('\n', FILE); \
228 if (write_symbols != NO_DEBUG) \
229 private_data_section (); \
232 fprintf (FILE, "\t.extern %s\n", RS6000_MCOUNT); \
233 rs6000_file_start (FILE, TARGET_CPU_DEFAULT); \
236 /* Output at end of assembler file.
238 On the RS/6000, referencing data should automatically pull in text. */
240 #define ASM_FILE_END(FILE) \
243 fputs ("_section_.text:\n", FILE); \
245 fputs (TARGET_32BIT \
246 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n", FILE); \
249 /* This macro produces the initial definition of a function name.
250 On the RS/6000, we need to place an extra '.' in the function name and
251 output the function descriptor.
253 The csect for the function will have already been created by the
254 `text_section' call previously done. We do have to go back to that
257 The third and fourth parameters to the .function pseudo-op (16 and 044)
258 are placeholders which no longer have any use. */
260 #define ASM_DECLARE_FUNCTION_NAME(FILE,NAME,DECL) \
261 { rtx sym_ref = XEXP (DECL_RTL (DECL), 0); \
262 if (TREE_PUBLIC (DECL)) \
264 if (!RS6000_WEAK || !DECL_WEAK (decl)) \
266 fputs ("\t.globl .", FILE); \
267 RS6000_OUTPUT_BASENAME (FILE, NAME); \
273 fputs ("\t.lglobl .", FILE); \
274 RS6000_OUTPUT_BASENAME (FILE, NAME); \
277 fputs ("\t.csect ", FILE); \
278 RS6000_OUTPUT_BASENAME (FILE, NAME); \
279 fputs (TARGET_32BIT ? "[DS]\n" : "[DS],3\n", FILE); \
280 RS6000_OUTPUT_BASENAME (FILE, NAME); \
281 fputs (":\n", FILE); \
282 fputs (TARGET_32BIT ? "\t.long ." : "\t.llong .", FILE); \
283 RS6000_OUTPUT_BASENAME (FILE, NAME); \
284 fputs (", TOC[tc0], 0\n", FILE); \
285 in_section = no_section; \
286 function_section(DECL); \
288 RS6000_OUTPUT_BASENAME (FILE, NAME); \
289 fputs (":\n", FILE); \
290 if (write_symbols != NO_DEBUG) \
291 xcoffout_declare_function (FILE, DECL, NAME); \
294 /* Output a reference to SYM on FILE. */
296 #define ASM_OUTPUT_SYMBOL_REF(FILE, SYM) \
297 rs6000_output_symbol_ref (FILE, SYM)
299 /* This says how to output an external. */
301 #undef ASM_OUTPUT_EXTERNAL
302 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \
303 { rtx _symref = XEXP (DECL_RTL (DECL), 0); \
304 if ((TREE_CODE (DECL) == VAR_DECL \
305 || TREE_CODE (DECL) == FUNCTION_DECL) \
306 && (NAME)[strlen (NAME) - 1] != ']') \
308 XSTR (_symref, 0) = concat (XSTR (_symref, 0), \
309 (TREE_CODE (DECL) == FUNCTION_DECL \
310 ? "[DS]" : "[RW]"), \
315 /* This is how to output an internal label prefix. rs6000.c uses this
316 when generating traceback tables. */
318 #define ASM_OUTPUT_INTERNAL_LABEL_PREFIX(FILE,PREFIX) \
319 fprintf (FILE, "%s..", PREFIX)
321 /* This is how to output a label for a jump table. Arguments are the same as
322 for (*targetm.asm_out.internal_label), except the insn for the jump table is
325 #define ASM_OUTPUT_CASE_LABEL(FILE,PREFIX,NUM,TABLEINSN) \
326 { ASM_OUTPUT_ALIGN (FILE, 2); (*targetm.asm_out.internal_label) (FILE, PREFIX, NUM); }
328 /* This is how to store into the string LABEL
329 the symbol_ref name of an internal numbered label where
330 PREFIX is the class of label and NUM is the number within the class.
331 This is suitable for output with `assemble_name'. */
333 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \
334 sprintf (LABEL, "*%s..%u", (PREFIX), (unsigned) (NUM))
336 /* This is how to output an assembler line to define N characters starting
339 #define ASM_OUTPUT_ASCII(FILE, P, N) output_ascii ((FILE), (P), (N))
341 /* This is how to advance the location counter by SIZE bytes. */
343 #define SKIP_ASM_OP "\t.space "
345 #define ASM_OUTPUT_SKIP(FILE,SIZE) \
346 fprintf (FILE, "%s"HOST_WIDE_INT_PRINT_UNSIGNED"\n", SKIP_ASM_OP, (SIZE))
348 /* This says how to output an assembler line
349 to define a global common symbol. */
351 #define COMMON_ASM_OP "\t.comm "
353 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \
354 do { fputs (COMMON_ASM_OP, (FILE)); \
355 RS6000_OUTPUT_BASENAME ((FILE), (NAME)); \
357 fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n", (SIZE), \
358 exact_log2 ((ALIGN) / BITS_PER_UNIT)); \
359 else if ((SIZE) > 4) \
360 fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",3\n", (SIZE)); \
362 fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED"\n", (SIZE)); \
365 /* This says how to output an assembler line
366 to define a local common symbol.
367 Alignment cannot be specified, but we can try to maintain
368 alignment after preceding TOC section if it was aligned
371 #define LOCAL_COMMON_ASM_OP "\t.lcomm "
373 #define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED) \
374 do { fputs (LOCAL_COMMON_ASM_OP, (FILE)); \
375 RS6000_OUTPUT_BASENAME ((FILE), (NAME)); \
376 fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%s\n", \
377 (TARGET_32BIT ? (SIZE) : (ROUNDED)), \
378 xcoff_bss_section_name); \
381 /* This is how we tell the assembler that two symbols have the same value. */
382 #define SET_ASM_OP "\t.set "
384 /* This is how we tell the assembler to equate two values. */
385 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \
386 do { fprintf ((FILE), "%s", SET_ASM_OP); \
387 RS6000_OUTPUT_BASENAME (FILE, LABEL1); \
388 fprintf (FILE, ","); \
389 RS6000_OUTPUT_BASENAME (FILE, LABEL2); \
390 fprintf (FILE, "\n"); \
393 /* Used by rs6000_assemble_integer, among others. */
394 #define DOUBLE_INT_ASM_OP "\t.llong\t"
396 /* Output before instructions. */
397 #define TEXT_SECTION_ASM_OP "\t.csect .text[PR]"
399 /* Output before writable data.
400 Align entire section to BIGGEST_ALIGNMENT. */
401 #define DATA_SECTION_ASM_OP "\t.csect .data[RW],3"
403 /* Define the name of the section to use for the EH language specific
404 data areas (.gcc_except_table on most other systems). */
405 #define TARGET_ASM_EXCEPTION_SECTION data_section
407 /* Define to prevent DWARF2 unwind info in the data section rather
408 than in the .eh_frame section. We do this because the AIX linker
409 would otherwise garbage collect these sections. */
410 #define EH_FRAME_IN_DATA_SECTION 1