scripts/elf-parse.h

Source file repositories/reference/linux-study-clean/scripts/elf-parse.h

File Facts

System
Linux kernel
Corpus path
scripts/elf-parse.h
Extension
.h
Size
7049 bytes
Lines
306
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct elf_funcs {
	int (*compare_extable)(const void *a, const void *b);
	uint64_t (*ehdr_shoff)(Elf_Ehdr *ehdr);
	uint16_t (*ehdr_shstrndx)(Elf_Ehdr *ehdr);
	uint16_t (*ehdr_shentsize)(Elf_Ehdr *ehdr);
	uint16_t (*ehdr_shnum)(Elf_Ehdr *ehdr);
	uint64_t (*shdr_addr)(Elf_Shdr *shdr);
	uint64_t (*shdr_offset)(Elf_Shdr *shdr);
	uint64_t (*shdr_size)(Elf_Shdr *shdr);
	uint64_t (*shdr_entsize)(Elf_Shdr *shdr);
	uint32_t (*shdr_link)(Elf_Shdr *shdr);
	uint32_t (*shdr_name)(Elf_Shdr *shdr);
	uint32_t (*shdr_type)(Elf_Shdr *shdr);
	uint8_t (*sym_type)(Elf_Sym *sym);
	uint32_t (*sym_name)(Elf_Sym *sym);
	uint64_t (*sym_value)(Elf_Sym *sym);
	uint16_t (*sym_shndx)(Elf_Sym *sym);
	uint64_t (*rela_offset)(Elf_Rela *rela);
	uint64_t (*rela_info)(Elf_Rela *rela);
	uint64_t (*rela_addend)(Elf_Rela *rela);
	void (*rela_write_addend)(Elf_Rela *rela, uint64_t val);
	uint32_t (*r)(const uint32_t *);
	uint16_t (*r2)(const uint16_t *);
	uint64_t (*r8)(const uint64_t *);
	void (*w)(uint32_t, uint32_t *);
	void (*w8)(uint64_t, uint64_t *);
};

extern struct elf_funcs elf_parser;

static inline uint64_t ehdr64_shoff(Elf_Ehdr *ehdr)
{
	return elf_parser.r8(&ehdr->e64.e_shoff);
}

static inline uint64_t ehdr32_shoff(Elf_Ehdr *ehdr)
{
	return elf_parser.r(&ehdr->e32.e_shoff);
}

static inline uint64_t ehdr_shoff(Elf_Ehdr *ehdr)
{
	return elf_parser.ehdr_shoff(ehdr);
}

#define EHDR_HALF(fn_name)				\
static inline uint16_t ehdr64_##fn_name(Elf_Ehdr *ehdr)	\
{							\
	return elf_parser.r2(&ehdr->e64.e_##fn_name);	\
}							\
							\
static inline uint16_t ehdr32_##fn_name(Elf_Ehdr *ehdr)	\
{							\
	return elf_parser.r2(&ehdr->e32.e_##fn_name);	\
}							\
							\
static inline uint16_t ehdr_##fn_name(Elf_Ehdr *ehdr)	\
{							\
	return elf_parser.ehdr_##fn_name(ehdr);		\
}

EHDR_HALF(shentsize)
EHDR_HALF(shstrndx)
EHDR_HALF(shnum)

#define SHDR_WORD(fn_name)				\
static inline uint32_t shdr64_##fn_name(Elf_Shdr *shdr)	\
{							\
	return elf_parser.r(&shdr->e64.sh_##fn_name);	\
}							\
							\
static inline uint32_t shdr32_##fn_name(Elf_Shdr *shdr)	\
{							\
	return elf_parser.r(&shdr->e32.sh_##fn_name);	\
}							\
							\
static inline uint32_t shdr_##fn_name(Elf_Shdr *shdr)	\
{							\
	return elf_parser.shdr_##fn_name(shdr);	\
}

#define SHDR_ADDR(fn_name)				\
static inline uint64_t shdr64_##fn_name(Elf_Shdr *shdr)	\
{							\
	return elf_parser.r8(&shdr->e64.sh_##fn_name);	\
}							\
							\
static inline uint64_t shdr32_##fn_name(Elf_Shdr *shdr)	\
{							\
	return elf_parser.r(&shdr->e32.sh_##fn_name);	\

Annotation

Implementation Notes