diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-05-04 09:37:27 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-05-15 13:31:17 -0400 |
commit | 1b16fffa389dcd4cc054f49e77a4e2ac61e8f287 (patch) | |
tree | afd1b77faeab302b896c8619ba239b889b1e0aec | |
parent | d8ed87bc171946313b2e6d26e1fec494da9154bc (diff) |
perf llvm-utils: Add bpf include path to clang command line
We'll start putting headers for helpers to be used in eBPF proggies in
there:
# perf trace -v --no-syscalls -e empty.c |& grep "llvm compiling command : "
llvm compiling command : /usr/lib64/ccache/clang -D__KERNEL__ -D__NR_CPUS__=4 -DLINUX_VERSION_CODE=0x41100 -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h -I/home/acme/lib/include/perf/bpf -Wno-unused-value -Wno-pointer-sign -working-directory /lib/modules/4.17.0-rc3-00034-gf4ef6a438cee/build -c /home/acme/bpf/empty.c -target bpf -O2 -o -
#
Notice the "-I/home/acme/lib/include/perf/bpf"
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-6xq94xro8xlb5s9urznh3f9k@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/Makefile.config | 7 | ||||
-rw-r--r-- | tools/perf/Makefile.perf | 4 | ||||
-rw-r--r-- | tools/perf/util/Build | 2 | ||||
-rw-r--r-- | tools/perf/util/llvm-utils.c | 19 |
4 files changed, 27 insertions, 5 deletions
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index ae7dc46e8f8a..3bca9a733f0e 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config | |||
@@ -885,6 +885,7 @@ endif | |||
885 | 885 | ||
886 | # Among the variables below, these: | 886 | # Among the variables below, these: |
887 | # perfexecdir | 887 | # perfexecdir |
888 | # perf_include_dir | ||
888 | # template_dir | 889 | # template_dir |
889 | # mandir | 890 | # mandir |
890 | # infodir | 891 | # infodir |
@@ -904,6 +905,7 @@ bindir = $(abspath $(prefix)/$(bindir_relative)) | |||
904 | mandir = share/man | 905 | mandir = share/man |
905 | infodir = share/info | 906 | infodir = share/info |
906 | perfexecdir = libexec/perf-core | 907 | perfexecdir = libexec/perf-core |
908 | perf_include_dir = lib/include/perf | ||
907 | sharedir = $(prefix)/share | 909 | sharedir = $(prefix)/share |
908 | template_dir = share/perf-core/templates | 910 | template_dir = share/perf-core/templates |
909 | STRACE_GROUPS_DIR = share/perf-core/strace/groups | 911 | STRACE_GROUPS_DIR = share/perf-core/strace/groups |
@@ -934,6 +936,7 @@ bindir_SQ = $(subst ','\'',$(bindir)) | |||
934 | mandir_SQ = $(subst ','\'',$(mandir)) | 936 | mandir_SQ = $(subst ','\'',$(mandir)) |
935 | infodir_SQ = $(subst ','\'',$(infodir)) | 937 | infodir_SQ = $(subst ','\'',$(infodir)) |
936 | perfexecdir_SQ = $(subst ','\'',$(perfexecdir)) | 938 | perfexecdir_SQ = $(subst ','\'',$(perfexecdir)) |
939 | perf_include_dir_SQ = $(subst ','\'',$(perf_include_dir)) | ||
937 | template_dir_SQ = $(subst ','\'',$(template_dir)) | 940 | template_dir_SQ = $(subst ','\'',$(template_dir)) |
938 | htmldir_SQ = $(subst ','\'',$(htmldir)) | 941 | htmldir_SQ = $(subst ','\'',$(htmldir)) |
939 | tipdir_SQ = $(subst ','\'',$(tipdir)) | 942 | tipdir_SQ = $(subst ','\'',$(tipdir)) |
@@ -944,14 +947,17 @@ srcdir_SQ = $(subst ','\'',$(srcdir)) | |||
944 | 947 | ||
945 | ifneq ($(filter /%,$(firstword $(perfexecdir))),) | 948 | ifneq ($(filter /%,$(firstword $(perfexecdir))),) |
946 | perfexec_instdir = $(perfexecdir) | 949 | perfexec_instdir = $(perfexecdir) |
950 | perf_include_instdir = $(perf_include_dir) | ||
947 | STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR) | 951 | STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR) |
948 | tip_instdir = $(tipdir) | 952 | tip_instdir = $(tipdir) |
949 | else | 953 | else |
950 | perfexec_instdir = $(prefix)/$(perfexecdir) | 954 | perfexec_instdir = $(prefix)/$(perfexecdir) |
955 | perf_include_instdir = $(prefix)/$(perf_include_dir) | ||
951 | STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR) | 956 | STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR) |
952 | tip_instdir = $(prefix)/$(tipdir) | 957 | tip_instdir = $(prefix)/$(tipdir) |
953 | endif | 958 | endif |
954 | perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir)) | 959 | perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir)) |
960 | perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir)) | ||
955 | STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR)) | 961 | STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR)) |
956 | tip_instdir_SQ = $(subst ','\'',$(tip_instdir)) | 962 | tip_instdir_SQ = $(subst ','\'',$(tip_instdir)) |
957 | 963 | ||
@@ -999,6 +1005,7 @@ $(call detected_var,ETC_PERFCONFIG_SQ) | |||
999 | $(call detected_var,STRACE_GROUPS_DIR_SQ) | 1005 | $(call detected_var,STRACE_GROUPS_DIR_SQ) |
1000 | $(call detected_var,prefix_SQ) | 1006 | $(call detected_var,prefix_SQ) |
1001 | $(call detected_var,perfexecdir_SQ) | 1007 | $(call detected_var,perfexecdir_SQ) |
1008 | $(call detected_var,perf_include_dir_SQ) | ||
1002 | $(call detected_var,tipdir_SQ) | 1009 | $(call detected_var,tipdir_SQ) |
1003 | $(call detected_var,srcdir_SQ) | 1010 | $(call detected_var,srcdir_SQ) |
1004 | $(call detected_var,LIBDIR) | 1011 | $(call detected_var,LIBDIR) |
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 83e453de36f8..d9663b1cf43e 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf | |||
@@ -767,6 +767,10 @@ ifndef NO_JVMTI | |||
767 | endif | 767 | endif |
768 | $(call QUIET_INSTALL, libexec) \ | 768 | $(call QUIET_INSTALL, libexec) \ |
769 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' | 769 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' |
770 | ifndef NO_LIBBPF | ||
771 | $(call QUIET_INSTALL, lib) \ | ||
772 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf' | ||
773 | endif | ||
770 | $(call QUIET_INSTALL, perf-archive) \ | 774 | $(call QUIET_INSTALL, perf-archive) \ |
771 | $(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' | 775 | $(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' |
772 | $(call QUIET_INSTALL, perf-with-kcore) \ | 776 | $(call QUIET_INSTALL, perf-with-kcore) \ |
diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 8052373bcd6a..5d4c45b76895 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build | |||
@@ -152,6 +152,8 @@ libperf-y += perf-hooks.o | |||
152 | libperf-$(CONFIG_CXX) += c++/ | 152 | libperf-$(CONFIG_CXX) += c++/ |
153 | 153 | ||
154 | CFLAGS_config.o += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" | 154 | CFLAGS_config.o += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" |
155 | CFLAGS_llvm-utils.o += -DPERF_INCLUDE_DIR="BUILD_STR($(perf_include_dir_SQ))" | ||
156 | |||
155 | # avoid compiler warnings in 32-bit mode | 157 | # avoid compiler warnings in 32-bit mode |
156 | CFLAGS_genelf_debug.o += -Wno-packed | 158 | CFLAGS_genelf_debug.o += -Wno-packed |
157 | 159 | ||
diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c index 1cca0a2fa641..976e658e38dc 100644 --- a/tools/perf/util/llvm-utils.c +++ b/tools/perf/util/llvm-utils.c | |||
@@ -14,11 +14,12 @@ | |||
14 | #include "config.h" | 14 | #include "config.h" |
15 | #include "util.h" | 15 | #include "util.h" |
16 | #include <sys/wait.h> | 16 | #include <sys/wait.h> |
17 | #include <subcmd/exec-cmd.h> | ||
17 | 18 | ||
18 | #define CLANG_BPF_CMD_DEFAULT_TEMPLATE \ | 19 | #define CLANG_BPF_CMD_DEFAULT_TEMPLATE \ |
19 | "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\ | 20 | "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\ |
20 | "-DLINUX_VERSION_CODE=$LINUX_VERSION_CODE " \ | 21 | "-DLINUX_VERSION_CODE=$LINUX_VERSION_CODE " \ |
21 | "$CLANG_OPTIONS $KERNEL_INC_OPTIONS " \ | 22 | "$CLANG_OPTIONS $KERNEL_INC_OPTIONS $PERF_BPF_INC_OPTIONS " \ |
22 | "-Wno-unused-value -Wno-pointer-sign " \ | 23 | "-Wno-unused-value -Wno-pointer-sign " \ |
23 | "-working-directory $WORKING_DIR " \ | 24 | "-working-directory $WORKING_DIR " \ |
24 | "-c \"$CLANG_SOURCE\" -target bpf -O2 -o -" | 25 | "-c \"$CLANG_SOURCE\" -target bpf -O2 -o -" |
@@ -212,7 +213,7 @@ version_notice(void) | |||
212 | " \t\thttp://llvm.org/apt\n\n" | 213 | " \t\thttp://llvm.org/apt\n\n" |
213 | " \tIf you are using old version of clang, change 'clang-bpf-cmd-template'\n" | 214 | " \tIf you are using old version of clang, change 'clang-bpf-cmd-template'\n" |
214 | " \toption in [llvm] section of ~/.perfconfig to:\n\n" | 215 | " \toption in [llvm] section of ~/.perfconfig to:\n\n" |
215 | " \t \"$CLANG_EXEC $CLANG_OPTIONS $KERNEL_INC_OPTIONS \\\n" | 216 | " \t \"$CLANG_EXEC $CLANG_OPTIONS $KERNEL_INC_OPTIONS $PERF_BPF_INC_OPTIONS \\\n" |
216 | " \t -working-directory $WORKING_DIR -c $CLANG_SOURCE \\\n" | 217 | " \t -working-directory $WORKING_DIR -c $CLANG_SOURCE \\\n" |
217 | " \t -emit-llvm -o - | /path/to/llc -march=bpf -filetype=obj -o -\"\n" | 218 | " \t -emit-llvm -o - | /path/to/llc -march=bpf -filetype=obj -o -\"\n" |
218 | " \t(Replace /path/to/llc with path to your llc)\n\n" | 219 | " \t(Replace /path/to/llc with path to your llc)\n\n" |
@@ -431,9 +432,11 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf, | |||
431 | const char *clang_opt = llvm_param.clang_opt; | 432 | const char *clang_opt = llvm_param.clang_opt; |
432 | char clang_path[PATH_MAX], abspath[PATH_MAX], nr_cpus_avail_str[64]; | 433 | char clang_path[PATH_MAX], abspath[PATH_MAX], nr_cpus_avail_str[64]; |
433 | char serr[STRERR_BUFSIZE]; | 434 | char serr[STRERR_BUFSIZE]; |
434 | char *kbuild_dir = NULL, *kbuild_include_opts = NULL; | 435 | char *kbuild_dir = NULL, *kbuild_include_opts = NULL, |
436 | *perf_bpf_include_opts = NULL; | ||
435 | const char *template = llvm_param.clang_bpf_cmd_template; | 437 | const char *template = llvm_param.clang_bpf_cmd_template; |
436 | char *command_echo, *command_out; | 438 | char *command_echo = NULL, *command_out; |
439 | char *perf_include_dir = system_path(PERF_INCLUDE_DIR); | ||
437 | 440 | ||
438 | if (path[0] != '-' && realpath(path, abspath) == NULL) { | 441 | if (path[0] != '-' && realpath(path, abspath) == NULL) { |
439 | err = errno; | 442 | err = errno; |
@@ -471,12 +474,14 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf, | |||
471 | 474 | ||
472 | snprintf(linux_version_code_str, sizeof(linux_version_code_str), | 475 | snprintf(linux_version_code_str, sizeof(linux_version_code_str), |
473 | "0x%x", kernel_version); | 476 | "0x%x", kernel_version); |
474 | 477 | if (asprintf(&perf_bpf_include_opts, "-I%s/bpf", perf_include_dir) < 0) | |
478 | goto errout; | ||
475 | force_set_env("NR_CPUS", nr_cpus_avail_str); | 479 | force_set_env("NR_CPUS", nr_cpus_avail_str); |
476 | force_set_env("LINUX_VERSION_CODE", linux_version_code_str); | 480 | force_set_env("LINUX_VERSION_CODE", linux_version_code_str); |
477 | force_set_env("CLANG_EXEC", clang_path); | 481 | force_set_env("CLANG_EXEC", clang_path); |
478 | force_set_env("CLANG_OPTIONS", clang_opt); | 482 | force_set_env("CLANG_OPTIONS", clang_opt); |
479 | force_set_env("KERNEL_INC_OPTIONS", kbuild_include_opts); | 483 | force_set_env("KERNEL_INC_OPTIONS", kbuild_include_opts); |
484 | force_set_env("PERF_BPF_INC_OPTIONS", perf_bpf_include_opts); | ||
480 | force_set_env("WORKING_DIR", kbuild_dir ? : "."); | 485 | force_set_env("WORKING_DIR", kbuild_dir ? : "."); |
481 | 486 | ||
482 | /* | 487 | /* |
@@ -512,6 +517,8 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf, | |||
512 | free(command_out); | 517 | free(command_out); |
513 | free(kbuild_dir); | 518 | free(kbuild_dir); |
514 | free(kbuild_include_opts); | 519 | free(kbuild_include_opts); |
520 | free(perf_bpf_include_opts); | ||
521 | free(perf_include_dir); | ||
515 | 522 | ||
516 | if (!p_obj_buf) | 523 | if (!p_obj_buf) |
517 | free(obj_buf); | 524 | free(obj_buf); |
@@ -526,6 +533,8 @@ errout: | |||
526 | free(kbuild_dir); | 533 | free(kbuild_dir); |
527 | free(kbuild_include_opts); | 534 | free(kbuild_include_opts); |
528 | free(obj_buf); | 535 | free(obj_buf); |
536 | free(perf_bpf_include_opts); | ||
537 | free(perf_include_dir); | ||
529 | if (p_obj_buf) | 538 | if (p_obj_buf) |
530 | *p_obj_buf = NULL; | 539 | *p_obj_buf = NULL; |
531 | if (p_obj_buf_sz) | 540 | if (p_obj_buf_sz) |