* final.c (HAVE_READONLY_DATA_SECTION): New.
[official-gcc.git] / gcc / config / rs6000 / xcoff.h
blobcae5a37e7588ee82e5a30d0bbb8e5b6bc26e673f
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
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 /* Select the section for an initialized data object.
140 On the RS/6000, we have a special section for all variables except those
141 that are static. */
143 #define TARGET_ASM_SELECT_SECTION rs6000_xcoff_select_section
145 /* Return non-zero if this entry is to be written into the constant
146 pool in a special way. We do so if this is a SYMBOL_REF, LABEL_REF
147 or a CONST containing one of them. If -mfp-in-toc (the default),
148 we also do this for floating-point constants. We actually can only
149 do this if the FP formats of the target and host machines are the
150 same, but we can't check that since not every file that uses
151 GO_IF_LEGITIMATE_ADDRESS_P includes real.h. We also do this when
152 we can write the entry into the TOC and the entry is not larger
153 than a TOC entry. */
155 #define ASM_OUTPUT_SPECIAL_POOL_ENTRY_P(X, MODE) \
156 (TARGET_TOC \
157 && (GET_CODE (X) == SYMBOL_REF \
158 || (GET_CODE (X) == CONST && GET_CODE (XEXP (X, 0)) == PLUS \
159 && GET_CODE (XEXP (XEXP (X, 0), 0)) == SYMBOL_REF) \
160 || GET_CODE (X) == LABEL_REF \
161 || (GET_CODE (X) == CONST_INT \
162 && GET_MODE_BITSIZE (MODE) <= GET_MODE_BITSIZE (Pmode)) \
163 || (GET_CODE (X) == CONST_DOUBLE \
164 && (TARGET_POWERPC64 \
165 || TARGET_MINIMAL_TOC \
166 || (GET_MODE_CLASS (GET_MODE (X)) == MODE_FLOAT \
167 && ! TARGET_NO_FP_IN_TOC)))))
169 /* Select section for constant in constant pool.
171 On RS/6000, all constants are in the private read-only data area.
172 However, if this is being placed in the TOC it must be output as a
173 toc entry. */
175 #define SELECT_RTX_SECTION(MODE, X, ALIGN) \
176 { if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (X, MODE)) \
177 toc_section (); \
178 else \
179 read_only_private_data_section (); \
182 /* If we are referencing a function that is static or is known to be
183 in this file, make the SYMBOL_REF special. We can use this to indicate
184 that we can branch to this function without emitting a no-op after the
185 call. Do not set this flag if the function is weakly defined. */
187 #define ENCODE_SECTION_INFO(DECL, FIRST) \
188 if (TREE_CODE (DECL) == FUNCTION_DECL \
189 && !TREE_PUBLIC (DECL) \
190 && !DECL_WEAK (DECL)) \
191 SYMBOL_REF_FLAG (XEXP (DECL_RTL (DECL), 0)) = 1;
193 /* FP save and restore routines. */
194 #define SAVE_FP_PREFIX "._savef"
195 #define SAVE_FP_SUFFIX ""
196 #define RESTORE_FP_PREFIX "._restf"
197 #define RESTORE_FP_SUFFIX ""
199 /* Function name to call to do profiling. */
200 #undef RS6000_MCOUNT
201 #define RS6000_MCOUNT ".__mcount"
203 /* Function names to call to do floating point truncation. */
205 #undef RS6000_ITRUNC
206 #define RS6000_ITRUNC "__itrunc"
207 #undef RS6000_UITRUNC
208 #define RS6000_UITRUNC "__uitrunc"
210 /* This outputs NAME to FILE up to the first null or '['. */
212 #define RS6000_OUTPUT_BASENAME(FILE, NAME) \
214 const char *_p; \
216 STRIP_NAME_ENCODING (_p, (NAME)); \
217 assemble_name ((FILE), _p); \
220 /* This is how to output the definition of a user-level label named NAME,
221 such as the label on a static function or variable NAME. */
223 #define ASM_OUTPUT_LABEL(FILE,NAME) \
224 do { RS6000_OUTPUT_BASENAME (FILE, NAME); fputs (":\n", FILE); } while (0)
226 /* This is how to output a command to make the user-level label named NAME
227 defined for reference from other files. */
229 #define ASM_GLOBALIZE_LABEL(FILE,NAME) \
230 do { fputs ("\t.globl ", FILE); \
231 RS6000_OUTPUT_BASENAME (FILE, NAME); putc ('\n', FILE);} while (0)
233 /* Remove any trailing [DS] or the like from the symbol name. */
235 #define STRIP_NAME_ENCODING(VAR,NAME) \
236 do \
238 const char *_name = (NAME); \
239 size_t _len; \
240 if (*_name == '*') \
241 _name++; \
242 _len = strlen (_name); \
243 if (_name[_len - 1] != ']') \
244 (VAR) = _name; \
245 else \
247 char *_new_name = (char *) alloca (_len + 1); \
248 strcpy (_new_name, _name); \
249 _new_name[_len - 4] = '\0'; \
250 (VAR) = _new_name; \
253 while (0)
255 /* Output at beginning of assembler file.
257 Initialize the section names for the RS/6000 at this point.
259 Specify filename, including full path, to assembler.
261 We want to go into the TOC section so at least one .toc will be emitted.
262 Also, in order to output proper .bs/.es pairs, we need at least one static
263 [RW] section emitted.
265 Finally, declare mcount when profiling to make the assembler happy. */
267 #define ASM_FILE_START(FILE) \
269 rs6000_gen_section_name (&xcoff_bss_section_name, \
270 main_input_filename, ".bss_"); \
271 rs6000_gen_section_name (&xcoff_private_data_section_name, \
272 main_input_filename, ".rw_"); \
273 rs6000_gen_section_name (&xcoff_read_only_section_name, \
274 main_input_filename, ".ro_"); \
276 fprintf (FILE, "\t.file\t\"%s\"\n", main_input_filename); \
277 if (TARGET_64BIT) \
278 fputs ("\t.machine\t\"ppc64\"\n", FILE); \
279 toc_section (); \
280 if (write_symbols != NO_DEBUG) \
281 private_data_section (); \
282 text_section (); \
283 if (profile_flag) \
284 fprintf (FILE, "\t.extern %s\n", RS6000_MCOUNT); \
285 rs6000_file_start (FILE, TARGET_CPU_DEFAULT); \
288 /* Output at end of assembler file.
290 On the RS/6000, referencing data should automatically pull in text. */
292 #define ASM_FILE_END(FILE) \
294 text_section (); \
295 fputs ("_section_.text:\n", FILE); \
296 data_section (); \
297 fputs (TARGET_32BIT \
298 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n", FILE); \
301 /* This macro produces the initial definition of a function name.
302 On the RS/6000, we need to place an extra '.' in the function name and
303 output the function descriptor.
305 The csect for the function will have already been created by the
306 `text_section' call previously done. We do have to go back to that
307 csect, however.
309 We also record that the function exists in the current compilation
310 unit, reachable by short branch, by setting SYMBOL_REF_FLAG.
312 The third and fourth parameters to the .function pseudo-op (16 and 044)
313 are placeholders which no longer have any use. */
315 #define ASM_DECLARE_FUNCTION_NAME(FILE,NAME,DECL) \
316 { rtx sym_ref = XEXP (DECL_RTL (DECL), 0); \
317 if (!DECL_WEAK (DECL)) \
318 SYMBOL_REF_FLAG (sym_ref) = 1; \
319 if (TREE_PUBLIC (DECL)) \
321 if (!RS6000_WEAK || !DECL_WEAK (decl)) \
323 fputs ("\t.globl .", FILE); \
324 RS6000_OUTPUT_BASENAME (FILE, NAME); \
325 putc ('\n', FILE); \
328 else \
330 fputs ("\t.lglobl .", FILE); \
331 RS6000_OUTPUT_BASENAME (FILE, NAME); \
332 putc ('\n', FILE); \
334 fputs ("\t.csect ", FILE); \
335 RS6000_OUTPUT_BASENAME (FILE, NAME); \
336 fputs (TARGET_32BIT ? "[DS]\n" : "[DS],3\n", FILE); \
337 RS6000_OUTPUT_BASENAME (FILE, NAME); \
338 fputs (":\n", FILE); \
339 fputs (TARGET_32BIT ? "\t.long ." : "\t.llong .", FILE); \
340 RS6000_OUTPUT_BASENAME (FILE, NAME); \
341 fputs (", TOC[tc0], 0\n", FILE); \
342 in_section = no_section; \
343 function_section(DECL); \
344 putc ('.', FILE); \
345 RS6000_OUTPUT_BASENAME (FILE, NAME); \
346 fputs (":\n", FILE); \
347 if (write_symbols == XCOFF_DEBUG) \
348 xcoffout_declare_function (FILE, DECL, NAME); \
351 /* Output a reference to SYM on FILE. */
353 #define ASM_OUTPUT_SYMBOL_REF(FILE, SYM) \
354 rs6000_output_symbol_ref (FILE, SYM)
356 /* This says how to output an external. */
358 #undef ASM_OUTPUT_EXTERNAL
359 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \
360 { rtx _symref = XEXP (DECL_RTL (DECL), 0); \
361 if ((TREE_CODE (DECL) == VAR_DECL \
362 || TREE_CODE (DECL) == FUNCTION_DECL) \
363 && (NAME)[strlen (NAME) - 1] != ']') \
365 char *_name = (char *) permalloc (strlen (XSTR (_symref, 0)) + 5); \
366 strcpy (_name, XSTR (_symref, 0)); \
367 strcat (_name, TREE_CODE (DECL) == FUNCTION_DECL ? "[DS]" : "[RW]"); \
368 XSTR (_symref, 0) = _name; \
372 /* This is how to output an internal numbered label where
373 PREFIX is the class of label and NUM is the number within the class. */
375 #define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM) \
376 fprintf (FILE, "%s..%u:\n", (PREFIX), (unsigned) (NUM))
378 /* This is how to output an internal label prefix. rs6000.c uses this
379 when generating traceback tables. */
381 #define ASM_OUTPUT_INTERNAL_LABEL_PREFIX(FILE,PREFIX) \
382 fprintf (FILE, "%s..", PREFIX)
384 /* This is how to output a label for a jump table. Arguments are the same as
385 for ASM_OUTPUT_INTERNAL_LABEL, except the insn for the jump table is
386 passed. */
388 #define ASM_OUTPUT_CASE_LABEL(FILE,PREFIX,NUM,TABLEINSN) \
389 { ASM_OUTPUT_ALIGN (FILE, 2); ASM_OUTPUT_INTERNAL_LABEL (FILE, PREFIX, NUM); }
391 /* This is how to store into the string LABEL
392 the symbol_ref name of an internal numbered label where
393 PREFIX is the class of label and NUM is the number within the class.
394 This is suitable for output with `assemble_name'. */
396 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \
397 sprintf (LABEL, "*%s..%u", (PREFIX), (unsigned) (NUM))
399 /* This is how to output an assembler line to define N characters starting
400 at P to FILE. */
402 #define ASM_OUTPUT_ASCII(FILE, P, N) output_ascii ((FILE), (P), (N))
404 /* This is how to advance the location counter by SIZE bytes. */
406 #define ASM_OUTPUT_SKIP(FILE,SIZE) \
407 fprintf (FILE, "\t.space %d\n", (SIZE))
409 /* This says how to output an assembler line
410 to define a global common symbol. */
412 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGNMENT) \
413 do { fputs ("\t.comm ", (FILE)); \
414 RS6000_OUTPUT_BASENAME ((FILE), (NAME)); \
415 if ( (SIZE) > 4) \
416 fprintf ((FILE), ",%d,3\n", (SIZE)); \
417 else \
418 fprintf ((FILE), ",%d\n", (SIZE)); \
419 } while (0)
421 /* This says how to output an assembler line
422 to define a local common symbol.
423 Alignment cannot be specified, but we can try to maintain
424 alignment after preceding TOC section if it was aligned
425 for 64-bit mode. */
427 #define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED) \
428 do { fputs ("\t.lcomm ", (FILE)); \
429 RS6000_OUTPUT_BASENAME ((FILE), (NAME)); \
430 fprintf ((FILE), ",%d,%s\n", (TARGET_32BIT ? (SIZE) : (ROUNDED)), \
431 xcoff_bss_section_name); \
432 } while (0)
434 /* This is how we tell the assembler that two symbols have the same value. */
435 #define SET_ASM_OP "\t.set "
437 /* Used by rs6000_assemble_integer, among others. */
438 #define DOUBLE_INT_ASM_OP "\t.llong\t"
440 /* Output before instructions. */
441 #define TEXT_SECTION_ASM_OP "\t.csect .text[PR]"
443 /* Output before writable data.
444 Align entire section to BIGGEST_ALIGNMENT. */
445 #define DATA_SECTION_ASM_OP "\t.csect .data[RW],3"
447 /* Define unique section name -- functions only. */
448 #define TARGET_ASM_UNIQUE_SECTION rs6000_xcoff_unique_section
450 /* Switch into a generic section. */
451 #define TARGET_ASM_NAMED_SECTION xcoff_asm_named_section
453 /* Define the name of the section to use for the EH language specific
454 data areas (.gcc_except_table on most other systems). */
455 #define TARGET_ASM_EXCEPTION_SECTION data_section
457 /* Define to prevent DWARF2 unwind info in the data section rather
458 than in the .eh_frame section. We do this because the AIX linker
459 would otherwise garbage collect these sections. */
460 #define EH_FRAME_IN_DATA_SECTION 1