Skip to content

Commit 0a9f4a2

Browse files
mauriciovasquezbernalanakryiko
authored andcommitted
bpftool: Add gen min_core_btf command
This command is implemented under the "gen" command in bpftool and the syntax is the following: $ bpftool gen min_core_btf INPUT OUTPUT OBJECT [OBJECT...] INPUT is the file that contains all the BTF types for a kernel and OUTPUT is the path of the minimize BTF file that will be created with only the types needed by the objects. Signed-off-by: Mauricio Vásquez <[email protected]> Signed-off-by: Rafael David Tinoco <[email protected]> Signed-off-by: Lorenzo Fontana <[email protected]> Signed-off-by: Leonardo Di Donato <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 8de6cae commit 0a9f4a2

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

tools/bpf/bpftool/bash-completion/bpftool

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,9 +1003,13 @@ _bpftool()
10031003
;;
10041004
esac
10051005
;;
1006+
min_core_btf)
1007+
_filedir
1008+
return 0
1009+
;;
10061010
*)
10071011
[[ $prev == $object ]] && \
1008-
COMPREPLY=( $( compgen -W 'object skeleton help' -- "$cur" ) )
1012+
COMPREPLY=( $( compgen -W 'object skeleton help min_core_btf' -- "$cur" ) )
10091013
;;
10101014
esac
10111015
;;

tools/bpf/bpftool/gen.c

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,7 @@ static int do_help(int argc, char **argv)
11081108
fprintf(stderr,
11091109
"Usage: %1$s %2$s object OUTPUT_FILE INPUT_FILE [INPUT_FILE...]\n"
11101110
" %1$s %2$s skeleton FILE [name OBJECT_NAME]\n"
1111+
" %1$s %2$s min_core_btf INPUT OUTPUT OBJECT [OBJECT...]\n"
11111112
" %1$s %2$s help\n"
11121113
"\n"
11131114
" " HELP_SPEC_OPTIONS " |\n"
@@ -1118,10 +1119,45 @@ static int do_help(int argc, char **argv)
11181119
return 0;
11191120
}
11201121

1122+
/* Create minimized BTF file for a set of BPF objects */
1123+
static int minimize_btf(const char *src_btf, const char *dst_btf, const char *objspaths[])
1124+
{
1125+
return -EOPNOTSUPP;
1126+
}
1127+
1128+
static int do_min_core_btf(int argc, char **argv)
1129+
{
1130+
const char *input, *output, **objs;
1131+
int i, err;
1132+
1133+
if (!REQ_ARGS(3)) {
1134+
usage();
1135+
return -1;
1136+
}
1137+
1138+
input = GET_ARG();
1139+
output = GET_ARG();
1140+
1141+
objs = (const char **) calloc(argc + 1, sizeof(*objs));
1142+
if (!objs) {
1143+
p_err("failed to allocate array for object names");
1144+
return -ENOMEM;
1145+
}
1146+
1147+
i = 0;
1148+
while (argc)
1149+
objs[i++] = GET_ARG();
1150+
1151+
err = minimize_btf(input, output, objs);
1152+
free(objs);
1153+
return err;
1154+
}
1155+
11211156
static const struct cmd cmds[] = {
1122-
{ "object", do_object },
1123-
{ "skeleton", do_skeleton },
1124-
{ "help", do_help },
1157+
{ "object", do_object },
1158+
{ "skeleton", do_skeleton },
1159+
{ "min_core_btf", do_min_core_btf},
1160+
{ "help", do_help },
11251161
{ 0 }
11261162
};
11271163

0 commit comments

Comments
 (0)