1 /* Definitions of target machine for GNU compiler,
2 for IBM RS/6000 POWER running AIX.
3 Copyright (C) 2000 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 RS/6000 uses the XCOFF format. */
28 #define XCOFF_DEBUGGING_INFO
30 /* Define if the object format being used is COFF or a superset. */
31 #define OBJECT_FORMAT_COFF
33 /* Define the magic numbers that we recognize as COFF.
35 AIX 4.3 adds U803XTOCMAGIC (0757) for 64-bit objects, but collect2.c
36 does not include files in the correct order to conditionally define
37 the symbolic name in this macro.
39 The AIX linker accepts import/export files as object files,
40 so accept "#!" (0x2321) magic number. */
41 #define MY_ISCOFF(magic) \
42 ((magic) == U802WRMAGIC || (magic) == U802ROMAGIC \
43 || (magic) == U802TOCMAGIC || (magic) == 0757 || (magic) == 0x2321)
45 /* This is the only version of nm that collect2 can work with. */
46 #define REAL_NM_FILE_NAME "/usr/ucb/nm"
48 /* We don't have GAS for the RS/6000 yet, so don't write out special
51 #define FASCIST_ASSEMBLER
53 /* AIX does not have any init/fini or ctor/dtor sections, so create
54 static constructors and destructors as normal functions. */
55 /* #define ASM_OUTPUT_CONSTRUCTOR(file, name) */
56 /* #define ASM_OUTPUT_DESTRUCTOR(file, name) */
58 /* The prefix to add to user-visible assembler symbols. */
59 #define USER_LABEL_PREFIX "."
61 /* Don't turn -B into -L if the argument specifies a relative file name. */
62 #define RELATIVE_PREFIX_NOT_LINKDIR
64 /* Names to predefine in the preprocessor for this target machine. */
66 #define CPP_PREDEFINES "-D_IBMR2 -D_POWER -D_AIX -D_AIX32 -D_LONG_LONG \
67 -Asystem(unix) -Asystem(aix) -Acpu(rs6000) -Amachine(rs6000)"
69 /* Define appropriate architecture macros for preprocessor depending on
72 #define CPP_SPEC "%{posix: -D_POSIX_SOURCE}\
73 %{ansi: -D_ANSI_C_SOURCE}\
76 /* Tell the assembler to assume that all undefined names are external.
78 Don't do this until the fixed IBM assembler is more generally available.
79 When this becomes permanently defined, the ASM_OUTPUT_EXTERNAL,
80 ASM_OUTPUT_EXTERNAL_LIBCALL, and RS6000_OUTPUT_BASENAME macros will no
81 longer be needed. Also, the extern declaration of mcount in ASM_FILE_START
82 will no longer be needed. */
84 /* #define ASM_SPEC "-u %(asm_cpu)" */
86 /* Default location of syscalls.exp under AIX */
88 #define LINK_SYSCALLS_SPEC "-bI:/lib/syscalls.exp"
90 #define LINK_SYSCALLS_SPEC ""
93 /* Default location of libg.exp under AIX */
95 #define LINK_LIBG_SPEC "-bexport:/usr/lib/libg.exp"
97 #define LINK_LIBG_SPEC ""
100 /* Define the options for the binder: Start text at 512, align all segments
101 to 512 bytes, and warn if there is text relocation.
103 The -bhalt:4 option supposedly changes the level at which ld will abort,
104 but it also suppresses warnings about multiply defined symbols and is
105 used by the AIX cc command. So we use it here.
107 -bnodelcsect undoes a poor choice of default relating to multiply-defined
108 csects. See AIX documentation for more information about this.
110 -bM:SRE tells the linker that the output file is Shared REusable. Note
111 that to actually build a shared library you will also need to specify an
112 export list with the -Wl,-bE option. */
114 #define LINK_SPEC "-T512 -H512 %{!r:-btextro} -bhalt:4 -bnodelcsect\
115 %{static:-bnso %(link_syscalls) } \
116 %{!shared:%{g*: %(link_libg) }} %{shared:-bM:SRE}"
118 /* Profiled library versions are used by linking with special directories. */
119 #define LIB_SPEC "%{pg:-L/lib/profiled -L/usr/lib/profiled}\
120 %{p:-L/lib/profiled -L/usr/lib/profiled} %{!shared:%{g*:-lg}} -lc"
122 /* Define the extra sections we need. We define three: one is the read-only
123 data section which is used for constants. This is a csect whose name is
124 derived from the name of the input file. The second is for initialized
125 global variables. This is a csect whose name is that of the variable.
126 The third is the TOC. */
128 #define EXTRA_SECTIONS \
129 read_only_data, private_data, read_only_private_data, toc, bss
131 /* Define the routines to implement these extra sections.
132 BIGGEST_ALIGNMENT is 64, so align the sections that much. */
134 #define EXTRA_SECTION_FUNCTIONS \
137 read_only_data_section () \
139 if (in_section != read_only_data) \
141 fprintf (asm_out_file, "\t.csect %s[RO],3\n", \
142 xcoff_read_only_section_name); \
143 in_section = read_only_data; \
148 private_data_section () \
150 if (in_section != private_data) \
152 fprintf (asm_out_file, "\t.csect %s[RW],3\n", \
153 xcoff_private_data_section_name); \
154 in_section = private_data; \
159 read_only_private_data_section () \
161 if (in_section != read_only_private_data) \
163 fprintf (asm_out_file, "\t.csect %s[RO],3\n", \
164 xcoff_private_data_section_name); \
165 in_section = read_only_private_data; \
172 if (TARGET_MINIMAL_TOC) \
174 /* toc_section is always called at least once from ASM_FILE_START, \
175 so this is guaranteed to always be defined once and only once \
177 if (! toc_initialized) \
179 fputs ("\t.toc\nLCTOC..1:\n", asm_out_file); \
180 fputs ("\t.tc toc_table[TC],toc_table[RW]\n", asm_out_file); \
181 toc_initialized = 1; \
184 if (in_section != toc) \
185 fprintf (asm_out_file, "\t.csect toc_table[RW]%s\n", \
186 (TARGET_32BIT ? "" : ",3")); \
190 if (in_section != toc) \
191 fputs ("\t.toc\n", asm_out_file); \
196 /* Define the name of our readonly data section. */
198 #define READONLY_DATA_SECTION read_only_data_section
200 /* Select the section for an initialized data object.
202 On the RS/6000, we have a special section for all variables except those
205 #define SELECT_SECTION(EXP,RELOC) \
207 if ((TREE_CODE (EXP) == STRING_CST \
208 && ! flag_writable_strings) \
209 || (TREE_CODE_CLASS (TREE_CODE (EXP)) == 'd' \
210 && TREE_READONLY (EXP) && ! TREE_THIS_VOLATILE (EXP) \
211 && DECL_INITIAL (EXP) \
212 && (DECL_INITIAL (EXP) == error_mark_node \
213 || TREE_CONSTANT (DECL_INITIAL (EXP))) \
216 if (TREE_PUBLIC (EXP)) \
217 read_only_data_section (); \
219 read_only_private_data_section (); \
223 if (TREE_PUBLIC (EXP)) \
226 private_data_section (); \
230 /* Select section for constant in constant pool.
232 On RS/6000, all constants are in the private read-only data area.
233 However, if this is being placed in the TOC it must be output as a
236 #define SELECT_RTX_SECTION(MODE, X) \
237 { if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (X, MODE)) \
240 read_only_private_data_section (); \
243 /* Indicate that jump tables go in the text section. */
245 #define JUMP_TABLES_IN_TEXT_SECTION 1
247 /* Enable AIX XL compiler calling convention breakage compatibility. */
248 #undef TARGET_XL_CALL
249 #define MASK_XL_CALL 0x40000000
250 #define TARGET_XL_CALL (target_flags & MASK_XL_CALL)
251 #undef SUBTARGET_SWITCHES
252 #define SUBTARGET_SWITCHES \
253 {"xl-call", MASK_XL_CALL, \
254 N_("Always pass floating-point arguments in memory") }, \
255 {"no-xl-call", - MASK_XL_CALL, \
256 N_("Don't always pass floating-point arguments in memory") }, \
257 SUBSUBTARGET_SWITCHES
258 #define SUBSUBTARGET_SWITCHES
260 /* Define any extra SPECS that the compiler needs to generate. */
261 #undef SUBTARGET_EXTRA_SPECS
262 #define SUBTARGET_EXTRA_SPECS \
263 { "link_syscalls", LINK_SYSCALLS_SPEC }, \
264 { "link_libg", LINK_LIBG_SPEC }
266 /* FP save and restore routines. */
267 #define SAVE_FP_PREFIX "._savef"
268 #define SAVE_FP_SUFFIX ""
269 #define RESTORE_FP_PREFIX "._restf"
270 #define RESTORE_FP_SUFFIX ""
272 /* Define cutoff for using external functions to save floating point. */
273 #define FP_SAVE_INLINE(FIRST_REG) ((FIRST_REG) == 62 || (FIRST_REG) == 63)
275 /* Function name to call to do profiling. */
276 #define RS6000_MCOUNT ".__mcount"
278 /* Function names to call to do floating point truncation. */
280 #define RS6000_ITRUNC "__itrunc"
281 #define RS6000_UITRUNC "__uitrunc"
283 /* Optabs entries for the int->float routines, using the standard
285 #define INIT_TARGET_OPTABS \
287 if (! TARGET_POWER2 && ! TARGET_POWERPC && TARGET_HARD_FLOAT) \
289 fixdfsi_libfunc = init_one_libfunc (RS6000_ITRUNC); \
290 fixunsdfsi_libfunc = init_one_libfunc (RS6000_UITRUNC); \
294 /* AIX always has a TOC. */
295 #define TARGET_NO_TOC 0
298 /* AIX allows r13 to be used. */
301 /* This outputs NAME to FILE up to the first null or '['. */
303 #define RS6000_OUTPUT_BASENAME(FILE, NAME) \
307 STRIP_NAME_ENCODING (_p, (NAME)); \
308 assemble_name ((FILE), _p); \
311 /* This is how to output the definition of a user-level label named NAME,
312 such as the label on a static function or variable NAME. */
314 #define ASM_OUTPUT_LABEL(FILE,NAME) \
315 do { RS6000_OUTPUT_BASENAME (FILE, NAME); fputs (":\n", FILE); } while (0)
317 /* This is how to output a command to make the user-level label named NAME
318 defined for reference from other files. */
320 #define ASM_GLOBALIZE_LABEL(FILE,NAME) \
321 do { fputs ("\t.globl ", FILE); \
322 RS6000_OUTPUT_BASENAME (FILE, NAME); putc ('\n', FILE);} while (0)
324 /* Remove any trailing [DS] or the like from the symbol name. */
326 #define STRIP_NAME_ENCODING(VAR,NAME) \
329 const char *_name = (NAME); \
333 _len = strlen (_name); \
334 if (_name[_len - 1] != ']') \
338 char *_new_name = (char *) alloca (_len + 1); \
339 strcpy (_new_name, _name); \
340 _new_name[_len - 4] = '\0'; \
346 /* Output at beginning of assembler file.
348 Initialize the section names for the RS/6000 at this point.
350 Specify filename, including full path, to assembler.
352 We want to go into the TOC section so at least one .toc will be emitted.
353 Also, in order to output proper .bs/.es pairs, we need at least one static
354 [RW] section emitted.
356 We then switch back to text to force the gcc2_compiled. label and the space
357 allocated after it (when profiling) into the text section.
359 Finally, declare mcount when profiling to make the assembler happy. */
361 #define ASM_FILE_START(FILE) \
363 rs6000_gen_section_name (&xcoff_bss_section_name, \
364 main_input_filename, ".bss_"); \
365 rs6000_gen_section_name (&xcoff_private_data_section_name, \
366 main_input_filename, ".rw_"); \
367 rs6000_gen_section_name (&xcoff_read_only_section_name, \
368 main_input_filename, ".ro_"); \
370 fprintf (FILE, "\t.file\t\"%s\"\n", main_input_filename); \
372 fputs ("\t.machine\t\"ppc64\"\n", FILE); \
374 if (write_symbols != NO_DEBUG) \
375 private_data_section (); \
378 fprintf (FILE, "\t.extern %s\n", RS6000_MCOUNT); \
379 rs6000_file_start (FILE, TARGET_CPU_DEFAULT); \
382 /* Output at end of assembler file.
384 On the RS/6000, referencing data should automatically pull in text. */
386 #define ASM_FILE_END(FILE) \
389 fputs ("_section_.text:\n", FILE); \
391 fputs (TARGET_32BIT \
392 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n", FILE); \
395 /* This macro produces the initial definition of a function name.
396 On the RS/6000, we need to place an extra '.' in the function name and
397 output the function descriptor.
399 The csect for the function will have already been created by the
400 `text_section' call previously done. We do have to go back to that
403 The third and fourth parameters to the .function pseudo-op (16 and 044)
404 are placeholders which no longer have any use. */
406 #define ASM_DECLARE_FUNCTION_NAME(FILE,NAME,DECL) \
407 { if (TREE_PUBLIC (DECL)) \
409 fputs ("\t.globl .", FILE); \
410 RS6000_OUTPUT_BASENAME (FILE, NAME); \
415 fputs ("\t.lglobl .", FILE); \
416 RS6000_OUTPUT_BASENAME (FILE, NAME); \
419 fputs ("\t.csect ", FILE); \
420 RS6000_OUTPUT_BASENAME (FILE, NAME); \
421 fputs (TARGET_32BIT ? "[DS]\n" : "[DS],3\n", FILE); \
422 RS6000_OUTPUT_BASENAME (FILE, NAME); \
423 fputs (":\n", FILE); \
424 fputs (TARGET_32BIT ? "\t.long ." : "\t.llong .", FILE); \
425 RS6000_OUTPUT_BASENAME (FILE, NAME); \
426 fputs (", TOC[tc0], 0\n", FILE); \
427 in_section = no_section; \
428 function_section(DECL); \
430 RS6000_OUTPUT_BASENAME (FILE, NAME); \
431 fputs (":\n", FILE); \
432 if (write_symbols == XCOFF_DEBUG) \
433 xcoffout_declare_function (FILE, DECL, NAME); \
436 /* This is how to output a reference to a user-level label named NAME.
437 `assemble_name' uses this. */
439 #define ASM_OUTPUT_LABELREF(FILE,NAME) \
442 /* This says how to output an external. */
444 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \
445 { rtx _symref = XEXP (DECL_RTL (DECL), 0); \
446 if ((TREE_CODE (DECL) == VAR_DECL \
447 || TREE_CODE (DECL) == FUNCTION_DECL) \
448 && (NAME)[strlen (NAME) - 1] != ']') \
450 char *_name = (char *) permalloc (strlen (XSTR (_symref, 0)) + 5); \
451 strcpy (_name, XSTR (_symref, 0)); \
452 strcat (_name, TREE_CODE (DECL) == FUNCTION_DECL ? "[DS]" : "[RW]"); \
453 XSTR (_symref, 0) = _name; \
457 /* This is how to output an internal numbered label where
458 PREFIX is the class of label and NUM is the number within the class. */
460 #define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM) \
461 fprintf (FILE, "%s..%d:\n", PREFIX, NUM)
463 /* This is how to output an internal label prefix. rs6000.c uses this
464 when generating traceback tables. */
466 #define ASM_OUTPUT_INTERNAL_LABEL_PREFIX(FILE,PREFIX) \
467 fprintf (FILE, "%s..", PREFIX)
469 /* This is how to output a label for a jump table. Arguments are the same as
470 for ASM_OUTPUT_INTERNAL_LABEL, except the insn for the jump table is
473 #define ASM_OUTPUT_CASE_LABEL(FILE,PREFIX,NUM,TABLEINSN) \
474 { ASM_OUTPUT_ALIGN (FILE, 2); ASM_OUTPUT_INTERNAL_LABEL (FILE, PREFIX, NUM); }
476 /* This is how to store into the string LABEL
477 the symbol_ref name of an internal numbered label where
478 PREFIX is the class of label and NUM is the number within the class.
479 This is suitable for output with `assemble_name'. */
481 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \
482 sprintf (LABEL, "*%s..%ld", (PREFIX), (long)(NUM))
484 /* This is how to output an assembler line to define N characters starting
487 #define ASM_OUTPUT_ASCII(FILE, P, N) output_ascii ((FILE), (P), (N))
489 /* This is how to advance the location counter by SIZE bytes. */
491 #define ASM_OUTPUT_SKIP(FILE,SIZE) \
492 fprintf (FILE, "\t.space %d\n", (SIZE))
494 /* This says how to output an assembler line
495 to define a global common symbol. */
497 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGNMENT) \
498 do { fputs (".comm ", (FILE)); \
499 RS6000_OUTPUT_BASENAME ((FILE), (NAME)); \
501 fprintf ((FILE), ",%d,3\n", (SIZE)); \
503 fprintf( (FILE), ",%d\n", (SIZE)); \
506 /* These are various definitions for DWARF output. They could just
507 use '.long' or '.word', but that aligns to a 4-byte boundary which
508 is not what is required. So we define a million macros... */
510 #define ASM_OUTPUT_DWARF_ADDR_VAR(FILE, LABEL, LENGTH) \
511 do { fprintf ((FILE), "\t.vbyte\t%d,", LENGTH); \
512 assemble_name (FILE, LABEL); \
515 #define ASM_OUTPUT_DWARF_DELTA_VAR(FILE, LABEL1, LABEL2, LENGTH) \
516 do { fprintf ((FILE), "\t.vbyte\t%d,", LENGTH); \
517 assemble_name (FILE, LABEL1); \
518 fprintf (FILE, "-"); \
519 assemble_name (FILE, LABEL2); \
522 #define ASM_OUTPUT_DWARF_DELTA2(FILE, LABEL1, LABEL2) \
523 ASM_OUTPUT_DWARF_DELTA_VAR (FILE, LABEL1, LABEL2, 2)
525 #define ASM_OUTPUT_DWARF_DELTA4(FILE, LABEL1, LABEL2) \
526 ASM_OUTPUT_DWARF_DELTA_VAR (FILE, LABEL1, LABEL2, 4)
528 #define ASM_OUTPUT_DWARF_DELTA(FILE, LABEL1, LABEL2) \
529 ASM_OUTPUT_DWARF_DELTA_VAR (FILE, LABEL1, LABEL2, DWARF_OFFSET_SIZE)
531 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE, LABEL1, LABEL2) \
532 ASM_OUTPUT_DWARF_DELTA_VAR (FILE, LABEL1, LABEL2, \
533 POINTER_SIZE / BITS_PER_UNIT)
535 #define ASM_OUTPUT_DWARF_ADDR(FILE, LABEL) \
536 ASM_OUTPUT_DWARF_ADDR_VAR (FILE, LABEL, POINTER_SIZE / BITS_PER_UNIT)
538 #define ASM_OUTPUT_DWARF_DATA4(FILE, VALUE) \
539 fprintf ((FILE), "\t.vbyte\t4,0x%x", (unsigned) (VALUE))
541 #define ASM_OUTPUT_DWARF_DATA2(FILE, VALUE) \
542 fprintf ((FILE), "\t.vbyte\t2,0x%x", (unsigned) (VALUE))
544 #define ASM_OUTPUT_DWARF_OFFSET4(FILE, LABEL) \
545 ASM_OUTPUT_DWARF_ADDR_VAR (FILE, LABEL, 4)
547 #define ASM_OUTPUT_DWARF_OFFSET(FILE, LABEL) \
548 ASM_OUTPUT_DWARF_ADDR_VAR (FILE, LABEL, DWARF_OFFSET_SIZE)
550 /* dwarf2out keys off this, but we don't have to have a real definition. */
551 #define UNALIGNED_INT_ASM_OP bite_me
553 /* Output before instructions. */
554 #define TEXT_SECTION_ASM_OP "\t.csect .text[PR]"
556 /* Output before writable data.
557 Align entire section to BIGGEST_ALIGNMENT. */
558 #define DATA_SECTION_ASM_OP "\t.csect .data[RW],3"
560 /* Define unique section name -- functions only. */
561 #define UNIQUE_SECTION(DECL,RELOC) \
567 if (TREE_CODE (DECL) == FUNCTION_DECL) { \
568 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
569 len = strlen (name) + 5; \
570 string = alloca (len) + 1; \
571 sprintf (string, ".%s[PR]", name); \
572 DECL_SECTION_NAME (DECL) = build_string (len, string); \
576 #define ASM_OUTPUT_SECTION_NAME(ASM_OUT_FILE,DECL,NAME,RELOC) \
577 do { fputs ("\t.csect ", ASM_OUT_FILE); \
578 fputs (TREE_STRING_POINTER (DECL_SECTION_NAME (DECL)), ASM_OUT_FILE); \
579 putc ('\n', ASM_OUT_FILE); \
582 /* __throw will restore its own return address to be the same as the
583 return address of the function that the throw is being made to.
584 This is unfortunate, because we want to check the original
585 return address to see if we need to restore the TOC.
586 So we have to squirrel it away with this. */
587 #define SETUP_FRAME_ADDRESSES() rs6000_aix_emit_builtin_unwind_init ()