diff mbox

[dwarves,v3,0/5] Emit global variables in BTF

Message ID 20241002235253.487251-1-stephen.s.brennan@oracle.com (mailing list archive)
State Not Applicable
Delegated to: BPF
Headers show

Commit Message

Stephen Brennan Oct. 2, 2024, 11:52 p.m. UTC
Hello all,

This is v3 of the series to add global variables to pahole's generated BTF.
Patches 1-3 of v2 were already merged. This series splits the last patch of v2
and does some small updates. It should apply cleanly to the "next" branch.
https://github.com/acmel/dwarves/commits/btf_global_vars/

Changes since v2:
1. Split things out into several smaller patches as can be seen in the log
   below.
2. Previously the global_var feature was defined with BTF_DEFAULT_FEATURE, but I
   think we agreed in the discussion of v2 that it would be better as
   BTF_NON_DEFAULT_FEATURE, so I changed it to align with our discussion.
3. Removed the "--encode_btf_global_vars" option.
3. I went through and straightened out my use of integer types for ELF section
   index (size_t, as returned by libelf) as well as the variable addr and size.
   To this end I did add a few checks to explicitly ensure we don't overflow the
   uint32_t fields in the DATASEC.

To test this out on a Linux build, you'll want to make the following change:

---------
---------

With a suitable kernel config that has BTF enabled, you could then build like
so:

    PATH=path/to/pahole_build_dir make all

And you'll be able to examine the size of the results with readelf, or dump the
results with bpftool.

v2: https://lore.kernel.org/dwarves/20240920081903.13473-1-stephen.s.brennan@oracle.com/T/
v1: https://lore.kernel.org/dwarves/20240912190827.230176-1-stephen.s.brennan@oracle.com/

Stephen Brennan (5):
  btf_encoder: use bitfield to control var encoding
  btf_encoder: stop indexing symbols for VARs
  btf_encoder: explicitly check addr/size for u32 overflow
  btf_encoder: allow encoding VARs from many sections
  pahole: add global_var BTF feature

 btf_encoder.c      | 348 +++++++++++++++++++++------------------------
 btf_encoder.h      |   7 +
 dwarves.h          |   1 +
 man-pages/pahole.1 |   7 +-
 pahole.c           |   3 +-
 5 files changed, 178 insertions(+), 188 deletions(-)

Comments

Jiri Olsa Oct. 3, 2024, 8:59 p.m. UTC | #1
On Wed, Oct 02, 2024 at 04:52:42PM -0700, Stephen Brennan wrote:
> Hello all,
> 
> This is v3 of the series to add global variables to pahole's generated BTF.
> Patches 1-3 of v2 were already merged. This series splits the last patch of v2
> and does some small updates. It should apply cleanly to the "next" branch.
> https://github.com/acmel/dwarves/commits/btf_global_vars/
> 
> Changes since v2:
> 1. Split things out into several smaller patches as can be seen in the log
>    below.

thanks for the split, so much better for review, lgtm

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka


> 2. Previously the global_var feature was defined with BTF_DEFAULT_FEATURE, but I
>    think we agreed in the discussion of v2 that it would be better as
>    BTF_NON_DEFAULT_FEATURE, so I changed it to align with our discussion.
> 3. Removed the "--encode_btf_global_vars" option.
> 3. I went through and straightened out my use of integer types for ELF section
>    index (size_t, as returned by libelf) as well as the variable addr and size.
>    To this end I did add a few checks to explicitly ensure we don't overflow the
>    uint32_t fields in the DATASEC.
> 
> To test this out on a Linux build, you'll want to make the following change:
> 
> ---------
> diff --git a/scripts/Makefile.btf b/scripts/Makefile.btf
> index b75f09f3f424..c88d9e526426 100644
> --- a/scripts/Makefile.btf
> +++ b/scripts/Makefile.btf
> @@ -19,7 +19,7 @@ pahole-flags-$(call test-ge, $(pahole-ver), 125)      += --skip_encoding_btf_inconsis
>  else
> 
>  # Switch to using --btf_features for v1.26 and later.
> -pahole-flags-$(call test-ge, $(pahole-ver), 126)  = -j --btf_features=encode_force,var,float,enum64,decl_tag,type_tag,optimized_func,consistent_func,decl_tag_kfuncs
> +pahole-flags-$(call test-ge, $(pahole-ver), 126)  = -j --btf_features=encode_force,var,float,enum64,decl_tag,type_tag,optimized_func,consistent_func,decl_tag_kfuncs,global_var
> 
>  ifneq ($(KBUILD_EXTMOD),)
>  module-pahole-flags-$(call test-ge, $(pahole-ver), 126) += --btf_features=distilled_base
> ---------
> 
> With a suitable kernel config that has BTF enabled, you could then build like
> so:
> 
>     PATH=path/to/pahole_build_dir make all
> 
> And you'll be able to examine the size of the results with readelf, or dump the
> results with bpftool.
> 
> v2: https://lore.kernel.org/dwarves/20240920081903.13473-1-stephen.s.brennan@oracle.com/T/
> v1: https://lore.kernel.org/dwarves/20240912190827.230176-1-stephen.s.brennan@oracle.com/
> 
> Stephen Brennan (5):
>   btf_encoder: use bitfield to control var encoding
>   btf_encoder: stop indexing symbols for VARs
>   btf_encoder: explicitly check addr/size for u32 overflow
>   btf_encoder: allow encoding VARs from many sections
>   pahole: add global_var BTF feature
> 
>  btf_encoder.c      | 348 +++++++++++++++++++++------------------------
>  btf_encoder.h      |   7 +
>  dwarves.h          |   1 +
>  man-pages/pahole.1 |   7 +-
>  pahole.c           |   3 +-
>  5 files changed, 178 insertions(+), 188 deletions(-)
> 
> -- 
> 2.43.5
> 
>
diff mbox

Patch

diff --git a/scripts/Makefile.btf b/scripts/Makefile.btf
index b75f09f3f424..c88d9e526426 100644
--- a/scripts/Makefile.btf
+++ b/scripts/Makefile.btf
@@ -19,7 +19,7 @@  pahole-flags-$(call test-ge, $(pahole-ver), 125)      += --skip_encoding_btf_inconsis
 else

 # Switch to using --btf_features for v1.26 and later.
-pahole-flags-$(call test-ge, $(pahole-ver), 126)  = -j --btf_features=encode_force,var,float,enum64,decl_tag,type_tag,optimized_func,consistent_func,decl_tag_kfuncs
+pahole-flags-$(call test-ge, $(pahole-ver), 126)  = -j --btf_features=encode_force,var,float,enum64,decl_tag,type_tag,optimized_func,consistent_func,decl_tag_kfuncs,global_var

 ifneq ($(KBUILD_EXTMOD),)
 module-pahole-flags-$(call test-ge, $(pahole-ver), 126) += --btf_features=distilled_base