]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/architecture.h
basic/architecture: Properly set LIB_ARCH_TUPLE for x32
[thirdparty/systemd.git] / src / basic / architecture.h
1 #pragma once
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2014 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <endian.h>
23
24 #include "macro.h"
25 #include "util.h"
26
27 /* A cleaned up architecture definition. We don't want to get lost in
28 * processor features, models, generations or even ABIs. Hence we
29 * focus on general family, and distinguish word width and
30 * endianness. */
31
32 enum {
33 ARCHITECTURE_X86 = 0,
34 ARCHITECTURE_X86_64,
35 ARCHITECTURE_PPC,
36 ARCHITECTURE_PPC_LE,
37 ARCHITECTURE_PPC64,
38 ARCHITECTURE_PPC64_LE,
39 ARCHITECTURE_IA64,
40 ARCHITECTURE_PARISC,
41 ARCHITECTURE_PARISC64,
42 ARCHITECTURE_S390,
43 ARCHITECTURE_S390X,
44 ARCHITECTURE_SPARC,
45 ARCHITECTURE_SPARC64,
46 ARCHITECTURE_MIPS,
47 ARCHITECTURE_MIPS_LE,
48 ARCHITECTURE_MIPS64,
49 ARCHITECTURE_MIPS64_LE,
50 ARCHITECTURE_ALPHA,
51 ARCHITECTURE_ARM,
52 ARCHITECTURE_ARM_BE,
53 ARCHITECTURE_ARM64,
54 ARCHITECTURE_ARM64_BE,
55 ARCHITECTURE_SH,
56 ARCHITECTURE_SH64,
57 ARCHITECTURE_M68K,
58 ARCHITECTURE_TILEGX,
59 ARCHITECTURE_CRIS,
60 ARCHITECTURE_NIOS2,
61 ARCHITECTURE_RISCV32,
62 ARCHITECTURE_RISCV64,
63 _ARCHITECTURE_MAX,
64 _ARCHITECTURE_INVALID = -1
65 };
66
67 int uname_architecture(void);
68
69 /*
70 * LIB_ARCH_TUPLE should resolve to the local library path
71 * architecture tuple systemd is built for, according to the Debian
72 * tuple list:
73 *
74 * https://wiki.debian.org/Multiarch/Tuples
75 *
76 * This is used in library search paths that should understand
77 * Debian's paths on all distributions.
78 */
79
80 #if defined(__x86_64__)
81 # define native_architecture() ARCHITECTURE_X86_64
82 # if defined(__ILP32__)
83 # define LIB_ARCH_TUPLE "x86_64-linux-gnux32"
84 # else
85 # define LIB_ARCH_TUPLE "x86_64-linux-gnu"
86 # endif
87 # define SECONDARY_ARCHITECTURE ARCHITECTURE_X86
88 #elif defined(__i386__)
89 # define native_architecture() ARCHITECTURE_X86
90 # define LIB_ARCH_TUPLE "i386-linux-gnu"
91 #elif defined(__powerpc64__)
92 # if __BYTE_ORDER == __BIG_ENDIAN
93 # define native_architecture() ARCHITECTURE_PPC64
94 # define LIB_ARCH_TUPLE "ppc64-linux-gnu"
95 # define SECONDARY_ARCHITECTURE ARCHITECTURE_PPC
96 # else
97 # define native_architecture() ARCHITECTURE_PPC64_LE
98 # define LIB_ARCH_TUPLE "powerpc64le-linux-gnu"
99 # define SECONDARY_ARCHITECTURE ARCHITECTURE_PPC_LE
100 # endif
101 #elif defined(__powerpc__)
102 # if __BYTE_ORDER == __BIG_ENDIAN
103 # define native_architecture() ARCHITECTURE_PPC
104 # define LIB_ARCH_TUPLE "powerpc-linux-gnu"
105 # else
106 # define native_architecture() ARCHITECTURE_PPC_LE
107 # error "Missing LIB_ARCH_TUPLE for PPCLE"
108 # endif
109 #elif defined(__ia64__)
110 # define native_architecture() ARCHITECTURE_IA64
111 # define LIB_ARCH_TUPLE "ia64-linux-gnu"
112 #elif defined(__hppa64__)
113 # define native_architecture() ARCHITECTURE_PARISC64
114 # error "Missing LIB_ARCH_TUPLE for HPPA64"
115 #elif defined(__hppa__)
116 # define native_architecture() ARCHITECTURE_PARISC
117 # define LIB_ARCH_TUPLE "hppa‑linux‑gnu"
118 #elif defined(__s390x__)
119 # define native_architecture() ARCHITECTURE_S390X
120 # define LIB_ARCH_TUPLE "s390x-linux-gnu"
121 # define SECONDARY_ARCHITECTURE ARCHITECTURE_S390
122 #elif defined(__s390__)
123 # define native_architecture() ARCHITECTURE_S390
124 # define LIB_ARCH_TUPLE "s390-linux-gnu"
125 #elif defined(__sparc__) && defined (__arch64__)
126 # define native_architecture() ARCHITECTURE_SPARC64
127 # define LIB_ARCH_TUPLE "sparc64-linux-gnu"
128 #elif defined(__sparc__)
129 # define native_architecture() ARCHITECTURE_SPARC
130 # define LIB_ARCH_TUPLE "sparc-linux-gnu"
131 #elif defined(__mips64) && defined(__LP64__)
132 # if __BYTE_ORDER == __BIG_ENDIAN
133 # define native_architecture() ARCHITECTURE_MIPS64
134 # define LIB_ARCH_TUPLE "mips64-linux-gnuabi64"
135 # else
136 # define native_architecture() ARCHITECTURE_MIPS64_LE
137 # define LIB_ARCH_TUPLE "mips64el-linux-gnuabi64"
138 # endif
139 #elif defined(__mips64)
140 # if __BYTE_ORDER == __BIG_ENDIAN
141 # define native_architecture() ARCHITECTURE_MIPS64
142 # define LIB_ARCH_TUPLE "mips64-linux-gnuabin32"
143 # else
144 # define native_architecture() ARCHITECTURE_MIPS64_LE
145 # define LIB_ARCH_TUPLE "mips64el-linux-gnuabin32"
146 # endif
147 #elif defined(__mips__)
148 # if __BYTE_ORDER == __BIG_ENDIAN
149 # define native_architecture() ARCHITECTURE_MIPS
150 # define LIB_ARCH_TUPLE "mips-linux-gnu"
151 # else
152 # define native_architecture() ARCHITECTURE_MIPS_LE
153 # define LIB_ARCH_TUPLE "mipsel-linux-gnu"
154 # endif
155 #elif defined(__alpha__)
156 # define native_architecture() ARCHITECTURE_ALPHA
157 # define LIB_ARCH_TUPLE "alpha-linux-gnu"
158 #elif defined(__aarch64__)
159 # if __BYTE_ORDER == __BIG_ENDIAN
160 # define native_architecture() ARCHITECTURE_ARM64_BE
161 # define LIB_ARCH_TUPLE "aarch64_be-linux-gnu"
162 # else
163 # define native_architecture() ARCHITECTURE_ARM64
164 # define LIB_ARCH_TUPLE "aarch64-linux-gnu"
165 # define SECONDARY_ARCHITECTURE ARCHITECTURE_ARM
166 # endif
167 #elif defined(__arm__)
168 # if __BYTE_ORDER == __BIG_ENDIAN
169 # define native_architecture() ARCHITECTURE_ARM_BE
170 # if defined(__ARM_EABI__)
171 # if defined(__ARM_PCS_VFP)
172 # define LIB_ARCH_TUPLE "armeb-linux-gnueabihf"
173 # else
174 # define LIB_ARCH_TUPLE "armeb-linux-gnueabi"
175 # endif
176 # else
177 # define LIB_ARCH_TUPLE "armeb-linux-gnu"
178 # endif
179 # else
180 # define native_architecture() ARCHITECTURE_ARM
181 # if defined(__ARM_EABI__)
182 # if defined(__ARM_PCS_VFP)
183 # define LIB_ARCH_TUPLE "arm-linux-gnueabihf"
184 # else
185 # define LIB_ARCH_TUPLE "arm-linux-gnueabi"
186 # endif
187 # else
188 # define LIB_ARCH_TUPLE "arm-linux-gnu"
189 # endif
190 # endif
191 #elif defined(__sh64__)
192 # define native_architecture() ARCHITECTURE_SH64
193 # error "Missing LIB_ARCH_TUPLE for SH64"
194 #elif defined(__sh__)
195 # define native_architecture() ARCHITECTURE_SH
196 # define LIB_ARCH_TUPLE "sh4-linux-gnu"
197 #elif defined(__m68k__)
198 # define native_architecture() ARCHITECTURE_M68K
199 # define LIB_ARCH_TUPLE "m68k-linux-gnu"
200 #elif defined(__tilegx__)
201 # define native_architecture() ARCHITECTURE_TILEGX
202 # define LIB_ARCH_TUPLE "tilegx-linux-gnu"
203 #elif defined(__cris__)
204 # define native_architecture() ARCHITECTURE_CRIS
205 # error "Missing LIB_ARCH_TUPLE for CRIS"
206 #elif defined(__nios2__)
207 # define native_architecture() ARCHITECTURE_NIOS2
208 # define LIB_ARCH_TUPLE "nios2-linux-gnu"
209 #elif defined(__riscv__) || defined(__riscv)
210 /* __riscv__ is obsolete, remove in 2018 */
211 # if __SIZEOF_POINTER__ == 4
212 # define native_architecture() ARCHITECTURE_RISCV32
213 # define LIB_ARCH_TUPLE "riscv32-linux-gnu"
214 # elif __SIZEOF_POINTER__ == 8
215 # define native_architecture() ARCHITECTURE_RISCV64
216 # define LIB_ARCH_TUPLE "riscv64-linux-gnu"
217 # else
218 # error "Unrecognized riscv architecture variant"
219 # endif
220 #else
221 # error "Please register your architecture here!"
222 #endif
223
224 const char *architecture_to_string(int a) _const_;
225 int architecture_from_string(const char *s) _pure_;