Lines Matching refs:obj
232 static struct btf_id *add_set(struct object *obj, char *name) in add_set() argument
247 return btf_id__add(&obj->sets, id, true); in add_set()
301 static int elf_collect(struct object *obj) in elf_collect() argument
309 fd = open(obj->path, O_RDWR, 0666); in elf_collect()
312 obj->path, strerror(errno)); in elf_collect()
326 obj->efile.fd = fd; in elf_collect()
327 obj->efile.elf = elf; in elf_collect()
370 obj->efile.symbols = data; in elf_collect()
371 obj->efile.symbols_shndx = idx; in elf_collect()
372 obj->efile.strtabidx = sh.sh_link; in elf_collect()
374 obj->efile.idlist = data; in elf_collect()
375 obj->efile.idlist_shndx = idx; in elf_collect()
376 obj->efile.idlist_addr = sh.sh_addr; in elf_collect()
386 static int symbols_collect(struct object *obj) in symbols_collect() argument
393 scn = elf_getscn(obj->efile.elf, obj->efile.symbols_shndx); in symbols_collect()
411 if (!gelf_getsym(obj->efile.symbols, i, &sym)) in symbols_collect()
414 if (sym.st_shndx != obj->efile.idlist_shndx) in symbols_collect()
417 name = elf_strptr(obj->efile.elf, obj->efile.strtabidx, in symbols_collect()
431 obj->nr_structs++; in symbols_collect()
432 id = add_symbol(&obj->structs, prefix, sizeof(BTF_STRUCT) - 1); in symbols_collect()
435 obj->nr_unions++; in symbols_collect()
436 id = add_symbol(&obj->unions, prefix, sizeof(BTF_UNION) - 1); in symbols_collect()
439 obj->nr_typedefs++; in symbols_collect()
440 id = add_symbol(&obj->typedefs, prefix, sizeof(BTF_TYPEDEF) - 1); in symbols_collect()
443 obj->nr_funcs++; in symbols_collect()
444 id = add_symbol(&obj->funcs, prefix, sizeof(BTF_FUNC) - 1); in symbols_collect()
447 id = add_set(obj, prefix); in symbols_collect()
474 static int symbols_resolve(struct object *obj) in symbols_resolve() argument
476 int nr_typedefs = obj->nr_typedefs; in symbols_resolve()
477 int nr_structs = obj->nr_structs; in symbols_resolve()
478 int nr_unions = obj->nr_unions; in symbols_resolve()
479 int nr_funcs = obj->nr_funcs; in symbols_resolve()
484 btf = btf__parse(obj->btf ?: obj->path, NULL); in symbols_resolve()
488 obj->btf ?: obj->path, strerror(-err)); in symbols_resolve()
514 root = &obj->funcs; in symbols_resolve()
517 root = &obj->structs; in symbols_resolve()
520 root = &obj->unions; in symbols_resolve()
523 root = &obj->typedefs; in symbols_resolve()
552 static int id_patch(struct object *obj, struct btf_id *id) in id_patch() argument
554 Elf_Data *data = obj->efile.idlist; in id_patch()
564 unsigned long idx = addr - obj->efile.idlist_addr; in id_patch()
582 static int __symbols_patch(struct object *obj, struct rb_root *root) in __symbols_patch() argument
591 if (id_patch(obj, id)) in __symbols_patch()
606 static int sets_patch(struct object *obj) in sets_patch() argument
608 Elf_Data *data = obj->efile.idlist; in sets_patch()
612 next = rb_first(&obj->sets); in sets_patch()
621 idx = addr - obj->efile.idlist_addr; in sets_patch()
644 static int symbols_patch(struct object *obj) in symbols_patch() argument
648 if (__symbols_patch(obj, &obj->structs) || in symbols_patch()
649 __symbols_patch(obj, &obj->unions) || in symbols_patch()
650 __symbols_patch(obj, &obj->typedefs) || in symbols_patch()
651 __symbols_patch(obj, &obj->funcs) || in symbols_patch()
652 __symbols_patch(obj, &obj->sets)) in symbols_patch()
655 if (sets_patch(obj)) in symbols_patch()
659 obj->efile.idlist->d_type = ELF_T_WORD; in symbols_patch()
661 elf_flagdata(obj->efile.idlist, ELF_C_SET, ELF_F_DIRTY); in symbols_patch()
663 err = elf_update(obj->efile.elf, ELF_C_WRITE); in symbols_patch()
670 err >= 0 ? "ok" : "failed", obj->path); in symbols_patch()
682 struct object obj = { in main() local
696 OPT_STRING(0, "btf", &obj.btf, "BTF data", in main()
709 obj.path = argv[0]; in main()
711 if (elf_collect(&obj)) in main()
718 if (obj.efile.idlist_shndx == -1 || in main()
719 obj.efile.symbols_shndx == -1) { in main()
727 if (symbols_collect(&obj)) in main()
730 if (symbols_resolve(&obj)) in main()
733 if (symbols_patch(&obj)) in main()
738 if (obj.efile.elf) { in main()
739 elf_end(obj.efile.elf); in main()
740 close(obj.efile.fd); in main()