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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
subcmd/parse-options.hstring.hstdlib.hfcntl.hunistd.herrno.hsys/stat.hsys/sendfile.hobjtool/builtin.hobjtool/objtool.hobjtool/warn.h
Detected Declarations
function parse_dumpfunction parse_hacksfunction strstrfunction cmd_parse_optionsfunction opts_validfunction copy_filefunction save_argvfunction make_backupfunction objtool_run
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
- Immediate include surface: `subcmd/parse-options.h`, `string.h`, `stdlib.h`, `fcntl.h`, `unistd.h`, `errno.h`, `sys/stat.h`, `sys/sendfile.h`.
- Detected declarations: `function parse_dump`, `function parse_hacks`, `function strstr`, `function cmd_parse_options`, `function opts_valid`, `function copy_file`, `function save_argv`, `function make_backup`, `function objtool_run`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source 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.