From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ophir Munk Subject: [PATCH v1] net/tap: explain how to compile eBPF C file Date: Mon, 11 Jun 2018 16:06:12 +0000 Message-ID: <1528733172-24747-1-git-send-email-ophirmu@mellanox.com> Mime-Version: 1.0 Content-Type: text/plain Cc: Thomas Monjalon , Olga Shern , Ophir Munk To: dev@dpdk.org, Pascal Mazon , Keith Wiles Return-path: Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on0074.outbound.protection.outlook.com [104.47.1.74]) by dpdk.org (Postfix) with ESMTP id D40871E401 for ; Mon, 11 Jun 2018 18:06:24 +0200 (CEST) List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This commit explains how to manually compile the C source file tap_bpf_program.c into an ELF file using the clang compiler. The code in tap_bpf_program.c requires definitions found in iproute2 source code. This commit suggests cloning the iproute2 git tree and include its path in the clang command. It also adds inclusion of file bpf_api.h (required for eBPF definitions) which is located in iproute2 source tree. For more details refer to TAP documentation. This commit is related to commits [1] and [2]. [1] commit cdc07e83bb24 ("net/tap: add eBPF program file") [2] commit aabe70df73a3 ("net/tap: add eBPF bytes code") Signed-off-by: Ophir Munk --- doc/guides/nics/tap.rst | 21 +++++++++++++++++---- drivers/net/tap/tap_bpf_program.c | 5 +++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/doc/guides/nics/tap.rst b/doc/guides/nics/tap.rst index 2714868..af6c534 100644 --- a/doc/guides/nics/tap.rst +++ b/doc/guides/nics/tap.rst @@ -234,13 +234,26 @@ C functions under different ELF sections. 2. Install ``LLVM`` library and ``clang`` compiler versions 3.7 and above -3. Compile ``tap_bpf_program.c`` via ``LLVM`` into an object file:: +3. The code in ``tap_bpf_program.c`` requires definitions found in iproute2 +source code. - clang -O2 -emit-llvm -c tap_bpf_program.c -o - | llc -march=bpf \ - -filetype=obj -o +Clone the iproute2 git tree and make it accessible to the build environment, say +under directory ```` :: + + git clone https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/ \ + + +The code in ``tap_bpf_program.c`` must include file ``bpf_api.h`` which is +located under ```` directory. This file contains eBPF +related definitions. +4. Compile ``tap_bpf_program.c`` via ``LLVM`` into an object file:: + + clang -I /iproute2/include \ + -O2 -emit-llvm -c tap_bpf_program.c -o - | llc -march=bpf \ + -filetype=obj -o -4. Use a tool that receives two parameters: an eBPF object file and a section +5. Use a tool that receives two parameters: an eBPF object file and a section name, and prints out the section as a C array of eBPF instructions. Embed the C array in your TAP PMD tree. diff --git a/drivers/net/tap/tap_bpf_program.c b/drivers/net/tap/tap_bpf_program.c index 1cb7382..60b069b 100644 --- a/drivers/net/tap/tap_bpf_program.c +++ b/drivers/net/tap/tap_bpf_program.c @@ -17,6 +17,11 @@ #include #include "tap_rss.h" +/* + * bpf_api.h file is located under iproute2 + * tree, see TAP documentation. + */ +#include "bpf_api.h" /** Create IPv4 address */ #define IPv4(a, b, c, d) ((__u32)(((a) & 0xff) << 24) | \ -- 1.8.3.1