tools/bpf/resolve_btfids/main.c
Source file repositories/reference/linux-study-clean/tools/bpf/resolve_btfids/main.c
File Facts
- System
- Linux kernel
- Corpus path
tools/bpf/resolve_btfids/main.c- Extension
.c- Size
- 36525 bytes
- Lines
- 1584
- 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
stdio.hstring.hunistd.hstdlib.hlibelf.hgelf.hsys/stat.hfcntl.herrno.hlinux/btf_ids.hlinux/kallsyms.hlinux/rbtree.hlinux/zalloc.hlinux/err.hlinux/limits.hbpf/btf.hbpf/libbpf.hsubcmd/parse-options.h
Detected Declarations
struct btf_idstruct objectstruct kfuncstruct btf2btf_contextenum btf_id_kindfunction eprintffunction is_btf_idfunction get_idfunction btf_id__free_allfunction bswap_32_datafunction elf_collectfunction symbols_collectfunction load_btffunction symbols_resolvefunction id_patchfunction __symbols_patchfunction cmp_idfunction sets_patchfunction symbols_patchfunction dump_raw_datafunction dump_raw_btf_idsfunction dump_raw_btffunction push_decl_tag_idfunction push_kfuncfunction collect_decl_tagsfunction btf_idfunction collect_kfuncsfunction build_btf2btf_contextfunction is_kf_implicit_argfunction process_kfunc_with_implicit_argsfunction btf2btffunction cmp_type_namesfunction sort_btf_by_namefunction finalize_btffunction make_out_pathfunction patch_btfidsfunction main
Annotated Snippet
struct btf_id {
struct rb_node rb_node;
char *name;
union {
int id;
int cnt;
};
enum btf_id_kind kind;
int addr_cnt;
Elf64_Addr addr[ADDR_CNT];
};
struct object {
const char *path;
const char *btf_path;
const char *base_btf_path;
struct btf *btf;
struct btf *base_btf;
bool distill_base;
struct {
int fd;
Elf *elf;
Elf_Data *symbols;
Elf_Data *idlist;
int symbols_shndx;
int idlist_shndx;
size_t strtabidx;
unsigned long idlist_addr;
int encoding;
} efile;
struct rb_root sets;
struct rb_root structs;
struct rb_root unions;
struct rb_root typedefs;
struct rb_root funcs;
int nr_funcs;
int nr_structs;
int nr_unions;
int nr_typedefs;
};
#define KF_IMPLICIT_ARGS (1 << 16)
#define KF_IMPL_SUFFIX "_impl"
struct kfunc {
const char *name;
u32 btf_id;
u32 flags;
};
struct btf2btf_context {
struct btf *btf;
u32 *decl_tags;
u32 nr_decl_tags;
u32 max_decl_tags;
struct kfunc *kfuncs;
u32 nr_kfuncs;
u32 max_kfuncs;
};
static int verbose;
static int warnings;
static int eprintf(int level, int var, const char *fmt, ...)
{
va_list args;
int ret = 0;
if (var >= level) {
va_start(args, fmt);
ret = vfprintf(stderr, fmt, args);
va_end(args);
}
return ret;
}
#ifndef pr_fmt
#define pr_fmt(fmt) fmt
#endif
#define pr_debug(fmt, ...) \
eprintf(1, verbose, pr_fmt(fmt), ##__VA_ARGS__)
#define pr_debugN(n, fmt, ...) \
eprintf(n, verbose, pr_fmt(fmt), ##__VA_ARGS__)
#define pr_debug2(fmt, ...) pr_debugN(2, pr_fmt(fmt), ##__VA_ARGS__)
#define pr_err(fmt, ...) \
Annotation
- Immediate include surface: `stdio.h`, `string.h`, `unistd.h`, `stdlib.h`, `libelf.h`, `gelf.h`, `sys/stat.h`, `fcntl.h`.
- Detected declarations: `struct btf_id`, `struct object`, `struct kfunc`, `struct btf2btf_context`, `enum btf_id_kind`, `function eprintf`, `function is_btf_id`, `function get_id`, `function btf_id__free_all`, `function bswap_32_data`.
- 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.