| 1 |
/* Definitions for 64-bit PowerPC running FreeBSD using the ELF format |
| 2 |
Copyright (C) 2012-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GCC. |
| 5 |
|
| 6 |
GCC is free software; you can redistribute it and/or modify it |
| 7 |
under the terms of the GNU General Public License as published |
| 8 |
by the Free Software Foundation; either version 3, or (at your |
| 9 |
option) any later version. |
| 10 |
|
| 11 |
GCC is distributed in the hope that it will be useful, but WITHOUT |
| 12 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 13 |
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
| 14 |
License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with GCC; see the file COPYING3. If not see |
| 18 |
<http://www.gnu.org/licenses/>. */ |
| 19 |
|
| 20 |
/* Undef gnu-user.h macros we don't want. */ |
| 21 |
#undef CPLUSPLUS_CPP_SPEC |
| 22 |
#undef LINK_GCC_C_SEQUENCE_SPEC |
| 23 |
|
| 24 |
/* Override the defaults, which exist to force the proper definition. */ |
| 25 |
|
| 26 |
#ifdef IN_LIBGCC2 |
| 27 |
#undef TARGET_64BIT |
| 28 |
#ifdef __powerpc64__ |
| 29 |
#define TARGET_64BIT 1 |
| 30 |
#else |
| 31 |
#define TARGET_64BIT 0 |
| 32 |
#endif |
| 33 |
#endif |
| 34 |
|
| 35 |
#undef TARGET_AIX |
| 36 |
#define TARGET_AIX TARGET_64BIT |
| 37 |
|
| 38 |
#ifdef HAVE_LD_NO_DOT_SYMS |
| 39 |
/* New ABI uses a local sym for the function entry point. */ |
| 40 |
extern int dot_symbols; |
| 41 |
#undef DOT_SYMBOLS |
| 42 |
#define DOT_SYMBOLS dot_symbols |
| 43 |
#endif |
| 44 |
|
| 45 |
#define TARGET_USES_LINUX64_OPT 1 |
| 46 |
#ifdef HAVE_LD_LARGE_TOC |
| 47 |
#undef TARGET_CMODEL |
| 48 |
#define TARGET_CMODEL rs6000_current_cmodel |
| 49 |
#define SET_CMODEL(opt) rs6000_current_cmodel = opt |
| 50 |
#else |
| 51 |
#define SET_CMODEL(opt) do {} while (0) |
| 52 |
#endif |
| 53 |
|
| 54 |
#undef PROCESSOR_DEFAULT |
| 55 |
#define PROCESSOR_DEFAULT PROCESSOR_PPC7450 |
| 56 |
#undef PROCESSOR_DEFAULT64 |
| 57 |
#define PROCESSOR_DEFAULT64 PROCESSOR_POWER8 |
| 58 |
|
| 59 |
/* We don't need to generate entries in .fixup, except when |
| 60 |
-mrelocatable or -mrelocatable-lib is given. */ |
| 61 |
#undef RELOCATABLE_NEEDS_FIXUP |
| 62 |
#define RELOCATABLE_NEEDS_FIXUP \ |
| 63 |
(rs6000_isa_flags & rs6000_isa_flags_explicit & OPTION_MASK_RELOCATABLE) |
| 64 |
|
| 65 |
#undef RS6000_ABI_NAME |
| 66 |
#define RS6000_ABI_NAME "freebsd" |
| 67 |
|
| 68 |
#define INVALID_64BIT "-m%s not supported in this configuration" |
| 69 |
#define INVALID_32BIT INVALID_64BIT |
| 70 |
|
| 71 |
/* Use LINUX64 instead of FREEBSD64 for compat with e.g. sysv4le.h */ |
| 72 |
#ifdef LINUX64_DEFAULT_ABI_ELFv2 |
| 73 |
#define ELFv2_ABI_CHECK (rs6000_elf_abi != 1) |
| 74 |
#else |
| 75 |
#define ELFv2_ABI_CHECK (rs6000_elf_abi == 2) |
| 76 |
#endif |
| 77 |
|
| 78 |
#undef SUBSUBTARGET_OVERRIDE_OPTIONS |
| 79 |
#define SUBSUBTARGET_OVERRIDE_OPTIONS \ |
| 80 |
do rs6000_linux64_override_options (); while (0) |
| 81 |
|
| 82 |
#undef ASM_SPEC |
| 83 |
#undef LINK_OS_FREEBSD_SPEC |
| 84 |
|
| 85 |
#define ASM_SPEC "%{m32:%(asm_spec32)}%{!m32:%(asm_spec64)} %(asm_spec_common)" |
| 86 |
#define LINK_OS_FREEBSD_SPEC "%{m32:%(link_os_freebsd_spec32)}%{!m32:%(link_os_freebsd_spec64)}" |
| 87 |
|
| 88 |
#define ASM_SPEC32 "-a32 \ |
| 89 |
%{mrelocatable} %{mrelocatable-lib} %{" FPIE_OR_FPIC_SPEC ":-K PIC} \ |
| 90 |
%{memb} %{!memb: %{msdata=eabi: -memb}} \ |
| 91 |
%{!mlittle: %{!mlittle-endian: %{!mbig: %{!mbig-endian: \ |
| 92 |
%{mcall-freebsd: -mbig} \ |
| 93 |
%{mcall-i960-old: -mlittle} \ |
| 94 |
%{mcall-linux: -mbig} \ |
| 95 |
%{mcall-gnu: -mbig} \ |
| 96 |
%{mcall-netbsd: -mbig} \ |
| 97 |
}}}}" |
| 98 |
|
| 99 |
#define ASM_SPEC64 "-a64" |
| 100 |
|
| 101 |
#define ASM_SPEC_COMMON "%(asm_cpu) \ |
| 102 |
%{,assembler|,assembler-with-cpp: %{mregnames} %{mno-regnames}}" \ |
| 103 |
ENDIAN_SELECT(" -mbig", " -mlittle", DEFAULT_ASM_ENDIAN) |
| 104 |
|
| 105 |
#undef SUBSUBTARGET_EXTRA_SPECS |
| 106 |
#define SUBSUBTARGET_EXTRA_SPECS \ |
| 107 |
{ "asm_spec_common", ASM_SPEC_COMMON }, \ |
| 108 |
{ "asm_spec32", ASM_SPEC32 }, \ |
| 109 |
{ "asm_spec64", ASM_SPEC64 }, \ |
| 110 |
{ "link_os_freebsd_spec32", LINK_OS_FREEBSD_SPEC32 }, \ |
| 111 |
{ "link_os_freebsd_spec64", LINK_OS_FREEBSD_SPEC64 }, |
| 112 |
|
| 113 |
#define LINK_OS_FREEBSD_SPEC_DEF "\ |
| 114 |
%{p:%nconsider using `-pg' instead of `-p' with gprof(1)} \ |
| 115 |
" FBSD_LINK_PG_NOTE " \ |
| 116 |
%{v:-V} \ |
| 117 |
%{assert*} %{R*} %{rpath*} %{defsym*} \ |
| 118 |
%{shared:-Bshareable %{h*} %{soname*}} \ |
| 119 |
%{!shared: \ |
| 120 |
%{!static: \ |
| 121 |
%{rdynamic: -export-dynamic} \ |
| 122 |
%{!dynamic-linker:-dynamic-linker " FBSD_DYNAMIC_LINKER "}} \ |
| 123 |
%{static:-Bstatic}} \ |
| 124 |
%{symbolic:-Bsymbolic}" |
| 125 |
|
| 126 |
#undef DEFAULT_ASM_ENDIAN |
| 127 |
#define LINK_OS_FREEBSD_SPEC32 "-melf32ppc_fbsd " LINK_OS_FREEBSD_SPEC_DEF |
| 128 |
#if (TARGET_DEFAULT & MASK_LITTLE_ENDIAN) |
| 129 |
#define DEFAULT_ASM_ENDIAN " -mlittle" |
| 130 |
#define LINK_OS_FREEBSD_SPEC64 "-melf64lppc_fbsd " LINK_OS_FREEBSD_SPEC_DEF |
| 131 |
#else |
| 132 |
#define DEFAULT_ASM_ENDIAN " -mbig" |
| 133 |
#define LINK_OS_FREEBSD_SPEC64 "-melf64ppc_fbsd " LINK_OS_FREEBSD_SPEC_DEF |
| 134 |
#endif |
| 135 |
|
| 136 |
#undef MULTILIB_DEFAULTS |
| 137 |
#define MULTILIB_DEFAULTS { "m64" } |
| 138 |
|
| 139 |
/* PowerPC-64 FreeBSD increases natural record alignment to doubleword if |
| 140 |
the first field is an FP double, only if in power alignment mode. */ |
| 141 |
#undef ROUND_TYPE_ALIGN |
| 142 |
#define ROUND_TYPE_ALIGN(STRUCT, COMPUTED, SPECIFIED) \ |
| 143 |
((TARGET_64BIT \ |
| 144 |
&& RECORD_OR_UNION_TYPE_P (STRUCT) \ |
| 145 |
&& TARGET_ALIGN_NATURAL == 0) \ |
| 146 |
? rs6000_special_round_type_align (STRUCT, COMPUTED, SPECIFIED) \ |
| 147 |
: MAX ((COMPUTED), (SPECIFIED))) |
| 148 |
|
| 149 |
/* Use the default for compiling target libs. */ |
| 150 |
#ifdef IN_TARGET_LIBS |
| 151 |
#undef TARGET_ALIGN_NATURAL |
| 152 |
#define TARGET_ALIGN_NATURAL 1 |
| 153 |
#endif |
| 154 |
|
| 155 |
/* Indicate that jump tables go in the text section. */ |
| 156 |
#undef JUMP_TABLES_IN_TEXT_SECTION |
| 157 |
#define JUMP_TABLES_IN_TEXT_SECTION TARGET_64BIT |
| 158 |
|
| 159 |
/* The linux ppc64 ABI isn't explicit on whether aggregates smaller |
| 160 |
than a doubleword should be padded upward or downward. You could |
| 161 |
reasonably assume that they follow the normal rules for structure |
| 162 |
layout treating the parameter area as any other block of memory, |
| 163 |
then map the reg param area to registers. i.e. pad upward. |
| 164 |
Setting both of the following defines results in this behavior. |
| 165 |
Setting just the first one will result in aggregates that fit in a |
| 166 |
doubleword being padded downward, and others being padded upward. |
| 167 |
Not a bad idea as this results in struct { int x; } being passed |
| 168 |
the same way as an int. */ |
| 169 |
#define AGGREGATE_PADDING_FIXED TARGET_64BIT |
| 170 |
#define AGGREGATES_PAD_UPWARD_ALWAYS 0 |
| 171 |
|
| 172 |
/* Specify padding for the last element of a block move between |
| 173 |
registers and memory. FIRST is nonzero if this is the only |
| 174 |
element. */ |
| 175 |
#define BLOCK_REG_PADDING(MODE, TYPE, FIRST) \ |
| 176 |
(!(FIRST) ? PAD_UPWARD : targetm.calls.function_arg_padding (MODE, TYPE)) |
| 177 |
|
| 178 |
/* FreeBSD doesn't support saving and restoring 64-bit regs with a 32-bit |
| 179 |
kernel. This is supported when running on a 64-bit kernel with |
| 180 |
COMPAT_FREEBSD32, but tell GCC it isn't so that our 32-bit binaries |
| 181 |
are compatible. */ |
| 182 |
#define OS_MISSING_POWERPC64 !TARGET_64BIT |
| 183 |
|
| 184 |
#undef FBSD_TARGET_CPU_CPP_BUILTINS |
| 185 |
#define FBSD_TARGET_CPU_CPP_BUILTINS() \ |
| 186 |
do \ |
| 187 |
{ \ |
| 188 |
builtin_define ("__PPC__"); \ |
| 189 |
builtin_define ("__ppc__"); \ |
| 190 |
builtin_define ("__powerpc__"); \ |
| 191 |
if (TARGET_64BIT) \ |
| 192 |
{ \ |
| 193 |
builtin_define ("__arch64__"); \ |
| 194 |
builtin_define ("__LP64__"); \ |
| 195 |
builtin_define ("__PPC64__"); \ |
| 196 |
builtin_define ("__powerpc64__"); \ |
| 197 |
builtin_assert ("cpu=powerpc64"); \ |
| 198 |
builtin_assert ("machine=powerpc64"); \ |
| 199 |
} \ |
| 200 |
else \ |
| 201 |
{ \ |
| 202 |
builtin_define_std ("PPC"); \ |
| 203 |
builtin_define_std ("powerpc"); \ |
| 204 |
builtin_assert ("cpu=powerpc"); \ |
| 205 |
builtin_assert ("machine=powerpc"); \ |
| 206 |
TARGET_OS_SYSV_CPP_BUILTINS (); \ |
| 207 |
} \ |
| 208 |
} \ |
| 209 |
while (0) |
| 210 |
|
| 211 |
#undef CPP_OS_DEFAULT_SPEC |
| 212 |
#define CPP_OS_DEFAULT_SPEC "%(cpp_os_freebsd)" |
| 213 |
|
| 214 |
#undef CPP_OS_FREEBSD_SPEC |
| 215 |
#define CPP_OS_FREEBSD_SPEC "" |
| 216 |
|
| 217 |
#undef STARTFILE_DEFAULT_SPEC |
| 218 |
#define STARTFILE_DEFAULT_SPEC "%(startfile_freebsd)" |
| 219 |
|
| 220 |
#undef ENDFILE_DEFAULT_SPEC |
| 221 |
#define ENDFILE_DEFAULT_SPEC "%(endfile_freebsd)" |
| 222 |
|
| 223 |
#undef LIB_DEFAULT_SPEC |
| 224 |
#define LIB_DEFAULT_SPEC "%(lib_freebsd)" |
| 225 |
|
| 226 |
#undef LINK_START_DEFAULT_SPEC |
| 227 |
#define LINK_START_DEFAULT_SPEC "%(link_start_freebsd)" |
| 228 |
|
| 229 |
#undef LINK_OS_DEFAULT_SPEC |
| 230 |
#define LINK_OS_DEFAULT_SPEC "%(link_os_freebsd)" |
| 231 |
|
| 232 |
/* XXX: This is wrong for many platforms in sysv4.h. |
| 233 |
We should work on getting that definition fixed. */ |
| 234 |
#undef LINK_SHLIB_SPEC |
| 235 |
#define LINK_SHLIB_SPEC "%{shared:-shared} %{!shared: %{static:-static}}" |
| 236 |
|
| 237 |
|
| 238 |
/************************[ Target stuff ]***********************************/ |
| 239 |
|
| 240 |
/* Define the actual types of some ANSI-mandated types. |
| 241 |
Needs to agree with <machine/ansi.h>. GCC defaults come from c-decl.cc, |
| 242 |
c-common.cc, and config/<arch>/<arch>.h. */ |
| 243 |
|
| 244 |
|
| 245 |
#undef SIZE_TYPE |
| 246 |
#define SIZE_TYPE (TARGET_64BIT ? "long unsigned int" : "unsigned int") |
| 247 |
|
| 248 |
#undef PTRDIFF_TYPE |
| 249 |
#define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int") |
| 250 |
|
| 251 |
/* rs6000.h gets this wrong for FreeBSD. We use the GCC defaults instead. */ |
| 252 |
#undef WCHAR_TYPE |
| 253 |
|
| 254 |
#undef WCHAR_TYPE_SIZE |
| 255 |
#define WCHAR_TYPE_SIZE 32 |
| 256 |
|
| 257 |
/* Function profiling bits */ |
| 258 |
#undef RS6000_MCOUNT |
| 259 |
#define RS6000_MCOUNT "_mcount" |
| 260 |
|
| 261 |
#define PROFILE_HOOK(LABEL) \ |
| 262 |
do { if (TARGET_64BIT) output_profile_hook (LABEL); } while (0) |
| 263 |
|
| 264 |
/* _init and _fini functions are built from bits spread across many |
| 265 |
object files, each potentially with a different TOC pointer. For |
| 266 |
that reason, place a nop after the call so that the linker can |
| 267 |
restore the TOC pointer if a TOC adjusting call stub is needed. */ |
| 268 |
#ifdef __powerpc64__ |
| 269 |
#define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC) \ |
| 270 |
asm (SECTION_OP "\n" \ |
| 271 |
" bl " #FUNC "\n" \ |
| 272 |
" nop\n" \ |
| 273 |
" .previous"); |
| 274 |
#endif |
| 275 |
|
| 276 |
/* FP save and restore routines. */ |
| 277 |
#undef SAVE_FP_PREFIX |
| 278 |
#define SAVE_FP_PREFIX (TARGET_64BIT ? "._savef" : "_savefpr_") |
| 279 |
#undef SAVE_FP_SUFFIX |
| 280 |
#define SAVE_FP_SUFFIX "" |
| 281 |
#undef RESTORE_FP_PREFIX |
| 282 |
#define RESTORE_FP_PREFIX (TARGET_64BIT ? "._restf" : "_restfpr_") |
| 283 |
#undef RESTORE_FP_SUFFIX |
| 284 |
#define RESTORE_FP_SUFFIX "" |
| 285 |
|
| 286 |
/* Select a format to encode pointers in exception handling data. CODE |
| 287 |
is 0 for data, 1 for code labels, 2 for function pointers. GLOBAL is |
| 288 |
true if the symbol may be affected by dynamic relocations. */ |
| 289 |
#undef ASM_PREFERRED_EH_DATA_FORMAT |
| 290 |
#define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \ |
| 291 |
(TARGET_64BIT || flag_pic \ |
| 292 |
? (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel \ |
| 293 |
| (TARGET_64BIT ? DW_EH_PE_udata8 : DW_EH_PE_sdata4)) \ |
| 294 |
: DW_EH_PE_absptr) |
| 295 |
|
| 296 |
/* Static stack checking is supported by means of probes. */ |
| 297 |
#define STACK_CHECK_STATIC_BUILTIN 1 |
| 298 |
|
| 299 |
/* The default value isn't sufficient in 64-bit mode. */ |
| 300 |
#define STACK_CHECK_PROTECT (TARGET_64BIT ? 16 * 1024 : 12 * 1024) |
| 301 |
|
| 302 |
/* Use standard DWARF numbering for DWARF debugging information. */ |
| 303 |
#define RS6000_USE_DWARF_NUMBERING |
| 304 |
|
| 305 |
/* PowerPC64 Linux word-aligns FP doubles when -malign-power is given. */ |
| 306 |
#undef ADJUST_FIELD_ALIGN |
| 307 |
#define ADJUST_FIELD_ALIGN(FIELD, TYPE, COMPUTED) \ |
| 308 |
((TARGET_64BIT \ |
| 309 |
&& TARGET_ALIGN_NATURAL == 0 \ |
| 310 |
&& TYPE_MODE (strip_array_types (TYPE)) == DFmode) \ |
| 311 |
? MIN ((COMPUTED), 32) \ |
| 312 |
: (COMPUTED)) |
| 313 |
|
| 314 |
#undef TOC_SECTION_ASM_OP |
| 315 |
#define TOC_SECTION_ASM_OP \ |
| 316 |
(TARGET_64BIT \ |
| 317 |
? "\t.section\t\".toc\",\"aw\"" \ |
| 318 |
: "\t.section\t\".got\",\"aw\"") |
| 319 |
|
| 320 |
#undef MINIMAL_TOC_SECTION_ASM_OP |
| 321 |
#define MINIMAL_TOC_SECTION_ASM_OP \ |
| 322 |
(TARGET_64BIT \ |
| 323 |
? "\t.section\t\".toc1\",\"aw\"" \ |
| 324 |
: (flag_pic \ |
| 325 |
? "\t.section\t\".got2\",\"aw\"" \ |
| 326 |
: "\t.section\t\".got1\",\"aw\"")) |
| 327 |
|
| 328 |
/* This is how to declare the size of a function. */ |
| 329 |
#undef ASM_DECLARE_FUNCTION_SIZE |
| 330 |
#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL) \ |
| 331 |
do \ |
| 332 |
{ \ |
| 333 |
if (!flag_inhibit_size_directive) \ |
| 334 |
{ \ |
| 335 |
fputs ("\t.size\t", (FILE)); \ |
| 336 |
if (TARGET_64BIT && DOT_SYMBOLS) \ |
| 337 |
putc ('.', (FILE)); \ |
| 338 |
assemble_name ((FILE), (FNAME)); \ |
| 339 |
fputs (",.-", (FILE)); \ |
| 340 |
rs6000_output_function_entry (FILE, FNAME); \ |
| 341 |
putc ('\n', (FILE)); \ |
| 342 |
} \ |
| 343 |
} \ |
| 344 |
while (0) |
| 345 |
|
| 346 |
#undef ASM_OUTPUT_SPECIAL_POOL_ENTRY_P |
| 347 |
#define ASM_OUTPUT_SPECIAL_POOL_ENTRY_P(X, MODE) \ |
| 348 |
(TARGET_TOC \ |
| 349 |
&& (SYMBOL_REF_P (X) \ |
| 350 |
|| (GET_CODE (X) == CONST && GET_CODE (XEXP (X, 0)) == PLUS \ |
| 351 |
&& SYMBOL_REF_P (XEXP (XEXP (X, 0), 0))) \ |
| 352 |
|| GET_CODE (X) == LABEL_REF \ |
| 353 |
|| (CONST_INT_P (X) \ |
| 354 |
&& GET_MODE_BITSIZE (MODE) <= GET_MODE_BITSIZE (Pmode)) \ |
| 355 |
|| (CONST_DOUBLE_P (X) \ |
| 356 |
&& ((TARGET_64BIT \ |
| 357 |
&& (TARGET_MINIMAL_TOC \ |
| 358 |
|| (SCALAR_FLOAT_MODE_P (GET_MODE (X)) \ |
| 359 |
&& ! TARGET_NO_FP_IN_TOC))) \ |
| 360 |
|| (!TARGET_64BIT \ |
| 361 |
&& !TARGET_NO_FP_IN_TOC \ |
| 362 |
&& SCALAR_FLOAT_MODE_P (GET_MODE (X)) \ |
| 363 |
&& BITS_PER_WORD == HOST_BITS_PER_INT))))) |
| 364 |
|
| 365 |
/* Use --as-needed -lgcc_s for eh support. */ |
| 366 |
#ifdef HAVE_LD_AS_NEEDED |
| 367 |
#define USE_LD_AS_NEEDED 1 |
| 368 |
#endif |
| 369 |
|
| 370 |
#define POWERPC_FREEBSD |