mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-11 11:09:06 +08:00
libbpf: Extract ELF processing state into separate struct
Name currently anonymous internal struct that keeps ELF-related state for bpf_object. Just a bit of clean up, no functional changes. Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Song Liu <songliubraving@fb.com> Link: https://lore.kernel.org/bpf/20211021014404.2635234-3-andrii@kernel.org
This commit is contained in:
committed by
Andrii Nakryiko
parent
38fb8cfc0c
commit
f687443178
62
src/libbpf.c
62
src/libbpf.c
@@ -462,33 +462,7 @@ struct module_btf {
|
|||||||
int fd_array_idx;
|
int fd_array_idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct bpf_object {
|
struct elf_state {
|
||||||
char name[BPF_OBJ_NAME_LEN];
|
|
||||||
char license[64];
|
|
||||||
__u32 kern_version;
|
|
||||||
|
|
||||||
struct bpf_program *programs;
|
|
||||||
size_t nr_programs;
|
|
||||||
struct bpf_map *maps;
|
|
||||||
size_t nr_maps;
|
|
||||||
size_t maps_cap;
|
|
||||||
|
|
||||||
char *kconfig;
|
|
||||||
struct extern_desc *externs;
|
|
||||||
int nr_extern;
|
|
||||||
int kconfig_map_idx;
|
|
||||||
int rodata_map_idx;
|
|
||||||
|
|
||||||
bool loaded;
|
|
||||||
bool has_subcalls;
|
|
||||||
|
|
||||||
struct bpf_gen *gen_loader;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Information when doing elf related work. Only valid if fd
|
|
||||||
* is valid.
|
|
||||||
*/
|
|
||||||
struct {
|
|
||||||
int fd;
|
int fd;
|
||||||
const void *obj_buf;
|
const void *obj_buf;
|
||||||
size_t obj_buf_sz;
|
size_t obj_buf_sz;
|
||||||
@@ -515,9 +489,34 @@ struct bpf_object {
|
|||||||
int rodata_shndx;
|
int rodata_shndx;
|
||||||
int bss_shndx;
|
int bss_shndx;
|
||||||
int st_ops_shndx;
|
int st_ops_shndx;
|
||||||
} efile;
|
};
|
||||||
|
|
||||||
|
struct bpf_object {
|
||||||
|
char name[BPF_OBJ_NAME_LEN];
|
||||||
|
char license[64];
|
||||||
|
__u32 kern_version;
|
||||||
|
|
||||||
|
struct bpf_program *programs;
|
||||||
|
size_t nr_programs;
|
||||||
|
struct bpf_map *maps;
|
||||||
|
size_t nr_maps;
|
||||||
|
size_t maps_cap;
|
||||||
|
|
||||||
|
char *kconfig;
|
||||||
|
struct extern_desc *externs;
|
||||||
|
int nr_extern;
|
||||||
|
int kconfig_map_idx;
|
||||||
|
int rodata_map_idx;
|
||||||
|
|
||||||
|
bool loaded;
|
||||||
|
bool has_subcalls;
|
||||||
|
|
||||||
|
struct bpf_gen *gen_loader;
|
||||||
|
|
||||||
|
/* Information when doing ELF related work. Only valid if efile.elf is not NULL */
|
||||||
|
struct elf_state efile;
|
||||||
/*
|
/*
|
||||||
* All loaded bpf_object is linked in a list, which is
|
* All loaded bpf_object are linked in a list, which is
|
||||||
* hidden to caller. bpf_objects__<func> handlers deal with
|
* hidden to caller. bpf_objects__<func> handlers deal with
|
||||||
* all objects.
|
* all objects.
|
||||||
*/
|
*/
|
||||||
@@ -551,7 +550,6 @@ struct bpf_object {
|
|||||||
|
|
||||||
char path[];
|
char path[];
|
||||||
};
|
};
|
||||||
#define obj_elf_valid(o) ((o)->efile.elf)
|
|
||||||
|
|
||||||
static const char *elf_sym_str(const struct bpf_object *obj, size_t off);
|
static const char *elf_sym_str(const struct bpf_object *obj, size_t off);
|
||||||
static const char *elf_sec_str(const struct bpf_object *obj, size_t off);
|
static const char *elf_sec_str(const struct bpf_object *obj, size_t off);
|
||||||
@@ -1185,7 +1183,7 @@ static struct bpf_object *bpf_object__new(const char *path,
|
|||||||
|
|
||||||
static void bpf_object__elf_finish(struct bpf_object *obj)
|
static void bpf_object__elf_finish(struct bpf_object *obj)
|
||||||
{
|
{
|
||||||
if (!obj_elf_valid(obj))
|
if (!obj->efile.elf)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (obj->efile.elf) {
|
if (obj->efile.elf) {
|
||||||
@@ -1210,7 +1208,7 @@ static int bpf_object__elf_init(struct bpf_object *obj)
|
|||||||
int err = 0;
|
int err = 0;
|
||||||
GElf_Ehdr *ep;
|
GElf_Ehdr *ep;
|
||||||
|
|
||||||
if (obj_elf_valid(obj)) {
|
if (obj->efile.elf) {
|
||||||
pr_warn("elf: init internal error\n");
|
pr_warn("elf: init internal error\n");
|
||||||
return -LIBBPF_ERRNO__LIBELF;
|
return -LIBBPF_ERRNO__LIBELF;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user