scripts/mod/modpost.c
Source file repositories/reference/linux-study-clean/scripts/mod/modpost.c
File Facts
- System
- Linux kernel
- Corpus path
scripts/mod/modpost.c- Extension
.c- Size
- 61547 bytes
- Lines
- 2420
- Domain
- Support Tooling And Documentation
- Bucket
- scripts
- Inferred role
- Support Tooling And Documentation: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
elf.hfnmatch.hstdio.hctype.hstring.hlimits.hstdbool.herrno.hhash.hhashtable.hlist.hxalloc.hmodpost.h../../include/linux/license.h
Detected Declarations
struct symbolstruct namespace_liststruct sectioncheckstruct dump_listenum mismatchfunction modpost_logfunction strendsfunction list_for_each_entryfunction get_symbol_flagsfunction hash_add_symbolfunction sym_add_unresolvedfunction hash_for_each_possiblefunction contains_namespacefunction list_for_each_entryfunction add_namespacefunction sym_set_crcfunction release_filefunction parse_elffunction parse_elf_finishfunction ignore_undef_symbolfunction handle_symbolfunction patternsfunction check_sectionfunction module_param_callfunction is_executable_sectionfunction default_mismatch_handlerfunction check_export_symbolfunction check_section_mismatchfunction addend_386_relfunction sign_extend32function addend_arm_relfunction addend_mips_relfunction get_rel_type_and_symfunction section_relafunction section_relfunction check_sec_reffunction extract_crcs_for_objectfunction versionsfunction read_symbolsfunction read_symbols_from_filesfunction __attribute__function buf_writefunction verify_module_namespacefunction check_exportsfunction list_for_each_entryfunction handle_white_list_exportsfunction symbol_getfunction check_modname_len
Annotated Snippet
struct symbol {
struct hlist_node hnode;/* link to hash table */
struct list_head list; /* link to module::exported_symbols or module::unresolved_symbols */
struct module *module;
char *namespace;
unsigned int crc;
bool crc_valid;
bool weak;
bool is_func;
bool is_gpl_only; /* exported by EXPORT_SYMBOL_GPL */
bool used; /* there exists a user of this symbol */
char name[];
};
static HASHTABLE_DEFINE(symbol_hashtable, 1U << 10);
/**
* Allocate a new symbols for use in the hash of exported symbols or
* the list of unresolved symbols per module
**/
static struct symbol *alloc_symbol(const char *name)
{
struct symbol *s = xmalloc(sizeof(*s) + strlen(name) + 1);
memset(s, 0, sizeof(*s));
strcpy(s->name, name);
return s;
}
static uint8_t get_symbol_flags(const struct symbol *sym)
{
return sym->is_gpl_only ? KSYM_FLAG_GPL_ONLY : 0;
}
/* For the hash of exported symbols */
static void hash_add_symbol(struct symbol *sym)
{
hash_add(symbol_hashtable, &sym->hnode, hash_str(sym->name));
}
static void sym_add_unresolved(const char *name, struct module *mod, bool weak)
{
struct symbol *sym;
sym = alloc_symbol(name);
sym->weak = weak;
list_add_tail(&sym->list, &mod->unresolved_symbols);
}
static struct symbol *sym_find_with_module(const char *name, struct module *mod)
{
struct symbol *s;
/* For our purposes, .foo matches foo. PPC64 needs this. */
if (name[0] == '.')
name++;
hash_for_each_possible(symbol_hashtable, s, hnode, hash_str(name)) {
if (strcmp(s->name, name) == 0 && (!mod || s->module == mod))
return s;
}
return NULL;
}
static struct symbol *find_symbol(const char *name)
{
return sym_find_with_module(name, NULL);
}
struct namespace_list {
struct list_head list;
char namespace[];
};
static bool contains_namespace(struct list_head *head, const char *namespace)
{
struct namespace_list *list;
/*
* The default namespace is null string "", which is always implicitly
* contained.
*/
if (!namespace[0])
return true;
list_for_each_entry(list, head, list) {
if (!strcmp(list->namespace, namespace))
return true;
Annotation
- Immediate include surface: `elf.h`, `fnmatch.h`, `stdio.h`, `ctype.h`, `string.h`, `limits.h`, `stdbool.h`, `errno.h`.
- Detected declarations: `struct symbol`, `struct namespace_list`, `struct sectioncheck`, `struct dump_list`, `enum mismatch`, `function modpost_log`, `function strends`, `function list_for_each_entry`, `function get_symbol_flags`, `function hash_add_symbol`.
- Atlas domain: Support Tooling And Documentation / scripts.
- Implementation status: integration 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.