diff mbox series

[bpf-next,1/2] tools/resolve_btfids: emit warnings and patch zero id for missing symbols

Message ID 20210725141814.2000828-2-hengqi.chen@gmail.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series expand bpf_d_path helper allowlist | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 7 maintainers not CCed: sdf@google.com jackmanb@google.com netdev@vger.kernel.org jetswayss@gmail.com kpsingh@kernel.org kafai@fb.com songliubraving@fb.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch warning CHECK: Alignment should match open parenthesis
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Hengqi Chen July 25, 2021, 2:18 p.m. UTC
Kernel functions referenced by .BTF_ids may changed from global to static
and get inlined and thus disappears from BTF. This causes kernel build
failure when resolve_btfids do id patch for symbols in .BTF_ids in vmlinux.
Update resolve_btfids to emit warning messages and patch zero id for missing
symbols instead of aborting kernel build process.

Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
---
 tools/bpf/resolve_btfids/main.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

--
2.25.1

Comments

Yonghong Song July 26, 2021, 3:32 a.m. UTC | #1
On 7/25/21 7:18 AM, Hengqi Chen wrote:
> Kernel functions referenced by .BTF_ids may changed from global to static
> and get inlined and thus disappears from BTF. This causes kernel build

the function could be renamed or removed too.

> failure when resolve_btfids do id patch for symbols in .BTF_ids in vmlinux.
> Update resolve_btfids to emit warning messages and patch zero id for missing
> symbols instead of aborting kernel build process.
> 
> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>

LGTM with one minor comment below.

Acked-by: Yonghong Song <yhs@fb.com>

> ---
>   tools/bpf/resolve_btfids/main.c | 13 +++++++------
>   1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
> index 3ad9301b0f00..3ea19e33250d 100644
> --- a/tools/bpf/resolve_btfids/main.c
> +++ b/tools/bpf/resolve_btfids/main.c
> @@ -291,7 +291,7 @@ static int compressed_section_fix(Elf *elf, Elf_Scn *scn, GElf_Shdr *sh)
>   	sh->sh_addralign = expected;
> 
>   	if (gelf_update_shdr(scn, sh) == 0) {
> -		printf("FAILED cannot update section header: %s\n",
> +		pr_err("FAILED cannot update section header: %s\n",
>   			elf_errmsg(-1));
>   		return -1;
>   	}
> @@ -317,6 +317,7 @@ static int elf_collect(struct object *obj)
> 
>   	elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL);
>   	if (!elf) {
> +		close(fd);
>   		pr_err("FAILED cannot create ELF descriptor: %s\n",
>   			elf_errmsg(-1));
>   		return -1;
> @@ -484,7 +485,7 @@ static int symbols_resolve(struct object *obj)
>   	err = libbpf_get_error(btf);
>   	if (err) {
>   		pr_err("FAILED: load BTF from %s: %s\n",
> -			obj->path, strerror(-err));
> +			obj->btf ?: obj->path, strerror(-err));

Why you change "obj->path" to "obj->btf ?: obj->path"?
Note that obj->path cannot be NULL.

>   		return -1;
>   	}
> 
[...]
Hengqi Chen July 26, 2021, 4:41 a.m. UTC | #2
On 2021/7/26 11:32 AM, Yonghong Song wrote:
> 
> 
> On 7/25/21 7:18 AM, Hengqi Chen wrote:
>> Kernel functions referenced by .BTF_ids may changed from global to static
>> and get inlined and thus disappears from BTF. This causes kernel build
> 
> the function could be renamed or removed too.
> 
>> failure when resolve_btfids do id patch for symbols in .BTF_ids in vmlinux.
>> Update resolve_btfids to emit warning messages and patch zero id for missing
>> symbols instead of aborting kernel build process.
>>
>> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
> 
> LGTM with one minor comment below.
> 
> Acked-by: Yonghong Song <yhs@fb.com>
> 
>> ---
>>   tools/bpf/resolve_btfids/main.c | 13 +++++++------
>>   1 file changed, 7 insertions(+), 6 deletions(-)
>>
>> diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
>> index 3ad9301b0f00..3ea19e33250d 100644
>> --- a/tools/bpf/resolve_btfids/main.c
>> +++ b/tools/bpf/resolve_btfids/main.c
>> @@ -291,7 +291,7 @@ static int compressed_section_fix(Elf *elf, Elf_Scn *scn, GElf_Shdr *sh)
>>       sh->sh_addralign = expected;
>>
>>       if (gelf_update_shdr(scn, sh) == 0) {
>> -        printf("FAILED cannot update section header: %s\n",
>> +        pr_err("FAILED cannot update section header: %s\n",
>>               elf_errmsg(-1));
>>           return -1;
>>       }
>> @@ -317,6 +317,7 @@ static int elf_collect(struct object *obj)
>>
>>       elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL);
>>       if (!elf) {
>> +        close(fd);
>>           pr_err("FAILED cannot create ELF descriptor: %s\n",
>>               elf_errmsg(-1));
>>           return -1;
>> @@ -484,7 +485,7 @@ static int symbols_resolve(struct object *obj)
>>       err = libbpf_get_error(btf);
>>       if (err) {
>>           pr_err("FAILED: load BTF from %s: %s\n",
>> -            obj->path, strerror(-err));
>> +            obj->btf ?: obj->path, strerror(-err));
> 
> Why you change "obj->path" to "obj->btf ?: obj->path"?
> Note that obj->path cannot be NULL.

The diff didn't see the whole picture. Let me quote it here:
```
btf = btf__parse(obj->btf ?: obj->path, NULL);
err = libbpf_get_error(btf);
if (err) {
        pr_err("FAILED: load BTF from %s: %s\n",
                obj->path, strerror(-err));
        return -1;
}
```

Because btf__parse parses either obj->btf or obj->path,
I think the error message should reveal this.

> 
>>           return -1;
>>       }
>>
> [...]
Yonghong Song July 26, 2021, 4:56 a.m. UTC | #3
On 7/25/21 9:41 PM, Hengqi Chen wrote:
> 
> 
> On 2021/7/26 11:32 AM, Yonghong Song wrote:
>>
>>
>> On 7/25/21 7:18 AM, Hengqi Chen wrote:
>>> Kernel functions referenced by .BTF_ids may changed from global to static
>>> and get inlined and thus disappears from BTF. This causes kernel build
>>
>> the function could be renamed or removed too.
>>
>>> failure when resolve_btfids do id patch for symbols in .BTF_ids in vmlinux.
>>> Update resolve_btfids to emit warning messages and patch zero id for missing
>>> symbols instead of aborting kernel build process.
>>>
>>> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
>>
>> LGTM with one minor comment below.
>>
>> Acked-by: Yonghong Song <yhs@fb.com>
>>
>>> ---
>>>    tools/bpf/resolve_btfids/main.c | 13 +++++++------
>>>    1 file changed, 7 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
>>> index 3ad9301b0f00..3ea19e33250d 100644
>>> --- a/tools/bpf/resolve_btfids/main.c
>>> +++ b/tools/bpf/resolve_btfids/main.c
>>> @@ -291,7 +291,7 @@ static int compressed_section_fix(Elf *elf, Elf_Scn *scn, GElf_Shdr *sh)
>>>        sh->sh_addralign = expected;
>>>
>>>        if (gelf_update_shdr(scn, sh) == 0) {
>>> -        printf("FAILED cannot update section header: %s\n",
>>> +        pr_err("FAILED cannot update section header: %s\n",
>>>                elf_errmsg(-1));
>>>            return -1;
>>>        }
>>> @@ -317,6 +317,7 @@ static int elf_collect(struct object *obj)
>>>
>>>        elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL);
>>>        if (!elf) {
>>> +        close(fd);
>>>            pr_err("FAILED cannot create ELF descriptor: %s\n",
>>>                elf_errmsg(-1));
>>>            return -1;
>>> @@ -484,7 +485,7 @@ static int symbols_resolve(struct object *obj)
>>>        err = libbpf_get_error(btf);
>>>        if (err) {
>>>            pr_err("FAILED: load BTF from %s: %s\n",
>>> -            obj->path, strerror(-err));
>>> +            obj->btf ?: obj->path, strerror(-err));
>>
>> Why you change "obj->path" to "obj->btf ?: obj->path"?
>> Note that obj->path cannot be NULL.
> 
> The diff didn't see the whole picture. Let me quote it here:
> ```
> btf = btf__parse(obj->btf ?: obj->path, NULL);
> err = libbpf_get_error(btf);
> if (err) {
>          pr_err("FAILED: load BTF from %s: %s\n",
>                  obj->path, strerror(-err));
>          return -1;
> }
> ```
> 
> Because btf__parse parses either obj->btf or obj->path,
> I think the error message should reveal this.

Okay, I see, obj->btf may not be NULL due to
                 OPT_STRING(0, "btf", &obj.btf, "BTF data",
                            "BTF data"),

How about
   obj->btf ? "input BTF data" : obj->path

The error message like
   FAILED: load BTF from : <error msg>
does not sound good.

> 
>>
>>>            return -1;
>>>        }
>>>
>> [...]
Hengqi Chen July 26, 2021, 5:22 a.m. UTC | #4
On 2021/7/26 12:56 PM, Yonghong Song wrote:
> 
> 
> On 7/25/21 9:41 PM, Hengqi Chen wrote:
>>
>>
>> On 2021/7/26 11:32 AM, Yonghong Song wrote:
>>>
>>>
>>> On 7/25/21 7:18 AM, Hengqi Chen wrote:
>>>> Kernel functions referenced by .BTF_ids may changed from global to static
>>>> and get inlined and thus disappears from BTF. This causes kernel build
>>>
>>> the function could be renamed or removed too.
>>>
>>>> failure when resolve_btfids do id patch for symbols in .BTF_ids in vmlinux.
>>>> Update resolve_btfids to emit warning messages and patch zero id for missing
>>>> symbols instead of aborting kernel build process.
>>>>
>>>> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
>>>
>>> LGTM with one minor comment below.
>>>
>>> Acked-by: Yonghong Song <yhs@fb.com>
>>>
>>>> ---
>>>>    tools/bpf/resolve_btfids/main.c | 13 +++++++------
>>>>    1 file changed, 7 insertions(+), 6 deletions(-)
>>>>
>>>> diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
>>>> index 3ad9301b0f00..3ea19e33250d 100644
>>>> --- a/tools/bpf/resolve_btfids/main.c
>>>> +++ b/tools/bpf/resolve_btfids/main.c
>>>> @@ -291,7 +291,7 @@ static int compressed_section_fix(Elf *elf, Elf_Scn *scn, GElf_Shdr *sh)
>>>>        sh->sh_addralign = expected;
>>>>
>>>>        if (gelf_update_shdr(scn, sh) == 0) {
>>>> -        printf("FAILED cannot update section header: %s\n",
>>>> +        pr_err("FAILED cannot update section header: %s\n",
>>>>                elf_errmsg(-1));
>>>>            return -1;
>>>>        }
>>>> @@ -317,6 +317,7 @@ static int elf_collect(struct object *obj)
>>>>
>>>>        elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL);
>>>>        if (!elf) {
>>>> +        close(fd);
>>>>            pr_err("FAILED cannot create ELF descriptor: %s\n",
>>>>                elf_errmsg(-1));
>>>>            return -1;
>>>> @@ -484,7 +485,7 @@ static int symbols_resolve(struct object *obj)
>>>>        err = libbpf_get_error(btf);
>>>>        if (err) {
>>>>            pr_err("FAILED: load BTF from %s: %s\n",
>>>> -            obj->path, strerror(-err));
>>>> +            obj->btf ?: obj->path, strerror(-err));
>>>
>>> Why you change "obj->path" to "obj->btf ?: obj->path"?
>>> Note that obj->path cannot be NULL.
>>
>> The diff didn't see the whole picture. Let me quote it here:
>> ```
>> btf = btf__parse(obj->btf ?: obj->path, NULL);
>> err = libbpf_get_error(btf);
>> if (err) {
>>          pr_err("FAILED: load BTF from %s: %s\n",
>>                  obj->path, strerror(-err));
>>          return -1;
>> }
>> ```
>>
>> Because btf__parse parses either obj->btf or obj->path,
>> I think the error message should reveal this.
> 
> Okay, I see, obj->btf may not be NULL due to
>                 OPT_STRING(0, "btf", &obj.btf, "BTF data",
>                            "BTF data"),
> 
> How about
>   obj->btf ? "input BTF data" : obj->path
> 
> The error message like
>   FAILED: load BTF from : <error msg>
> does not sound good.
> 

Sorry, I am confused.

If obj->btf is set, say, vmlinux.btf, the message should look like:
 FAILED: load BTF from vmlinux.btf: <error msg>

Otherwise, it should look like:
 FAILED: load BTF from vmlinux: <error msg>

Am I missing something ?

>>
>>>
>>>>            return -1;
>>>>        }
>>>>
>>> [...]
Yonghong Song July 26, 2021, 5:33 a.m. UTC | #5
On 7/25/21 10:22 PM, Hengqi Chen wrote:
> 
> 
> On 2021/7/26 12:56 PM, Yonghong Song wrote:
>>
>>
>> On 7/25/21 9:41 PM, Hengqi Chen wrote:
>>>
>>>
>>> On 2021/7/26 11:32 AM, Yonghong Song wrote:
>>>>
>>>>
>>>> On 7/25/21 7:18 AM, Hengqi Chen wrote:
>>>>> Kernel functions referenced by .BTF_ids may changed from global to static
>>>>> and get inlined and thus disappears from BTF. This causes kernel build
>>>>
>>>> the function could be renamed or removed too.
>>>>
>>>>> failure when resolve_btfids do id patch for symbols in .BTF_ids in vmlinux.
>>>>> Update resolve_btfids to emit warning messages and patch zero id for missing
>>>>> symbols instead of aborting kernel build process.
>>>>>
>>>>> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
>>>>
>>>> LGTM with one minor comment below.
>>>>
>>>> Acked-by: Yonghong Song <yhs@fb.com>
>>>>
>>>>> ---
>>>>>     tools/bpf/resolve_btfids/main.c | 13 +++++++------
>>>>>     1 file changed, 7 insertions(+), 6 deletions(-)
>>>>>
>>>>> diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
>>>>> index 3ad9301b0f00..3ea19e33250d 100644
>>>>> --- a/tools/bpf/resolve_btfids/main.c
>>>>> +++ b/tools/bpf/resolve_btfids/main.c
>>>>> @@ -291,7 +291,7 @@ static int compressed_section_fix(Elf *elf, Elf_Scn *scn, GElf_Shdr *sh)
>>>>>         sh->sh_addralign = expected;
>>>>>
>>>>>         if (gelf_update_shdr(scn, sh) == 0) {
>>>>> -        printf("FAILED cannot update section header: %s\n",
>>>>> +        pr_err("FAILED cannot update section header: %s\n",
>>>>>                 elf_errmsg(-1));
>>>>>             return -1;
>>>>>         }
>>>>> @@ -317,6 +317,7 @@ static int elf_collect(struct object *obj)
>>>>>
>>>>>         elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL);
>>>>>         if (!elf) {
>>>>> +        close(fd);
>>>>>             pr_err("FAILED cannot create ELF descriptor: %s\n",
>>>>>                 elf_errmsg(-1));
>>>>>             return -1;
>>>>> @@ -484,7 +485,7 @@ static int symbols_resolve(struct object *obj)
>>>>>         err = libbpf_get_error(btf);
>>>>>         if (err) {
>>>>>             pr_err("FAILED: load BTF from %s: %s\n",
>>>>> -            obj->path, strerror(-err));
>>>>> +            obj->btf ?: obj->path, strerror(-err));
>>>>
>>>> Why you change "obj->path" to "obj->btf ?: obj->path"?
>>>> Note that obj->path cannot be NULL.
>>>
>>> The diff didn't see the whole picture. Let me quote it here:
>>> ```
>>> btf = btf__parse(obj->btf ?: obj->path, NULL);
>>> err = libbpf_get_error(btf);
>>> if (err) {
>>>           pr_err("FAILED: load BTF from %s: %s\n",
>>>                   obj->path, strerror(-err));
>>>           return -1;
>>> }
>>> ```
>>>
>>> Because btf__parse parses either obj->btf or obj->path,
>>> I think the error message should reveal this.
>>
>> Okay, I see, obj->btf may not be NULL due to
>>                  OPT_STRING(0, "btf", &obj.btf, "BTF data",
>>                             "BTF data"),
>>
>> How about
>>    obj->btf ? "input BTF data" : obj->path
>>
>> The error message like
>>    FAILED: load BTF from : <error msg>
>> does not sound good.
>>
> 
> Sorry, I am confused.
> 
> If obj->btf is set, say, vmlinux.btf, the message should look like:
>   FAILED: load BTF from vmlinux.btf: <error msg>
> 
> Otherwise, it should look like:
>   FAILED: load BTF from vmlinux: <error msg>
> 
> Am I missing something ?

Ah, you are right. Your patch looks good. I didn't pay attention
and thought
   OPT_STRING(0, "btf", &obj.btf, "BTF data","BTF data")
is a string input for *btf data*, but actually it is actually
/sys/kernel/btf/vmlinux.

> 
>>>
>>>>
>>>>>             return -1;
>>>>>         }
>>>>>
>>>> [...]
Andrii Nakryiko July 26, 2021, 8:16 p.m. UTC | #6
On Sun, Jul 25, 2021 at 7:18 AM Hengqi Chen <hengqi.chen@gmail.com> wrote:
>
> Kernel functions referenced by .BTF_ids may changed from global to static
> and get inlined and thus disappears from BTF. This causes kernel build
> failure when resolve_btfids do id patch for symbols in .BTF_ids in vmlinux.
> Update resolve_btfids to emit warning messages and patch zero id for missing
> symbols instead of aborting kernel build process.
>
> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
> ---
>  tools/bpf/resolve_btfids/main.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
> index 3ad9301b0f00..3ea19e33250d 100644
> --- a/tools/bpf/resolve_btfids/main.c
> +++ b/tools/bpf/resolve_btfids/main.c
> @@ -291,7 +291,7 @@ static int compressed_section_fix(Elf *elf, Elf_Scn *scn, GElf_Shdr *sh)
>         sh->sh_addralign = expected;
>
>         if (gelf_update_shdr(scn, sh) == 0) {
> -               printf("FAILED cannot update section header: %s\n",
> +               pr_err("FAILED cannot update section header: %s\n",
>                         elf_errmsg(-1));
>                 return -1;
>         }
> @@ -317,6 +317,7 @@ static int elf_collect(struct object *obj)
>
>         elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL);
>         if (!elf) {
> +               close(fd);
>                 pr_err("FAILED cannot create ELF descriptor: %s\n",
>                         elf_errmsg(-1));
>                 return -1;
> @@ -484,7 +485,7 @@ static int symbols_resolve(struct object *obj)
>         err = libbpf_get_error(btf);
>         if (err) {
>                 pr_err("FAILED: load BTF from %s: %s\n",
> -                       obj->path, strerror(-err));
> +                       obj->btf ?: obj->path, strerror(-err));
>                 return -1;
>         }
>
> @@ -555,8 +556,7 @@ static int id_patch(struct object *obj, struct btf_id *id)
>         int i;
>
>         if (!id->id) {
> -               pr_err("FAILED unresolved symbol %s\n", id->name);
> -               return -EINVAL;
> +               pr_err("WARN: unresolved symbol %s\n", id->name);

we should probably give a bit more information for people to get back
to us for this. For starters, maybe prefix the message with
"resolve_btfids:" so that people at least can grep something relevant?

>         }
>
>         for (i = 0; i < id->addr_cnt; i++) {
> @@ -734,8 +734,9 @@ int main(int argc, const char **argv)
>
>         err = 0;
>  out:
> -       if (obj.efile.elf)
> +       if (obj.efile.elf) {
>                 elf_end(obj.efile.elf);
> -       close(obj.efile.fd);
> +               close(obj.efile.fd);
> +       }
>         return err;
>  }
> --
> 2.25.1
Hengqi Chen July 27, 2021, 2:59 a.m. UTC | #7
On 2021/7/27 4:16 AM, Andrii Nakryiko wrote:
> On Sun, Jul 25, 2021 at 7:18 AM Hengqi Chen <hengqi.chen@gmail.com> wrote:
>>
>> Kernel functions referenced by .BTF_ids may changed from global to static
>> and get inlined and thus disappears from BTF. This causes kernel build
>> failure when resolve_btfids do id patch for symbols in .BTF_ids in vmlinux.
>> Update resolve_btfids to emit warning messages and patch zero id for missing
>> symbols instead of aborting kernel build process.
>>
>> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
>> ---
>>  tools/bpf/resolve_btfids/main.c | 13 +++++++------
>>  1 file changed, 7 insertions(+), 6 deletions(-)
>>
>> diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
>> index 3ad9301b0f00..3ea19e33250d 100644
>> --- a/tools/bpf/resolve_btfids/main.c
>> +++ b/tools/bpf/resolve_btfids/main.c
>> @@ -291,7 +291,7 @@ static int compressed_section_fix(Elf *elf, Elf_Scn *scn, GElf_Shdr *sh)
>>         sh->sh_addralign = expected;
>>
>>         if (gelf_update_shdr(scn, sh) == 0) {
>> -               printf("FAILED cannot update section header: %s\n",
>> +               pr_err("FAILED cannot update section header: %s\n",
>>                         elf_errmsg(-1));
>>                 return -1;
>>         }
>> @@ -317,6 +317,7 @@ static int elf_collect(struct object *obj)
>>
>>         elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL);
>>         if (!elf) {
>> +               close(fd);
>>                 pr_err("FAILED cannot create ELF descriptor: %s\n",
>>                         elf_errmsg(-1));
>>                 return -1;
>> @@ -484,7 +485,7 @@ static int symbols_resolve(struct object *obj)
>>         err = libbpf_get_error(btf);
>>         if (err) {
>>                 pr_err("FAILED: load BTF from %s: %s\n",
>> -                       obj->path, strerror(-err));
>> +                       obj->btf ?: obj->path, strerror(-err));
>>                 return -1;
>>         }
>>
>> @@ -555,8 +556,7 @@ static int id_patch(struct object *obj, struct btf_id *id)
>>         int i;
>>
>>         if (!id->id) {
>> -               pr_err("FAILED unresolved symbol %s\n", id->name);
>> -               return -EINVAL;
>> +               pr_err("WARN: unresolved symbol %s\n", id->name);
> 
> we should probably give a bit more information for people to get back
> to us for this. For starters, maybe prefix the message with
> "resolve_btfids:" so that people at least can grep something relevant?
> 

OK, will do.

>>         }
>>
>>         for (i = 0; i < id->addr_cnt; i++) {
>> @@ -734,8 +734,9 @@ int main(int argc, const char **argv)
>>
>>         err = 0;
>>  out:
>> -       if (obj.efile.elf)
>> +       if (obj.efile.elf) {
>>                 elf_end(obj.efile.elf);
>> -       close(obj.efile.fd);
>> +               close(obj.efile.fd);
>> +       }
>>         return err;
>>  }
>> --
>> 2.25.1
diff mbox series

Patch

diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
index 3ad9301b0f00..3ea19e33250d 100644
--- a/tools/bpf/resolve_btfids/main.c
+++ b/tools/bpf/resolve_btfids/main.c
@@ -291,7 +291,7 @@  static int compressed_section_fix(Elf *elf, Elf_Scn *scn, GElf_Shdr *sh)
 	sh->sh_addralign = expected;

 	if (gelf_update_shdr(scn, sh) == 0) {
-		printf("FAILED cannot update section header: %s\n",
+		pr_err("FAILED cannot update section header: %s\n",
 			elf_errmsg(-1));
 		return -1;
 	}
@@ -317,6 +317,7 @@  static int elf_collect(struct object *obj)

 	elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL);
 	if (!elf) {
+		close(fd);
 		pr_err("FAILED cannot create ELF descriptor: %s\n",
 			elf_errmsg(-1));
 		return -1;
@@ -484,7 +485,7 @@  static int symbols_resolve(struct object *obj)
 	err = libbpf_get_error(btf);
 	if (err) {
 		pr_err("FAILED: load BTF from %s: %s\n",
-			obj->path, strerror(-err));
+			obj->btf ?: obj->path, strerror(-err));
 		return -1;
 	}

@@ -555,8 +556,7 @@  static int id_patch(struct object *obj, struct btf_id *id)
 	int i;

 	if (!id->id) {
-		pr_err("FAILED unresolved symbol %s\n", id->name);
-		return -EINVAL;
+		pr_err("WARN: unresolved symbol %s\n", id->name);
 	}

 	for (i = 0; i < id->addr_cnt; i++) {
@@ -734,8 +734,9 @@  int main(int argc, const char **argv)

 	err = 0;
 out:
-	if (obj.efile.elf)
+	if (obj.efile.elf) {
 		elf_end(obj.efile.elf);
-	close(obj.efile.fd);
+		close(obj.efile.fd);
+	}
 	return err;
 }