tools/objtool/elf.c
Source file repositories/reference/linux-study-clean/tools/objtool/elf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/objtool/elf.c- Extension
.c- Size
- 41387 bytes
- Lines
- 1853
- 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
sys/types.hsys/stat.hsys/mman.hfcntl.hstdio.hstdlib.hstring.hunistd.herrno.hctype.hlinux/align.hlinux/kernel.hlinux/interval_tree_generic.hlinux/log2.hobjtool/builtin.hobjtool/elf.hobjtool/warn.h
Detected Declarations
struct symbol_holefunction str_hash_demangledfunction __elf_hash_delfunction __sym_startfunction __sym_lastfunction symbol_hole_by_offsetfunction elf_hash_for_each_possiblefunction elf_hash_for_each_possiblefunction elf_hash_for_each_possiblefunction __sym_for_eachfunction __sym_for_eachfunction __sym_for_eachfunction find_symbol_hole_containingfunction __sym_for_eachfunction elf_hash_for_each_possiblefunction elf_hash_for_each_possiblefunction elf_hash_for_each_possiblefunction for_offset_rangefunction is_dwarf_sectionfunction read_sectionsfunction demangled_name_lenfunction elf_add_symbolfunction __sym_for_eachfunction read_symbolsfunction sec_for_each_symfunction mark_group_symsfunction for_each_secfunction elf_update_sym_relocsfunction elf_update_symbolfunction elf_write_symbolfunction read_relocsfunction list_for_each_entryfunction mark_rodatafunction for_each_secfunction elf_add_stringfunction elf_alloc_relocfunction elf_write_insnfunction elf_truncate_sectionfunction elf_writefunction elf_close
Annotated Snippet
struct symbol_hole {
unsigned long key;
const struct symbol *sym;
};
/*
* Find the last symbol before @offset.
*/
static int symbol_hole_by_offset(const void *key, const struct rb_node *node)
{
const struct symbol *s = rb_entry(node, struct symbol, node);
struct symbol_hole *sh = (void *)key;
if (sh->key < s->offset)
return -1;
if (sh->key >= s->offset + s->len) {
sh->sym = s;
return 1;
}
return 0;
}
struct section *find_section_by_name(const struct elf *elf, const char *name)
{
struct section *sec;
elf_hash_for_each_possible(elf, section_name, sec, name_hash, str_hash(name)) {
if (!strcmp(sec->name, name))
return sec;
}
return NULL;
}
static struct section *find_section_by_index(struct elf *elf,
unsigned int idx)
{
struct section *sec;
elf_hash_for_each_possible(elf, section, sec, hash, idx) {
if (sec->idx == idx)
return sec;
}
return NULL;
}
static struct symbol *find_symbol_by_index(struct elf *elf, unsigned int idx)
{
struct symbol *sym;
elf_hash_for_each_possible(elf, symbol, sym, hash, idx) {
if (sym->idx == idx)
return sym;
}
return NULL;
}
struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset)
{
struct rb_root_cached *tree = (struct rb_root_cached *)&sec->symbol_tree;
struct symbol *sym;
__sym_for_each(sym, tree, offset, offset) {
if (sym->offset == offset && !is_sec_sym(sym))
return sym->alias;
}
return NULL;
}
struct symbol *find_func_by_offset(struct section *sec, unsigned long offset)
{
struct rb_root_cached *tree = (struct rb_root_cached *)&sec->symbol_tree;
struct symbol *func;
__sym_for_each(func, tree, offset, offset) {
if (func->offset == offset && is_func_sym(func))
return func->alias;
}
return NULL;
}
struct symbol *find_symbol_containing(const struct section *sec, unsigned long offset)
{
struct rb_root_cached *tree = (struct rb_root_cached *)&sec->symbol_tree;
Annotation
- Immediate include surface: `sys/types.h`, `sys/stat.h`, `sys/mman.h`, `fcntl.h`, `stdio.h`, `stdlib.h`, `string.h`, `unistd.h`.
- Detected declarations: `struct symbol_hole`, `function str_hash_demangled`, `function __elf_hash_del`, `function __sym_start`, `function __sym_last`, `function symbol_hole_by_offset`, `function elf_hash_for_each_possible`, `function elf_hash_for_each_possible`, `function elf_hash_for_each_possible`, `function __sym_for_each`.
- 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.