提交 688c4e83 编写于 作者: A Andrii Nakryiko 提交者: Zheng Zengkai

libbpf: Extract ELF processing state into separate struct

mainline inclusion
from mainline-5.16-rc1
commit 29a30ff5
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=29a30ff501518a49282754909543cef1ef49e4bc

-------------------------------------------------

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: NAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Acked-by: NSong Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20211021014404.2635234-3-andrii@kernel.org
(cherry picked from commit 29a30ff5)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 037e50e9
...@@ -442,6 +442,35 @@ struct module_btf { ...@@ -442,6 +442,35 @@ struct module_btf {
int fd_array_idx; int fd_array_idx;
}; };
struct elf_state {
int fd;
const void *obj_buf;
size_t obj_buf_sz;
Elf *elf;
GElf_Ehdr ehdr;
Elf_Data *symbols;
Elf_Data *data;
Elf_Data *rodata;
Elf_Data *bss;
Elf_Data *st_ops_data;
size_t shstrndx; /* section index for section name strings */
size_t strtabidx;
struct {
GElf_Shdr shdr;
Elf_Data *data;
} *reloc_sects;
int nr_reloc_sects;
int maps_shndx;
int btf_maps_shndx;
__u32 btf_maps_sec_btf_id;
int text_shndx;
int symbols_shndx;
int data_shndx;
int rodata_shndx;
int bss_shndx;
int st_ops_shndx;
};
struct bpf_object { struct bpf_object {
char name[BPF_OBJ_NAME_LEN]; char name[BPF_OBJ_NAME_LEN];
char license[64]; char license[64];
...@@ -464,40 +493,10 @@ struct bpf_object { ...@@ -464,40 +493,10 @@ struct bpf_object {
struct bpf_gen *gen_loader; struct bpf_gen *gen_loader;
/* Information when doing ELF related work. Only valid if efile.elf is not NULL */
struct elf_state efile;
/* /*
* Information when doing elf related work. Only valid if fd * All loaded bpf_object are linked in a list, which is
* is valid.
*/
struct {
int fd;
const void *obj_buf;
size_t obj_buf_sz;
Elf *elf;
GElf_Ehdr ehdr;
Elf_Data *symbols;
Elf_Data *data;
Elf_Data *rodata;
Elf_Data *bss;
Elf_Data *st_ops_data;
size_t shstrndx; /* section index for section name strings */
size_t strtabidx;
struct {
GElf_Shdr shdr;
Elf_Data *data;
} *reloc_sects;
int nr_reloc_sects;
int maps_shndx;
int btf_maps_shndx;
__u32 btf_maps_sec_btf_id;
int text_shndx;
int symbols_shndx;
int data_shndx;
int rodata_shndx;
int bss_shndx;
int st_ops_shndx;
} efile;
/*
* All loaded bpf_object is 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.
*/ */
...@@ -531,7 +530,6 @@ struct bpf_object { ...@@ -531,7 +530,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);
...@@ -1165,7 +1163,7 @@ static struct bpf_object *bpf_object__new(const char *path, ...@@ -1165,7 +1163,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) {
...@@ -1190,7 +1188,7 @@ static int bpf_object__elf_init(struct bpf_object *obj) ...@@ -1190,7 +1188,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;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册