summaryrefslogtreecommitdiff
path: root/scripts/elf-parse.h
diff options
context:
space:
mode:
authorNathan Chancellor <nathan@kernel.org>2026-10-11 01:22:02 +0100
committerNathan Chancellor <nathan@kernel.org>2026-10-11 01:22:02 +0100
commitfd26cc1da1ec4dbe4ca19d0c94f802ff4300a788 (patch)
treef343bf7e191d0567d77f8f352fdd53111b75e8e1 /scripts/elf-parse.h
parent185b2c6a021ac46c62342fa814e5e2393f8396c5 (diff)
parentae5f6044c4cdffe2b3361b15c1d6fc67b339f2a4 (diff)
downloadlinux-next-fd26cc1da1ec4dbe4ca19d0c94f802ff4300a788.tar.gz
linux-next-fd26cc1da1ec4dbe4ca19d0c94f802ff4300a788.zip
Merge branch 'kbuild-next-speedups' into kbuild-for-next
* kbuild-next-speedups: kbuild: Mark the initcall ordering recipe as recursive kbuild: Mark the gzip recipes as recursive kconfig: Improve ergonomics around disabling warnings with cc-option scripts/Kconfig.toolchain: Drop compiler symbols from dependencies kbuild: keep .modinfo when vmlinux is linked with --gc-sections kbuild: compress the kernel with pigz if available kbuild: avoid re-running compiler and linker probes kbuild: move the toolchain checks into scripts/Kconfig.toolchain kallsyms: reimplement mksysmap in C elf-parse: add section flags, symbol binding and mapping helpers kbuild: only emit vmlinux relocations when required kbuild: do not sort nm output where the order is irrelevant sorttable: parse nm output correctly kallsyms: output binary data to speed output and kallsyms assembly kallsyms: index symbols by token to speed up table compression kbuild: do not allocate .modinfo in vmlinux Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Diffstat (limited to 'scripts/elf-parse.h')
-rw-r--r--scripts/elf-parse.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/scripts/elf-parse.h b/scripts/elf-parse.h
index f4411e03069d..c5ad754da254 100644
--- a/scripts/elf-parse.h
+++ b/scripts/elf-parse.h
@@ -37,10 +37,12 @@ struct elf_funcs {
uint64_t (*shdr_offset)(Elf_Shdr *shdr);
uint64_t (*shdr_size)(Elf_Shdr *shdr);
uint64_t (*shdr_entsize)(Elf_Shdr *shdr);
+ uint64_t (*shdr_flags)(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);
+ uint8_t (*sym_bind)(Elf_Sym *sym);
uint32_t (*sym_name)(Elf_Sym *sym);
uint64_t (*sym_value)(Elf_Sym *sym);
uint16_t (*sym_shndx)(Elf_Sym *sym);
@@ -143,6 +145,7 @@ SHDR_ADDR(addr)
SHDR_ADDR(offset)
SHDR_ADDR(size)
SHDR_ADDR(entsize)
+SHDR_ADDR(flags)
SHDR_WORD(link)
SHDR_WORD(name)
@@ -211,6 +214,21 @@ static inline uint8_t sym_type(Elf_Sym *sym)
return elf_parser.sym_type(sym);
}
+static inline uint8_t sym64_bind(Elf_Sym *sym)
+{
+ return ELF64_ST_BIND(sym->e64.st_info);
+}
+
+static inline uint8_t sym32_bind(Elf_Sym *sym)
+{
+ return ELF32_ST_BIND(sym->e32.st_info);
+}
+
+static inline uint8_t sym_bind(Elf_Sym *sym)
+{
+ return elf_parser.sym_bind(sym);
+}
+
SYM_ADDR(value)
SYM_WORD(name)
SYM_HALF(shndx)
@@ -298,8 +316,44 @@ static inline void w8le(uint64_t val, uint64_t *x)
}
void *elf_map(char const *fname, size_t *size, uint32_t types);
+void *elf_map_ro(char const *fname, size_t *size, uint32_t types);
void elf_unmap(void *addr, size_t size);
int elf_map_machine(void *addr);
int elf_map_long_size(void *addr);
+/* A mapped file with its section headers, section names and symbol table. */
+struct elf_file {
+ void *base;
+ size_t size;
+ const char *shdrs;
+ unsigned int shnum, shentsize;
+ const char *shstrtab;
+ Elf_Shdr *symtab;
+ const char *strtab;
+ size_t nr_syms;
+};
+
+int elf_open_ro(char const *fname, uint32_t types, struct elf_file *elf);
+void elf_close(struct elf_file *elf);
+
+static inline Elf_Shdr *elf_section(const struct elf_file *elf,
+ unsigned int index)
+{
+ return (Elf_Shdr *)(elf->shdrs + (size_t)index * elf->shentsize);
+}
+
+static inline const char *elf_section_name(const struct elf_file *elf,
+ Elf_Shdr *shdr)
+{
+ return elf->shstrtab + shdr_name(shdr);
+}
+
+static inline Elf_Sym *elf_symbol(const struct elf_file *elf, size_t index)
+{
+ const char *base = elf->base;
+
+ return (Elf_Sym *)(base + shdr_offset(elf->symtab) +
+ index * shdr_entsize(elf->symtab));
+}
+
#endif /* _SCRIPTS_ELF_PARSE_H */