scripts/verify_builtin_ranges.awk

Source file repositories/reference/linux-study-clean/scripts/verify_builtin_ranges.awk

File Facts

System
Linux kernel
Corpus path
scripts/verify_builtin_ranges.awk
Extension
.awk
Size
9334 bytes
Lines
371
Domain
Support Tooling And Documentation
Bucket
scripts
Inferred role
Support Tooling And Documentation: scripts
Status
atlas-only

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

function get_module_info(fn, mod, obj, s) {
	if (fn in omod)
		return omod[fn];

	if (match(fn, /\/[^/]+$/) == 0)
		return "";

	obj = fn;
	mod = "";
	fn = substr(fn, 1, RSTART) "." substr(fn, RSTART + 1) ".cmd";
	if (getline s <fn == 1) {
		if (match(s, /DKBUILD_MODFILE=['"]+[^'"]+/) > 0) {
			mod = substr(s, RSTART + 16, RLENGTH - 16);
			gsub(/['"]/, "", mod);
		} else if (match(s, /RUST_MODFILE=[^ ]+/) > 0)
			mod = substr(s, RSTART + 13, RLENGTH - 13);
	} else {
		print "ERROR: Failed to read: " fn "\n\n" \
		      "  For kernels built with O=<objdir>, cd to <objdir>\n" \
		      "  and execute this script as ./source/scripts/..." \
		      >"/dev/stderr";
		close(fn);
		total = 0;
		exit(1);
	}
	close(fn);

	# A single module (common case) also reflects objects that are not part
	# of a module.  Some of those objects have names that are also a module
	# name (e.g. core).  We check the associated module file name, and if
	# they do not match, the object is not part of a module.
	if (mod !~ / /) {
		if (!(mod in mods))
			mod = "";
	}

	gsub(/([^/ ]*\/)+/, "", mod);
	gsub(/-/, "_", mod);

	# At this point, mod is a single (valid) module name, or a list of
	# module names (that do not need validation).
	omod[obj] = mod;

	return mod;
}

# Return a representative integer value for a given hexadecimal address.
#
# Since all kernel addresses fall within the same memory region, we can safely
# strip off the first 6 hex digits before performing the hex-to-dec conversion,
# thereby avoiding integer overflows.
#
function addr2val(val) {
	sub(/^0x/, "", val);
	if (length(val) == 16)
		val = substr(val, 5);
	return strtonum("0x" val);
}

# Determine the kernel build directory to use (default is .).
#
BEGIN {
	if (ARGC < 6) {
		print "Syntax: verify_builtin_ranges.awk <ranges-file> <system-map>\n" \
		      "          <builtin-file> <vmlinux-map> <vmlinux-o-map>\n" \
		      >"/dev/stderr";
		total = 0;
		exit(1);
	}
}

Annotation

Implementation Notes