Skip to content

Commit

Permalink
libbpf: do not resolve size on duplicate FUNCs
Browse files Browse the repository at this point in the history
FUNCs do not have sizes, thus currently btf__resolve_size will fail
with -EINVAL. Add conditions so that we only update size when the BTF
object is not function or function prototype.

Signed-off-by: Eric Long <i@hack3r.moe>
  • Loading branch information
hack3ric authored and Kernel Patches Daemon committed Sep 29, 2024
1 parent e8d83e7 commit ec51029
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions tools/lib/bpf/linker.c
Original file line number Diff line number Diff line change
Expand Up @@ -2449,20 +2449,24 @@ static int linker_append_btf(struct bpf_linker *linker, struct src_obj *obj)
* the same extern VARs/FUNCs.
*/
if (glob_sym && glob_sym->var_idx >= 0) {
const struct btf_type *t = btf__type_by_id(linker->btf, glob_sym->underlying_btf_id);
int kind = btf_kind(t);
__s64 sz;

dst_var = &dst_sec->sec_vars[glob_sym->var_idx];
/* Because underlying BTF type might have
* changed, so might its size have changed, so
* re-calculate and update it in sec_var.
*/
sz = btf__resolve_size(linker->btf, glob_sym->underlying_btf_id);
if (sz < 0) {
pr_warn("global '%s': failed to resolve size of underlying type: %d\n",
name, (int)sz);
return -EINVAL;
if (kind != BTF_KIND_FUNC && kind != BTF_KIND_FUNC_PROTO) {
/* Because underlying BTF type might have
* changed, so might its size have changed, so
* re-calculate and update it in sec_var.
*/
sz = btf__resolve_size(linker->btf, glob_sym->underlying_btf_id);
if (sz < 0) {
pr_warn("global '%s': failed to resolve size of underlying type: %d\n",
name, (int)sz);
return -EINVAL;
}
dst_var->size = sz;
}
dst_var->size = sz;
continue;
}

Expand Down

0 comments on commit ec51029

Please sign in to comment.