]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/rs6000/aix.h
1 /* Definitions of target machine for GNU compiler,
2 for IBM RS/6000 POWER running AIX.
3 Copyright (C) 2000, 2001 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. */
22 /* Yes! We are AIX! */
23 #define DEFAULT_ABI ABI_AIX
24 #define TARGET_OBJECT_FORMAT OBJECT_XCOFF
26 /* The AIX linker will discard static constructors in object files before
27 collect has a chance to see them, so scan the object files directly. */
28 #define COLLECT_EXPORT_LIST
30 /* The RS/6000 uses the XCOFF format. */
31 #define XCOFF_DEBUGGING_INFO
33 /* Define if the object format being used is COFF or a superset. */
34 #define OBJECT_FORMAT_COFF
36 /* Define the magic numbers that we recognize as COFF.
38 AIX 4.3 adds U803XTOCMAGIC (0757) for 64-bit objects and AIX V5 adds
39 U64_TOCMAGIC (0767), but collect2.c does not include files in the
40 correct order to conditionally define the symbolic name in this macro.
42 The AIX linker accepts import/export files as object files,
43 so accept "#!" (0x2321) magic number. */
44 #define MY_ISCOFF(magic) \
45 ((magic) == U802WRMAGIC || (magic) == U802ROMAGIC \
46 || (magic) == U802TOCMAGIC || (magic) == 0757 || (magic) == 0767 \
49 /* This is the only version of nm that collect2 can work with. */
50 #define REAL_NM_FILE_NAME "/usr/ucb/nm"
52 /* We don't have GAS for the RS/6000 yet, so don't write out special
55 #define FASCIST_ASSEMBLER
57 /* We define this to prevent the name mangler from putting dollar signs into
60 #define NO_DOLLAR_IN_LABEL
62 /* We define this to 0 so that gcc will never accept a dollar sign in a
63 variable name. This is needed because the AIX assembler will not accept
66 #define DOLLARS_IN_IDENTIFIERS 0
68 /* AIX does not have any init/fini or ctor/dtor sections, so create
69 static constructors and destructors as normal functions. */
70 /* #define ASM_OUTPUT_CONSTRUCTOR(file, name) */
71 /* #define ASM_OUTPUT_DESTRUCTOR(file, name) */
73 /* The prefix to add to user-visible assembler symbols. */
74 #define USER_LABEL_PREFIX "."
76 /* Don't turn -B into -L if the argument specifies a relative file name. */
77 #define RELATIVE_PREFIX_NOT_LINKDIR
79 /* Because of the above, we must have gcc search itself to find libgcc.a. */
80 #define LINK_LIBGCC_SPECIAL_1
82 /* Names to predefine in the preprocessor for this target machine. */
83 #define CPP_PREDEFINES "-D_IBMR2 -D_POWER -D_AIX -D_AIX32 -D_LONG_LONG \
84 -Asystem=unix -Asystem=aix -Acpu=rs6000 -Amachine=rs6000"
86 /* Define appropriate architecture macros for preprocessor depending on
89 #define CPP_SPEC "%{posix: -D_POSIX_SOURCE}\
90 %{ansi: -D_ANSI_C_SOURCE}\
93 /* Tell the assembler to assume that all undefined names are external.
95 Don't do this until the fixed IBM assembler is more generally available.
96 When this becomes permanently defined, the ASM_OUTPUT_EXTERNAL,
97 ASM_OUTPUT_EXTERNAL_LIBCALL, and RS6000_OUTPUT_BASENAME macros will no
98 longer be needed. Also, the extern declaration of mcount in ASM_FILE_START
99 will no longer be needed. */
101 /* #define ASM_SPEC "-u %(asm_cpu)" */
103 /* Default location of syscalls.exp under AIX */
104 #ifndef CROSS_COMPILE
105 #define LINK_SYSCALLS_SPEC "-bI:/lib/syscalls.exp"
107 #define LINK_SYSCALLS_SPEC ""
110 /* Default location of libg.exp under AIX */
111 #ifndef CROSS_COMPILE
112 #define LINK_LIBG_SPEC "-bexport:/usr/lib/libg.exp"
114 #define LINK_LIBG_SPEC ""
117 /* Define the options for the binder: Start text at 512, align all segments
118 to 512 bytes, and warn if there is text relocation.
120 The -bhalt:4 option supposedly changes the level at which ld will abort,
121 but it also suppresses warnings about multiply defined symbols and is
122 used by the AIX cc command. So we use it here.
124 -bnodelcsect undoes a poor choice of default relating to multiply-defined
125 csects. See AIX documentation for more information about this.
127 -bM:SRE tells the linker that the output file is Shared REusable. Note
128 that to actually build a shared library you will also need to specify an
129 export list with the -Wl,-bE option. */
131 #define LINK_SPEC "-T512 -H512 %{!r:-btextro} -bhalt:4 -bnodelcsect\
132 %{static:-bnso %(link_syscalls) } \
133 %{!shared:%{g*: %(link_libg) }} %{shared:-bM:SRE}"
135 /* Profiled library versions are used by linking with special directories. */
136 #define LIB_SPEC "%{pg:-L/lib/profiled -L/usr/lib/profiled}\
137 %{p:-L/lib/profiled -L/usr/lib/profiled} %{!shared:%{g*:-lg}} -lc"
139 /* Define the extra sections we need. We define three: one is the read-only
140 data section which is used for constants. This is a csect whose name is
141 derived from the name of the input file. The second is for initialized
142 global variables. This is a csect whose name is that of the variable.
143 The third is the TOC. */
145 #define EXTRA_SECTIONS \
146 read_only_data, private_data, read_only_private_data, toc, bss
148 /* Define the routines to implement these extra sections.
149 BIGGEST_ALIGNMENT is 64, so align the sections that much. */
151 #define EXTRA_SECTION_FUNCTIONS \
154 read_only_data_section () \
156 if (in_section != read_only_data) \
158 fprintf (asm_out_file, "\t.csect %s[RO],3\n", \
159 xcoff_read_only_section_name); \
160 in_section = read_only_data; \
165 private_data_section () \
167 if (in_section != private_data) \
169 fprintf (asm_out_file, "\t.csect %s[RW],3\n", \
170 xcoff_private_data_section_name); \
171 in_section = private_data; \
176 read_only_private_data_section () \
178 if (in_section != read_only_private_data) \
180 fprintf (asm_out_file, "\t.csect %s[RO],3\n", \
181 xcoff_private_data_section_name); \
182 in_section = read_only_private_data; \
189 if (TARGET_MINIMAL_TOC) \
191 /* toc_section is always called at least once from ASM_FILE_START, \
192 so this is guaranteed to always be defined once and only once \
194 if (! toc_initialized) \
196 fputs ("\t.toc\nLCTOC..1:\n", asm_out_file); \
197 fputs ("\t.tc toc_table[TC],toc_table[RW]\n", asm_out_file); \
198 toc_initialized = 1; \
201 if (in_section != toc) \
202 fprintf (asm_out_file, "\t.csect toc_table[RW]%s\n", \
203 (TARGET_32BIT ? "" : ",3")); \
207 if (in_section != toc) \
208 fputs ("\t.toc\n", asm_out_file); \
213 /* Define the name of our readonly data section. */
215 #define READONLY_DATA_SECTION read_only_data_section
217 /* Select the section for an initialized data object.
219 On the RS/6000, we have a special section for all variables except those
222 #define SELECT_SECTION(EXP,RELOC) \
224 if ((TREE_CODE (EXP) == STRING_CST \
225 && ! flag_writable_strings) \
226 || (TREE_CODE_CLASS (TREE_CODE (EXP)) == 'd' \
227 && TREE_READONLY (EXP) && ! TREE_THIS_VOLATILE (EXP) \
228 && DECL_INITIAL (EXP) \
229 && (DECL_INITIAL (EXP) == error_mark_node \
230 || TREE_CONSTANT (DECL_INITIAL (EXP))) \
233 if (TREE_PUBLIC (EXP)) \
234 read_only_data_section (); \
236 read_only_private_data_section (); \
240 if (TREE_PUBLIC (EXP)) \
243 private_data_section (); \
247 /* Return non-zero if this entry is to be written into the constant
248 pool in a special way. We do so if this is a SYMBOL_REF, LABEL_REF
249 or a CONST containing one of them. If -mfp-in-toc (the default),
250 we also do this for floating-point constants. We actually can only
251 do this if the FP formats of the target and host machines are the
252 same, but we can't check that since not every file that uses
253 GO_IF_LEGITIMATE_ADDRESS_P includes real.h. We also do this when
254 we can write the entry into the TOC and the entry is not larger
257 #define ASM_OUTPUT_SPECIAL_POOL_ENTRY_P(X, MODE) \
259 && (GET_CODE (X) == SYMBOL_REF \
260 || (GET_CODE (X) == CONST && GET_CODE (XEXP (X, 0)) == PLUS \
261 && GET_CODE (XEXP (XEXP (X, 0), 0)) == SYMBOL_REF) \
262 || GET_CODE (X) == LABEL_REF \
263 || (GET_CODE (X) == CONST_INT \
264 && GET_MODE_BITSIZE (MODE) <= GET_MODE_BITSIZE (Pmode)) \
265 || (GET_CODE (X) == CONST_DOUBLE \
266 && (TARGET_POWERPC64 \
267 || TARGET_MINIMAL_TOC \
268 || (GET_MODE_CLASS (GET_MODE (X)) == MODE_FLOAT \
269 && ! TARGET_NO_FP_IN_TOC)))))
271 /* Select section for constant in constant pool.
273 On RS/6000, all constants are in the private read-only data area.
274 However, if this is being placed in the TOC it must be output as a
277 #define SELECT_RTX_SECTION(MODE, X) \
278 { if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (X, MODE)) \
281 read_only_private_data_section (); \
284 /* If we are referencing a function that is static or is known to be
285 in this file, make the SYMBOL_REF special. We can use this to indicate
286 that we can branch to this function without emitting a no-op after the
287 call. Do not set this flag if the function is weakly defined. */
289 #define ENCODE_SECTION_INFO(DECL) \
290 if (TREE_CODE (DECL) == FUNCTION_DECL \
291 && (TREE_ASM_WRITTEN (DECL) || ! TREE_PUBLIC (DECL)) \
292 && ! DECL_WEAK (DECL)) \
293 SYMBOL_REF_FLAG (XEXP (DECL_RTL (DECL), 0)) = 1;
295 /* Indicate that jump tables go in the text section. */
297 #define JUMP_TABLES_IN_TEXT_SECTION 1
299 /* Enable AIX XL compiler calling convention breakage compatibility. */
300 #undef TARGET_XL_CALL
301 #define MASK_XL_CALL 0x40000000
302 #define TARGET_XL_CALL (target_flags & MASK_XL_CALL)
303 #undef SUBTARGET_SWITCHES
304 #define SUBTARGET_SWITCHES \
305 {"xl-call", MASK_XL_CALL, \
306 N_("Always pass floating-point arguments in memory") }, \
307 {"no-xl-call", - MASK_XL_CALL, \
308 N_("Don't always pass floating-point arguments in memory") }, \
309 SUBSUBTARGET_SWITCHES
310 #define SUBSUBTARGET_SWITCHES
312 /* Define any extra SPECS that the compiler needs to generate. */
313 #undef SUBTARGET_EXTRA_SPECS
314 #define SUBTARGET_EXTRA_SPECS \
315 { "link_syscalls", LINK_SYSCALLS_SPEC }, \
316 { "link_libg", LINK_LIBG_SPEC }
318 /* FP save and restore routines. */
319 #define SAVE_FP_PREFIX "._savef"
320 #define SAVE_FP_SUFFIX ""
321 #define RESTORE_FP_PREFIX "._restf"
322 #define RESTORE_FP_SUFFIX ""
324 /* Define cutoff for using external functions to save floating point. */
325 #define FP_SAVE_INLINE(FIRST_REG) ((FIRST_REG) == 62 || (FIRST_REG) == 63)
327 /* Function name to call to do profiling. */
328 #define RS6000_MCOUNT ".__mcount"
330 /* Function names to call to do floating point truncation. */
332 #define RS6000_ITRUNC "__itrunc"
333 #define RS6000_UITRUNC "__uitrunc"
335 /* Optabs entries for the int->float routines, using the standard
337 #define INIT_TARGET_OPTABS \
339 if (! TARGET_POWER2 && ! TARGET_POWERPC && TARGET_HARD_FLOAT) \
341 fixdfsi_libfunc = init_one_libfunc (RS6000_ITRUNC); \
342 fixunsdfsi_libfunc = init_one_libfunc (RS6000_UITRUNC); \
346 /* AIX always has a TOC. */
347 #define TARGET_NO_TOC 0
350 /* AIX allows r13 to be used. */
353 /* This outputs NAME to FILE up to the first null or '['. */
355 #define RS6000_OUTPUT_BASENAME(FILE, NAME) \
359 STRIP_NAME_ENCODING (_p, (NAME)); \
360 assemble_name ((FILE), _p); \
363 /* This is how to output the definition of a user-level label named NAME,
364 such as the label on a static function or variable NAME. */
366 #define ASM_OUTPUT_LABEL(FILE,NAME) \
367 do { RS6000_OUTPUT_BASENAME (FILE, NAME); fputs (":\n", FILE); } while (0)
369 /* This is how to output a command to make the user-level label named NAME
370 defined for reference from other files. */
372 #define ASM_GLOBALIZE_LABEL(FILE,NAME) \
373 do { fputs ("\t.globl ", FILE); \
374 RS6000_OUTPUT_BASENAME (FILE, NAME); putc ('\n', FILE);} while (0)
376 /* Remove any trailing [DS] or the like from the symbol name. */
378 #define STRIP_NAME_ENCODING(VAR,NAME) \
381 const char *_name = (NAME); \
385 _len = strlen (_name); \
386 if (_name[_len - 1] != ']') \
390 char *_new_name = (char *) alloca (_len + 1); \
391 strcpy (_new_name, _name); \
392 _new_name[_len - 4] = '\0'; \
398 /* Output at beginning of assembler file.
400 Initialize the section names for the RS/6000 at this point.
402 Specify filename, including full path, to assembler.
404 We want to go into the TOC section so at least one .toc will be emitted.
405 Also, in order to output proper .bs/.es pairs, we need at least one static
406 [RW] section emitted.
408 Finally, declare mcount when profiling to make the assembler happy. */
410 #define ASM_FILE_START(FILE) \
412 rs6000_gen_section_name (&xcoff_bss_section_name, \
413 main_input_filename, ".bss_"); \
414 rs6000_gen_section_name (&xcoff_private_data_section_name, \
415 main_input_filename, ".rw_"); \
416 rs6000_gen_section_name (&xcoff_read_only_section_name, \
417 main_input_filename, ".ro_"); \
419 fprintf (FILE, "\t.file\t\"%s\"\n", main_input_filename); \
421 fputs ("\t.machine\t\"ppc64\"\n", FILE); \
423 if (write_symbols != NO_DEBUG) \
424 private_data_section (); \
427 fprintf (FILE, "\t.extern %s\n", RS6000_MCOUNT); \
428 rs6000_file_start (FILE, TARGET_CPU_DEFAULT); \
431 /* Output at end of assembler file.
433 On the RS/6000, referencing data should automatically pull in text. */
435 #define ASM_FILE_END(FILE) \
438 fputs ("_section_.text:\n", FILE); \
440 fputs (TARGET_32BIT \
441 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n", FILE); \
444 /* This macro produces the initial definition of a function name.
445 On the RS/6000, we need to place an extra '.' in the function name and
446 output the function descriptor.
448 The csect for the function will have already been created by the
449 `text_section' call previously done. We do have to go back to that
452 The third and fourth parameters to the .function pseudo-op (16 and 044)
453 are placeholders which no longer have any use. */
455 #define ASM_DECLARE_FUNCTION_NAME(FILE,NAME,DECL) \
456 { if (TREE_PUBLIC (DECL)) \
458 fputs ("\t.globl .", FILE); \
459 RS6000_OUTPUT_BASENAME (FILE, NAME); \
464 fputs ("\t.lglobl .", FILE); \
465 RS6000_OUTPUT_BASENAME (FILE, NAME); \
468 fputs ("\t.csect ", FILE); \
469 RS6000_OUTPUT_BASENAME (FILE, NAME); \
470 fputs (TARGET_32BIT ? "[DS]\n" : "[DS],3\n", FILE); \
471 RS6000_OUTPUT_BASENAME (FILE, NAME); \
472 fputs (":\n", FILE); \
473 fputs (TARGET_32BIT ? "\t.long ." : "\t.llong .", FILE); \
474 RS6000_OUTPUT_BASENAME (FILE, NAME); \
475 fputs (", TOC[tc0], 0\n", FILE); \
476 in_section = no_section; \
477 function_section(DECL); \
479 RS6000_OUTPUT_BASENAME (FILE, NAME); \
480 fputs (":\n", FILE); \
481 if (write_symbols == XCOFF_DEBUG) \
482 xcoffout_declare_function (FILE, DECL, NAME); \
485 /* Output a reference to SYM on FILE. */
487 #define ASM_OUTPUT_SYMBOL_REF(FILE, SYM) \
488 rs6000_output_symbol_ref (FILE, SYM)
490 /* This is how to output a reference to a user-level label named NAME.
491 `assemble_name' uses this. */
493 #define ASM_OUTPUT_LABELREF(FILE,NAME) \
496 /* This says how to output an external. */
498 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \
499 { rtx _symref = XEXP (DECL_RTL (DECL), 0); \
500 if ((TREE_CODE (DECL) == VAR_DECL \
501 || TREE_CODE (DECL) == FUNCTION_DECL) \
502 && (NAME)[strlen (NAME) - 1] != ']') \
504 char *_name = (char *) permalloc (strlen (XSTR (_symref, 0)) + 5); \
505 strcpy (_name, XSTR (_symref, 0)); \
506 strcat (_name, TREE_CODE (DECL) == FUNCTION_DECL ? "[DS]" : "[RW]"); \
507 XSTR (_symref, 0) = _name; \
511 /* This is how to output an internal numbered label where
512 PREFIX is the class of label and NUM is the number within the class. */
514 #define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM) \
515 fprintf (FILE, "%s..%d:\n", PREFIX, NUM)
517 /* This is how to output an internal label prefix. rs6000.c uses this
518 when generating traceback tables. */
520 #define ASM_OUTPUT_INTERNAL_LABEL_PREFIX(FILE,PREFIX) \
521 fprintf (FILE, "%s..", PREFIX)
523 /* This is how to output a label for a jump table. Arguments are the same as
524 for ASM_OUTPUT_INTERNAL_LABEL, except the insn for the jump table is
527 #define ASM_OUTPUT_CASE_LABEL(FILE,PREFIX,NUM,TABLEINSN) \
528 { ASM_OUTPUT_ALIGN (FILE, 2); ASM_OUTPUT_INTERNAL_LABEL (FILE, PREFIX, NUM); }
530 /* This is how to store into the string LABEL
531 the symbol_ref name of an internal numbered label where
532 PREFIX is the class of label and NUM is the number within the class.
533 This is suitable for output with `assemble_name'. */
535 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \
536 sprintf (LABEL, "*%s..%ld", (PREFIX), (long)(NUM))
538 /* This is how to output an assembler line to define N characters starting
541 #define ASM_OUTPUT_ASCII(FILE, P, N) output_ascii ((FILE), (P), (N))
543 /* This is how to advance the location counter by SIZE bytes. */
545 #define ASM_OUTPUT_SKIP(FILE,SIZE) \
546 fprintf (FILE, "\t.space %d\n", (SIZE))
548 /* This says how to output an assembler line
549 to define a global common symbol. */
551 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGNMENT) \
552 do { fputs (".comm ", (FILE)); \
553 RS6000_OUTPUT_BASENAME ((FILE), (NAME)); \
555 fprintf ((FILE), ",%d,3\n", (SIZE)); \
557 fprintf( (FILE), ",%d\n", (SIZE)); \
560 /* These are various definitions for DWARF output. They could just
561 use '.long' or '.word', but that aligns to a 4-byte boundary which
562 is not what is required. So we define a million macros... */
564 #define UNALIGNED_SHORT_ASM_OP "\t.vbyte\t2,"
565 #define UNALIGNED_INT_ASM_OP "\t.vbyte\t4,"
566 #define UNALIGNED_DOUBLE_INT_ASM_OP "\t.vbyte\t8,"
568 /* Output before instructions. */
569 #define TEXT_SECTION_ASM_OP "\t.csect .text[PR]"
571 /* Output before writable data.
572 Align entire section to BIGGEST_ALIGNMENT. */
573 #define DATA_SECTION_ASM_OP "\t.csect .data[RW],3"
575 /* Define unique section name -- functions only. */
576 #define UNIQUE_SECTION(DECL,RELOC) \
582 if (TREE_CODE (DECL) == FUNCTION_DECL) { \
583 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
584 len = strlen (name) + 5; \
585 string = alloca (len) + 1; \
586 sprintf (string, ".%s[PR]", name); \
587 DECL_SECTION_NAME (DECL) = build_string (len, string); \
591 #define ASM_OUTPUT_SECTION_NAME(ASM_OUT_FILE,DECL,NAME,RELOC) \
592 do { fputs ("\t.csect ", ASM_OUT_FILE); \
593 fputs (TREE_STRING_POINTER (DECL_SECTION_NAME (DECL)), ASM_OUT_FILE); \
594 putc ('\n', ASM_OUT_FILE); \
597 /* Define the name of the section to use for the exception tables.
598 TODO: test and see if we can use read_only_data_section, if so,
601 #define EXCEPTION_SECTION data_section
603 /* __throw will restore its own return address to be the same as the
604 return address of the function that the throw is being made to.
605 This is unfortunate, because we want to check the original
606 return address to see if we need to restore the TOC.
607 So we have to squirrel it away with this. */
608 #define SETUP_FRAME_ADDRESSES() rs6000_aix_emit_builtin_unwind_init ()
610 #define PROFILE_HOOK(LABEL) output_profile_hook (LABEL)