tools: libbpf: don't return '.text' as a program for multi-function programs
authorJakub Kicinski <jakub.kicinski@netronome.com>
Thu, 28 Jun 2018 21:41:39 +0000 (14:41 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Sat, 30 Jun 2018 23:01:50 +0000 (01:01 +0200)
Make bpf_program__next() skip over '.text' section if object file
has pseudo calls.  The '.text' section is hardly a program in that
case, it's more of a storage for code of functions other than main.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/lib/bpf/libbpf.c

index e2401b9..38ed3e9 100644 (file)
@@ -1865,8 +1865,8 @@ void *bpf_object__priv(struct bpf_object *obj)
        return obj ? obj->priv : ERR_PTR(-EINVAL);
 }
 
-struct bpf_program *
-bpf_program__next(struct bpf_program *prev, struct bpf_object *obj)
+static struct bpf_program *
+__bpf_program__next(struct bpf_program *prev, struct bpf_object *obj)
 {
        size_t idx;
 
@@ -1887,6 +1887,18 @@ bpf_program__next(struct bpf_program *prev, struct bpf_object *obj)
        return &obj->programs[idx];
 }
 
+struct bpf_program *
+bpf_program__next(struct bpf_program *prev, struct bpf_object *obj)
+{
+       struct bpf_program *prog = prev;
+
+       do {
+               prog = __bpf_program__next(prog, obj);
+       } while (prog && bpf_program__is_function_storage(prog, obj));
+
+       return prog;
+}
+
 int bpf_program__set_priv(struct bpf_program *prog, void *priv,
                          bpf_program_clear_priv_t clear_priv)
 {