scripts/kallsyms.c
Source file repositories/reference/linux-study-clean/scripts/kallsyms.c
File Facts
- System
- Linux kernel
- Corpus path
scripts/kallsyms.c- Extension
.c- Size
- 16048 bytes
- Lines
- 713
- 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.
- 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
errno.hgetopt.hstdbool.hstdio.hstdlib.hstring.hctype.hlimits.hxalloc.h
Detected Declarations
struct sym_entrystruct addr_rangefunction usagefunction is_ignored_symbolfunction check_symbol_rangefunction symbol_in_rangefunction string_starts_withfunction symbol_validfunction shrink_tablefunction read_mapfunction output_labelfunction expand_symbolfunction compare_namesfunction sort_symbols_by_namefunction write_srcfunction learn_symbolfunction forget_symbolfunction build_initial_token_tablefunction compress_symbolsfunction find_best_tokenfunction optimize_resultfunction insert_real_symbols_in_tablefunction optimize_token_tablefunction may_be_linker_script_provide_symbolfunction compare_symbolsfunction sort_symbolsfunction main
Annotated Snippet
struct sym_entry {
unsigned long long addr;
unsigned int len;
unsigned int seq;
unsigned char sym[];
};
struct addr_range {
const char *start_sym, *end_sym;
unsigned long long start, end;
};
static unsigned long long _text;
static struct addr_range text_ranges[] = {
{ "_stext", "_etext" },
{ "_sinittext", "_einittext" },
};
#define text_range_text (&text_ranges[0])
#define text_range_inittext (&text_ranges[1])
static struct sym_entry **table;
static unsigned int table_size, table_cnt;
static int all_symbols;
static int pc_relative;
static int token_profit[0x10000];
/* the table that holds the result of the compression */
static unsigned char best_table[256][2];
static unsigned char best_table_len[256];
static void usage(void)
{
fprintf(stderr, "Usage: kallsyms [--all-symbols] in.map > out.S\n");
exit(1);
}
static char *sym_name(const struct sym_entry *s)
{
return (char *)s->sym + 1;
}
static bool is_ignored_symbol(const char *name, char type)
{
if (type == 'u' || type == 'n')
return true;
if (toupper(type) == 'A') {
/* Keep these useful absolute symbols */
if (strcmp(name, "__kernel_syscall_via_break") &&
strcmp(name, "__kernel_syscall_via_epc") &&
strcmp(name, "__kernel_sigtramp") &&
strcmp(name, "__gp"))
return true;
}
return false;
}
static void check_symbol_range(const char *sym, unsigned long long addr,
struct addr_range *ranges, int entries)
{
size_t i;
struct addr_range *ar;
for (i = 0; i < entries; ++i) {
ar = &ranges[i];
if (strcmp(sym, ar->start_sym) == 0) {
ar->start = addr;
return;
} else if (strcmp(sym, ar->end_sym) == 0) {
ar->end = addr;
return;
}
}
}
static struct sym_entry *read_symbol(FILE *in, char **buf, size_t *buf_len)
{
char *name, type, *p;
unsigned long long addr;
size_t len;
ssize_t readlen;
struct sym_entry *sym;
errno = 0;
readlen = getline(buf, buf_len, in);
if (readlen < 0) {
Annotation
- Immediate include surface: `errno.h`, `getopt.h`, `stdbool.h`, `stdio.h`, `stdlib.h`, `string.h`, `ctype.h`, `limits.h`.
- Detected declarations: `struct sym_entry`, `struct addr_range`, `function usage`, `function is_ignored_symbol`, `function check_symbol_range`, `function symbol_in_range`, `function string_starts_with`, `function symbol_valid`, `function shrink_table`, `function read_map`.
- Atlas domain: Support Tooling And Documentation / scripts.
- 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.