diff mbox series

libbpf: add specific btf name info when do core

Message ID 20240321170444.388225-1-chen.dylane@gmail.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series libbpf: add specific btf name info when do core | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-42 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18 and -O2 optimization
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / test (test_maps, false, 360) / test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17 and -O2 optimization
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-8 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-10 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-7 success Logs for s390x-gcc / build-release

Commit Message

Tao Chen March 21, 2024, 5:04 p.m. UTC
No logic changed, just add specific btf name when core info
print, maybe it seems more understandable.

Signed-off-by: Tao Chen <chen.dylane@gmail.com>
---
 tools/lib/bpf/libbpf.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Comments

Andrii Nakryiko March 21, 2024, 6:52 p.m. UTC | #1
On Thu, Mar 21, 2024 at 10:04 AM Tao Chen <chen.dylane@gmail.com> wrote:
>
> No logic changed, just add specific btf name when core info
> print, maybe it seems more understandable.
>
> Signed-off-by: Tao Chen <chen.dylane@gmail.com>
> ---
>  tools/lib/bpf/libbpf.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
>

Can you elaborate on what problem you are trying to solve?
Conceptually libbpf does look for types in vmlinux (meaning main
kernel BTF), even if user overrides BTF location (presumably because
of old kernel). So even when we emit "vmlinux" in logs, it seems
correct.

pw-bot: cr


> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index afd09571c482..b32154288b4a 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -5653,7 +5653,8 @@ static int load_module_btfs(struct bpf_object *obj)
>  }
>
>  static struct bpf_core_cand_list *
> -bpf_core_find_cands(struct bpf_object *obj, const struct btf *local_btf, __u32 local_type_id)
> +bpf_core_find_cands(struct bpf_object *obj, const struct btf *local_btf, __u32 local_type_id,
> +                   const char *targ_btf_path)
>  {
>         struct bpf_core_cand local_cand = {};
>         struct bpf_core_cand_list *cands;
> @@ -5680,7 +5681,8 @@ bpf_core_find_cands(struct bpf_object *obj, const struct btf *local_btf, __u32 l
>
>         /* Attempt to find target candidates in vmlinux BTF first */
>         main_btf = obj->btf_vmlinux_override ?: obj->btf_vmlinux;
> -       err = bpf_core_add_cands(&local_cand, local_essent_len, main_btf, "vmlinux", 1, cands);
> +       err = bpf_core_add_cands(&local_cand, local_essent_len, main_btf,
> +                                targ_btf_path ?: "vmlinux", 1, cands);
>         if (err)
>                 goto err_out;
>
> @@ -5793,7 +5795,8 @@ static int bpf_core_resolve_relo(struct bpf_program *prog,
>                                  int relo_idx,
>                                  const struct btf *local_btf,
>                                  struct hashmap *cand_cache,
> -                                struct bpf_core_relo_res *targ_res)
> +                                struct bpf_core_relo_res *targ_res,
> +                                const char *targ_btf_path)
>  {
>         struct bpf_core_spec specs_scratch[3] = {};
>         struct bpf_core_cand_list *cands = NULL;
> @@ -5813,7 +5816,7 @@ static int bpf_core_resolve_relo(struct bpf_program *prog,
>
>         if (relo->kind != BPF_CORE_TYPE_ID_LOCAL &&
>             !hashmap__find(cand_cache, local_id, &cands)) {
> -               cands = bpf_core_find_cands(prog->obj, local_btf, local_id);
> +               cands = bpf_core_find_cands(prog->obj, local_btf, local_id, targ_btf_path);
>                 if (IS_ERR(cands)) {
>                         pr_warn("prog '%s': relo #%d: target candidate search failed for [%d] %s %s: %ld\n",
>                                 prog_name, relo_idx, local_id, btf_kind_str(local_type),
> @@ -5920,7 +5923,8 @@ bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)
>                         if (prog->obj->gen_loader)
>                                 continue;
>
> -                       err = bpf_core_resolve_relo(prog, rec, i, obj->btf, cand_cache, &targ_res);
> +                       err = bpf_core_resolve_relo(prog, rec, i, obj->btf, cand_cache, &targ_res,
> +                                                   targ_btf_path);
>                         if (err) {
>                                 pr_warn("prog '%s': relo #%d: failed to relocate: %d\n",
>                                         prog->name, i, err);
> --
> 2.34.1
>
Tao Chen March 22, 2024, 1:36 p.m. UTC | #2
Hi, Nakryiko, thank you for your reply. I try to familiarize with core 
in libbpf, the debug info is really helpful for me. But i use the old 
kernel btf, so origion debuginfo like:
  struct task_struct___x: found target candidate [130] struct 
task_struct in [vmlinux]
I think it may be more clear, if we print btf name when we use old 
kernel btf like:
  struct task_struct___x: found target candidate [130] struct 
task_struct in [/boot/***.btf]
The patch just solve debug info show for newbies above.

在 2024/3/22 上午2:52, Andrii Nakryiko 写道:
> On Thu, Mar 21, 2024 at 10:04 AM Tao Chen <chen.dylane@gmail.com> wrote:
>>
>> No logic changed, just add specific btf name when core info
>> print, maybe it seems more understandable.
>>
>> Signed-off-by: Tao Chen <chen.dylane@gmail.com>
>> ---
>>   tools/lib/bpf/libbpf.c | 14 +++++++++-----
>>   1 file changed, 9 insertions(+), 5 deletions(-)
>>
> 
> Can you elaborate on what problem you are trying to solve?
> Conceptually libbpf does look for types in vmlinux (meaning main
> kernel BTF), even if user overrides BTF location (presumably because
> of old kernel). So even when we emit "vmlinux" in logs, it seems
> correct.
> 
> pw-bot: cr
> 
> 
>> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
>> index afd09571c482..b32154288b4a 100644
>> --- a/tools/lib/bpf/libbpf.c
>> +++ b/tools/lib/bpf/libbpf.c
>> @@ -5653,7 +5653,8 @@ static int load_module_btfs(struct bpf_object *obj)
>>   }
>>
>>   static struct bpf_core_cand_list *
>> -bpf_core_find_cands(struct bpf_object *obj, const struct btf *local_btf, __u32 local_type_id)
>> +bpf_core_find_cands(struct bpf_object *obj, const struct btf *local_btf, __u32 local_type_id,
>> +                   const char *targ_btf_path)
>>   {
>>          struct bpf_core_cand local_cand = {};
>>          struct bpf_core_cand_list *cands;
>> @@ -5680,7 +5681,8 @@ bpf_core_find_cands(struct bpf_object *obj, const struct btf *local_btf, __u32 l
>>
>>          /* Attempt to find target candidates in vmlinux BTF first */
>>          main_btf = obj->btf_vmlinux_override ?: obj->btf_vmlinux;
>> -       err = bpf_core_add_cands(&local_cand, local_essent_len, main_btf, "vmlinux", 1, cands);
>> +       err = bpf_core_add_cands(&local_cand, local_essent_len, main_btf,
>> +                                targ_btf_path ?: "vmlinux", 1, cands);
>>          if (err)
>>                  goto err_out;
>>
>> @@ -5793,7 +5795,8 @@ static int bpf_core_resolve_relo(struct bpf_program *prog,
>>                                   int relo_idx,
>>                                   const struct btf *local_btf,
>>                                   struct hashmap *cand_cache,
>> -                                struct bpf_core_relo_res *targ_res)
>> +                                struct bpf_core_relo_res *targ_res,
>> +                                const char *targ_btf_path)
>>   {
>>          struct bpf_core_spec specs_scratch[3] = {};
>>          struct bpf_core_cand_list *cands = NULL;
>> @@ -5813,7 +5816,7 @@ static int bpf_core_resolve_relo(struct bpf_program *prog,
>>
>>          if (relo->kind != BPF_CORE_TYPE_ID_LOCAL &&
>>              !hashmap__find(cand_cache, local_id, &cands)) {
>> -               cands = bpf_core_find_cands(prog->obj, local_btf, local_id);
>> +               cands = bpf_core_find_cands(prog->obj, local_btf, local_id, targ_btf_path);
>>                  if (IS_ERR(cands)) {
>>                          pr_warn("prog '%s': relo #%d: target candidate search failed for [%d] %s %s: %ld\n",
>>                                  prog_name, relo_idx, local_id, btf_kind_str(local_type),
>> @@ -5920,7 +5923,8 @@ bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)
>>                          if (prog->obj->gen_loader)
>>                                  continue;
>>
>> -                       err = bpf_core_resolve_relo(prog, rec, i, obj->btf, cand_cache, &targ_res);
>> +                       err = bpf_core_resolve_relo(prog, rec, i, obj->btf, cand_cache, &targ_res,
>> +                                                   targ_btf_path);
>>                          if (err) {
>>                                  pr_warn("prog '%s': relo #%d: failed to relocate: %d\n",
>>                                          prog->name, i, err);
>> --
>> 2.34.1
>>
Andrii Nakryiko March 22, 2024, 5:57 p.m. UTC | #3
On Fri, Mar 22, 2024 at 6:37 AM Tao Chen <chen.dylane@gmail.com> wrote:
>
> Hi, Nakryiko, thank you for your reply. I try to familiarize with core
> in libbpf, the debug info is really helpful for me. But i use the old
> kernel btf, so origion debuginfo like:
>   struct task_struct___x: found target candidate [130] struct
> task_struct in [vmlinux]

the idea here is to not emit path to BTF (otherwise we normally should
emit [/sys/kernel/btf/vmlinux], but rather distinguish whether it's a
kernel BTF ([vmlinux]) or some kernel module BTF ([<module-name>]).

In your case you are overriding vmlinux BTF by using btf_custom_path
option (so you should know where to find it, if you need to debug
something). It's still, conceptually, a [vmlinux], and I'd like to
keep it this way.

> I think it may be more clear, if we print btf name when we use old
> kernel btf like:
>   struct task_struct___x: found target candidate [130] struct
> task_struct in [/boot/***.btf]
> The patch just solve debug info show for newbies above.
>
> 在 2024/3/22 上午2:52, Andrii Nakryiko 写道:
> > On Thu, Mar 21, 2024 at 10:04 AM Tao Chen <chen.dylane@gmail.com> wrote:
> >>
> >> No logic changed, just add specific btf name when core info
> >> print, maybe it seems more understandable.
> >>
> >> Signed-off-by: Tao Chen <chen.dylane@gmail.com>
> >> ---
> >>   tools/lib/bpf/libbpf.c | 14 +++++++++-----
> >>   1 file changed, 9 insertions(+), 5 deletions(-)
> >>
> >
> > Can you elaborate on what problem you are trying to solve?
> > Conceptually libbpf does look for types in vmlinux (meaning main
> > kernel BTF), even if user overrides BTF location (presumably because
> > of old kernel). So even when we emit "vmlinux" in logs, it seems
> > correct.
> >
> > pw-bot: cr
> >
> >
> >> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> >> index afd09571c482..b32154288b4a 100644
> >> --- a/tools/lib/bpf/libbpf.c
> >> +++ b/tools/lib/bpf/libbpf.c
> >> @@ -5653,7 +5653,8 @@ static int load_module_btfs(struct bpf_object *obj)
> >>   }
> >>
> >>   static struct bpf_core_cand_list *
> >> -bpf_core_find_cands(struct bpf_object *obj, const struct btf *local_btf, __u32 local_type_id)
> >> +bpf_core_find_cands(struct bpf_object *obj, const struct btf *local_btf, __u32 local_type_id,
> >> +                   const char *targ_btf_path)
> >>   {
> >>          struct bpf_core_cand local_cand = {};
> >>          struct bpf_core_cand_list *cands;
> >> @@ -5680,7 +5681,8 @@ bpf_core_find_cands(struct bpf_object *obj, const struct btf *local_btf, __u32 l
> >>
> >>          /* Attempt to find target candidates in vmlinux BTF first */
> >>          main_btf = obj->btf_vmlinux_override ?: obj->btf_vmlinux;
> >> -       err = bpf_core_add_cands(&local_cand, local_essent_len, main_btf, "vmlinux", 1, cands);
> >> +       err = bpf_core_add_cands(&local_cand, local_essent_len, main_btf,
> >> +                                targ_btf_path ?: "vmlinux", 1, cands);
> >>          if (err)
> >>                  goto err_out;
> >>
> >> @@ -5793,7 +5795,8 @@ static int bpf_core_resolve_relo(struct bpf_program *prog,
> >>                                   int relo_idx,
> >>                                   const struct btf *local_btf,
> >>                                   struct hashmap *cand_cache,
> >> -                                struct bpf_core_relo_res *targ_res)
> >> +                                struct bpf_core_relo_res *targ_res,
> >> +                                const char *targ_btf_path)
> >>   {
> >>          struct bpf_core_spec specs_scratch[3] = {};
> >>          struct bpf_core_cand_list *cands = NULL;
> >> @@ -5813,7 +5816,7 @@ static int bpf_core_resolve_relo(struct bpf_program *prog,
> >>
> >>          if (relo->kind != BPF_CORE_TYPE_ID_LOCAL &&
> >>              !hashmap__find(cand_cache, local_id, &cands)) {
> >> -               cands = bpf_core_find_cands(prog->obj, local_btf, local_id);
> >> +               cands = bpf_core_find_cands(prog->obj, local_btf, local_id, targ_btf_path);
> >>                  if (IS_ERR(cands)) {
> >>                          pr_warn("prog '%s': relo #%d: target candidate search failed for [%d] %s %s: %ld\n",
> >>                                  prog_name, relo_idx, local_id, btf_kind_str(local_type),
> >> @@ -5920,7 +5923,8 @@ bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)
> >>                          if (prog->obj->gen_loader)
> >>                                  continue;
> >>
> >> -                       err = bpf_core_resolve_relo(prog, rec, i, obj->btf, cand_cache, &targ_res);
> >> +                       err = bpf_core_resolve_relo(prog, rec, i, obj->btf, cand_cache, &targ_res,
> >> +                                                   targ_btf_path);
> >>                          if (err) {
> >>                                  pr_warn("prog '%s': relo #%d: failed to relocate: %d\n",
> >>                                          prog->name, i, err);
> >> --
> >> 2.34.1
> >>
Tao Chen March 23, 2024, 2:40 p.m. UTC | #4
Got it, thanks for your detailed reply.

在 2024/3/23 上午1:57, Andrii Nakryiko 写道:
> On Fri, Mar 22, 2024 at 6:37 AM Tao Chen <chen.dylane@gmail.com> wrote:
>>
>> Hi, Nakryiko, thank you for your reply. I try to familiarize with core
>> in libbpf, the debug info is really helpful for me. But i use the old
>> kernel btf, so origion debuginfo like:
>>    struct task_struct___x: found target candidate [130] struct
>> task_struct in [vmlinux]
> 
> the idea here is to not emit path to BTF (otherwise we normally should
> emit [/sys/kernel/btf/vmlinux], but rather distinguish whether it's a
> kernel BTF ([vmlinux]) or some kernel module BTF ([<module-name>]).
> 
> In your case you are overriding vmlinux BTF by using btf_custom_path
> option (so you should know where to find it, if you need to debug
> something). It's still, conceptually, a [vmlinux], and I'd like to
> keep it this way.
> 
>> I think it may be more clear, if we print btf name when we use old
>> kernel btf like:
>>    struct task_struct___x: found target candidate [130] struct
>> task_struct in [/boot/***.btf]
>> The patch just solve debug info show for newbies above.
>>
>> 在 2024/3/22 上午2:52, Andrii Nakryiko 写道:
>>> On Thu, Mar 21, 2024 at 10:04 AM Tao Chen <chen.dylane@gmail.com> wrote:
>>>>
>>>> No logic changed, just add specific btf name when core info
>>>> print, maybe it seems more understandable.
>>>>
>>>> Signed-off-by: Tao Chen <chen.dylane@gmail.com>
>>>> ---
>>>>    tools/lib/bpf/libbpf.c | 14 +++++++++-----
>>>>    1 file changed, 9 insertions(+), 5 deletions(-)
>>>>
>>>
>>> Can you elaborate on what problem you are trying to solve?
>>> Conceptually libbpf does look for types in vmlinux (meaning main
>>> kernel BTF), even if user overrides BTF location (presumably because
>>> of old kernel). So even when we emit "vmlinux" in logs, it seems
>>> correct.
>>>
>>> pw-bot: cr
>>>
>>>
>>>> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
>>>> index afd09571c482..b32154288b4a 100644
>>>> --- a/tools/lib/bpf/libbpf.c
>>>> +++ b/tools/lib/bpf/libbpf.c
>>>> @@ -5653,7 +5653,8 @@ static int load_module_btfs(struct bpf_object *obj)
>>>>    }
>>>>
>>>>    static struct bpf_core_cand_list *
>>>> -bpf_core_find_cands(struct bpf_object *obj, const struct btf *local_btf, __u32 local_type_id)
>>>> +bpf_core_find_cands(struct bpf_object *obj, const struct btf *local_btf, __u32 local_type_id,
>>>> +                   const char *targ_btf_path)
>>>>    {
>>>>           struct bpf_core_cand local_cand = {};
>>>>           struct bpf_core_cand_list *cands;
>>>> @@ -5680,7 +5681,8 @@ bpf_core_find_cands(struct bpf_object *obj, const struct btf *local_btf, __u32 l
>>>>
>>>>           /* Attempt to find target candidates in vmlinux BTF first */
>>>>           main_btf = obj->btf_vmlinux_override ?: obj->btf_vmlinux;
>>>> -       err = bpf_core_add_cands(&local_cand, local_essent_len, main_btf, "vmlinux", 1, cands);
>>>> +       err = bpf_core_add_cands(&local_cand, local_essent_len, main_btf,
>>>> +                                targ_btf_path ?: "vmlinux", 1, cands);
>>>>           if (err)
>>>>                   goto err_out;
>>>>
>>>> @@ -5793,7 +5795,8 @@ static int bpf_core_resolve_relo(struct bpf_program *prog,
>>>>                                    int relo_idx,
>>>>                                    const struct btf *local_btf,
>>>>                                    struct hashmap *cand_cache,
>>>> -                                struct bpf_core_relo_res *targ_res)
>>>> +                                struct bpf_core_relo_res *targ_res,
>>>> +                                const char *targ_btf_path)
>>>>    {
>>>>           struct bpf_core_spec specs_scratch[3] = {};
>>>>           struct bpf_core_cand_list *cands = NULL;
>>>> @@ -5813,7 +5816,7 @@ static int bpf_core_resolve_relo(struct bpf_program *prog,
>>>>
>>>>           if (relo->kind != BPF_CORE_TYPE_ID_LOCAL &&
>>>>               !hashmap__find(cand_cache, local_id, &cands)) {
>>>> -               cands = bpf_core_find_cands(prog->obj, local_btf, local_id);
>>>> +               cands = bpf_core_find_cands(prog->obj, local_btf, local_id, targ_btf_path);
>>>>                   if (IS_ERR(cands)) {
>>>>                           pr_warn("prog '%s': relo #%d: target candidate search failed for [%d] %s %s: %ld\n",
>>>>                                   prog_name, relo_idx, local_id, btf_kind_str(local_type),
>>>> @@ -5920,7 +5923,8 @@ bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)
>>>>                           if (prog->obj->gen_loader)
>>>>                                   continue;
>>>>
>>>> -                       err = bpf_core_resolve_relo(prog, rec, i, obj->btf, cand_cache, &targ_res);
>>>> +                       err = bpf_core_resolve_relo(prog, rec, i, obj->btf, cand_cache, &targ_res,
>>>> +                                                   targ_btf_path);
>>>>                           if (err) {
>>>>                                   pr_warn("prog '%s': relo #%d: failed to relocate: %d\n",
>>>>                                           prog->name, i, err);
>>>> --
>>>> 2.34.1
>>>>
diff mbox series

Patch

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index afd09571c482..b32154288b4a 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -5653,7 +5653,8 @@  static int load_module_btfs(struct bpf_object *obj)
 }
 
 static struct bpf_core_cand_list *
-bpf_core_find_cands(struct bpf_object *obj, const struct btf *local_btf, __u32 local_type_id)
+bpf_core_find_cands(struct bpf_object *obj, const struct btf *local_btf, __u32 local_type_id,
+		    const char *targ_btf_path)
 {
 	struct bpf_core_cand local_cand = {};
 	struct bpf_core_cand_list *cands;
@@ -5680,7 +5681,8 @@  bpf_core_find_cands(struct bpf_object *obj, const struct btf *local_btf, __u32 l
 
 	/* Attempt to find target candidates in vmlinux BTF first */
 	main_btf = obj->btf_vmlinux_override ?: obj->btf_vmlinux;
-	err = bpf_core_add_cands(&local_cand, local_essent_len, main_btf, "vmlinux", 1, cands);
+	err = bpf_core_add_cands(&local_cand, local_essent_len, main_btf,
+				 targ_btf_path ?: "vmlinux", 1, cands);
 	if (err)
 		goto err_out;
 
@@ -5793,7 +5795,8 @@  static int bpf_core_resolve_relo(struct bpf_program *prog,
 				 int relo_idx,
 				 const struct btf *local_btf,
 				 struct hashmap *cand_cache,
-				 struct bpf_core_relo_res *targ_res)
+				 struct bpf_core_relo_res *targ_res,
+				 const char *targ_btf_path)
 {
 	struct bpf_core_spec specs_scratch[3] = {};
 	struct bpf_core_cand_list *cands = NULL;
@@ -5813,7 +5816,7 @@  static int bpf_core_resolve_relo(struct bpf_program *prog,
 
 	if (relo->kind != BPF_CORE_TYPE_ID_LOCAL &&
 	    !hashmap__find(cand_cache, local_id, &cands)) {
-		cands = bpf_core_find_cands(prog->obj, local_btf, local_id);
+		cands = bpf_core_find_cands(prog->obj, local_btf, local_id, targ_btf_path);
 		if (IS_ERR(cands)) {
 			pr_warn("prog '%s': relo #%d: target candidate search failed for [%d] %s %s: %ld\n",
 				prog_name, relo_idx, local_id, btf_kind_str(local_type),
@@ -5920,7 +5923,8 @@  bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)
 			if (prog->obj->gen_loader)
 				continue;
 
-			err = bpf_core_resolve_relo(prog, rec, i, obj->btf, cand_cache, &targ_res);
+			err = bpf_core_resolve_relo(prog, rec, i, obj->btf, cand_cache, &targ_res,
+						    targ_btf_path);
 			if (err) {
 				pr_warn("prog '%s': relo #%d: failed to relocate: %d\n",
 					prog->name, i, err);