Lines Matching refs:obj
260 static struct btf_id *add_set(struct object *obj, char *name, bool is_set8) in add_set() argument
275 return btf_id__add(&obj->sets, id, true); in add_set()
329 static int elf_collect(struct object *obj) in elf_collect() argument
338 fd = open(obj->path, O_RDWR, 0666); in elf_collect()
341 obj->path, strerror(errno)); in elf_collect()
355 obj->efile.fd = fd; in elf_collect()
356 obj->efile.elf = elf; in elf_collect()
365 if (gelf_getehdr(obj->efile.elf, &ehdr) == NULL) { in elf_collect()
370 obj->efile.encoding = ehdr.e_ident[EI_DATA]; in elf_collect()
406 obj->efile.symbols = data; in elf_collect()
407 obj->efile.symbols_shndx = idx; in elf_collect()
408 obj->efile.strtabidx = sh.sh_link; in elf_collect()
410 obj->efile.idlist = data; in elf_collect()
411 obj->efile.idlist_shndx = idx; in elf_collect()
412 obj->efile.idlist_addr = sh.sh_addr; in elf_collect()
420 obj->base_btf_path = NULL; in elf_collect()
430 static int symbols_collect(struct object *obj) in symbols_collect() argument
437 scn = elf_getscn(obj->efile.elf, obj->efile.symbols_shndx); in symbols_collect()
455 if (!gelf_getsym(obj->efile.symbols, i, &sym)) in symbols_collect()
458 if (sym.st_shndx != obj->efile.idlist_shndx) in symbols_collect()
461 name = elf_strptr(obj->efile.elf, obj->efile.strtabidx, in symbols_collect()
475 obj->nr_structs++; in symbols_collect()
476 id = add_symbol(&obj->structs, prefix, sizeof(BTF_STRUCT) - 1); in symbols_collect()
479 obj->nr_unions++; in symbols_collect()
480 id = add_symbol(&obj->unions, prefix, sizeof(BTF_UNION) - 1); in symbols_collect()
483 obj->nr_typedefs++; in symbols_collect()
484 id = add_symbol(&obj->typedefs, prefix, sizeof(BTF_TYPEDEF) - 1); in symbols_collect()
487 obj->nr_funcs++; in symbols_collect()
488 id = add_symbol(&obj->funcs, prefix, sizeof(BTF_FUNC) - 1); in symbols_collect()
491 id = add_set(obj, prefix, true); in symbols_collect()
503 id = add_set(obj, prefix, false); in symbols_collect()
532 static int symbols_resolve(struct object *obj) in symbols_resolve() argument
534 int nr_typedefs = obj->nr_typedefs; in symbols_resolve()
535 int nr_structs = obj->nr_structs; in symbols_resolve()
536 int nr_unions = obj->nr_unions; in symbols_resolve()
537 int nr_funcs = obj->nr_funcs; in symbols_resolve()
543 if (obj->base_btf_path) { in symbols_resolve()
544 base_btf = btf__parse(obj->base_btf_path, NULL); in symbols_resolve()
548 obj->base_btf_path, strerror(-err)); in symbols_resolve()
553 btf = btf__parse_split(obj->btf ?: obj->path, base_btf); in symbols_resolve()
557 obj->btf ?: obj->path, strerror(-err)); in symbols_resolve()
583 root = &obj->funcs; in symbols_resolve()
586 root = &obj->structs; in symbols_resolve()
589 root = &obj->unions; in symbols_resolve()
592 root = &obj->typedefs; in symbols_resolve()
623 static int id_patch(struct object *obj, struct btf_id *id) in id_patch() argument
625 Elf_Data *data = obj->efile.idlist; in id_patch()
637 unsigned long idx = addr - obj->efile.idlist_addr; in id_patch()
655 static int __symbols_patch(struct object *obj, struct rb_root *root) in __symbols_patch() argument
664 if (id_patch(obj, id)) in __symbols_patch()
679 static int sets_patch(struct object *obj) in sets_patch() argument
681 Elf_Data *data = obj->efile.idlist; in sets_patch()
684 next = rb_first(&obj->sets); in sets_patch()
693 off = addr - obj->efile.idlist_addr; in sets_patch()
722 if (obj->efile.encoding != ELFDATANATIVE) { in sets_patch()
741 static int symbols_patch(struct object *obj) in symbols_patch() argument
745 if (__symbols_patch(obj, &obj->structs) || in symbols_patch()
746 __symbols_patch(obj, &obj->unions) || in symbols_patch()
747 __symbols_patch(obj, &obj->typedefs) || in symbols_patch()
748 __symbols_patch(obj, &obj->funcs) || in symbols_patch()
749 __symbols_patch(obj, &obj->sets)) in symbols_patch()
752 if (sets_patch(obj)) in symbols_patch()
756 obj->efile.idlist->d_type = ELF_T_WORD; in symbols_patch()
758 elf_flagdata(obj->efile.idlist, ELF_C_SET, ELF_F_DIRTY); in symbols_patch()
760 err = elf_update(obj->efile.elf, ELF_C_WRITE); in symbols_patch()
767 err >= 0 ? "ok" : "failed", obj->path); in symbols_patch()
778 struct object obj = { in main() local
793 OPT_STRING(0, "btf", &obj.btf, "BTF data", in main()
795 OPT_STRING('b', "btf_base", &obj.base_btf_path, "file", in main()
808 obj.path = argv[0]; in main()
810 if (elf_collect(&obj)) in main()
817 if (obj.efile.idlist_shndx == -1 || in main()
818 obj.efile.symbols_shndx == -1) { in main()
824 if (symbols_collect(&obj)) in main()
827 if (symbols_resolve(&obj)) in main()
830 if (symbols_patch(&obj)) in main()
836 if (obj.efile.elf) { in main()
837 elf_end(obj.efile.elf); in main()
838 close(obj.efile.fd); in main()