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

libbpf: Add per-file linker opts

mainline inclusion
from mainline-5.14-rc1
commit fdbf5dde
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=fdbf5ddeb855a80831af2e5bb9db9218926e6789

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

For better future extensibility add per-file linker options. Currently
the set of available options is empty. This changes bpf_linker__add_file()
API, but it's not a breaking change as bpf_linker APIs hasn't been released
yet.
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210507054119.270888-3-andrii@kernel.org
(cherry picked from commit fdbf5dde)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 a690e6b0
...@@ -638,7 +638,7 @@ static int do_object(int argc, char **argv) ...@@ -638,7 +638,7 @@ static int do_object(int argc, char **argv)
while (argc) { while (argc) {
file = GET_ARG(); file = GET_ARG();
err = bpf_linker__add_file(linker, file); err = bpf_linker__add_file(linker, file, NULL);
if (err) { if (err) {
p_err("failed to link '%s': %s (%d)", file, strerror(err), err); p_err("failed to link '%s': %s (%d)", file, strerror(err), err);
goto out; goto out;
......
...@@ -771,10 +771,18 @@ struct bpf_linker_opts { ...@@ -771,10 +771,18 @@ struct bpf_linker_opts {
}; };
#define bpf_linker_opts__last_field sz #define bpf_linker_opts__last_field sz
struct bpf_linker_file_opts {
/* size of this struct, for forward/backward compatiblity */
size_t sz;
};
#define bpf_linker_file_opts__last_field sz
struct bpf_linker; struct bpf_linker;
LIBBPF_API struct bpf_linker *bpf_linker__new(const char *filename, struct bpf_linker_opts *opts); LIBBPF_API struct bpf_linker *bpf_linker__new(const char *filename, struct bpf_linker_opts *opts);
LIBBPF_API int bpf_linker__add_file(struct bpf_linker *linker, const char *filename); LIBBPF_API int bpf_linker__add_file(struct bpf_linker *linker,
const char *filename,
const struct bpf_linker_file_opts *opts);
LIBBPF_API int bpf_linker__finalize(struct bpf_linker *linker); LIBBPF_API int bpf_linker__finalize(struct bpf_linker *linker);
LIBBPF_API void bpf_linker__free(struct bpf_linker *linker); LIBBPF_API void bpf_linker__free(struct bpf_linker *linker);
......
...@@ -158,7 +158,9 @@ struct bpf_linker { ...@@ -158,7 +158,9 @@ struct bpf_linker {
static int init_output_elf(struct bpf_linker *linker, const char *file); static int init_output_elf(struct bpf_linker *linker, const char *file);
static int linker_load_obj_file(struct bpf_linker *linker, const char *filename, struct src_obj *obj); static int linker_load_obj_file(struct bpf_linker *linker, const char *filename,
const struct bpf_linker_file_opts *opts,
struct src_obj *obj);
static int linker_sanity_check_elf(struct src_obj *obj); static int linker_sanity_check_elf(struct src_obj *obj);
static int linker_sanity_check_elf_symtab(struct src_obj *obj, struct src_sec *sec); static int linker_sanity_check_elf_symtab(struct src_obj *obj, struct src_sec *sec);
static int linker_sanity_check_elf_relos(struct src_obj *obj, struct src_sec *sec); static int linker_sanity_check_elf_relos(struct src_obj *obj, struct src_sec *sec);
...@@ -435,15 +437,19 @@ static int init_output_elf(struct bpf_linker *linker, const char *file) ...@@ -435,15 +437,19 @@ static int init_output_elf(struct bpf_linker *linker, const char *file)
return 0; return 0;
} }
int bpf_linker__add_file(struct bpf_linker *linker, const char *filename) int bpf_linker__add_file(struct bpf_linker *linker, const char *filename,
const struct bpf_linker_file_opts *opts)
{ {
struct src_obj obj = {}; struct src_obj obj = {};
int err = 0; int err = 0;
if (!OPTS_VALID(opts, bpf_linker_file_opts))
return -EINVAL;
if (!linker->elf) if (!linker->elf)
return -EINVAL; return -EINVAL;
err = err ?: linker_load_obj_file(linker, filename, &obj); err = err ?: linker_load_obj_file(linker, filename, opts, &obj);
err = err ?: linker_append_sec_data(linker, &obj); err = err ?: linker_append_sec_data(linker, &obj);
err = err ?: linker_append_elf_syms(linker, &obj); err = err ?: linker_append_elf_syms(linker, &obj);
err = err ?: linker_append_elf_relos(linker, &obj); err = err ?: linker_append_elf_relos(linker, &obj);
...@@ -529,7 +535,9 @@ static struct src_sec *add_src_sec(struct src_obj *obj, const char *sec_name) ...@@ -529,7 +535,9 @@ static struct src_sec *add_src_sec(struct src_obj *obj, const char *sec_name)
return sec; return sec;
} }
static int linker_load_obj_file(struct bpf_linker *linker, const char *filename, struct src_obj *obj) static int linker_load_obj_file(struct bpf_linker *linker, const char *filename,
const struct bpf_linker_file_opts *opts,
struct src_obj *obj)
{ {
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
const int host_endianness = ELFDATA2LSB; const int host_endianness = ELFDATA2LSB;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册