Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

resolve_btfids: Factor out load_btf()

Increase the lifetime of parsed BTF in resolve_btfids by factoring
load_btf() routine out of symbols_resolve() and storing the base_btf
and btf pointers in the struct object.

Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Tested-by: Alan Maguire <alan.maguire@oracle.com>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/bpf/20251219181321.1283664-3-ihor.solodrai@linux.dev

authored by

Ihor Solodrai and committed by
Andrii Nakryiko
5f347a0f c1c7d617

+34 -13
+34 -13
tools/bpf/resolve_btfids/main.c
··· 116 116 const char *btf_path; 117 117 const char *base_btf_path; 118 118 119 + struct btf *btf; 120 + struct btf *base_btf; 121 + 119 122 struct { 120 123 int fd; 121 124 Elf *elf; ··· 532 529 return 0; 533 530 } 534 531 535 - static int symbols_resolve(struct object *obj) 532 + static int load_btf(struct object *obj) 536 533 { 537 - int nr_typedefs = obj->nr_typedefs; 538 - int nr_structs = obj->nr_structs; 539 - int nr_unions = obj->nr_unions; 540 - int nr_funcs = obj->nr_funcs; 541 - struct btf *base_btf = NULL; 542 - int err, type_id; 543 - struct btf *btf; 544 - __u32 nr_types; 534 + struct btf *base_btf = NULL, *btf = NULL; 535 + int err; 545 536 546 537 if (obj->base_btf_path) { 547 538 base_btf = btf__parse(obj->base_btf_path, NULL); ··· 543 546 if (err) { 544 547 pr_err("FAILED: load base BTF from %s: %s\n", 545 548 obj->base_btf_path, strerror(-err)); 546 - return -1; 549 + goto out_err; 547 550 } 548 551 } 549 552 ··· 552 555 if (err) { 553 556 pr_err("FAILED: load BTF from %s: %s\n", 554 557 obj->btf_path ?: obj->path, strerror(-err)); 555 - goto out; 558 + goto out_err; 556 559 } 560 + 561 + obj->base_btf = base_btf; 562 + obj->btf = btf; 563 + 564 + return 0; 565 + 566 + out_err: 567 + btf__free(base_btf); 568 + btf__free(btf); 569 + return err; 570 + } 571 + 572 + static int symbols_resolve(struct object *obj) 573 + { 574 + int nr_typedefs = obj->nr_typedefs; 575 + int nr_structs = obj->nr_structs; 576 + int nr_unions = obj->nr_unions; 577 + int nr_funcs = obj->nr_funcs; 578 + struct btf *btf = obj->btf; 579 + int err, type_id; 580 + __u32 nr_types; 557 581 558 582 err = -1; 559 583 nr_types = btf__type_cnt(btf); ··· 633 615 634 616 err = 0; 635 617 out: 636 - btf__free(base_btf); 637 - btf__free(btf); 638 618 return err; 639 619 } 640 620 ··· 840 824 if (symbols_collect(&obj)) 841 825 goto out; 842 826 827 + if (load_btf(&obj)) 828 + goto out; 829 + 843 830 if (symbols_resolve(&obj)) 844 831 goto out; 845 832 ··· 852 833 if (!(fatal_warnings && warnings)) 853 834 err = 0; 854 835 out: 836 + btf__free(obj.base_btf); 837 + btf__free(obj.btf); 855 838 if (obj.efile.elf) { 856 839 elf_end(obj.efile.elf); 857 840 close(obj.efile.fd);