tools/lib/bpf/linker.c
Source file repositories/reference/linux-study-clean/tools/lib/bpf/linker.c
File Facts
- System
- Linux kernel
- Corpus path
tools/lib/bpf/linker.c- Extension
.c- Size
- 82959 bytes
- Lines
- 3117
- 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
stdbool.hstddef.hstdio.hstdlib.hstring.hunistd.herrno.hlinux/err.hlinux/btf.helf.hlibelf.hfcntl.hsys/mman.hlibbpf.hbtf.hlibbpf_internal.hstrset.h
Detected Declarations
struct src_secstruct src_objstruct btf_ext_sec_datastruct glob_symstruct dst_secstruct bpf_linkerfunction bpf_linker__freefunction init_output_elffunction bpf_linker_add_filefunction bpf_linker__add_filefunction bpf_linker__add_fdfunction bpf_linker__add_buffunction is_dwarf_sec_namefunction is_ignored_secfunction linker_load_obj_filefunction linker_sanity_check_elffunction linker_sanity_check_elf_symtabfunction linker_sanity_check_elf_relosfunction check_btf_type_idfunction check_btf_str_offfunction linker_sanity_check_btffunction linker_sanity_check_btf_extfunction init_secfunction secs_matchfunction sec_content_is_samefunction is_exec_secfunction exec_sec_bswapfunction extend_secfunction is_data_secfunction is_relo_secfunction linker_append_sec_datafunction linker_append_elf_symsfunction glob_sym_btf_matchesfunction map_defs_matchfunction glob_map_defs_matchfunction glob_syms_matchfunction btf_is_non_staticfunction find_glob_sym_btffunction complete_extern_btf_infofunction sym_update_bindfunction sym_update_typefunction sym_update_visibilityfunction linker_append_elf_symfunction funcsfunction linker_append_elf_relosfunction linker_fixup_btffunction linker_append_btffunction linker_append_btf_ext
Annotated Snippet
struct src_sec {
const char *sec_name;
/* positional (not necessarily ELF) index in an array of sections */
int id;
/* positional (not necessarily ELF) index of a matching section in a final object file */
int dst_id;
/* section data offset in a matching output section */
int dst_off;
/* whether section is omitted from the final ELF file */
bool skipped;
/* whether section is an ephemeral section, not mapped to an ELF section */
bool ephemeral;
/* ELF info */
size_t sec_idx;
Elf_Scn *scn;
Elf64_Shdr *shdr;
Elf_Data *data;
/* corresponding BTF DATASEC type ID */
int sec_type_id;
};
struct src_obj {
const char *filename;
int fd;
Elf *elf;
/* Section header strings section index */
size_t shstrs_sec_idx;
/* SYMTAB section index */
size_t symtab_sec_idx;
struct btf *btf;
struct btf_ext *btf_ext;
/* List of sections (including ephemeral). Slot zero is unused. */
struct src_sec *secs;
int sec_cnt;
/* mapping of symbol indices from src to dst ELF */
int *sym_map;
/* mapping from the src BTF type IDs to dst ones */
int *btf_type_map;
};
/* single .BTF.ext data section */
struct btf_ext_sec_data {
size_t rec_cnt;
__u32 rec_sz;
void *recs;
};
struct glob_sym {
/* ELF symbol index */
int sym_idx;
/* associated section id for .ksyms, .kconfig, etc, but not .extern */
int sec_id;
/* extern name offset in STRTAB */
int name_off;
/* optional associated BTF type ID */
int btf_id;
/* BTF type ID to which VAR/FUNC type is pointing to; used for
* rewriting types when extern VAR/FUNC is resolved to a concrete
* definition
*/
int underlying_btf_id;
/* sec_var index in the corresponding dst_sec, if exists */
int var_idx;
/* extern or resolved/global symbol */
bool is_extern;
/* weak or strong symbol, never goes back from strong to weak */
bool is_weak;
};
struct dst_sec {
char *sec_name;
/* positional (not necessarily ELF) index in an array of sections */
int id;
bool ephemeral;
/* ELF info */
size_t sec_idx;
Elf_Scn *scn;
Elf64_Shdr *shdr;
Elf_Data *data;
/* final output section size */
int sec_sz;
Annotation
- Immediate include surface: `stdbool.h`, `stddef.h`, `stdio.h`, `stdlib.h`, `string.h`, `unistd.h`, `errno.h`, `linux/err.h`.
- Detected declarations: `struct src_sec`, `struct src_obj`, `struct btf_ext_sec_data`, `struct glob_sym`, `struct dst_sec`, `struct bpf_linker`, `function bpf_linker__free`, `function init_output_elf`, `function bpf_linker_add_file`, `function bpf_linker__add_file`.
- 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.