提交 3fe1d8c7 编写于 作者: A Andrii Nakryiko 提交者: Zheng Zengkai

libbpf: Use Elf64-specific types explicitly for dealing with ELF

mainline inclusion
from mainline-5.16-rc1
commit ad23b723
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=ad23b7238474c6319bf692ae6ce037d9696df1d1

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

Minimize the usage of class-agnostic gelf_xxx() APIs from libelf. These
APIs require copying ELF data structures into local GElf_xxx structs and
have a more cumbersome API. BPF ELF file is defined to be always 64-bit
ELF object, even when intended to be run on 32-bit host architectures,
so there is no need to do class-agnostic conversions everywhere. BPF
static linker implementation within libbpf has been using Elf64-specific
types since initial implementation.

Add two simple helpers, elf_sym_by_idx() and elf_rel_by_idx(), for more
succinct direct access to ELF symbol and relocation records within ELF
data itself and switch all the GElf_xxx usage into Elf64_xxx
equivalents. The only remaining place within libbpf.c that's still using
gelf API is gelf_getclass(), as there doesn't seem to be a direct way to
get underlying ELF bitness.

No functional changes intended.
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-4-andrii@kernel.org
(cherry picked from commit ad23b723)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 688c4e83
此差异已折叠。
...@@ -52,8 +52,8 @@ ...@@ -52,8 +52,8 @@
#endif #endif
/* Older libelf all end up in this expression, for both 32 and 64 bit */ /* Older libelf all end up in this expression, for both 32 and 64 bit */
#ifndef GELF_ST_VISIBILITY #ifndef ELF64_ST_VISIBILITY
#define GELF_ST_VISIBILITY(o) ((o) & 0x03) #define ELF64_ST_VISIBILITY(o) ((o) & 0x03)
#endif #endif
#define BTF_INFO_ENC(kind, kind_flag, vlen) \ #define BTF_INFO_ENC(kind, kind_flag, vlen) \
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include <linux/btf.h> #include <linux/btf.h>
#include <elf.h> #include <elf.h>
#include <libelf.h> #include <libelf.h>
#include <gelf.h>
#include <fcntl.h> #include <fcntl.h>
#include "libbpf.h" #include "libbpf.h"
#include "btf.h" #include "btf.h"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册