Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752796AbcLFHO5 (ORCPT ); Tue, 6 Dec 2016 02:14:57 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:46258 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752217AbcLFHOs (ORCPT ); Tue, 6 Dec 2016 02:14:48 -0500 From: Wang Nan To: CC: , , Wang Nan , Arnaldo Carvalho de Melo , "Alexei Starovoitov" , He Kuang , Jiri Olsa , Zefan Li , Subject: [PATCH v4 14/18] perf clang: Link BPF functions declaration into perf Date: Tue, 6 Dec 2016 07:13:52 +0000 Message-ID: <20161206071356.5312-15-wangnan0@huawei.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161206071356.5312-1-wangnan0@huawei.com> References: <20161206071356.5312-1-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5773 Lines: 113 Hardcode BPF functions declarations. Following commits will utilizes clang's virtual file system to automatically include this header to all BPF scripts. The generated header is wrapped by a BUILTIN_CLANG_NO_DEFAULT_INCLUDE. This macro will be used by following commits to allow user disable this feature. The C string looks ugly and heavily uses magic numbers because the header is designed to be included automatically at very first, makes any dependency or potential conflict harmful. Actually it is automatically generated using a script: https://patchwork.kernel.org/patch/9350221 However, that script is fragile so not included by this commit. Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: He Kuang Cc: Jiri Olsa Cc: Zefan Li Cc: pi3orama@163.com --- tools/perf/util/c++/Build | 1 + tools/perf/util/c++/bpf-funcs-str.c | 49 ++++++++++++++++++++++++++++++++ tools/perf/util/c++/clang-bpf-includes.h | 12 ++++++++ 3 files changed, 62 insertions(+) create mode 100644 tools/perf/util/c++/bpf-funcs-str.c create mode 100644 tools/perf/util/c++/clang-bpf-includes.h diff --git a/tools/perf/util/c++/Build b/tools/perf/util/c++/Build index 988fef1..bd71abf 100644 --- a/tools/perf/util/c++/Build +++ b/tools/perf/util/c++/Build @@ -1,2 +1,3 @@ libperf-$(CONFIG_CLANGLLVM) += clang.o libperf-$(CONFIG_CLANGLLVM) += clang-test.o +libperf-$(CONFIG_CLANGLLVM) += bpf-funcs-str.o diff --git a/tools/perf/util/c++/bpf-funcs-str.c b/tools/perf/util/c++/bpf-funcs-str.c new file mode 100644 index 0000000..ab1a0e3 --- /dev/null +++ b/tools/perf/util/c++/bpf-funcs-str.c @@ -0,0 +1,49 @@ +#include "clang-bpf-includes.h" +const char clang_builtin_bpf_funcs_str[] = +"#ifdef BUILTIN_CLANG_DEFAULT_INCLUDE\n" +"#ifndef BPF_FUNCS_DEFINED\n" +"#define BPF_FUNCS_DEFINED\n" +"static void *(*bpf_map_lookup_elem)(void *, void *) = (void *)1;\n" +"static long (*bpf_map_update_elem)(void *, void *, void *, unsigned long) = (void *)2;\n" +"static long (*bpf_map_delete_elem)(void *, void *) = (void *)3;\n" +"static long (*bpf_probe_read)(void *, unsigned long, unsigned long) = (void *)4;\n" +"static long (*bpf_ktime_get_ns)(void) = (void *)5;\n" +"static long (*bpf_trace_printk)(void *, unsigned long, ...) = (void *)6;\n" +"static long (*bpf_get_prandom_u32)(void) = (void *)7;\n" +"static long (*bpf_get_smp_processor_id)(void) = (void *)8;\n" +"static long (*bpf_skb_store_bytes)(void *, unsigned long, void *, unsigned long, unsigned long) = (void *)9;\n" +"static long (*bpf_l3_csum_replace)(void *, unsigned long, unsigned long, unsigned long, unsigned long) = (void *)10;\n" +"static long (*bpf_l4_csum_replace)(void *, unsigned long, unsigned long, unsigned long, unsigned long) = (void *)11;\n" +"static void (*bpf_tail_call)(void *, void *, unsigned long) = (void *)12;\n" +"static long (*bpf_clone_redirect)(void *, unsigned long, unsigned long) = (void *)13;\n" +"static long (*bpf_get_current_pid_tgid)(void) = (void *)14;\n" +"static long (*bpf_get_current_uid_gid)(void) = (void *)15;\n" +"static long (*bpf_get_current_comm)(void *, unsigned long) = (void *)16;\n" +"static long (*bpf_get_cgroup_classid)(void *) = (void *)17;\n" +"static long (*bpf_skb_vlan_push)(void *, unsigned long, unsigned long) = (void *)18;\n" +"static long (*bpf_skb_vlan_pop)(void *) = (void *)19;\n" +"static long (*bpf_skb_get_tunnel_key)(void *, void *, unsigned long, unsigned long) = (void *)20;\n" +"static long (*bpf_skb_set_tunnel_key)(void *, void *, unsigned long, unsigned long) = (void *)21;\n" +"static long (*bpf_perf_event_read)(void *, unsigned long) = (void *)22;\n" +"static long (*bpf_redirect)(unsigned long, unsigned long) = (void *)23;\n" +"static long (*bpf_get_route_realm)(void *) = (void *)24;\n" +"static long (*bpf_perf_event_output)(void *, void *, unsigned long, void *, unsigned long) = (void *)25;\n" +"static long (*bpf_skb_load_bytes)(void *, unsigned long, void *, unsigned long) = (void *)26;\n" +"static long (*bpf_get_stackid)(void *, void *, unsigned long) = (void *)27;\n" +"static long (*bpf_csum_diff)(void *, unsigned long, void *, unsigned long, unsigned long) = (void *)28;\n" +"static long (*bpf_skb_get_tunnel_opt)(void *, void *, unsigned long) = (void *)29;\n" +"static long (*bpf_skb_set_tunnel_opt)(void *, void *, unsigned long) = (void *)30;\n" +"static long (*bpf_skb_change_proto)(void *, unsigned long, unsigned long) = (void *)31;\n" +"static long (*bpf_skb_change_type)(void *, unsigned long) = (void *)32;\n" +"static long (*bpf_skb_under_cgroup)(void *, void *, unsigned long) = (void *)33;\n" +"static long (*bpf_get_hash_recalc)(void *) = (void *)34;\n" +"static long (*bpf_get_current_task)(void) = (void *)35;\n" +"static long (*bpf_probe_write_user)(unsigned long, void *, unsigned long) = (void *)36;\n" +"static long (*bpf_current_task_under_cgroup)(void *, unsigned long) = (void *)37;\n" +"static long (*bpf_skb_change_tail)(void *, unsigned long, unsigned long) = (void *)38;\n" +"static long (*bpf_skb_pull_data)(void *, unsigned long) = (void *)39;\n" +"static long (*bpf_csum_update)(void *, unsigned long) = (void *)40;\n" +"static long (*bpf_set_hash_invalid)(void *) = (void *)41;\n" +"#endif\n" +"#endif\n" +; diff --git a/tools/perf/util/c++/clang-bpf-includes.h b/tools/perf/util/c++/clang-bpf-includes.h new file mode 100644 index 0000000..385a5bb --- /dev/null +++ b/tools/perf/util/c++/clang-bpf-includes.h @@ -0,0 +1,12 @@ +#ifndef CLANG_BPF_INCLUDS_H +#define CLANG_BPF_INCLUDS_H +#ifdef __cplusplus +extern "C" { +#endif + +extern const char clang_builtin_bpf_funcs_str[]; + +#ifdef __cplusplus +} +#endif +#endif -- 2.10.1