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@lucon.org).
9 This file is part of GCC.
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)
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.
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.
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/>. */
30 /* C libraries supported on Linux. */
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)
36 #define OPTION_MUSL_P(opts) (DEFAULT_LIBC == LIBC_MUSL)
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)
42 #define OPTION_MUSL_P(opts) ((opts)->x_linux_libc == LIBC_MUSL)
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)
48 #define OPTION_MUSL OPTION_MUSL_P (&global_options)
50 #define GNU_USER_TARGET_OS_CPP_BUILTINS() \
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"); \
61 #define GNU_USER_TARGET_D_OS_VERSIONS() \
63 builtin_version ("linux"); \
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"); \
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
79 #define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4) \
80 "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
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)
95 #error "Unsupported DEFAULT_LIBC"
96 #endif /* DEFAULT_LIBC */
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"
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)
129 /* Whether we have Bionic libc runtime */
130 #undef TARGET_HAS_BIONIC
131 #define TARGET_HAS_BIONIC (OPTION_BIONIC)
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 },
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 },
149 #define INCLUDE_DEFAULTS_MUSL_LOCAL
152 #ifdef PREFIX_INCLUDE_DIR
153 #define INCLUDE_DEFAULTS_MUSL_PREFIX \
154 { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
156 #define INCLUDE_DEFAULTS_MUSL_PREFIX
159 #ifdef CROSS_INCLUDE_DIR
160 #define INCLUDE_DEFAULTS_MUSL_CROSS \
161 { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
163 #define INCLUDE_DEFAULTS_MUSL_CROSS
166 #ifdef TOOL_INCLUDE_DIR
167 #define INCLUDE_DEFAULTS_MUSL_TOOL \
168 { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
170 #define INCLUDE_DEFAULTS_MUSL_TOOL
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 },
178 #define INCLUDE_DEFAULTS_MUSL_NATIVE
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
187 # undef INCLUDE_DEFAULTS_MUSL_CROSS
188 # define INCLUDE_DEFAULTS_MUSL_CROSS
191 #undef INCLUDE_DEFAULTS
192 #define INCLUDE_DEFAULTS \
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 } \
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. */
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
221 #else /* !uClinux, i.e., normal Linux */
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