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-2022 Free Software Foundation, Inc. 6 Contributed by Eric Youngdale. 7 Modified for stabs-in-ELF by H.J. Lu (hjl (at) 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 #define GNU_USER_TARGET_D_OS_VERSIONS() \ 62 do { \ 63 builtin_version ("linux"); \ 64 if (OPTION_GLIBC) \ 65 builtin_version ("CRuntime_Glibc"); \ 66 else if (OPTION_UCLIBC) \ 67 builtin_version ("CRuntime_UClibc"); \ 68 else if (OPTION_BIONIC) \ 69 builtin_version ("CRuntime_Bionic"); \ 70 else if (OPTION_MUSL) \ 71 builtin_version ("CRuntime_Musl"); \ 72 } while (0) 73 74 /* Determine which dynamic linker to use depending on whether GLIBC or 75 uClibc or Bionic or musl is the default C library and whether 76 -muclibc or -mglibc or -mbionic or -mmusl has been passed to change 77 the default. */ 78 79 #define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4) \ 80 "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}" 81 82 #if DEFAULT_LIBC == LIBC_GLIBC 83 #define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \ 84 CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M) 85 #elif DEFAULT_LIBC == LIBC_UCLIBC 86 #define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \ 87 CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M) 88 #elif DEFAULT_LIBC == LIBC_BIONIC 89 #define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \ 90 CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M) 91 #elif DEFAULT_LIBC == LIBC_MUSL 92 #define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \ 93 CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B) 94 #else 95 #error "Unsupported DEFAULT_LIBC" 96 #endif /* DEFAULT_LIBC */ 97 98 /* For most targets the following definitions suffice; 99 GLIBC_DYNAMIC_LINKER must be defined for each target using them, or 100 GLIBC_DYNAMIC_LINKER32 and GLIBC_DYNAMIC_LINKER64 for targets 101 supporting both 32-bit and 64-bit compilation. */ 102 #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0" 103 #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0" 104 #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0" 105 #define UCLIBC_DYNAMIC_LINKERX32 "/lib/ldx32-uClibc.so.0" 106 #define BIONIC_DYNAMIC_LINKER "/system/bin/linker" 107 #define BIONIC_DYNAMIC_LINKER32 "/system/bin/linker" 108 #define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64" 109 #define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32" 110 /* Should be redefined for each target that supports musl. */ 111 #define MUSL_DYNAMIC_LINKER "/dev/null" 112 #define MUSL_DYNAMIC_LINKER32 "/dev/null" 113 #define MUSL_DYNAMIC_LINKER64 "/dev/null" 114 #define MUSL_DYNAMIC_LINKERX32 "/dev/null" 115 116 #define GNU_USER_DYNAMIC_LINKER \ 117 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \ 118 BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER) 119 #define GNU_USER_DYNAMIC_LINKER32 \ 120 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \ 121 BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32) 122 #define GNU_USER_DYNAMIC_LINKER64 \ 123 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \ 124 BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64) 125 #define GNU_USER_DYNAMIC_LINKERX32 \ 126 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \ 127 BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32) 128 129 /* Whether we have Bionic libc runtime */ 130 #undef TARGET_HAS_BIONIC 131 #define TARGET_HAS_BIONIC (OPTION_BIONIC) 132 133 /* musl avoids problematic includes by rearranging the include directories. 134 * Unfortunately, this is mostly duplicated from cppdefault.cc */ 135 #if DEFAULT_LIBC == LIBC_MUSL 136 #define INCLUDE_DEFAULTS_MUSL_GPP \ 137 { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, \ 138 GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, \ 139 { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, \ 140 GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, \ 141 { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, \ 142 GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, 143 144 #ifdef LOCAL_INCLUDE_DIR 145 #define INCLUDE_DEFAULTS_MUSL_LOCAL \ 146 { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, \ 147 { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 }, 148 #else 149 #define INCLUDE_DEFAULTS_MUSL_LOCAL 150 #endif 151 152 #ifdef PREFIX_INCLUDE_DIR 153 #define INCLUDE_DEFAULTS_MUSL_PREFIX \ 154 { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0}, 155 #else 156 #define INCLUDE_DEFAULTS_MUSL_PREFIX 157 #endif 158 159 #ifdef CROSS_INCLUDE_DIR 160 #define INCLUDE_DEFAULTS_MUSL_CROSS \ 161 { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0}, 162 #else 163 #define INCLUDE_DEFAULTS_MUSL_CROSS 164 #endif 165 166 #ifdef TOOL_INCLUDE_DIR 167 #define INCLUDE_DEFAULTS_MUSL_TOOL \ 168 { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0}, 169 #else 170 #define INCLUDE_DEFAULTS_MUSL_TOOL 171 #endif 172 173 #ifdef NATIVE_SYSTEM_HEADER_DIR 174 #define INCLUDE_DEFAULTS_MUSL_NATIVE \ 175 { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \ 176 { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 }, 177 #else 178 #define INCLUDE_DEFAULTS_MUSL_NATIVE 179 #endif 180 181 #if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT) 182 # undef INCLUDE_DEFAULTS_MUSL_LOCAL 183 # define INCLUDE_DEFAULTS_MUSL_LOCAL 184 # undef INCLUDE_DEFAULTS_MUSL_NATIVE 185 # define INCLUDE_DEFAULTS_MUSL_NATIVE 186 #else 187 # undef INCLUDE_DEFAULTS_MUSL_CROSS 188 # define INCLUDE_DEFAULTS_MUSL_CROSS 189 #endif 190 191 #undef INCLUDE_DEFAULTS 192 #define INCLUDE_DEFAULTS \ 193 { \ 194 INCLUDE_DEFAULTS_MUSL_GPP \ 195 INCLUDE_DEFAULTS_MUSL_LOCAL \ 196 INCLUDE_DEFAULTS_MUSL_PREFIX \ 197 INCLUDE_DEFAULTS_MUSL_CROSS \ 198 INCLUDE_DEFAULTS_MUSL_TOOL \ 199 INCLUDE_DEFAULTS_MUSL_NATIVE \ 200 { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 }, \ 201 { 0, 0, 0, 0, 0, 0 } \ 202 } 203 #endif 204 205 #if (DEFAULT_LIBC == LIBC_UCLIBC) && defined (SINGLE_LIBC) /* uClinux */ 206 /* This is a *uclinux* target. We don't define below macros to normal linux 207 versions, because doing so would require *uclinux* targets to include 208 linux.cc, linux-protos.h, linux.opt, etc. We could, alternatively, add 209 these files to *uclinux* targets, but that would only pollute option list 210 (add -mglibc, etc.) without adding any useful support. */ 211 212 /* Define TARGET_LIBC_HAS_FUNCTION for *uclinux* targets to 213 no_c99_libc_has_function, because uclibc does not, normally, have 214 c99 runtime. If, in special cases, uclibc does have c99 runtime, 215 this should be defined to a new hook. Also please note that for targets 216 like *-linux-uclibc that similar check will also need to be added to 217 linux_libc_has_function. */ 218 # undef TARGET_LIBC_HAS_FUNCTION 219 # define TARGET_LIBC_HAS_FUNCTION no_c99_libc_has_function 220 221 #else /* !uClinux, i.e., normal Linux */ 222 223 /* Determine what functions are present at the runtime; 224 this includes full c99 runtime and sincos. */ 225 # undef TARGET_LIBC_HAS_FUNCTION 226 # define TARGET_LIBC_HAS_FUNCTION linux_libc_has_function 227 228 #endif 229