aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2016-03-23 16:34:29 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-03-23 16:39:19 -0400
commit78478269d2c9be315164d15c14e6e222a06d2f40 (patch)
tree2f2745ab81cf650f8921c6430da30a84734d7a39
parent0741208a7cd4fc651316f1f861ad9e83495765fc (diff)
perf llvm: Use realpath to canonicalize paths
To kill the last user of make_nonrelative_path(), that gets ditched, one more panicking function killed. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-3hu56rvyh4q5gxogovb6ko8a@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/Build1
-rw-r--r--tools/perf/util/abspath.c37
-rw-r--r--tools/perf/util/cache.h1
-rw-r--r--tools/perf/util/llvm-utils.c17
4 files changed, 12 insertions, 44 deletions
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index eea25e2424e9..da48fd843438 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -1,4 +1,3 @@
1libperf-y += abspath.o
2libperf-y += alias.o 1libperf-y += alias.o
3libperf-y += annotate.o 2libperf-y += annotate.o
4libperf-y += build-id.o 3libperf-y += build-id.o
diff --git a/tools/perf/util/abspath.c b/tools/perf/util/abspath.c
deleted file mode 100644
index 0e76affe9c36..000000000000
--- a/tools/perf/util/abspath.c
+++ /dev/null
@@ -1,37 +0,0 @@
1#include "cache.h"
2
3static const char *get_pwd_cwd(void)
4{
5 static char cwd[PATH_MAX + 1];
6 char *pwd;
7 struct stat cwd_stat, pwd_stat;
8 if (getcwd(cwd, PATH_MAX) == NULL)
9 return NULL;
10 pwd = getenv("PWD");
11 if (pwd && strcmp(pwd, cwd)) {
12 stat(cwd, &cwd_stat);
13 if (!stat(pwd, &pwd_stat) &&
14 pwd_stat.st_dev == cwd_stat.st_dev &&
15 pwd_stat.st_ino == cwd_stat.st_ino) {
16 strlcpy(cwd, pwd, PATH_MAX);
17 }
18 }
19 return cwd;
20}
21
22const char *make_nonrelative_path(const char *path)
23{
24 static char buf[PATH_MAX + 1];
25
26 if (is_absolute_path(path)) {
27 if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
28 die("Too long path: %.*s", 60, path);
29 } else {
30 const char *cwd = get_pwd_cwd();
31 if (!cwd)
32 die("Cannot determine the current working directory");
33 if (snprintf(buf, PATH_MAX, "%s/%s", cwd, path) >= PATH_MAX)
34 die("Too long path: %.*s", 60, path);
35 }
36 return buf;
37}
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index da322bea56f7..1f5a93c2c9a2 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -64,7 +64,6 @@ static inline int is_absolute_path(const char *path)
64 return path[0] == '/'; 64 return path[0] == '/';
65} 65}
66 66
67const char *make_nonrelative_path(const char *path);
68char *strip_path_suffix(const char *path, const char *suffix); 67char *strip_path_suffix(const char *path, const char *suffix);
69 68
70char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2))); 69char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 00724d496d38..aab855f491ca 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -3,11 +3,11 @@
3 * Copyright (C) 2015, Huawei Inc. 3 * Copyright (C) 2015, Huawei Inc.
4 */ 4 */
5 5
6#include <limits.h>
6#include <stdio.h> 7#include <stdio.h>
7#include "util.h" 8#include <stdlib.h>
8#include "debug.h" 9#include "debug.h"
9#include "llvm-utils.h" 10#include "llvm-utils.h"
10#include "cache.h"
11 11
12#define CLANG_BPF_CMD_DEFAULT_TEMPLATE \ 12#define CLANG_BPF_CMD_DEFAULT_TEMPLATE \
13 "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\ 13 "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\
@@ -334,10 +334,18 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
334 unsigned int kernel_version; 334 unsigned int kernel_version;
335 char linux_version_code_str[64]; 335 char linux_version_code_str[64];
336 const char *clang_opt = llvm_param.clang_opt; 336 const char *clang_opt = llvm_param.clang_opt;
337 char clang_path[PATH_MAX], nr_cpus_avail_str[64]; 337 char clang_path[PATH_MAX], abspath[PATH_MAX], nr_cpus_avail_str[64];
338 char serr[STRERR_BUFSIZE];
338 char *kbuild_dir = NULL, *kbuild_include_opts = NULL; 339 char *kbuild_dir = NULL, *kbuild_include_opts = NULL;
339 const char *template = llvm_param.clang_bpf_cmd_template; 340 const char *template = llvm_param.clang_bpf_cmd_template;
340 341
342 if (path[0] != '-' && realpath(path, abspath) == NULL) {
343 err = errno;
344 pr_err("ERROR: problems with path %s: %s\n",
345 path, strerror_r(err, serr, sizeof(serr)));
346 return -err;
347 }
348
341 if (!template) 349 if (!template)
342 template = CLANG_BPF_CMD_DEFAULT_TEMPLATE; 350 template = CLANG_BPF_CMD_DEFAULT_TEMPLATE;
343 351
@@ -387,8 +395,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
387 * stdin to be source file (testing). 395 * stdin to be source file (testing).
388 */ 396 */
389 force_set_env("CLANG_SOURCE", 397 force_set_env("CLANG_SOURCE",
390 (path[0] == '-') ? path : 398 (path[0] == '-') ? path : abspath);
391 make_nonrelative_path(path));
392 399
393 pr_debug("llvm compiling command template: %s\n", template); 400 pr_debug("llvm compiling command template: %s\n", template);
394 err = read_from_pipe(template, &obj_buf, &obj_buf_sz); 401 err = read_from_pipe(template, &obj_buf, &obj_buf_sz);