tools/perf/util/symbol-minimal.c
Source file repositories/reference/linux-study-clean/tools/perf/util/symbol-minimal.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/symbol-minimal.c- Extension
.c- Size
- 7810 bytes
- Lines
- 368
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
dso.hsymbol.hsymsrc.herrno.hunistd.hfcntl.hstring.hstdlib.hbyteswap.hsys/stat.hlinux/zalloc.hinternal/lib.h
Detected Declarations
function check_need_swapfunction read_build_idfunction filename__read_debuglinkfunction filename__read_build_idfunction sysfs__read_build_idfunction symsrc__initfunction symsrc__possibly_runtimefunction symsrc__has_symtabfunction symsrc__destroyfunction dso__synthesize_plt_symbolsfunction fd__is_64_bitfunction dso__type_fdfunction dso__load_symfunction file__read_mapsfunction kcore_extract__createfunction kcore_extract__deletefunction symbol__elf_init
Annotated Snippet
if (need_swap) {
nhdr->n_namesz = bswap_32(nhdr->n_namesz);
nhdr->n_descsz = bswap_32(nhdr->n_descsz);
nhdr->n_type = bswap_32(nhdr->n_type);
}
namesz = NOTE_ALIGN(nhdr->n_namesz);
descsz = NOTE_ALIGN(nhdr->n_descsz);
ptr += sizeof(*nhdr);
name = ptr;
ptr += namesz;
if (nhdr->n_type == NT_GNU_BUILD_ID &&
nhdr->n_namesz == sizeof("GNU")) {
if (memcmp(name, "GNU", sizeof("GNU")) == 0) {
size_t sz = min(size, descsz);
memcpy(bid->data, ptr, sz);
memset(bid->data + sz, 0, size - sz);
bid->size = sz;
return 0;
}
}
ptr += descsz;
}
return -1;
}
int filename__read_debuglink(const char *filename __maybe_unused,
char *debuglink __maybe_unused,
size_t size __maybe_unused)
{
return -1;
}
/*
* Just try PT_NOTE header otherwise fails
*/
int filename__read_build_id(const char *filename, struct build_id *bid)
{
int fd, ret = -1;
bool need_swap = false, elf32;
union {
struct {
Elf32_Ehdr ehdr32;
Elf32_Phdr *phdr32;
};
struct {
Elf64_Ehdr ehdr64;
Elf64_Phdr *phdr64;
};
} hdrs;
void *phdr, *buf = NULL;
ssize_t phdr_size, ehdr_size, buf_size = 0;
if (!filename)
return -EFAULT;
errno = 0;
if (!is_regular_file(filename))
return errno == 0 ? -EWOULDBLOCK : -errno;
fd = open(filename, O_RDONLY);
if (fd < 0)
return -1;
if (read(fd, hdrs.ehdr32.e_ident, EI_NIDENT) != EI_NIDENT)
goto out;
if (memcmp(hdrs.ehdr32.e_ident, ELFMAG, SELFMAG) ||
hdrs.ehdr32.e_ident[EI_VERSION] != EV_CURRENT)
goto out;
need_swap = check_need_swap(hdrs.ehdr32.e_ident[EI_DATA]);
elf32 = hdrs.ehdr32.e_ident[EI_CLASS] == ELFCLASS32;
ehdr_size = (elf32 ? sizeof(hdrs.ehdr32) : sizeof(hdrs.ehdr64)) - EI_NIDENT;
if (read(fd,
(elf32 ? (void *)&hdrs.ehdr32 : (void *)&hdrs.ehdr64) + EI_NIDENT,
ehdr_size) != ehdr_size)
goto out;
if (need_swap) {
if (elf32) {
hdrs.ehdr32.e_phoff = bswap_32(hdrs.ehdr32.e_phoff);
hdrs.ehdr32.e_phentsize = bswap_16(hdrs.ehdr32.e_phentsize);
hdrs.ehdr32.e_phnum = bswap_16(hdrs.ehdr32.e_phnum);
} else {
hdrs.ehdr64.e_phoff = bswap_64(hdrs.ehdr64.e_phoff);
hdrs.ehdr64.e_phentsize = bswap_16(hdrs.ehdr64.e_phentsize);
Annotation
- Immediate include surface: `dso.h`, `symbol.h`, `symsrc.h`, `errno.h`, `unistd.h`, `fcntl.h`, `string.h`, `stdlib.h`.
- Detected declarations: `function check_need_swap`, `function read_build_id`, `function filename__read_debuglink`, `function filename__read_build_id`, `function sysfs__read_build_id`, `function symsrc__init`, `function symsrc__possibly_runtime`, `function symsrc__has_symtab`, `function symsrc__destroy`, `function dso__synthesize_plt_symbols`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.