Lines Matching defs:obj

259 static struct btf_id *add_set(struct object *obj, char *name, bool is_set8)
274 return btf_id__add(&obj->sets, id, true);
328 static int elf_collect(struct object *obj)
337 fd = open(obj->path, O_RDWR, 0666);
340 obj->path, strerror(errno));
354 obj->efile.fd = fd;
355 obj->efile.elf = elf;
364 if (gelf_getehdr(obj->efile.elf, &ehdr) == NULL) {
369 obj->efile.encoding = ehdr.e_ident[EI_DATA];
405 obj->efile.symbols = data;
406 obj->efile.symbols_shndx = idx;
407 obj->efile.strtabidx = sh.sh_link;
409 obj->efile.idlist = data;
410 obj->efile.idlist_shndx = idx;
411 obj->efile.idlist_addr = sh.sh_addr;
421 static int symbols_collect(struct object *obj)
428 scn = elf_getscn(obj->efile.elf, obj->efile.symbols_shndx);
446 if (!gelf_getsym(obj->efile.symbols, i, &sym))
449 if (sym.st_shndx != obj->efile.idlist_shndx)
452 name = elf_strptr(obj->efile.elf, obj->efile.strtabidx,
466 obj->nr_structs++;
467 id = add_symbol(&obj->structs, prefix, sizeof(BTF_STRUCT) - 1);
470 obj->nr_unions++;
471 id = add_symbol(&obj->unions, prefix, sizeof(BTF_UNION) - 1);
474 obj->nr_typedefs++;
475 id = add_symbol(&obj->typedefs, prefix, sizeof(BTF_TYPEDEF) - 1);
478 obj->nr_funcs++;
479 id = add_symbol(&obj->funcs, prefix, sizeof(BTF_FUNC) - 1);
482 id = add_set(obj, prefix, true);
494 id = add_set(obj, prefix, false);
523 static int symbols_resolve(struct object *obj)
525 int nr_typedefs = obj->nr_typedefs;
526 int nr_structs = obj->nr_structs;
527 int nr_unions = obj->nr_unions;
528 int nr_funcs = obj->nr_funcs;
534 if (obj->base_btf_path) {
535 base_btf = btf__parse(obj->base_btf_path, NULL);
539 obj->base_btf_path, strerror(-err));
544 btf = btf__parse_split(obj->btf ?: obj->path, base_btf);
548 obj->btf ?: obj->path, strerror(-err));
574 root = &obj->funcs;
577 root = &obj->structs;
580 root = &obj->unions;
583 root = &obj->typedefs;
613 static int id_patch(struct object *obj, struct btf_id *id)
615 Elf_Data *data = obj->efile.idlist;
625 unsigned long idx = addr - obj->efile.idlist_addr;
643 static int __symbols_patch(struct object *obj, struct rb_root *root)
652 if (id_patch(obj, id))
667 static int sets_patch(struct object *obj)
669 Elf_Data *data = obj->efile.idlist;
672 next = rb_first(&obj->sets);
681 off = addr - obj->efile.idlist_addr;
710 if (obj->efile.encoding != ELFDATANATIVE) {
729 static int symbols_patch(struct object *obj)
733 if (__symbols_patch(obj, &obj->structs) ||
734 __symbols_patch(obj, &obj->unions) ||
735 __symbols_patch(obj, &obj->typedefs) ||
736 __symbols_patch(obj, &obj->funcs) ||
737 __symbols_patch(obj, &obj->sets))
740 if (sets_patch(obj))
744 obj->efile.idlist->d_type = ELF_T_WORD;
746 elf_flagdata(obj->efile.idlist, ELF_C_SET, ELF_F_DIRTY);
748 err = elf_update(obj->efile.elf, ELF_C_WRITE);
755 err >= 0 ? "ok" : "failed", obj->path);
766 struct object obj = {
780 OPT_STRING(0, "btf", &obj.btf, "BTF data",
782 OPT_STRING('b', "btf_base", &obj.base_btf_path, "file",
793 obj.path = argv[0];
795 if (elf_collect(&obj))
802 if (obj.efile.idlist_shndx == -1 ||
803 obj.efile.symbols_shndx == -1) {
809 if (symbols_collect(&obj))
812 if (symbols_resolve(&obj))
815 if (symbols_patch(&obj))
820 if (obj.efile.elf) {
821 elf_end(obj.efile.elf);
822 close(obj.efile.fd);