tools/objtool/builtin-check.c

Source file repositories/reference/linux-study-clean/tools/objtool/builtin-check.c

File Facts

System
Linux kernel
Corpus path
tools/objtool/builtin-check.c
Extension
.c
Size
8567 bytes
Lines
349
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.

Dependency Surface

Detected Declarations

Annotated Snippet

if (opts.dump_orc) {
			ERROR("--dump can't be combined with other actions");
			return false;
		}

		return true;
	}

	if (opts.dump_orc)
		return true;

	ERROR("At least one action required");
	return false;
}

static int copy_file(const char *src, const char *dst)
{
	size_t to_copy, copied;
	int dst_fd, src_fd;
	struct stat stat;
	off_t offset = 0;

	src_fd = open(src, O_RDONLY);
	if (src_fd == -1) {
		ERROR("can't open %s for reading: %s", src, strerror(errno));
		return 1;
	}

	dst_fd = open(dst, O_WRONLY | O_CREAT | O_TRUNC, 0400);
	if (dst_fd == -1) {
		ERROR("can't open %s for writing: %s", dst, strerror(errno));
		return 1;
	}

	if (fstat(src_fd, &stat) == -1) {
		ERROR_GLIBC("fstat");
		return 1;
	}

	if (fchmod(dst_fd, stat.st_mode) == -1) {
		ERROR_GLIBC("fchmod");
		return 1;
	}

	for (to_copy = stat.st_size; to_copy > 0; to_copy -= copied) {
		copied = sendfile(dst_fd, src_fd, &offset, to_copy);
		if (copied == -1) {
			ERROR_GLIBC("sendfile");
			return 1;
		}
	}

	close(dst_fd);
	close(src_fd);
	return 0;
}

static void save_argv(int argc, const char **argv)
{
	orig_argv = calloc(argc, sizeof(char *));
	if (!orig_argv) {
		ERROR_GLIBC("calloc");
		exit(1);
	}

	for (int i = 0; i < argc; i++) {
		orig_argv[i] = strdup(argv[i]);
		if (!orig_argv[i]) {
			ERROR_GLIBC("strdup(%s)", argv[i]);
			exit(1);
		}
	}
}

int make_backup(void)
{
	char *backup;

	/*
	 * Make a backup before kbuild deletes the file so the error
	 * can be recreated without recompiling or relinking.
	 */
	backup = malloc(strlen(objname) + strlen(ORIG_SUFFIX) + 1);
	if (!backup) {
		ERROR_GLIBC("malloc");
		return 1;
	}

	strcpy(backup, objname);
	strcat(backup, ORIG_SUFFIX);

Annotation

Implementation Notes