BPF List
 help / color / mirror / Atom feed
* pahole v1.30 and libbpf: Introduce kflag for type_tags and decl_tags in BTF
@ 2025-04-18 18:57 Sedat Dilek
  2025-04-23 17:50 ` Andrii Nakryiko
  0 siblings, 1 reply; 3+ messages in thread
From: Sedat Dilek @ 2025-04-18 18:57 UTC (permalink / raw)
  To: Ihor Solodrai, Alan Maguire, Jiri Olsa, Eduard Zingerman
  Cc: Arnaldo Carvalho de Melo, Alexei Starovoitov, Andrii Nakryiko,
	Mykola Lysenko, bpf, sudipm.mukherjee, cavok

[ QUESTION ]

How to check if libbpf API functions
 * btf__add_decl_attr()
 * btf__add_type_attr()
work as expected with pahole v1.30?

Looks like I need Linux version >= v6.15-rc1?

dileks@iniza:~/src/linux/git$ git log --oneline -1
51d1b1d42841c557dabde5b140ae20774591e6dc
51d1b1d42841 libbpf: Introduce kflag for type_tags and decl_tags in BTF

Add the following functions to libbpf API:
 * btf__add_type_attr()
 * btf__add_decl_attr()

dileks@iniza:~/src/linux/git$ git describe --contains
51d1b1d42841c557dabde5b140ae20774591e6dc
v6.15-rc1~98^2~87^2~5

Currently, I use Debian-kernel v6.12.22 and want to build a selfmade
v6.12.24 (when it is released).

If you need further information, please let me know.

Best Thanks,
-Sedat-

P.S.: My investigations

[ DEBIAN PAHOLE ]

Debian/unstable AMD64 ships on my request pahole version 1.30-1.
This version was built against libbpf-dev version (1:1.5.0-2)

Link: https://packages.debian.org/sid/pahole
Link: https://packages.debian.org/sid/libbpf-dev
Link: https://bugs.debian.org/1103000


[ SELFMADE PAHOLE ]

Prereq: libbpf API version >= 1.6.0

dileks@iniza:~/src/pahole/git$ git describe
v1.29-16-gb45268b74da1

dileks@iniza:~/src/pahole/git$ git log --oneline -1
b45268b74da1 (HEAD -> pahole-v1.30, tag: v1.30, origin/next,
origin/master, origin/HEAD, master) Prep 1.30

root# /opt/pahole/bin/pahole --version
v1.30

INFO: git describe should report v1.30


[ BUILD INSTRUCTIONS ]

VER="1.30"
PREFIX="/opt/pahole-$VER"
PREFIX_CMAKE_OPTS="-DCMAKE_INSTALL_PREFIX=$PREFIX"

echo $PREFIX_CMAKE_OPTS

cd ..
mkdir build
cd build

# NOTE: See upstream commit "CMakeList.txt: Respect CMAKE_INSTALL_LIBDIR"
##cmake $PREFIX_CMAKE_OPTS -D__LIB=lib ../git
LC_ALL=C.UTF-8 cmake $PREFIX_CMAKE_OPTS ../git
make
sudo make install

NOTE: Do NOT forget to run `ldconfig` as root (see below).


[ LDCONFIG ]

File: /etc/ld.so.conf.d/a-local-pahole.conf

# pahole lib configuration
/opt/pahole/lib

root# cd /opt
root# ln -sf pahole-$VER pahole
root# ldconfig
root# ldconfig --print-cache | grep pahole


[ PAHOLE - CMAKE LOG (LIBBPF) ]

[...]
-- Submodule update
Submodule 'lib/bpf' (https://github.com/libbpf/libbpf) registered for
path 'lib/bpf'
Cloning into '/home/dileks/src/pahole/git/lib/bpf'...
Submodule path 'lib/bpf': checked out '42a6ef63161a8dc4288172b27f3870e50b3606f7'
-- Submodule update - done

Link: https://web.git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?h=v1.30&id=fe2dcd28ba9d348744ee93fed43cbed5dc0d6a43


[ BTF FEATURES ]

root# /opt/pahole/bin/pahole --usage | grep feature
           [--btf_encode_force] [--btf_features=FEATURE_LIST]
           [--btf_features_strict=FEATURE_LIST_STRICT] [--btf_gen_all]
           [--skip_missing] [--sort] [--structs] [--supported_btf_features]

NOTE: --btf_feature*s* (all options plural) VS. commit 40e82f5be9a7
("pahole: Introduce --btf_feature=attributes")

root# /opt/pahole/bin/pahole --supported_btf_features
encode_force,var,float,decl_tag,type_tag,enum64,optimized_func,consistent_func,decl_tag_kfuncs,reproducible_build,distilled_base,global_var,attributes

NOTE: Supported = attributes


[ LIBBPF API VERSION >= 1.6.0 ]

Link: https://web.git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?h=v1.30&id=fe2dcd28ba9d348744ee93fed43cbed5dc0d6a43

commit fe2dcd28ba9d348744ee93fed43cbed5dc0d6a43 ("pahole: Sync with
libbpf mainline")

Pull recently added libbpf API functions:
 * btf__add_decl_attr()
 * btf__add_type_attr()

root# llvm-dwarfdump-19 /opt/pahole/bin/pahole | grep btf | grep add
               DW_AT_name      ("btf__add_type_attr")
               DW_AT_name      ("btf__add_enum64")


[ pahole.git - lib/bpf/src/libbpf.map ]

LIBBPF_1.6.0 {
       global:
               bpf_linker__add_buf;
               bpf_linker__add_fd;
               bpf_linker__new_fd;
               btf__add_decl_attr;
               btf__add_type_attr;
} LIBBPF_1.5.0;

-EOT-

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: pahole v1.30 and libbpf: Introduce kflag for type_tags and decl_tags in BTF
  2025-04-18 18:57 pahole v1.30 and libbpf: Introduce kflag for type_tags and decl_tags in BTF Sedat Dilek
@ 2025-04-23 17:50 ` Andrii Nakryiko
  2025-04-24  7:48   ` Alan Maguire
  0 siblings, 1 reply; 3+ messages in thread
From: Andrii Nakryiko @ 2025-04-23 17:50 UTC (permalink / raw)
  To: sedat.dilek
  Cc: Ihor Solodrai, Alan Maguire, Jiri Olsa, Eduard Zingerman,
	Arnaldo Carvalho de Melo, Alexei Starovoitov, Andrii Nakryiko,
	Mykola Lysenko, bpf, sudipm.mukherjee, cavok

On Fri, Apr 18, 2025 at 11:58 AM Sedat Dilek <sedat.dilek@gmail.com> wrote:
>
> [ QUESTION ]
>
> How to check if libbpf API functions
>  * btf__add_decl_attr()
>  * btf__add_type_attr()
> work as expected with pahole v1.30?

What does it mean "work as expected"?

Can you be a bit more explicit about what is the problem and what
doesn't work? I didn't get that from the below investigation notes,
sorry.

>
> Looks like I need Linux version >= v6.15-rc1?
>
> dileks@iniza:~/src/linux/git$ git log --oneline -1
> 51d1b1d42841c557dabde5b140ae20774591e6dc
> 51d1b1d42841 libbpf: Introduce kflag for type_tags and decl_tags in BTF
>
> Add the following functions to libbpf API:
>  * btf__add_type_attr()
>  * btf__add_decl_attr()
>
> dileks@iniza:~/src/linux/git$ git describe --contains
> 51d1b1d42841c557dabde5b140ae20774591e6dc
> v6.15-rc1~98^2~87^2~5
>
> Currently, I use Debian-kernel v6.12.22 and want to build a selfmade
> v6.12.24 (when it is released).
>
> If you need further information, please let me know.
>
> Best Thanks,
> -Sedat-
>
> P.S.: My investigations
>
> [ DEBIAN PAHOLE ]
>
> Debian/unstable AMD64 ships on my request pahole version 1.30-1.
> This version was built against libbpf-dev version (1:1.5.0-2)
>
> Link: https://packages.debian.org/sid/pahole
> Link: https://packages.debian.org/sid/libbpf-dev
> Link: https://bugs.debian.org/1103000
>
>
> [ SELFMADE PAHOLE ]
>
> Prereq: libbpf API version >= 1.6.0
>
> dileks@iniza:~/src/pahole/git$ git describe
> v1.29-16-gb45268b74da1
>
> dileks@iniza:~/src/pahole/git$ git log --oneline -1
> b45268b74da1 (HEAD -> pahole-v1.30, tag: v1.30, origin/next,
> origin/master, origin/HEAD, master) Prep 1.30
>
> root# /opt/pahole/bin/pahole --version
> v1.30
>
> INFO: git describe should report v1.30
>
>
> [ BUILD INSTRUCTIONS ]
>
> VER="1.30"
> PREFIX="/opt/pahole-$VER"
> PREFIX_CMAKE_OPTS="-DCMAKE_INSTALL_PREFIX=$PREFIX"
>
> echo $PREFIX_CMAKE_OPTS
>
> cd ..
> mkdir build
> cd build
>
> # NOTE: See upstream commit "CMakeList.txt: Respect CMAKE_INSTALL_LIBDIR"
> ##cmake $PREFIX_CMAKE_OPTS -D__LIB=lib ../git
> LC_ALL=C.UTF-8 cmake $PREFIX_CMAKE_OPTS ../git
> make
> sudo make install
>
> NOTE: Do NOT forget to run `ldconfig` as root (see below).
>
>
> [ LDCONFIG ]
>
> File: /etc/ld.so.conf.d/a-local-pahole.conf
>
> # pahole lib configuration
> /opt/pahole/lib
>
> root# cd /opt
> root# ln -sf pahole-$VER pahole
> root# ldconfig
> root# ldconfig --print-cache | grep pahole
>
>
> [ PAHOLE - CMAKE LOG (LIBBPF) ]
>
> [...]
> -- Submodule update
> Submodule 'lib/bpf' (https://github.com/libbpf/libbpf) registered for
> path 'lib/bpf'
> Cloning into '/home/dileks/src/pahole/git/lib/bpf'...
> Submodule path 'lib/bpf': checked out '42a6ef63161a8dc4288172b27f3870e50b3606f7'
> -- Submodule update - done
>
> Link: https://web.git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?h=v1.30&id=fe2dcd28ba9d348744ee93fed43cbed5dc0d6a43
>
>
> [ BTF FEATURES ]
>
> root# /opt/pahole/bin/pahole --usage | grep feature
>            [--btf_encode_force] [--btf_features=FEATURE_LIST]
>            [--btf_features_strict=FEATURE_LIST_STRICT] [--btf_gen_all]
>            [--skip_missing] [--sort] [--structs] [--supported_btf_features]
>
> NOTE: --btf_feature*s* (all options plural) VS. commit 40e82f5be9a7
> ("pahole: Introduce --btf_feature=attributes")
>
> root# /opt/pahole/bin/pahole --supported_btf_features
> encode_force,var,float,decl_tag,type_tag,enum64,optimized_func,consistent_func,decl_tag_kfuncs,reproducible_build,distilled_base,global_var,attributes
>
> NOTE: Supported = attributes
>
>
> [ LIBBPF API VERSION >= 1.6.0 ]
>
> Link: https://web.git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?h=v1.30&id=fe2dcd28ba9d348744ee93fed43cbed5dc0d6a43
>
> commit fe2dcd28ba9d348744ee93fed43cbed5dc0d6a43 ("pahole: Sync with
> libbpf mainline")
>
> Pull recently added libbpf API functions:
>  * btf__add_decl_attr()
>  * btf__add_type_attr()
>
> root# llvm-dwarfdump-19 /opt/pahole/bin/pahole | grep btf | grep add
>                DW_AT_name      ("btf__add_type_attr")
>                DW_AT_name      ("btf__add_enum64")
>
>
> [ pahole.git - lib/bpf/src/libbpf.map ]
>
> LIBBPF_1.6.0 {
>        global:
>                bpf_linker__add_buf;
>                bpf_linker__add_fd;
>                bpf_linker__new_fd;
>                btf__add_decl_attr;
>                btf__add_type_attr;
> } LIBBPF_1.5.0;
>
> -EOT-

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: pahole v1.30 and libbpf: Introduce kflag for type_tags and decl_tags in BTF
  2025-04-23 17:50 ` Andrii Nakryiko
@ 2025-04-24  7:48   ` Alan Maguire
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Maguire @ 2025-04-24  7:48 UTC (permalink / raw)
  To: sedat.dilek
  Cc: Ihor Solodrai, Jiri Olsa, Eduard Zingerman,
	Arnaldo Carvalho de Melo, Alexei Starovoitov, Andrii Nakryiko,
	Mykola Lysenko, bpf, sudipm.mukherjee, cavok,
	dwarves@vger.kernel.org

On 23/04/2025 18:50, Andrii Nakryiko wrote:
> On Fri, Apr 18, 2025 at 11:58 AM Sedat Dilek <sedat.dilek@gmail.com> wrote:
>>
>> [ QUESTION ]
>>
>> How to check if libbpf API functions
>>  * btf__add_decl_attr()
>>  * btf__add_type_attr()
>> work as expected with pahole v1.30?
> 
> What does it mean "work as expected"?
> 
> Can you be a bit more explicit about what is the problem and what
> doesn't work? I didn't get that from the below investigation notes,
> sorry.
> 
>>
>> Looks like I need Linux version >= v6.15-rc1?
>>

hi Sedat, I'm presuming you just want a way to test these new APIs using
pahole-generated BTF (if that's not what you're asking, as Andrii says
please do let us know what you're trying to do in more detail).

There are two aspects to this; can I generate those attributes, and can
the kernel handle them?

For the first case, type attributes are currently generated if the
"attributes" BTF feature is specified. Whether you have this
functionality in pahole v1.30 depends how you build pahole; if you use
the git submodule, you will have the required function. If not, the new
functionality Ihor added should dynamically detect the presence of
btf__add_type_attr() in the shared library libbpf.so for cases where the
"attributes" flag is specified. If your libbpf.so does not have that
function, the feature request is ignored. btf__add_decl_attr() isn't
used in pahole yet. You can run

pahole --supported_btf_features

...to see if the feature is supported; looks like it is in your case
from what you sent.

Now the next issue is whether a kernel can parse type tags with kind
flag set; only kernels that specify the "attributes" BTF feature in
scripts/Makefile.btf should generate such type tags, as these are the
kernels that can validate BTF containing them.

You can see type attributes in action for vmlinux BTF by running
"bpftool btf dump file vmlinux format c"; a few of the arena-related
kfunc parameters should have address_space(1) attributes associated with
them; example

extern void __attribute__((address_space(1)))
*bpf_arena_alloc_pages(void *p__map, void
__attribute__((address_space(1))) *addr__ign, u32 page_cnt, int node_id,
u64 flags) __weak __ksym;

Note that you need a matching bpftool that also understands that the
kind flag set means an __attribute__((address_space(1))) ; otherwise
these will incorrectly show as
__attribute__(btf_type_tag("address_space(1)")). So make sure you use
the bpftool from a kernel supporting the "attributes" BTF feature.

It would be good to have a standalone pahole selftest covering type
attribute generation; if that's something you would like to contribute
that would be great. We can't really test the decl attribute from the
pahole side until pahole starts using it.

From a libbpf perspective, looks like bpf selftests have test coverage
for btf__add_type_attr() already as part of prog_tests/btf_dump.c.

Alan


>> dileks@iniza:~/src/linux/git$ git log --oneline -1
>> 51d1b1d42841c557dabde5b140ae20774591e6dc
>> 51d1b1d42841 libbpf: Introduce kflag for type_tags and decl_tags in BTF
>>
>> Add the following functions to libbpf API:
>>  * btf__add_type_attr()
>>  * btf__add_decl_attr()
>>
>> dileks@iniza:~/src/linux/git$ git describe --contains
>> 51d1b1d42841c557dabde5b140ae20774591e6dc
>> v6.15-rc1~98^2~87^2~5
>>
>> Currently, I use Debian-kernel v6.12.22 and want to build a selfmade
>> v6.12.24 (when it is released).
>>
>> If you need further information, please let me know.
>>
>> Best Thanks,
>> -Sedat-
>>
>> P.S.: My investigations
>>
>> [ DEBIAN PAHOLE ]
>>
>> Debian/unstable AMD64 ships on my request pahole version 1.30-1.
>> This version was built against libbpf-dev version (1:1.5.0-2)
>>
>> Link: https://packages.debian.org/sid/pahole
>> Link: https://packages.debian.org/sid/libbpf-dev
>> Link: https://bugs.debian.org/1103000
>>
>>
>> [ SELFMADE PAHOLE ]
>>
>> Prereq: libbpf API version >= 1.6.0
>>
>> dileks@iniza:~/src/pahole/git$ git describe
>> v1.29-16-gb45268b74da1
>>
>> dileks@iniza:~/src/pahole/git$ git log --oneline -1
>> b45268b74da1 (HEAD -> pahole-v1.30, tag: v1.30, origin/next,
>> origin/master, origin/HEAD, master) Prep 1.30
>>
>> root# /opt/pahole/bin/pahole --version
>> v1.30
>>
>> INFO: git describe should report v1.30
>>
>>
>> [ BUILD INSTRUCTIONS ]
>>
>> VER="1.30"
>> PREFIX="/opt/pahole-$VER"
>> PREFIX_CMAKE_OPTS="-DCMAKE_INSTALL_PREFIX=$PREFIX"
>>
>> echo $PREFIX_CMAKE_OPTS
>>
>> cd ..
>> mkdir build
>> cd build
>>
>> # NOTE: See upstream commit "CMakeList.txt: Respect CMAKE_INSTALL_LIBDIR"
>> ##cmake $PREFIX_CMAKE_OPTS -D__LIB=lib ../git
>> LC_ALL=C.UTF-8 cmake $PREFIX_CMAKE_OPTS ../git
>> make
>> sudo make install
>>
>> NOTE: Do NOT forget to run `ldconfig` as root (see below).
>>
>>
>> [ LDCONFIG ]
>>
>> File: /etc/ld.so.conf.d/a-local-pahole.conf
>>
>> # pahole lib configuration
>> /opt/pahole/lib
>>
>> root# cd /opt
>> root# ln -sf pahole-$VER pahole
>> root# ldconfig
>> root# ldconfig --print-cache | grep pahole
>>
>>
>> [ PAHOLE - CMAKE LOG (LIBBPF) ]
>>
>> [...]
>> -- Submodule update
>> Submodule 'lib/bpf' (https://github.com/libbpf/libbpf) registered for
>> path 'lib/bpf'
>> Cloning into '/home/dileks/src/pahole/git/lib/bpf'...
>> Submodule path 'lib/bpf': checked out '42a6ef63161a8dc4288172b27f3870e50b3606f7'
>> -- Submodule update - done
>>
>> Link: https://web.git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?h=v1.30&id=fe2dcd28ba9d348744ee93fed43cbed5dc0d6a43
>>
>>
>> [ BTF FEATURES ]
>>
>> root# /opt/pahole/bin/pahole --usage | grep feature
>>            [--btf_encode_force] [--btf_features=FEATURE_LIST]
>>            [--btf_features_strict=FEATURE_LIST_STRICT] [--btf_gen_all]
>>            [--skip_missing] [--sort] [--structs] [--supported_btf_features]
>>
>> NOTE: --btf_feature*s* (all options plural) VS. commit 40e82f5be9a7
>> ("pahole: Introduce --btf_feature=attributes")
>>
>> root# /opt/pahole/bin/pahole --supported_btf_features
>> encode_force,var,float,decl_tag,type_tag,enum64,optimized_func,consistent_func,decl_tag_kfuncs,reproducible_build,distilled_base,global_var,attributes
>>
>> NOTE: Supported = attributes
>>
>>
>> [ LIBBPF API VERSION >= 1.6.0 ]
>>
>> Link: https://web.git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?h=v1.30&id=fe2dcd28ba9d348744ee93fed43cbed5dc0d6a43
>>
>> commit fe2dcd28ba9d348744ee93fed43cbed5dc0d6a43 ("pahole: Sync with
>> libbpf mainline")
>>
>> Pull recently added libbpf API functions:
>>  * btf__add_decl_attr()
>>  * btf__add_type_attr()
>>
>> root# llvm-dwarfdump-19 /opt/pahole/bin/pahole | grep btf | grep add
>>                DW_AT_name      ("btf__add_type_attr")
>>                DW_AT_name      ("btf__add_enum64")
>>
>>
>> [ pahole.git - lib/bpf/src/libbpf.map ]
>>
>> LIBBPF_1.6.0 {
>>        global:
>>                bpf_linker__add_buf;
>>                bpf_linker__add_fd;
>>                bpf_linker__new_fd;
>>                btf__add_decl_attr;
>>                btf__add_type_attr;
>> } LIBBPF_1.5.0;
>>
>> -EOT-


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-24  7:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-18 18:57 pahole v1.30 and libbpf: Introduce kflag for type_tags and decl_tags in BTF Sedat Dilek
2025-04-23 17:50 ` Andrii Nakryiko
2025-04-24  7:48   ` Alan Maguire

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox