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.

Dependency Surface

Detected Declarations

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

Implementation Notes