Lines Matching refs:dso
26 #include "dso.h"
42 char dso__symtab_origin(const struct dso *dso)
65 if (dso == NULL || dso->symtab_type == DSO_BINARY_TYPE__NOT_FOUND)
67 return origin[dso->symtab_type];
70 bool dso__is_object_file(const struct dso *dso)
72 switch (dso->binary_type) {
103 int dso__read_binary_type_filename(const struct dso *dso,
119 len = __symbol__join_symfs(filename, size, dso->long_name);
150 if (dso__build_id_filename(dso, filename, size, false) == NULL)
155 if (dso__build_id_filename(dso, filename, size, true) == NULL)
161 snprintf(filename + len, size - len, "%s.debug", dso->long_name);
166 snprintf(filename + len, size - len, "%s", dso->long_name);
175 if (strlen(dso->long_name) < 9 ||
176 strncmp(dso->long_name, "/usr/lib/", 9)) {
181 snprintf(filename + len, size - len, "%s", dso->long_name + 4);
189 last_slash = dso->long_name + dso->long_name_len;
190 while (last_slash != dso->long_name && *last_slash != '/')
194 dir_size = last_slash - dso->long_name + 2;
199 len += scnprintf(filename + len, dir_size, "%s", dso->long_name);
206 if (!dso->has_build_id) {
211 build_id__sprintf(&dso->bid, build_id_hex);
220 __symbol__join_symfs(filename, size, dso->long_name);
226 root_dir, dso->long_name);
231 __symbol__join_symfs(filename, size, dso->long_name);
236 snprintf(filename, size, "%s", dso->long_name);
310 bool dso__needs_decompress(struct dso *dso)
312 return dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP ||
313 dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
359 static int decompress_kmodule(struct dso *dso, const char *name,
362 if (!dso__needs_decompress(dso))
365 if (dso->comp == COMP_ID__NONE)
368 return filename__decompress(name, pathname, len, dso->comp,
369 &dso->load_errno);
372 int dso__decompress_kmodule_fd(struct dso *dso, const char *name)
374 return decompress_kmodule(dso, name, NULL, 0);
377 int dso__decompress_kmodule_path(struct dso *dso, const char *name,
380 int fd = decompress_kmodule(dso, name, pathname, len);
466 void dso__set_module_info(struct dso *dso, struct kmod_path *m,
470 dso->symtab_type = DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE;
472 dso->symtab_type = DSO_BINARY_TYPE__GUEST_KMODULE;
476 dso->symtab_type++;
477 dso->comp = m->comp;
480 dso__set_short_name(dso, strdup(m->name), true);
490 static void dso__list_add(struct dso *dso)
492 list_add_tail(&dso->data.open_entry, &dso__data_open);
496 static void dso__list_del(struct dso *dso)
498 list_del_init(&dso->data.open_entry);
516 pr_debug("dso open failed: %s\n",
527 char *dso__filename_with_chroot(const struct dso *dso, const char *filename)
529 return filename_with_chroot(nsinfo__pid(dso->nsinfo), filename);
532 static int __open_dso(struct dso *dso, struct machine *machine)
542 mutex_lock(&dso->lock);
546 if (dso__read_binary_type_filename(dso, dso->binary_type,
553 if (errno != ENOENT || dso->nsinfo == NULL)
556 new_name = dso__filename_with_chroot(dso, name);
564 if (dso__needs_decompress(dso)) {
568 if (dso__decompress_kmodule_path(dso, name, newpath, len) < 0) {
569 fd = -dso->load_errno;
583 mutex_unlock(&dso->lock);
592 * @dso: dso object
594 * Open @dso's data file descriptor and updates
597 static int open_dso(struct dso *dso, struct machine *machine)
602 if (dso->binary_type != DSO_BINARY_TYPE__BUILD_ID_CACHE) {
603 mutex_lock(&dso->lock);
604 nsinfo__mountns_enter(dso->nsinfo, &nsc);
605 mutex_unlock(&dso->lock);
607 fd = __open_dso(dso, machine);
608 if (dso->binary_type != DSO_BINARY_TYPE__BUILD_ID_CACHE)
612 dso__list_add(dso);
623 static void close_data_fd(struct dso *dso)
625 if (dso->data.fd >= 0) {
626 close(dso->data.fd);
627 dso->data.fd = -1;
628 dso->data.file_size = 0;
629 dso__list_del(dso);
635 * @dso: dso object
637 * Close @dso's data file descriptor and updates
640 static void close_dso(struct dso *dso)
642 close_data_fd(dso);
647 struct dso *dso;
649 dso = list_first_entry(&dso__data_open, struct dso, data.open_entry);
650 close_dso(dso);
675 * Used only by tests/dso-data.c to reset the environment
696 * Check and close LRU dso if we crossed allowed limit
697 * for opened dso file descriptors. The limit is half
710 * @dso: dso object
712 * External interface to close @dso's data file descriptor.
714 void dso__data_close(struct dso *dso)
717 close_dso(dso);
721 static void try_to_open_dso(struct dso *dso, struct machine *machine)
730 if (dso->data.fd >= 0)
733 if (dso->binary_type != DSO_BINARY_TYPE__NOT_FOUND) {
734 dso->data.fd = open_dso(dso, machine);
739 dso->binary_type = binary_type_data[i++];
741 dso->data.fd = open_dso(dso, machine);
742 if (dso->data.fd >= 0)
745 } while (dso->binary_type != DSO_BINARY_TYPE__NOT_FOUND);
747 if (dso->data.fd >= 0)
748 dso->data.status = DSO_DATA_STATUS_OK;
750 dso->data.status = DSO_DATA_STATUS_ERROR;
754 * dso__data_get_fd - Get dso's data file descriptor
755 * @dso: dso object
758 * External interface to find dso's file, open it and
762 int dso__data_get_fd(struct dso *dso, struct machine *machine)
764 if (dso->data.status == DSO_DATA_STATUS_ERROR)
770 try_to_open_dso(dso, machine);
772 if (dso->data.fd < 0)
775 return dso->data.fd;
778 void dso__data_put_fd(struct dso *dso __maybe_unused)
783 bool dso__data_status_seen(struct dso *dso, enum dso_data_status_seen by)
787 if (dso->data.status_seen & flag)
790 dso->data.status_seen |= flag;
796 static ssize_t bpf_read(struct dso *dso, u64 offset, char *data)
803 node = perf_env__find_bpf_prog_info(dso->bpf_prog.env, dso->bpf_prog.id);
805 dso->data.status = DSO_DATA_STATUS_ERROR;
820 static int bpf_size(struct dso *dso)
824 node = perf_env__find_bpf_prog_info(dso->bpf_prog.env, dso->bpf_prog.id);
826 dso->data.status = DSO_DATA_STATUS_ERROR;
830 dso->data.file_size = node->info_linear->info.jited_prog_len;
836 dso_cache__free(struct dso *dso)
838 struct rb_root *root = &dso->data.cache;
841 mutex_lock(&dso->lock);
850 mutex_unlock(&dso->lock);
853 static struct dso_cache *__dso_cache__find(struct dso *dso, u64 offset)
855 const struct rb_root *root = &dso->data.cache;
879 dso_cache__insert(struct dso *dso, struct dso_cache *new)
881 struct rb_root *root = &dso->data.cache;
887 mutex_lock(&dso->lock);
908 mutex_unlock(&dso->lock);
925 static ssize_t file_read(struct dso *dso, struct machine *machine,
933 * dso->data.fd might be closed if other thread opened another
934 * file (dso) due to open file limit (RLIMIT_NOFILE).
936 try_to_open_dso(dso, machine);
938 if (dso->data.fd < 0) {
939 dso->data.status = DSO_DATA_STATUS_ERROR;
944 ret = pread(dso->data.fd, data, DSO__DATA_CACHE_SIZE, offset);
950 static struct dso_cache *dso_cache__populate(struct dso *dso,
964 if (dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO)
965 *ret = bpf_read(dso, cache_offset, cache->data);
968 if (dso->binary_type == DSO_BINARY_TYPE__OOL)
971 *ret = file_read(dso, machine, cache_offset, cache->data);
981 old = dso_cache__insert(dso, cache);
991 static struct dso_cache *dso_cache__find(struct dso *dso,
996 struct dso_cache *cache = __dso_cache__find(dso, offset);
998 return cache ? cache : dso_cache__populate(dso, machine, offset, ret);
1001 static ssize_t dso_cache_io(struct dso *dso, struct machine *machine,
1007 cache = dso_cache__find(dso, machine, offset, &ret);
1015 * Reads and caches dso data DSO__DATA_CACHE_SIZE size chunks
1019 static ssize_t cached_io(struct dso *dso, struct machine *machine,
1028 ret = dso_cache_io(dso, machine, offset, p, size, out);
1048 static int file_size(struct dso *dso, struct machine *machine)
1057 * dso->data.fd might be closed if other thread opened another
1058 * file (dso) due to open file limit (RLIMIT_NOFILE).
1060 try_to_open_dso(dso, machine);
1062 if (dso->data.fd < 0) {
1064 dso->data.status = DSO_DATA_STATUS_ERROR;
1068 if (fstat(dso->data.fd, &st) < 0) {
1070 pr_err("dso cache fstat failed: %s\n",
1072 dso->data.status = DSO_DATA_STATUS_ERROR;
1075 dso->data.file_size = st.st_size;
1082 int dso__data_file_size(struct dso *dso, struct machine *machine)
1084 if (dso->data.file_size)
1087 if (dso->data.status == DSO_DATA_STATUS_ERROR)
1090 if (dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO)
1091 return bpf_size(dso);
1093 return file_size(dso, machine);
1097 * dso__data_size - Return dso data size
1098 * @dso: dso object
1101 * Return: dso data size
1103 off_t dso__data_size(struct dso *dso, struct machine *machine)
1105 if (dso__data_file_size(dso, machine))
1108 /* For now just estimate dso data size is close to file size */
1109 return dso->data.file_size;
1112 static ssize_t data_read_write_offset(struct dso *dso, struct machine *machine,
1116 if (dso__data_file_size(dso, machine))
1120 if (offset > dso->data.file_size)
1126 return cached_io(dso, machine, offset, data, size, out);
1130 * dso__data_read_offset - Read data from dso file offset
1131 * @dso: dso object
1137 * External interface to read data from dso file offset. Open
1138 * dso data file and use cached_read to get the data.
1140 ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,
1143 if (dso->data.status == DSO_DATA_STATUS_ERROR)
1146 return data_read_write_offset(dso, machine, offset, data, size, true);
1150 * dso__data_read_addr - Read data from dso address
1151 * @dso: dso object
1157 * External interface to read data from dso address.
1159 ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
1165 return dso__data_read_offset(dso, machine, offset, data, size);
1169 * dso__data_write_cache_offs - Write data to dso data cache at file offset
1170 * @dso: dso object
1176 * Write into the dso file data cache, but do not change the file itself.
1178 ssize_t dso__data_write_cache_offs(struct dso *dso, struct machine *machine,
1183 if (dso->data.status == DSO_DATA_STATUS_ERROR)
1186 return data_read_write_offset(dso, machine, offset, data, size, false);
1190 * dso__data_write_cache_addr - Write data to dso data cache at dso address
1191 * @dso: dso object
1197 * External interface to write into the dso file data cache, but do not change
1200 ssize_t dso__data_write_cache_addr(struct dso *dso, struct map *map,
1206 return dso__data_write_cache_offs(dso, machine, offset, data, size);
1212 struct dso *dso = dso__new(name);
1214 if (dso) {
1215 map = map__new2(0, dso);
1216 dso__put(dso);
1222 struct dso *machine__findnew_kernel(struct machine *machine, const char *name,
1226 * The kernel dso could be created by build_id processing.
1228 struct dso *dso = machine__findnew_dso(machine, name);
1232 * processing we had no idea this was the kernel dso.
1234 if (dso != NULL) {
1235 dso__set_short_name(dso, short_name, false);
1236 dso->kernel = dso_type;
1239 return dso;
1242 static void dso__set_long_name_id(struct dso *dso, const char *name, struct dso_id *id, bool name_allocated)
1244 struct rb_root *root = dso->root;
1249 if (dso->long_name_allocated)
1250 free((char *)dso->long_name);
1253 rb_erase(&dso->rb_node, root);
1258 RB_CLEAR_NODE(&dso->rb_node);
1259 dso->root = NULL;
1262 dso->long_name = name;
1263 dso->long_name_len = strlen(name);
1264 dso->long_name_allocated = name_allocated;
1267 __dsos__findnew_link_by_longname_id(root, dso, NULL, id);
1270 void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated)
1272 dso__set_long_name_id(dso, name, NULL, name_allocated);
1275 void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated)
1280 if (dso->short_name_allocated)
1281 free((char *)dso->short_name);
1283 dso->short_name = name;
1284 dso->short_name_len = strlen(name);
1285 dso->short_name_allocated = name_allocated;
1288 int dso__name_len(const struct dso *dso)
1290 if (!dso)
1293 return dso->long_name_len;
1295 return dso->short_name_len;
1298 bool dso__loaded(const struct dso *dso)
1300 return dso->loaded;
1303 bool dso__sorted_by_name(const struct dso *dso)
1305 return dso->sorted_by_name;
1308 void dso__set_sorted_by_name(struct dso *dso)
1310 dso->sorted_by_name = true;
1313 struct dso *dso__new_id(const char *name, struct dso_id *id)
1315 struct dso *dso = calloc(1, sizeof(*dso) + strlen(name) + 1);
1317 if (dso != NULL) {
1318 strcpy(dso->name, name);
1320 dso->id = *id;
1321 dso__set_long_name_id(dso, dso->name, id, false);
1322 dso__set_short_name(dso, dso->name, false);
1323 dso->symbols = RB_ROOT_CACHED;
1324 dso->symbol_names = NULL;
1325 dso->symbol_names_len = 0;
1326 dso->data.cache = RB_ROOT;
1327 dso->inlined_nodes = RB_ROOT_CACHED;
1328 dso->srclines = RB_ROOT_CACHED;
1329 dso->data.fd = -1;
1330 dso->data.status = DSO_DATA_STATUS_UNKNOWN;
1331 dso->symtab_type = DSO_BINARY_TYPE__NOT_FOUND;
1332 dso->binary_type = DSO_BINARY_TYPE__NOT_FOUND;
1333 dso->is_64_bit = (sizeof(void *) == 8);
1334 dso->loaded = 0;
1335 dso->rel = 0;
1336 dso->sorted_by_name = 0;
1337 dso->has_build_id = 0;
1338 dso->has_srcline = 1;
1339 dso->a2l_fails = 1;
1340 dso->kernel = DSO_SPACE__USER;
1341 dso->needs_swap = DSO_SWAP__UNSET;
1342 dso->comp = COMP_ID__NONE;
1343 RB_CLEAR_NODE(&dso->rb_node);
1344 dso->root = NULL;
1345 INIT_LIST_HEAD(&dso->node);
1346 INIT_LIST_HEAD(&dso->data.open_entry);
1347 mutex_init(&dso->lock);
1348 refcount_set(&dso->refcnt, 1);
1351 return dso;
1354 struct dso *dso__new(const char *name)
1359 void dso__delete(struct dso *dso)
1361 if (!RB_EMPTY_NODE(&dso->rb_node))
1363 dso->long_name);
1366 inlines__tree_delete(&dso->inlined_nodes);
1367 srcline__tree_delete(&dso->srclines);
1368 symbols__delete(&dso->symbols);
1369 dso->symbol_names_len = 0;
1370 zfree(&dso->symbol_names);
1371 if (dso->short_name_allocated) {
1372 zfree((char **)&dso->short_name);
1373 dso->short_name_allocated = false;
1376 if (dso->long_name_allocated) {
1377 zfree((char **)&dso->long_name);
1378 dso->long_name_allocated = false;
1381 dso__data_close(dso);
1382 auxtrace_cache__free(dso->auxtrace_cache);
1383 dso_cache__free(dso);
1384 dso__free_a2l(dso);
1385 zfree(&dso->symsrc_filename);
1386 nsinfo__zput(dso->nsinfo);
1387 mutex_destroy(&dso->lock);
1388 free(dso);
1391 struct dso *dso__get(struct dso *dso)
1393 if (dso)
1394 refcount_inc(&dso->refcnt);
1395 return dso;
1398 void dso__put(struct dso *dso)
1400 if (dso && refcount_dec_and_test(&dso->refcnt))
1401 dso__delete(dso);
1404 void dso__set_build_id(struct dso *dso, struct build_id *bid)
1406 dso->bid = *bid;
1407 dso->has_build_id = 1;
1410 bool dso__build_id_equal(const struct dso *dso, struct build_id *bid)
1412 if (dso->bid.size > bid->size && dso->bid.size == BUILD_ID_SIZE) {
1417 return !memcmp(dso->bid.data, bid->data, bid->size) &&
1418 !memchr_inv(&dso->bid.data[bid->size], 0,
1419 dso->bid.size - bid->size);
1422 return dso->bid.size == bid->size &&
1423 memcmp(dso->bid.data, bid->data, dso->bid.size) == 0;
1426 void dso__read_running_kernel_build_id(struct dso *dso, struct machine *machine)
1433 if (sysfs__read_build_id(path, &dso->bid) == 0)
1434 dso->has_build_id = true;
1437 int dso__kernel_module_get_build_id(struct dso *dso,
1445 const char *name = dso->short_name + 1;
1451 if (sysfs__read_build_id(filename, &dso->bid) == 0)
1452 dso->has_build_id = true;
1457 static size_t dso__fprintf_buildid(struct dso *dso, FILE *fp)
1461 build_id__sprintf(&dso->bid, sbuild_id);
1465 size_t dso__fprintf(struct dso *dso, FILE *fp)
1468 size_t ret = fprintf(fp, "dso: %s (", dso->short_name);
1470 if (dso->short_name != dso->long_name)
1471 ret += fprintf(fp, "%s, ", dso->long_name);
1472 ret += fprintf(fp, "%sloaded, ", dso__loaded(dso) ? "" : "NOT ");
1473 ret += dso__fprintf_buildid(dso, fp);
1475 for (nd = rb_first_cached(&dso->symbols); nd; nd = rb_next(nd)) {
1483 enum dso_type dso__type(struct dso *dso, struct machine *machine)
1488 fd = dso__data_get_fd(dso, machine);
1491 dso__data_put_fd(dso);
1497 int dso__strerror_load(struct dso *dso, char *buf, size_t buflen)
1499 int idx, errnum = dso->load_errno;