scripts/sorttable.c
Source file repositories/reference/linux-study-clean/scripts/sorttable.c
File Facts
- System
- Linux kernel
- Corpus path
scripts/sorttable.c- Extension
.c- Size
- 23911 bytes
- Lines
- 1006
- 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
sys/types.hsys/stat.hgetopt.hfcntl.hstdio.hstdlib.hstdbool.hstring.hunistd.herrno.hpthread.helf-parse.hasm/orc_types.h
Detected Declarations
struct func_infostruct elf_mcount_locfunction is_shndx_specialfunction get_secindexfunction compare_extable_32function compare_extable_64function orc_ipfunction orc_sort_cmpfunction compare_values_64function compare_values_32function rela_write_addendfunction add_fieldfunction cmp_func_addrfunction find_funcfunction cmp_funcsfunction parse_symbolsfunction fill_relocsfunction replace_relocsfunction fill_addrsfunction replace_addrsfunction get_mcount_locfunction parse_symbolsfunction do_sortfunction compare_relative_tablefunction sort_relative_tablefunction sort_relative_table_with_datafunction do_filefunction main
Annotated Snippet
struct func_info {
uint64_t addr;
uint64_t size;
};
/* List of functions created by: nm -S vmlinux */
static struct func_info *function_list;
static int function_list_size;
/* Allocate functions in 1k blocks */
#define FUNC_BLK_SIZE 1024
#define FUNC_BLK_MASK (FUNC_BLK_SIZE - 1)
static int add_field(uint64_t addr, uint64_t size)
{
struct func_info *fi;
int fsize = function_list_size;
if (!(fsize & FUNC_BLK_MASK)) {
fsize += FUNC_BLK_SIZE;
fi = realloc(function_list, fsize * sizeof(struct func_info));
if (!fi)
return -1;
function_list = fi;
}
fi = &function_list[function_list_size++];
fi->addr = addr;
fi->size = size;
return 0;
}
/* Used for when mcount/fentry is before the function entry */
static int before_func;
/* Only return match if the address lies inside the function size */
static int cmp_func_addr(const void *K, const void *A)
{
uint64_t key = *(const uint64_t *)K;
const struct func_info *a = A;
if (key + before_func < a->addr)
return -1;
return key >= a->addr + a->size;
}
/* Find the function in function list that is bounded by the function size */
static int find_func(uint64_t key)
{
return bsearch(&key, function_list, function_list_size,
sizeof(struct func_info), cmp_func_addr) != NULL;
}
static int cmp_funcs(const void *A, const void *B)
{
const struct func_info *a = A;
const struct func_info *b = B;
if (a->addr < b->addr)
return -1;
return a->addr > b->addr;
}
static int parse_symbols(const char *fname)
{
FILE *fp;
char addr_str[20]; /* Only need 17, but round up to next int size */
char size_str[20];
char type;
fp = fopen(fname, "r");
if (!fp) {
perror(fname);
return -1;
}
while (fscanf(fp, "%16s %16s %c %*s\n", addr_str, size_str, &type) == 3) {
uint64_t addr;
uint64_t size;
/* Only care about functions */
if (type != 't' && type != 'T' && type != 'W')
continue;
addr = strtoull(addr_str, NULL, 16);
size = strtoull(size_str, NULL, 16);
if (add_field(addr, size) < 0)
return -1;
}
fclose(fp);
Annotation
- Immediate include surface: `sys/types.h`, `sys/stat.h`, `getopt.h`, `fcntl.h`, `stdio.h`, `stdlib.h`, `stdbool.h`, `string.h`.
- Detected declarations: `struct func_info`, `struct elf_mcount_loc`, `function is_shndx_special`, `function get_secindex`, `function compare_extable_32`, `function compare_extable_64`, `function orc_ip`, `function orc_sort_cmp`, `function compare_values_64`, `function compare_values_32`.
- 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.