1 /* Definitions of target machine for GNU compiler,
2    for PowerPC machines running Linux.
3    Copyright (C) 1996-2022 Free Software Foundation, Inc.
4    Contributed by Michael Meissner (meissner@cygnus.com).
5 
6    This file is part of GCC.
7 
8    GCC is free software; you can redistribute it and/or modify it
9    under the terms of the GNU General Public License as published
10    by the Free Software Foundation; either version 3, or (at your
11    option) any later version.
12 
13    GCC is distributed in the hope that it will be useful, but WITHOUT
14    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16    License for more details.
17 
18    You should have received a copy of the GNU General Public License
19    along with GCC; see the file COPYING3.  If not see
20    <http://www.gnu.org/licenses/>.  */
21 
22 /* Linux doesn't support saving and restoring 64-bit regs in a 32-bit
23    process.  */
24 #define OS_MISSING_POWERPC64 1
25 
26 /* We use glibc _mcount for profiling.  */
27 #define NO_PROFILE_COUNTERS 1
28 
29 #ifdef SINGLE_LIBC
30 #define OPTION_GLIBC_P(opts)  (DEFAULT_LIBC == LIBC_GLIBC)
31 #define OPTION_UCLIBC_P(opts) (DEFAULT_LIBC == LIBC_UCLIBC)
32 #define OPTION_BIONIC_P(opts) (DEFAULT_LIBC == LIBC_BIONIC)
33 #undef OPTION_MUSL_P
34 #define OPTION_MUSL_P(opts)   (DEFAULT_LIBC == LIBC_MUSL)
35 #else
36 #define OPTION_GLIBC_P(opts)  ((opts)->x_linux_libc == LIBC_GLIBC)
37 #define OPTION_UCLIBC_P(opts) ((opts)->x_linux_libc == LIBC_UCLIBC)
38 #define OPTION_BIONIC_P(opts) ((opts)->x_linux_libc == LIBC_BIONIC)
39 #undef OPTION_MUSL_P
40 #define OPTION_MUSL_P(opts)   ((opts)->x_linux_libc == LIBC_MUSL)
41 #endif
42 #define OPTION_GLIBC                    OPTION_GLIBC_P (&global_options)
43 #define OPTION_UCLIBC                   OPTION_UCLIBC_P (&global_options)
44 #define OPTION_BIONIC                   OPTION_BIONIC_P (&global_options)
45 #undef OPTION_MUSL
46 #define OPTION_MUSL           OPTION_MUSL_P (&global_options)
47 
48 /* Determine what functions are present at the runtime;
49    this includes full c99 runtime and sincos.  */
50 #undef TARGET_LIBC_HAS_FUNCTION
51 #define TARGET_LIBC_HAS_FUNCTION linux_libc_has_function
52 
53 #undef  TARGET_OS_CPP_BUILTINS
54 #define TARGET_OS_CPP_BUILTINS()                            \
55   do                                                                  \
56     {                                                                 \
57       if (strcmp (rs6000_abi_name, "linux") == 0) \
58           GNU_USER_TARGET_OS_CPP_BUILTINS();                \
59       builtin_define_std ("PPC");                           \
60       builtin_define_std ("powerpc");                       \
61       builtin_assert ("cpu=powerpc");                       \
62       builtin_assert ("machine=powerpc");                   \
63       TARGET_OS_SYSV_CPP_BUILTINS ();                       \
64     }                                                                 \
65   while (0)
66 
67 #undef    CPP_OS_DEFAULT_SPEC
68 #define CPP_OS_DEFAULT_SPEC "%(cpp_os_linux)"
69 
70 #undef  LINK_SHLIB_SPEC
71 #define LINK_SHLIB_SPEC "%{shared:-shared} %{!shared: %{static:-static}} \
72   %{static-pie:-static -pie --no-dynamic-linker -z text}"
73 
74 #undef    LIB_DEFAULT_SPEC
75 #define LIB_DEFAULT_SPEC "%(lib_linux)"
76 
77 #undef    STARTFILE_DEFAULT_SPEC
78 #define STARTFILE_DEFAULT_SPEC "%(startfile_linux)"
79 
80 #undef    ENDFILE_DEFAULT_SPEC
81 #define ENDFILE_DEFAULT_SPEC "%(endfile_linux)"
82 
83 #undef    LINK_START_DEFAULT_SPEC
84 #define LINK_START_DEFAULT_SPEC "%(link_start_linux)"
85 
86 #undef    LINK_OS_DEFAULT_SPEC
87 #define LINK_OS_DEFAULT_SPEC "%(link_os_linux)"
88 
89 #undef  DEFAULT_ASM_ENDIAN
90 #if (TARGET_DEFAULT & MASK_LITTLE_ENDIAN)
91 #define DEFAULT_ASM_ENDIAN " -mlittle"
92 #define LINK_OS_LINUX_EMUL ENDIAN_SELECT(" -m elf32ppclinux",         \
93                                                    " -m elf32lppclinux",        \
94                                                    " -m elf32lppclinux")
95 #else
96 #define DEFAULT_ASM_ENDIAN " -mbig"
97 #define LINK_OS_LINUX_EMUL ENDIAN_SELECT(" -m elf32ppclinux",         \
98                                                    " -m elf32lppclinux",        \
99                                                    " -m elf32ppclinux")
100 #endif
101 
102 #undef LINK_OS_LINUX_SPEC
103 #define LINK_OS_LINUX_SPEC LINK_OS_LINUX_EMUL " %{!shared: %{!static: \
104   %{!static-pie: \
105     %{rdynamic:-export-dynamic} \
106     -dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}}"
107 
108 /* For backward compatibility, we must continue to use the AIX
109    structure return convention.  */
110 #undef  DRAFT_V4_STRUCT_RET
111 #define DRAFT_V4_STRUCT_RET 1
112 
113 /* We are 32-bit all the time, so optimize a little.  */
114 #undef TARGET_64BIT
115 #define TARGET_64BIT 0
116 
117 /* We don't need to generate entries in .fixup, except when
118    -mrelocatable or -mrelocatable-lib is given.  */
119 #undef RELOCATABLE_NEEDS_FIXUP
120 #define RELOCATABLE_NEEDS_FIXUP \
121   (rs6000_isa_flags & rs6000_isa_flags_explicit & OPTION_MASK_RELOCATABLE)
122 
123 #undef    RS6000_ABI_NAME
124 #define   RS6000_ABI_NAME "linux"
125 
126 #ifdef TARGET_LIBC_PROVIDES_SSP
127 /* ppc32 glibc provides __stack_chk_guard in -0x7008(2).  */
128 #define TARGET_THREAD_SSP_OFFSET        -0x7008
129 #endif
130 
131 #define POWERPC_LINUX
132 
133 /* ppc linux has 128-bit long double support in glibc 2.4 and later.  */
134 #ifdef TARGET_DEFAULT_LONG_DOUBLE_128
135 #define RS6000_DEFAULT_LONG_DOUBLE_SIZE 128
136 #endif
137 
138 /* Static stack checking is supported by means of probes.  */
139 #define STACK_CHECK_STATIC_BUILTIN 1
140 
141 /* Software floating point support for exceptions and rounding modes
142    depends on the C library in use.  */
143 #undef TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P
144 #define TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P \
145   rs6000_linux_float_exceptions_rounding_supported_p
146 
147 /* Support for TARGET_ATOMIC_ASSIGN_EXPAND_FENV without FPRs depends
148    on glibc 2.19 or greater.  */
149 #if TARGET_GLIBC_MAJOR > 2 \
150   || (TARGET_GLIBC_MAJOR == 2 && TARGET_GLIBC_MINOR >= 19)
151 #define RS6000_GLIBC_ATOMIC_FENV 1
152 #endif
153