BPF List
 help / color / mirror / Atom feed
From: Quentin Monnet <quentin@isovalent.com>
To: Andrii Nakryiko <andrii@kernel.org>,
	bpf@vger.kernel.org, netdev@vger.kernel.org, ast@fb.com,
	daniel@iogearbox.net
Cc: kernel-team@fb.com
Subject: Re: [PATCH v2 bpf-next 08/11] bpftool: add `gen object` command to perform BPF static linking
Date: Mon, 15 Mar 2021 09:24:19 +0000	[thread overview]
Message-ID: <af200ca7-5946-9df6-71ec-98042aecfa27@isovalent.com> (raw)
In-Reply-To: <20210313193537.1548766-9-andrii@kernel.org>

2021-03-13 11:35 UTC-0800 ~ Andrii Nakryiko <andrii@kernel.org>
> Add `bpftool gen object <output-file> <input_file>...` command to statically
> link multiple BPF ELF object files into a single output BPF ELF object file.
> 
> Similarly to existing '*.o' convention, bpftool is establishing a '*.bpfo'
> convention for statically-linked BPF object files. Both .o and .bpfo suffixes
> will be stripped out during BPF skeleton generation to infer BPF object name.
> 
> This patch also updates bash completions and man page. Man page gets a short
> section on `gen object` command, but also updates the skeleton example to show
> off workflow for BPF application with two .bpf.c files, compiled individually
> with Clang, then resulting object files are linked together with `gen object`,
> and then final object file is used to generate usable BPF skeleton. This
> should help new users understand realistic workflow w.r.t. compiling
> mutli-file BPF application.
> 
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> ---
>  .../bpf/bpftool/Documentation/bpftool-gen.rst | 65 +++++++++++++++----
>  tools/bpf/bpftool/bash-completion/bpftool     |  2 +-
>  tools/bpf/bpftool/gen.c                       | 49 +++++++++++++-
>  3 files changed, 99 insertions(+), 17 deletions(-)
> 
> diff --git a/tools/bpf/bpftool/Documentation/bpftool-gen.rst b/tools/bpf/bpftool/Documentation/bpftool-gen.rst
> index 84cf0639696f..4cdce187c393 100644
> --- a/tools/bpf/bpftool/Documentation/bpftool-gen.rst
> +++ b/tools/bpf/bpftool/Documentation/bpftool-gen.rst
> @@ -14,16 +14,37 @@ SYNOPSIS
>  
>  	*OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] }
>  
> -	*COMMAND* := { **skeleton** | **help** }
> +	*COMMAND* := { **object** | **skeleton** | **help** }
>  
>  GEN COMMANDS
>  =============
>  
> +|	**bpftool** **gen object** *OUTPUT_FILE* *INPUT_FILE* [*INPUT_FILE*...]
>  |	**bpftool** **gen skeleton** *FILE*
>  |	**bpftool** **gen help**
>  
>  DESCRIPTION
>  ===========
> +	**bpftool gen object** *OUTPUT_FILE* *INPUT_FILE* [*INPUT_FILE*...]
> +		  Statically link (combine) together one or more *INPUT_FILE*'s
> +		  into a single resulting *OUTPUT_FILE*. All the files involed

Typo: "involed"

> +		  are BPF ELF object files.
> +
> +		  The rules of BPF static linking are mostly the same as for
> +		  user-space object files, but in addition to combining data
> +		  and instruction sections, .BTF and .BTF.ext (if present in
> +		  any of the input files) data are combined together. .BTF
> +		  data is deduplicated, so all the common types across
> +		  *INPUT_FILE*'s will only be represented once in the resulting
> +		  BTF information.
> +
> +		  BPF static linking allows to partition BPF source code into
> +		  individually compiled files that are then linked into
> +		  a single resulting BPF object file, which can be used to
> +		  generated BPF skeleton (with **gen skeleton** command) or
> +		  passed directly into **libbpf** (using **bpf_object__open()**
> +		  family of APIs).
> +
>  	**bpftool gen skeleton** *FILE*
>  		  Generate BPF skeleton C header file for a given *FILE*.
>  

> diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
> index fdffbc64c65c..7ca23c58f2c0 100644
> --- a/tools/bpf/bpftool/bash-completion/bpftool
> +++ b/tools/bpf/bpftool/bash-completion/bpftool
> @@ -981,7 +981,7 @@ _bpftool()
>              ;;
>          gen)
>              case $command in
> -                skeleton)
> +                object|skeleton)
>                      _filedir
>                      ;;
>                  *)

Suggesting the "object" keyword for completing "bpftool gen [tab]"
is missing. It is just a few lines below:

------
diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
index fdffbc64c65c..223438e86932 100644
--- a/tools/bpf/bpftool/bash-completion/bpftool
+++ b/tools/bpf/bpftool/bash-completion/bpftool
@@ -981,12 +981,12 @@ _bpftool()
             ;;
         gen)
             case $command in
-                skeleton)
+                object|skeleton)
                     _filedir
                     ;;
                 *)
                     [[ $prev == $object ]] && \
-                        COMPREPLY=( $( compgen -W 'skeleton help' -- "$cur" ) )
+                        COMPREPLY=( $( compgen -W 'object skeleton help' -- "$cur" ) )
                     ;;
             esac
             ;;
------

Looks good otherwise. Thanks for the documentation, it's great to
have the example in the man page.

Pending the two nits above are fixed:
Reviewed-by: Quentin Monnet <quentin@isovalent.com>

Quentin

  reply	other threads:[~2021-03-15  9:25 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-13 19:35 [PATCH v2 bpf-next 00/11] BPF static linking Andrii Nakryiko
2021-03-13 19:35 ` [PATCH v2 bpf-next 01/11] libbpf: expose btf_type_by_id() internally Andrii Nakryiko
2021-03-13 19:35 ` [PATCH v2 bpf-next 02/11] libbpf: generalize BTF and BTF.ext type ID and strings iteration Andrii Nakryiko
2021-03-13 19:35 ` [PATCH v2 bpf-next 03/11] libbpf: rename internal memory-management helpers Andrii Nakryiko
2021-03-13 19:35 ` [PATCH v2 bpf-next 04/11] libbpf: extract internal set-of-strings datastructure APIs Andrii Nakryiko
2021-03-13 19:35 ` [PATCH v2 bpf-next 05/11] libbpf: add generic BTF type shallow copy API Andrii Nakryiko
2021-03-13 19:35 ` [PATCH v2 bpf-next 06/11] libbpf: add BPF static linker APIs Andrii Nakryiko
2021-06-07 23:11   ` Tom Stellard
2021-06-08  0:25     ` Andrii Nakryiko
     [not found]       ` <b1bdf1df-e3a8-1ce8-fc33-4ab40b39fb06@redhat.com>
2021-06-08  2:41         ` Tom Stellard
2021-06-08  4:08           ` Andrii Nakryiko
2021-06-08  6:47             ` Yonghong Song
2021-06-09  3:44             ` Tom Stellard
2021-06-09  4:41               ` Andrii Nakryiko
2021-03-13 19:35 ` [PATCH v2 bpf-next 07/11] libbpf: add BPF static linker BTF and BTF.ext support Andrii Nakryiko
2021-03-17  5:25   ` Alexei Starovoitov
2021-03-17 22:10     ` Andrii Nakryiko
2021-03-13 19:35 ` [PATCH v2 bpf-next 08/11] bpftool: add `gen object` command to perform BPF static linking Andrii Nakryiko
2021-03-15  9:24   ` Quentin Monnet [this message]
2021-03-16  5:16     ` Andrii Nakryiko
2021-03-13 19:35 ` [PATCH v2 bpf-next 09/11] selftests/bpf: re-generate vmlinux.h and BPF skeletons if bpftool changed Andrii Nakryiko
2021-03-13 19:35 ` [PATCH v2 bpf-next 10/11] selftests/bpf: pass all BPF .o's through BPF static linker Andrii Nakryiko
2021-03-17  5:34   ` Alexei Starovoitov
2021-03-17 20:47     ` Andrii Nakryiko
2021-03-17 21:00       ` Alexei Starovoitov
2021-03-17 21:22         ` Andrii Nakryiko
2021-03-13 19:35 ` [PATCH v2 bpf-next 11/11] selftests/bpf: add multi-file statically linked BPF object file test Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=af200ca7-5946-9df6-71ec-98042aecfa27@isovalent.com \
    --to=quentin@isovalent.com \
    --cc=andrii@kernel.org \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox