scripts/genksyms/genksyms.c

Source file repositories/reference/linux-study-clean/scripts/genksyms/genksyms.c

File Facts

System
Linux kernel
Corpus path
scripts/genksyms/genksyms.c
Extension
.c
Size
21230 bytes
Lines
851
Domain
Support Tooling And Documentation
Bucket
scripts
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.

Dependency Surface

Detected Declarations

Annotated Snippet

if (defn) {
			free_list(last_enum_expr, NULL);
			last_enum_expr = copy_list_range(defn, NULL);
			enum_counter = 1;
		} else {
			struct string_list *expr;
			char buf[20];

			snprintf(buf, sizeof(buf), "%d", enum_counter++);
			if (last_enum_expr) {
				expr = copy_list_range(last_enum_expr, NULL);
				defn = concat_list(mk_node("("),
						   expr,
						   mk_node(")"),
						   mk_node("+"),
						   mk_node(buf), NULL);
			} else {
				defn = mk_node(buf);
			}
		}
	} else {
		free_list(last_enum_expr, NULL);
		last_enum_expr = NULL;
		enum_counter = 0;
		if (!name)
			/* Anonymous enum definition, nothing more to do */
			return NULL;
	}

	return defn;
}

static struct symbol *__add_symbol(const char *name, enum symbol_type type,
			    struct string_list *defn, int is_extern,
			    int is_reference)
{
	unsigned long h;
	struct symbol *sym;
	enum symbol_status status = STATUS_UNCHANGED;

	if ((type == SYM_ENUM_CONST || type == SYM_ENUM) && !is_reference) {
		defn = process_enum(name, type, defn);
		if (defn == NULL)
			return NULL;
	}

	h = crc32(name);
	hash_for_each_possible(symbol_hashtable, sym, hnode, h) {
		if (map_to_ns(sym->type) != map_to_ns(type) ||
		    strcmp(name, sym->name))
			continue;

		if (is_reference) {
			break;
		} else if (sym->type == type && equal_list(sym->defn, defn)) {
			if (!sym->is_declared && sym->is_override) {
				print_location();
				print_type_name(type, name);
				fprintf(stderr, " modversion is unchanged\n");
			}
			sym->is_declared = 1;
		} else if (sym->is_declared) {
			error_with_pos("redefinition of %s", name);
		} else if (sym->is_override && flag_preserve) {
			print_location();
			fprintf(stderr, "ignoring ");
			print_type_name(type, name);
			fprintf(stderr, " modversion change\n");
			sym->is_declared = 1;
		} else {
			status = is_unknown_symbol(sym) ?
					STATUS_DEFINED : STATUS_MODIFIED;
			break;
		}
		free_list(defn, NULL);
		return sym;
	}

	if (sym) {
		hash_del(&sym->hnode);

		free_list(sym->defn, NULL);
		free(sym->name);
		free(sym);
		--nsyms;
	}

	sym = xmalloc(sizeof(*sym));
	sym->name = xstrdup(name);
	sym->type = type;

Annotation

Implementation Notes