tools/perf/util/dso.c
Source file repositories/reference/linux-study-clean/tools/perf/util/dso.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/dso.c- Extension
.c- Size
- 49777 bytes
- Lines
- 2007
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
asm/bug.hlinux/kernel.hlinux/string.hlinux/zalloc.hsys/time.hsys/resource.hsys/types.hsys/stat.hunistd.herrno.hfcntl.hstdlib.hbpf/libbpf.hbpf-event.hbpf-utils.hcompress.henv.hnamespaces.hpath.hmap.hsymbol.hsrcline.hdso.hdsos.hmachine.hauxtrace.hutil.hdebug.hstring2.hvdso.hannotate-data.hlibdw.h
Detected Declarations
struct find_file_offset_datafunction dso__set_nsinfofunction dso__symtab_originfunction dso__is_object_filefunction dso__read_binary_type_filenamefunction is_supported_compressionfunction is_kernel_modulefunction dso__needs_decompressfunction filename__decompressfunction decompress_kmodulefunction dso__decompress_kmodule_fdfunction dso__decompress_kmodule_pathfunction __kmod_path__parsefunction dso__set_module_infofunction dso__data_open_lock_initfunction dso__list_addfunction dso__list_delfunction do_openfunction __open_dsofunction open_dsofunction close_data_fdfunction close_dsofunction close_first_dsofunction get_fd_limitfunction reset_fd_limitfunction may_cache_fdfunction check_data_closefunction dso__data_closefunction try_to_open_dsofunction dso__data_put_fdfunction dso__data_put_fdfunction dso__data_status_seenfunction bpf_readfunction bpf_sizefunction dso_cache__freefunction dso_cache__insertfunction dso_cache__memcpyfunction file_readfunction dso_cache_iofunction cached_iofunction file_sizefunction dso__data_file_sizefunction dso__data_sizefunction data_read_write_offsetfunction dso__data_read_offsetfunction dso_swap_type__from_elf_datafunction dso__read_e_machinefunction dso__e_machine
Annotated Snippet
struct find_file_offset_data {
u64 ip;
u64 offset;
};
/* This will be called for each PHDR in an ELF binary */
static int find_file_offset(u64 start, u64 len, u64 pgoff, void *arg)
{
struct find_file_offset_data *data = arg;
if (start <= data->ip && data->ip < start + len) {
data->offset = pgoff + data->ip - start;
return 1;
}
return 0;
}
static const u8 *__dso__read_symbol(struct dso *dso, const char *symfs_filename,
u64 start, size_t len,
u8 **out_buf, u64 *out_buf_len, bool *is_64bit)
{
struct nscookie nsc;
int fd;
ssize_t count;
struct find_file_offset_data data = {
.ip = start,
};
u8 *code_buf = NULL;
int saved_errno;
nsinfo__mountns_enter(dso__nsinfo(dso), &nsc);
fd = open(symfs_filename, O_RDONLY);
saved_errno = errno;
nsinfo__mountns_exit(&nsc);
if (fd < 0) {
errno = saved_errno;
return NULL;
}
if (file__read_maps(fd, /*exe=*/true, find_file_offset, &data, is_64bit) <= 0) {
close(fd);
errno = ENOENT;
return NULL;
}
code_buf = malloc(len);
if (code_buf == NULL) {
close(fd);
errno = ENOMEM;
return NULL;
}
count = pread(fd, code_buf, len, data.offset);
saved_errno = errno;
close(fd);
if ((u64)count != len) {
free(code_buf);
errno = saved_errno;
return NULL;
}
*out_buf = code_buf;
*out_buf_len = len;
return code_buf;
}
/*
* Read a symbol into memory for disassembly by a library like capstone of
* libLLVM. If memory is allocated out_buf holds it.
*/
const u8 *dso__read_symbol(struct dso *dso, const char *symfs_filename,
const struct map *map, const struct symbol *sym,
u8 **out_buf, u64 *out_buf_len, bool *is_64bit)
{
u64 start = map__rip_2objdump(map, sym->start);
u64 end = map__rip_2objdump(map, sym->end);
size_t len = end - start;
*out_buf = NULL;
*out_buf_len = 0;
*is_64bit = false;
if (dso__binary_type(dso) == DSO_BINARY_TYPE__BPF_IMAGE) {
/*
* Note, there is fallback BPF image disassembly in the objdump
* version but it currently does nothing.
*/
errno = EOPNOTSUPP;
return NULL;
}
if (dso__binary_type(dso) == DSO_BINARY_TYPE__BPF_PROG_INFO) {
#ifdef HAVE_LIBBPF_SUPPORT
struct bpf_prog_info_node *info_node;
struct perf_bpil *info_linear;
Annotation
- Immediate include surface: `asm/bug.h`, `linux/kernel.h`, `linux/string.h`, `linux/zalloc.h`, `sys/time.h`, `sys/resource.h`, `sys/types.h`, `sys/stat.h`.
- Detected declarations: `struct find_file_offset_data`, `function dso__set_nsinfo`, `function dso__symtab_origin`, `function dso__is_object_file`, `function dso__read_binary_type_filename`, `function is_supported_compression`, `function is_kernel_module`, `function dso__needs_decompress`, `function filename__decompress`, `function decompress_kmodule`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.