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