1 // SPDX-License-Identifier: GPL-2.0
5 #include "../util/env.h"
6 #include "../util/debug.h"
7 #include <linux/zalloc.h>
9 const char *const arc_triplets
[] = {
11 "arc-snps-linux-uclibc-",
12 "arc-snps-linux-gnu-",
16 const char *const arm_triplets
[] = {
18 "arm-linux-androideabi-",
20 "arm-unknown-linux-gnu-",
21 "arm-unknown-linux-gnueabi-",
23 "arm-linux-gnueabihf-",
28 const char *const arm64_triplets
[] = {
29 "aarch64-linux-android-",
34 const char *const powerpc_triplets
[] = {
35 "powerpc-unknown-linux-gnu-",
37 "powerpc64-unknown-linux-gnu-",
38 "powerpc64-linux-gnu-",
39 "powerpc64le-linux-gnu-",
43 const char *const s390_triplets
[] = {
49 const char *const sh_triplets
[] = {
50 "sh-unknown-linux-gnu-",
51 "sh64-unknown-linux-gnu-",
57 const char *const sparc_triplets
[] = {
58 "sparc-unknown-linux-gnu-",
59 "sparc64-unknown-linux-gnu-",
64 const char *const x86_triplets
[] = {
65 "x86_64-pc-linux-gnu-",
66 "x86_64-unknown-linux-gnu-",
71 "i686-linux-android-",
72 "i686-android-linux-",
78 const char *const mips_triplets
[] = {
79 "mips-unknown-linux-gnu-",
80 "mipsel-linux-android-",
83 "mips64el-linux-gnuabi64-",
84 "mips64-linux-gnuabi64-",
89 static bool lookup_path(char *name
)
92 char *path
, *tmp
= NULL
;
94 char *env
= getenv("PATH");
103 path
= strtok_r(env
, ":", &tmp
);
105 scnprintf(buf
, sizeof(buf
), "%s/%s", path
, name
);
106 if (access(buf
, F_OK
) == 0) {
110 path
= strtok_r(NULL
, ":", &tmp
);
116 static int lookup_triplets(const char *const *triplets
, const char *name
)
121 for (i
= 0; triplets
[i
] != NULL
; i
++) {
122 scnprintf(buf
, sizeof(buf
), "%s%s", triplets
[i
], name
);
123 if (lookup_path(buf
))
129 static int perf_env__lookup_binutils_path(struct perf_env
*env
,
130 const char *name
, const char **path
)
133 const char *arch
= perf_env__arch(env
), *cross_env
;
134 const char *const *path_list
;
138 * We don't need to try to find objdump path for native system.
139 * Just use default binutils path (e.g.: "objdump").
141 if (!strcmp(perf_env__arch(NULL
), arch
))
144 cross_env
= getenv("CROSS_COMPILE");
146 if (asprintf(&buf
, "%s%s", cross_env
, name
) < 0)
149 if (access(buf
, F_OK
) == 0)
153 if (lookup_path(buf
))
158 if (!strcmp(arch
, "arc"))
159 path_list
= arc_triplets
;
160 else if (!strcmp(arch
, "arm"))
161 path_list
= arm_triplets
;
162 else if (!strcmp(arch
, "arm64"))
163 path_list
= arm64_triplets
;
164 else if (!strcmp(arch
, "powerpc"))
165 path_list
= powerpc_triplets
;
166 else if (!strcmp(arch
, "sh"))
167 path_list
= sh_triplets
;
168 else if (!strcmp(arch
, "s390"))
169 path_list
= s390_triplets
;
170 else if (!strcmp(arch
, "sparc"))
171 path_list
= sparc_triplets
;
172 else if (!strcmp(arch
, "x86"))
173 path_list
= x86_triplets
;
174 else if (!strcmp(arch
, "mips"))
175 path_list
= mips_triplets
;
177 ui__error("binutils for %s not supported.\n", arch
);
181 idx
= lookup_triplets(path_list
, name
);
183 ui__error("Please install %s for %s.\n"
184 "You can add it to PATH, set CROSS_COMPILE or "
185 "override the default using --%s.\n",
190 if (asprintf(&buf
, "%s%s", path_list
[idx
], name
) < 0)
202 int perf_env__lookup_objdump(struct perf_env
*env
, const char **path
)
205 * For live mode, env->arch will be NULL and we can use
206 * the native objdump tool.
208 if (env
->arch
== NULL
)
211 return perf_env__lookup_binutils_path(env
, "objdump", path
);
215 * Some architectures have a single address space for kernel and user addresses,
216 * which makes it possible to determine if an address is in kernel space or user
219 bool perf_env__single_address_space(struct perf_env
*env
)
221 return strcmp(perf_env__arch(env
), "sparc");