tools/objtool/klp-diff.c
Source file repositories/reference/linux-study-clean/tools/objtool/klp-diff.c
File Facts
- System
- Linux kernel
- Corpus path
tools/objtool/klp-diff.c- Extension
.c- Size
- 56796 bytes
- Lines
- 2214
- 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.hstdlib.hstring.hlibgen.hstdio.hctype.hobjtool/objtool.hobjtool/warn.hobjtool/arch.hobjtool/klp.hobjtool/util.harch/special.hlinux/align.hlinux/objtool_types.hlinux/livepatch_external.hlinux/stringify.hlinux/string.hlinux/jhash.h
Detected Declarations
struct elfsstruct exportstruct llvm_suffix_pairfunction read_exportsfunction read_sym_checksumsfunction for_each_symfunction is_uncorrelated_static_localfunction is_local_labelfunction is_special_sectionfunction is_special_section_auxfunction ___ADDRESSABLEfunction is_abs_symfunction is_initcall_symfunction is_anonymous_rodatafunction dont_correlatefunction is_llvm_symfunction maybe_same_filefunction maybe_same_filefunction is_tu_local_symfunction namefunction update_suffix_mapfunction for_each_symfunction hash_for_each_possiblefunction find_twinfunction hash_for_each_possiblefunction for_each_sym_by_namefunction for_each_sym_by_demangled_namefunction for_each_sym_by_demangled_namefunction correlate_symbolsfunction for_each_symfunction for_each_symfunction for_each_symfunction for_each_symfunction find_symposfunction for_each_symfunction for_each_symfunction mark_included_functionfunction functionsfunction clone_included_functionsfunction for_each_symfunction hash_for_each_possiblefunction klp_reloc_neededfunction convert_reloc_sym_to_secsymfunction convert_reloc_secsym_to_symfunction datafunction convert_reloc_symfunction relocationfunction sym_type
Annotated Snippet
struct elfs {
struct elf *orig, *patched, *out;
const char *modname;
};
struct export {
struct hlist_node hash;
char *mod, *sym;
};
bool debug, debug_correlate, debug_clone;
int indent;
static const char * const klp_diff_usage[] = {
"objtool klp diff [<options>] <in1.o> <in2.o> <out.o>",
NULL,
};
static const struct option klp_diff_options[] = {
OPT_GROUP("Options:"),
OPT_BOOLEAN('d', "debug", &debug, "enable all debug output"),
OPT_BOOLEAN(0, "debug-correlate", &debug_correlate, "enable correlation debug output"),
OPT_BOOLEAN(0, "debug-clone", &debug_clone, "enable cloning debug output"),
OPT_END(),
};
static DEFINE_HASHTABLE(exports, 15);
static char *escape_str(const char *orig)
{
size_t len = 0;
const char *a;
char *b, *new;
for (a = orig; *a; a++) {
switch (*a) {
case '\001': len += 5; break;
case '\n':
case '\t': len += 2; break;
default: len++;
}
}
new = malloc(len + 1);
if (!new)
return NULL;
for (a = orig, b = new; *a; a++) {
switch (*a) {
case '\001': memcpy(b, "<SOH>", 5); b += 5; break;
case '\n': *b++ = '\\'; *b++ = 'n'; break;
case '\t': *b++ = '\\'; *b++ = 't'; break;
default: *b++ = *a;
}
}
*b = '\0';
return new;
}
static int read_exports(void)
{
const char *symvers = "Module.symvers";
char line[1024], *path = NULL;
unsigned int line_num = 1;
FILE *file;
file = fopen(symvers, "r");
if (!file) {
path = top_level_dir(symvers);
if (!path) {
ERROR("can't open '%s', \"objtool diff\" should be run from the kernel tree", symvers);
return -1;
}
file = fopen(path, "r");
if (!file) {
ERROR_GLIBC("fopen");
return -1;
}
}
while (fgets(line, 1024, file)) {
char *sym, *mod, *type;
struct export *export;
sym = strchr(line, '\t');
if (!sym) {
ERROR("malformed Module.symvers (sym) at line %d", line_num);
return -1;
Annotation
- Immediate include surface: `subcmd/parse-options.h`, `stdlib.h`, `string.h`, `libgen.h`, `stdio.h`, `ctype.h`, `objtool/objtool.h`, `objtool/warn.h`.
- Detected declarations: `struct elfs`, `struct export`, `struct llvm_suffix_pair`, `function read_exports`, `function read_sym_checksums`, `function for_each_sym`, `function is_uncorrelated_static_local`, `function is_local_label`, `function is_special_section`, `function is_special_section_aux`.
- 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.