1/* Definitions of target machine for GNU compiler,
2   for IBM RS/6000 POWER running AIX.
3   Copyright (C) 2000-2020 Free Software Foundation, Inc.
4
5   This file is part of GCC.
6
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 3, or (at your
10   option) any later version.
11
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.
16
17   You should have received a copy of the GNU General Public License
18   along with GCC; see the file COPYING3.  If not see
19   <http://www.gnu.org/licenses/>.  */
20
21/* Yes!  We are AIX!  */
22#define DEFAULT_ABI ABI_AIX
23#undef  TARGET_AIX
24#define TARGET_AIX 1
25
26/* System headers are not C++-aware.  */
27#define SYSTEM_IMPLICIT_EXTERN_C 1
28
29/* Linux64.h wants to redefine TARGET_AIX based on -m64, but it can't be used
30   in the #if conditional in options-default.h, so provide another macro.  */
31#undef  TARGET_AIX_OS
32#define TARGET_AIX_OS 1
33
34/* AIX always has a TOC.  */
35#define TARGET_HAS_TOC 1
36#define FIXED_R2 1
37
38/* AIX allows r13 to be used in 32-bit mode.  */
39#define FIXED_R13 0
40
41/* 32-bit and 64-bit AIX stack boundary is 128.  */
42#undef  STACK_BOUNDARY
43#define STACK_BOUNDARY 128
44
45/* Offset within stack frame to start allocating local variables at.
46   If FRAME_GROWS_DOWNWARD, this is the offset to the END of the
47   first local allocated.  Otherwise, it is the offset to the BEGINNING
48   of the first local allocated.
49
50   On the RS/6000, the frame pointer is the same as the stack pointer,
51   except for dynamic allocations.  So we start after the fixed area and
52   outgoing parameter area.
53
54   If the function uses dynamic stack space (CALLS_ALLOCA is set), that
55   space needs to be aligned to STACK_BOUNDARY, i.e. the sum of the
56   sizes of the fixed area and the parameter area must be a multiple of
57   STACK_BOUNDARY.  */
58
59#undef RS6000_STARTING_FRAME_OFFSET
60#define RS6000_STARTING_FRAME_OFFSET					\
61  (cfun->calls_alloca							\
62   ? RS6000_ALIGN (crtl->outgoing_args_size + RS6000_SAVE_AREA, 16)	\
63   : (RS6000_ALIGN (crtl->outgoing_args_size, 16) + RS6000_SAVE_AREA))
64
65/* Offset from the stack pointer register to an item dynamically
66   allocated on the stack, e.g., by `alloca'.
67
68   The default value for this macro is `STACK_POINTER_OFFSET' plus the
69   length of the outgoing arguments.  The default is correct for most
70   machines.  See `function.c' for details.
71
72   This value must be a multiple of STACK_BOUNDARY (hard coded in
73   `emit-rtl.c').  */
74#undef STACK_DYNAMIC_OFFSET
75#define STACK_DYNAMIC_OFFSET(FUNDECL)					\
76   RS6000_ALIGN (crtl->outgoing_args_size.to_constant ()		\
77		 + STACK_POINTER_OFFSET, 16)
78
79#undef  TARGET_IEEEQUAD
80#define TARGET_IEEEQUAD 0
81
82#undef  TARGET_IEEEQUAD_DEFAULT
83#define TARGET_IEEEQUAD_DEFAULT 0
84
85/* The AIX linker will discard static constructors in object files before
86   collect has a chance to see them, so scan the object files directly.  */
87#define COLLECT_EXPORT_LIST
88
89/* On AIX, initialisers specified with -binitfini are called in breadth-first
90   order.
91   e.g. if a.out depends on lib1.so, the init function for a.out is called before
92   the init function for lib1.so.
93
94   To ensure global C++ constructors in linked libraries are run before global
95   C++ constructors from the current module, there is additional symbol scanning
96   logic in collect2.
97
98   The global initialiser/finaliser functions are named __GLOBAL_AIXI_{libname}
99   and __GLOBAL_AIXD_{libname} and are exported from each shared library.
100
101   collect2 will detect these symbols when they exist in shared libraries that
102   the current program is being linked against.  All such initiliser functions
103   will be called prior to the constructors of the current program, and
104   finaliser functions called after destructors.
105
106   Reference counting generated by collect2 will ensure that constructors are
107   only invoked once in the case of multiple dependencies on a library.
108
109   -binitfini is still used in parallel to this solution.
110   This handles the case where a library is loaded through dlopen(), and also
111   handles the option -blazy.
112*/
113#define COLLECT_SHARED_INIT_FUNC(STREAM, FUNC) \
114	  fprintf ((STREAM), "void %s() {\n\t%s();\n}\n", aix_shared_initname, (FUNC))
115#define COLLECT_SHARED_FINI_FUNC(STREAM, FUNC) \
116	  fprintf ((STREAM), "void %s() {\n\t%s();\n}\n", aix_shared_fininame, (FUNC))
117
118#if HAVE_AS_REF
119/* Issue assembly directives that create a reference to the given DWARF table
120   identifier label from the current function section.  This is defined to
121   ensure we drag frame tables associated with needed function bodies in
122   a link with garbage collection activated.  */
123#define ASM_OUTPUT_DWARF_TABLE_REF rs6000_aix_asm_output_dwarf_table_ref
124#endif
125
126/* This is the only version of nm that collect2 can work with.  */
127#define REAL_NM_FILE_NAME "/usr/ucb/nm"
128
129#define USER_LABEL_PREFIX  ""
130
131/* Don't turn -B into -L if the argument specifies a relative file name.  */
132#define RELATIVE_PREFIX_NOT_LINKDIR
133
134/* Because of the above, we must have gcc search itself to find libgcc.a.  */
135#define LINK_LIBGCC_SPECIAL_1
136
137/* Names to predefine in the preprocessor for this target machine.  */
138#define TARGET_OS_AIX_CPP_BUILTINS()		\
139  do						\
140    {						\
141      builtin_define ("_IBMR2");		\
142      builtin_define ("_POWER");		\
143      builtin_define ("__unix__");              \
144      builtin_define ("_AIX");			\
145      builtin_define ("_AIX32");		\
146      builtin_define ("_AIX41");		\
147      builtin_define ("_LONG_LONG");		\
148      if (TARGET_LONG_DOUBLE_128)		\
149        builtin_define ("__LONGDOUBLE128");	\
150      builtin_assert ("system=unix");		\
151      builtin_assert ("system=aix");		\
152      if (TARGET_64BIT)				\
153	{					\
154	  builtin_define ("__PPC__");		\
155	  builtin_define ("__PPC64__");		\
156	  builtin_define ("__powerpc__");	\
157	  builtin_define ("__powerpc64__");	\
158	  builtin_assert ("cpu=powerpc64");	\
159	  builtin_assert ("machine=powerpc64");	\
160	}					\
161      else					\
162	{					\
163	  builtin_define ("__PPC__");		\
164	  builtin_define ("__powerpc__");	\
165	  builtin_assert ("cpu=powerpc");	\
166	  builtin_assert ("machine=powerpc");	\
167	}					\
168    }						\
169  while (0)
170
171/* Define appropriate architecture macros for preprocessor depending on
172   target switches.  */
173
174#define CPP_SPEC "%{posix: -D_POSIX_SOURCE}\
175   %{ansi: -D_ANSI_C_SOURCE}"
176
177#define CC1_SPEC "%(cc1_cpu)"
178
179#undef ASM_DEFAULT_SPEC
180#define ASM_DEFAULT_SPEC ""
181
182/* Tell the assembler to assume that all undefined names are external.
183
184   Don't do this until the fixed IBM assembler is more generally available.
185   When this becomes permanently defined, the ASM_OUTPUT_EXTERNAL,
186   ASM_OUTPUT_EXTERNAL_LIBCALL, and RS6000_OUTPUT_BASENAME macros will no
187   longer be needed.  Also, the extern declaration of mcount in
188   rs6000_xcoff_file_start will no longer be needed.  */
189
190/* #define ASM_SPEC "-u %(asm_cpu)" */
191
192/* Default location of syscalls.exp under AIX */
193#define LINK_SYSCALLS_SPEC "-bI:%R/lib/syscalls.exp"
194
195/* Default location of libg.exp under AIX */
196#define LINK_LIBG_SPEC "-bexport:%R/usr/lib/libg.exp"
197
198/* Define the options for the binder: Start text at 512, align all segments
199   to 512 bytes, and warn if there is text relocation.
200
201   The -bhalt:4 option supposedly changes the level at which ld will abort,
202   but it also suppresses warnings about multiply defined symbols and is
203   used by the AIX cc command.  So we use it here.
204
205   -bnodelcsect undoes a poor choice of default relating to multiply-defined
206   csects.  See AIX documentation for more information about this.
207
208   -bM:SRE tells the linker that the output file is Shared REusable.  Note
209   that to actually build a shared library you will also need to specify an
210   export list with the -Wl,-bE option.  */
211
212#define LINK_SPEC "-T512 -H512 %{!r:-btextro} -bhalt:4 -bnodelcsect\
213%{static:-bnso %(link_syscalls) } \
214%{!shared:%{g*: %(link_libg) }} %{shared:-bM:SRE}"
215
216/* Profiled library versions are used by linking with special directories.  */
217#define LIB_SPEC "%{pg:-L%R/lib/profiled -L%R/usr/lib/profiled}\
218%{p:-L%R/lib/profiled -L%R/usr/lib/profiled} %{!shared:%{g*:-lg}} -lc"
219
220/* Static linking with shared libstdc++ requires libsupc++ as well.  */
221#define LIBSTDCXX_STATIC "supc++"
222
223/* This now supports a natural alignment mode.  */
224/* AIX word-aligns FP doubles but doubleword-aligns 64-bit ints.  */
225#define ADJUST_FIELD_ALIGN(FIELD, TYPE, COMPUTED) \
226  ((TARGET_ALIGN_NATURAL == 0						\
227    && TYPE_MODE (strip_array_types (TYPE)) == DFmode)			\
228   ? MIN ((COMPUTED), 32)						\
229   : (COMPUTED))
230
231/* AIX increases natural record alignment to doubleword if the first
232   field is an FP double while the FP fields remain word aligned.  */
233#define ROUND_TYPE_ALIGN(STRUCT, COMPUTED, SPECIFIED)			\
234  ((TREE_CODE (STRUCT) == RECORD_TYPE					\
235    || TREE_CODE (STRUCT) == UNION_TYPE					\
236    || TREE_CODE (STRUCT) == QUAL_UNION_TYPE)				\
237   && TARGET_ALIGN_NATURAL == 0						\
238   ? rs6000_special_round_type_align (STRUCT, COMPUTED, SPECIFIED)	\
239   : MAX ((COMPUTED), (SPECIFIED)))
240
241/* The AIX ABI isn't explicit on whether aggregates smaller than a
242   word/doubleword should be padded upward or downward.  One could
243   reasonably assume that they follow the normal rules for structure
244   layout treating the parameter area as any other block of memory,
245   then map the reg param area to registers, i.e., pad upward, which
246   is the way IBM Compilers for AIX behave.
247   Setting both of the following defines results in this behavior.  */
248#define AGGREGATE_PADDING_FIXED 1
249#define AGGREGATES_PAD_UPWARD_ALWAYS 1
250
251/* Specify padding for the last element of a block move between
252   registers and memory.  FIRST is nonzero if this is the only
253   element.  */
254#define BLOCK_REG_PADDING(MODE, TYPE, FIRST) \
255  (!(FIRST) ? PAD_UPWARD : targetm.calls.function_arg_padding (MODE, TYPE))
256
257/* Indicate that jump tables go in the text section.  */
258
259#define JUMP_TABLES_IN_TEXT_SECTION 1
260
261/* Define any extra SPECS that the compiler needs to generate.  */
262#undef  SUBTARGET_EXTRA_SPECS
263#define SUBTARGET_EXTRA_SPECS						\
264  { "link_syscalls",            LINK_SYSCALLS_SPEC },			\
265  { "link_libg",                LINK_LIBG_SPEC }
266
267#define PROFILE_HOOK(LABEL)   output_profile_hook (LABEL)
268
269/* No version of AIX fully supports AltiVec or 64-bit instructions in
270   32-bit mode.  */
271#define OS_MISSING_POWERPC64 1
272#define OS_MISSING_ALTIVEC 1
273
274/* WINT_TYPE */
275#define WINT_TYPE "int"
276
277/* Static stack checking is supported by means of probes.  */
278#define STACK_CHECK_STATIC_BUILTIN 1
279
280/* Use standard DWARF numbering for DWARF debugging information.  */
281#define RS6000_USE_DWARF_NUMBERING
282
283/* Replace -m64 with -maix64 and -m32 with -maix32.  */
284#undef SUBTARGET_DRIVER_SELF_SPECS
285#define SUBTARGET_DRIVER_SELF_SPECS	\
286"%{m64:-maix64} %<m64",			\
287"%{m32:-maix32} %<m32"
288