| 1 | /* Definitions for systems using the Linux kernel, with or without |
| 2 | MMU, using ELF at the compiler level but possibly FLT for final |
| 3 | linked executables and shared libraries in some no-MMU cases, and |
| 4 | possibly with a choice of libc implementations. |
| 5 | Copyright (C) 1995-2025 Free Software Foundation, Inc. |
| 6 | Contributed by Eric Youngdale. |
| 7 | Modified for stabs-in-ELF by H.J. Lu (hjl@lucon.org). |
| 8 | |
| 9 | This file is part of GCC. |
| 10 | |
| 11 | GCC is free software; you can redistribute it and/or modify |
| 12 | it under the terms of the GNU General Public License as published by |
| 13 | the Free Software Foundation; either version 3, or (at your option) |
| 14 | any later version. |
| 15 | |
| 16 | GCC is distributed in the hope that it will be useful, |
| 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | GNU General Public License for more details. |
| 20 | |
| 21 | Under Section 7 of GPL version 3, you are granted additional |
| 22 | permissions described in the GCC Runtime Library Exception, version |
| 23 | 3.1, as published by the Free Software Foundation. |
| 24 | |
| 25 | You should have received a copy of the GNU General Public License and |
| 26 | a copy of the GCC Runtime Library Exception along with this program; |
| 27 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 28 | <http://www.gnu.org/licenses/>. */ |
| 29 | |
| 30 | /* C libraries supported on Linux. */ |
| 31 | #ifdef SINGLE_LIBC |
| 32 | #define OPTION_GLIBC_P(opts) (DEFAULT_LIBC == LIBC_GLIBC) |
| 33 | #define OPTION_UCLIBC_P(opts) (DEFAULT_LIBC == LIBC_UCLIBC) |
| 34 | #define OPTION_BIONIC_P(opts) (DEFAULT_LIBC == LIBC_BIONIC) |
| 35 | #undef OPTION_MUSL_P |
| 36 | #define OPTION_MUSL_P(opts) (DEFAULT_LIBC == LIBC_MUSL) |
| 37 | #else |
| 38 | #define OPTION_GLIBC_P(opts) ((opts)->x_linux_libc == LIBC_GLIBC) |
| 39 | #define OPTION_UCLIBC_P(opts) ((opts)->x_linux_libc == LIBC_UCLIBC) |
| 40 | #define OPTION_BIONIC_P(opts) ((opts)->x_linux_libc == LIBC_BIONIC) |
| 41 | #undef OPTION_MUSL_P |
| 42 | #define OPTION_MUSL_P(opts) ((opts)->x_linux_libc == LIBC_MUSL) |
| 43 | #endif |
| 44 | #define OPTION_GLIBC OPTION_GLIBC_P (&global_options) |
| 45 | #define OPTION_UCLIBC OPTION_UCLIBC_P (&global_options) |
| 46 | #define OPTION_BIONIC OPTION_BIONIC_P (&global_options) |
| 47 | #undef OPTION_MUSL |
| 48 | #define OPTION_MUSL OPTION_MUSL_P (&global_options) |
| 49 | |
| 50 | #define GNU_USER_TARGET_OS_CPP_BUILTINS() \ |
| 51 | do { \ |
| 52 | if (OPTION_GLIBC) \ |
| 53 | builtin_define ("__gnu_linux__"); \ |
| 54 | builtin_define_std ("linux"); \ |
| 55 | builtin_define_std ("unix"); \ |
| 56 | builtin_assert ("system=linux"); \ |
| 57 | builtin_assert ("system=unix"); \ |
| 58 | builtin_assert ("system=posix"); \ |
| 59 | } while (0) |
| 60 | |
| 61 | /* Determine which dynamic linker to use depending on whether GLIBC or |
| 62 | uClibc or Bionic or musl is the default C library and whether |
| 63 | -muclibc or -mglibc or -mbionic or -mmusl has been passed to change |
| 64 | the default. */ |
| 65 | |
| 66 | #define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4) \ |
| 67 | "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}" |
| 68 | |
| 69 | #if DEFAULT_LIBC == LIBC_GLIBC |
| 70 | #define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \ |
| 71 | CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M) |
| 72 | #elif DEFAULT_LIBC == LIBC_UCLIBC |
| 73 | #define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \ |
| 74 | CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M) |
| 75 | #elif DEFAULT_LIBC == LIBC_BIONIC |
| 76 | #define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \ |
| 77 | CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M) |
| 78 | #elif DEFAULT_LIBC == LIBC_MUSL |
| 79 | #define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \ |
| 80 | CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B) |
| 81 | #else |
| 82 | #error "Unsupported DEFAULT_LIBC" |
| 83 | #endif /* DEFAULT_LIBC */ |
| 84 | |
| 85 | /* For most targets the following definitions suffice; |
| 86 | GLIBC_DYNAMIC_LINKER must be defined for each target using them, or |
| 87 | GLIBC_DYNAMIC_LINKER32 and GLIBC_DYNAMIC_LINKER64 for targets |
| 88 | supporting both 32-bit and 64-bit compilation. */ |
| 89 | #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0" |
| 90 | #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0" |
| 91 | #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0" |
| 92 | #define UCLIBC_DYNAMIC_LINKERX32 "/lib/ldx32-uClibc.so.0" |
| 93 | #define BIONIC_DYNAMIC_LINKER "/system/bin/linker" |
| 94 | #define BIONIC_DYNAMIC_LINKER32 "/system/bin/linker" |
| 95 | #define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64" |
| 96 | #define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32" |
| 97 | /* Should be redefined for each target that supports musl. */ |
| 98 | #define MUSL_DYNAMIC_LINKER "/dev/null" |
| 99 | #define MUSL_DYNAMIC_LINKER32 "/dev/null" |
| 100 | #define MUSL_DYNAMIC_LINKER64 "/dev/null" |
| 101 | #define MUSL_DYNAMIC_LINKERX32 "/dev/null" |
| 102 | |
| 103 | #define GNU_USER_DYNAMIC_LINKER \ |
| 104 | CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \ |
| 105 | BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER) |
| 106 | #define GNU_USER_DYNAMIC_LINKER32 \ |
| 107 | CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \ |
| 108 | BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32) |
| 109 | #define GNU_USER_DYNAMIC_LINKER64 \ |
| 110 | CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \ |
| 111 | BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64) |
| 112 | #define GNU_USER_DYNAMIC_LINKERX32 \ |
| 113 | CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \ |
| 114 | BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32) |
| 115 | |
| 116 | /* Whether we have Bionic libc runtime */ |
| 117 | #undef TARGET_HAS_BIONIC |
| 118 | #define TARGET_HAS_BIONIC (OPTION_BIONIC) |
| 119 | |
| 120 | /* musl avoids problematic includes by rearranging the include directories. |
| 121 | * Unfortunately, this is mostly duplicated from cppdefault.cc */ |
| 122 | #if DEFAULT_LIBC == LIBC_MUSL |
| 123 | #define INCLUDE_DEFAULTS_MUSL_GPP \ |
| 124 | { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, \ |
| 125 | GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, \ |
| 126 | { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, \ |
| 127 | GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, \ |
| 128 | { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, \ |
| 129 | GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, |
| 130 | |
| 131 | #ifdef LOCAL_INCLUDE_DIR |
| 132 | #define INCLUDE_DEFAULTS_MUSL_LOCAL \ |
| 133 | { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, \ |
| 134 | { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 }, |
| 135 | #else |
| 136 | #define INCLUDE_DEFAULTS_MUSL_LOCAL |
| 137 | #endif |
| 138 | |
| 139 | #ifdef PREFIX_INCLUDE_DIR |
| 140 | #define INCLUDE_DEFAULTS_MUSL_PREFIX \ |
| 141 | { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0}, |
| 142 | #else |
| 143 | #define INCLUDE_DEFAULTS_MUSL_PREFIX |
| 144 | #endif |
| 145 | |
| 146 | #ifdef CROSS_INCLUDE_DIR |
| 147 | #define INCLUDE_DEFAULTS_MUSL_CROSS \ |
| 148 | { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0}, |
| 149 | #else |
| 150 | #define INCLUDE_DEFAULTS_MUSL_CROSS |
| 151 | #endif |
| 152 | |
| 153 | #ifdef TOOL_INCLUDE_DIR |
| 154 | #define INCLUDE_DEFAULTS_MUSL_TOOL \ |
| 155 | { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0}, |
| 156 | #else |
| 157 | #define INCLUDE_DEFAULTS_MUSL_TOOL |
| 158 | #endif |
| 159 | |
| 160 | #ifdef NATIVE_SYSTEM_HEADER_DIR |
| 161 | #define INCLUDE_DEFAULTS_MUSL_NATIVE \ |
| 162 | { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \ |
| 163 | { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 }, |
| 164 | #else |
| 165 | #define INCLUDE_DEFAULTS_MUSL_NATIVE |
| 166 | #endif |
| 167 | |
| 168 | #if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT) |
| 169 | # undef INCLUDE_DEFAULTS_MUSL_LOCAL |
| 170 | # define INCLUDE_DEFAULTS_MUSL_LOCAL |
| 171 | # undef INCLUDE_DEFAULTS_MUSL_NATIVE |
| 172 | # define INCLUDE_DEFAULTS_MUSL_NATIVE |
| 173 | #else |
| 174 | # undef INCLUDE_DEFAULTS_MUSL_CROSS |
| 175 | # define INCLUDE_DEFAULTS_MUSL_CROSS |
| 176 | #endif |
| 177 | |
| 178 | #undef INCLUDE_DEFAULTS |
| 179 | #define INCLUDE_DEFAULTS \ |
| 180 | { \ |
| 181 | INCLUDE_DEFAULTS_MUSL_GPP \ |
| 182 | INCLUDE_DEFAULTS_MUSL_LOCAL \ |
| 183 | INCLUDE_DEFAULTS_MUSL_PREFIX \ |
| 184 | INCLUDE_DEFAULTS_MUSL_CROSS \ |
| 185 | INCLUDE_DEFAULTS_MUSL_TOOL \ |
| 186 | INCLUDE_DEFAULTS_MUSL_NATIVE \ |
| 187 | { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 }, \ |
| 188 | { 0, 0, 0, 0, 0, 0 } \ |
| 189 | } |
| 190 | #endif |
| 191 | |
| 192 | #if (DEFAULT_LIBC == LIBC_UCLIBC) && defined (SINGLE_LIBC) /* uClinux */ |
| 193 | /* This is a *uclinux* target. We don't define below macros to normal linux |
| 194 | versions, because doing so would require *uclinux* targets to include |
| 195 | linux.cc, linux-protos.h, linux.opt, etc. We could, alternatively, add |
| 196 | these files to *uclinux* targets, but that would only pollute option list |
| 197 | (add -mglibc, etc.) without adding any useful support. */ |
| 198 | |
| 199 | /* Define TARGET_LIBC_HAS_FUNCTION for *uclinux* targets to |
| 200 | no_c99_libc_has_function, because uclibc does not, normally, have |
| 201 | c99 runtime. If, in special cases, uclibc does have c99 runtime, |
| 202 | this should be defined to a new hook. Also please note that for targets |
| 203 | like *-linux-uclibc that similar check will also need to be added to |
| 204 | linux_libc_has_function. */ |
| 205 | # undef TARGET_LIBC_HAS_FUNCTION |
| 206 | # define TARGET_LIBC_HAS_FUNCTION no_c99_libc_has_function |
| 207 | |
| 208 | #else /* !uClinux, i.e., normal Linux */ |
| 209 | |
| 210 | /* Determine what functions are present at the runtime; |
| 211 | this includes full c99 runtime and sincos. */ |
| 212 | # undef TARGET_LIBC_HAS_FUNCTION |
| 213 | # define TARGET_LIBC_HAS_FUNCTION linux_libc_has_function |
| 214 | |
| 215 | # undef TARGET_LIBM_FUNCTION_MAX_ERROR |
| 216 | # define TARGET_LIBM_FUNCTION_MAX_ERROR linux_libm_function_max_error |
| 217 | |
| 218 | #undef TARGET_FORTIFY_SOURCE_DEFAULT_LEVEL |
| 219 | #define TARGET_FORTIFY_SOURCE_DEFAULT_LEVEL linux_fortify_source_default_level |
| 220 | |
| 221 | #endif |
| 222 | |