mirror of
https://github.com/netdata/libbpf.git
synced 2026-03-13 21:09:07 +08:00
Merge branch 'libbpf:master' into master
Some checks failed
libbpf-build / Debian Build (${{ matrix.name }}) (ASan+UBSan, RUN_ASAN) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (clang ASan+UBSan, RUN_CLANG_ASAN) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (clang, RUN_CLANG) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (clang-14, RUN_CLANG14) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (clang-15, RUN_CLANG15) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (clang-16, RUN_CLANG16) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (default, RUN) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (gcc-10 ASan+UBSan, RUN_GCC10_ASAN) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (gcc-10, RUN_GCC10) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (gcc-11, RUN_GCC11) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (gcc-12, RUN_GCC12) (push) Has been cancelled
libbpf-ci / Kernel ${{ matrix.kernel }} on ${{ matrix.arch }} + selftests (s390x, LATEST, [s390x docker-noble-main]) (push) Has been cancelled
libbpf-ci / Kernel ${{ matrix.kernel }} on ${{ matrix.arch }} + selftests (x86_64, 4.9.0, ubuntu-24.04) (push) Has been cancelled
libbpf-ci / Kernel ${{ matrix.kernel }} on ${{ matrix.arch }} + selftests (x86_64, 5.5.0, ubuntu-24.04) (push) Has been cancelled
libbpf-ci / Kernel ${{ matrix.kernel }} on ${{ matrix.arch }} + selftests (x86_64, LATEST, ubuntu-24.04) (push) Has been cancelled
libbpf-build / Ubuntu Build (${{ matrix.arch }}) (aarch64) (push) Has been cancelled
libbpf-build / Ubuntu Build (${{ matrix.arch }}) (ppc64le) (push) Has been cancelled
libbpf-build / Ubuntu Build (${{ matrix.arch }}) (s390x) (push) Has been cancelled
libbpf-build / Ubuntu Build (${{ matrix.arch }}) (x86) (push) Has been cancelled
CIFuzz / Fuzzing (address) (push) Has been cancelled
CIFuzz / Fuzzing (memory) (push) Has been cancelled
CIFuzz / Fuzzing (undefined) (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
lint / ShellCheck (push) Has been cancelled
pahole-staging / Kernel LATEST + staging pahole (push) Has been cancelled
libbpf-ci-coverity / Coverity (push) Has been cancelled
Some checks failed
libbpf-build / Debian Build (${{ matrix.name }}) (ASan+UBSan, RUN_ASAN) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (clang ASan+UBSan, RUN_CLANG_ASAN) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (clang, RUN_CLANG) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (clang-14, RUN_CLANG14) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (clang-15, RUN_CLANG15) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (clang-16, RUN_CLANG16) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (default, RUN) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (gcc-10 ASan+UBSan, RUN_GCC10_ASAN) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (gcc-10, RUN_GCC10) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (gcc-11, RUN_GCC11) (push) Has been cancelled
libbpf-build / Debian Build (${{ matrix.name }}) (gcc-12, RUN_GCC12) (push) Has been cancelled
libbpf-ci / Kernel ${{ matrix.kernel }} on ${{ matrix.arch }} + selftests (s390x, LATEST, [s390x docker-noble-main]) (push) Has been cancelled
libbpf-ci / Kernel ${{ matrix.kernel }} on ${{ matrix.arch }} + selftests (x86_64, 4.9.0, ubuntu-24.04) (push) Has been cancelled
libbpf-ci / Kernel ${{ matrix.kernel }} on ${{ matrix.arch }} + selftests (x86_64, 5.5.0, ubuntu-24.04) (push) Has been cancelled
libbpf-ci / Kernel ${{ matrix.kernel }} on ${{ matrix.arch }} + selftests (x86_64, LATEST, ubuntu-24.04) (push) Has been cancelled
libbpf-build / Ubuntu Build (${{ matrix.arch }}) (aarch64) (push) Has been cancelled
libbpf-build / Ubuntu Build (${{ matrix.arch }}) (ppc64le) (push) Has been cancelled
libbpf-build / Ubuntu Build (${{ matrix.arch }}) (s390x) (push) Has been cancelled
libbpf-build / Ubuntu Build (${{ matrix.arch }}) (x86) (push) Has been cancelled
CIFuzz / Fuzzing (address) (push) Has been cancelled
CIFuzz / Fuzzing (memory) (push) Has been cancelled
CIFuzz / Fuzzing (undefined) (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
lint / ShellCheck (push) Has been cancelled
pahole-staging / Kernel LATEST + staging pahole (push) Has been cancelled
libbpf-ci-coverity / Coverity (push) Has been cancelled
This commit is contained in:
5
.github/actions/build-selftests/action.yml
vendored
5
.github/actions/build-selftests/action.yml
vendored
@@ -12,6 +12,9 @@ inputs:
|
||||
description: 'where is vmlinux file'
|
||||
required: true
|
||||
default: '${{ github.workspace }}/vmlinux'
|
||||
llvm-version:
|
||||
description: 'llvm version'
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
@@ -28,4 +31,6 @@ runs:
|
||||
export REPO_ROOT="${{ github.workspace }}"
|
||||
export REPO_PATH="${{ inputs.repo-path }}"
|
||||
export VMLINUX_BTF="${{ inputs.vmlinux }}"
|
||||
export LLVM_VERSION="${{ inputs.llvm-version }}"
|
||||
|
||||
${{ github.action_path }}/build_selftests.sh
|
||||
|
||||
@@ -10,22 +10,21 @@ foldable start prepare_selftests "Building selftests"
|
||||
|
||||
LIBBPF_PATH="${REPO_ROOT}"
|
||||
|
||||
llvm_default_version() {
|
||||
echo "16"
|
||||
}
|
||||
|
||||
llvm_latest_version() {
|
||||
echo "17"
|
||||
echo "19"
|
||||
}
|
||||
|
||||
LLVM_VERSION=$(llvm_default_version)
|
||||
if [[ "${LLVM_VERSION}" == $(llvm_latest_version) ]]; then
|
||||
REPO_DISTRO_SUFFIX=""
|
||||
else
|
||||
REPO_DISTRO_SUFFIX="-${LLVM_VERSION}"
|
||||
fi
|
||||
|
||||
echo "deb https://apt.llvm.org/focal/ llvm-toolchain-focal${REPO_DISTRO_SUFFIX} main" \
|
||||
DISTRIB_CODENAME="noble"
|
||||
test -f /etc/lsb-release && . /etc/lsb-release
|
||||
echo "${DISTRIB_CODENAME}"
|
||||
|
||||
echo "deb https://apt.llvm.org/${DISTRIB_CODENAME}/ llvm-toolchain-${DISTRIB_CODENAME}${REPO_DISTRO_SUFFIX} main" \
|
||||
| sudo tee /etc/apt/sources.list.d/llvm.list
|
||||
|
||||
PREPARE_SELFTESTS_SCRIPT=${THISDIR}/prepare_selftests-${KERNEL}.sh
|
||||
|
||||
3712
.github/actions/build-selftests/vmlinux.h
vendored
3712
.github/actions/build-selftests/vmlinux.h
vendored
File diff suppressed because it is too large
Load Diff
6
.github/actions/vmtest/action.yml
vendored
6
.github/actions/vmtest/action.yml
vendored
@@ -13,6 +13,10 @@ inputs:
|
||||
description: 'pahole rev or master'
|
||||
required: true
|
||||
default: 'master'
|
||||
llvm-version:
|
||||
description: 'llvm version'
|
||||
required: false
|
||||
default: '17'
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
@@ -38,6 +42,7 @@ runs:
|
||||
with:
|
||||
pahole: ${{ inputs.pahole }}
|
||||
arch: ${{ inputs.arch }}
|
||||
llvm-version: ${{ inputs.llvm-version }}
|
||||
# 1. download CHECKPOINT kernel source
|
||||
- name: Get checkpoint commit
|
||||
shell: bash
|
||||
@@ -93,6 +98,7 @@ runs:
|
||||
with:
|
||||
repo-path: '.kernel'
|
||||
kernel: ${{ inputs.kernel }}
|
||||
llvm-version: ${{ inputs.llvm-version }}
|
||||
# 4. prepare rootfs
|
||||
- name: prepare rootfs
|
||||
uses: libbpf/ci/prepare-rootfs@main
|
||||
|
||||
10
.github/workflows/test.yml
vendored
10
.github/workflows/test.yml
vendored
@@ -13,22 +13,22 @@ concurrency:
|
||||
jobs:
|
||||
vmtest:
|
||||
runs-on: ${{ matrix.runs_on }}
|
||||
name: Kernel ${{ matrix.kernel }} on ${{ matrix.runs_on }} + selftests
|
||||
name: Kernel ${{ matrix.kernel }} on ${{ matrix.arch }} + selftests
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- kernel: 'LATEST'
|
||||
runs_on: ubuntu-20.04
|
||||
runs_on: ubuntu-24.04
|
||||
arch: 'x86_64'
|
||||
- kernel: '5.5.0'
|
||||
runs_on: ubuntu-20.04
|
||||
runs_on: ubuntu-24.04
|
||||
arch: 'x86_64'
|
||||
- kernel: '4.9.0'
|
||||
runs_on: ubuntu-20.04
|
||||
runs_on: ubuntu-24.04
|
||||
arch: 'x86_64'
|
||||
- kernel: 'LATEST'
|
||||
runs_on: s390x
|
||||
runs_on: ["s390x", "docker-noble-main"]
|
||||
arch: 's390x'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
@@ -1 +1 @@
|
||||
e1533b6319ab9c3a97dad314dd88b3783bc41b69
|
||||
b408473ea01b2e499d23503e2bf898416da9d7ac
|
||||
|
||||
@@ -1 +1 @@
|
||||
ec5b8c76ab1c6d163762d60cfbedcd27e7527144
|
||||
2ad6d23f465a4f851e3bcf6d74c315ce7b2c205b
|
||||
|
||||
@@ -12,3 +12,4 @@ xdp_bonding/xdp_bonding_features # started failing after net merge from 359e
|
||||
tc_redirect/tc_redirect_dtime # uapi breakage after net-next commit 885c36e59f46 ("net: Re-use and set mono_delivery_time bit for userspace tstamp packets")
|
||||
migrate_reuseport/IPv4 TCP_NEW_SYN_RECV reqsk_timer_handler # flaky, under investigation
|
||||
migrate_reuseport/IPv6 TCP_NEW_SYN_RECV reqsk_timer_handler # flaky, under investigation
|
||||
verify_pkcs7_sig # keeps failing
|
||||
|
||||
@@ -67,12 +67,14 @@ local_configs_path=${PROJECT_NAME}/vmtest/configs
|
||||
DENYLIST=$(read_lists \
|
||||
"$configs_path/DENYLIST" \
|
||||
"$configs_path/DENYLIST.${ARCH}" \
|
||||
"$local_configs_path/DENYLIST" \
|
||||
"$local_configs_path/DENYLIST-${KERNEL}" \
|
||||
"$local_configs_path/DENYLIST-${KERNEL}.${ARCH}" \
|
||||
)
|
||||
ALLOWLIST=$(read_lists \
|
||||
"$configs_path/ALLOWLIST" \
|
||||
"$configs_path/ALLOWLIST.${ARCH}" \
|
||||
"$local_configs_path/ALLOWLIST" \
|
||||
"$local_configs_path/ALLOWLIST-${KERNEL}" \
|
||||
"$local_configs_path/ALLOWLIST-${KERNEL}.${ARCH}" \
|
||||
)
|
||||
|
||||
@@ -7512,4 +7512,13 @@ struct bpf_iter_num {
|
||||
__u64 __opaque[1];
|
||||
} __attribute__((aligned(8)));
|
||||
|
||||
/*
|
||||
* Flags to control BPF kfunc behaviour.
|
||||
* - BPF_F_PAD_ZEROS: Pad destination buffer with zeros. (See the respective
|
||||
* helper documentation for details.)
|
||||
*/
|
||||
enum bpf_kfunc_flags {
|
||||
BPF_F_PAD_ZEROS = (1ULL << 0),
|
||||
};
|
||||
|
||||
#endif /* _UAPI__LINUX_BPF_H__ */
|
||||
|
||||
@@ -41,6 +41,10 @@
|
||||
*/
|
||||
#define XDP_UMEM_TX_SW_CSUM (1 << 1)
|
||||
|
||||
/* Request to reserve tx_metadata_len bytes of per-chunk metadata.
|
||||
*/
|
||||
#define XDP_UMEM_TX_METADATA_LEN (1 << 2)
|
||||
|
||||
struct sockaddr_xdp {
|
||||
__u16 sxdp_family;
|
||||
__u16 sxdp_flags;
|
||||
|
||||
@@ -1349,12 +1349,14 @@ union perf_mem_data_src {
|
||||
#define PERF_MEM_LVLNUM_L2 0x02 /* L2 */
|
||||
#define PERF_MEM_LVLNUM_L3 0x03 /* L3 */
|
||||
#define PERF_MEM_LVLNUM_L4 0x04 /* L4 */
|
||||
/* 5-0x7 available */
|
||||
#define PERF_MEM_LVLNUM_L2_MHB 0x05 /* L2 Miss Handling Buffer */
|
||||
#define PERF_MEM_LVLNUM_MSC 0x06 /* Memory-side Cache */
|
||||
/* 0x7 available */
|
||||
#define PERF_MEM_LVLNUM_UNC 0x08 /* Uncached */
|
||||
#define PERF_MEM_LVLNUM_CXL 0x09 /* CXL */
|
||||
#define PERF_MEM_LVLNUM_IO 0x0a /* I/O */
|
||||
#define PERF_MEM_LVLNUM_ANY_CACHE 0x0b /* Any cache */
|
||||
#define PERF_MEM_LVLNUM_LFB 0x0c /* LFB */
|
||||
#define PERF_MEM_LVLNUM_LFB 0x0c /* LFB / L1 Miss Handling Buffer */
|
||||
#define PERF_MEM_LVLNUM_RAM 0x0d /* RAM */
|
||||
#define PERF_MEM_LVLNUM_PMEM 0x0e /* PMEM */
|
||||
#define PERF_MEM_LVLNUM_NA 0x0f /* N/A */
|
||||
|
||||
@@ -119,13 +119,13 @@ $(OBJDIR)/libbpf.so.$(LIBBPF_VERSION): $(SHARED_OBJS)
|
||||
-Wl,-soname,libbpf.so.$(LIBBPF_MAJOR_VERSION) \
|
||||
$^ $(ALL_LDFLAGS) -o $@
|
||||
|
||||
$(OBJDIR)/libbpf.pc: force
|
||||
$(OBJDIR)/libbpf.pc: force | $(OBJDIR)
|
||||
$(Q)sed -e "s|@PREFIX@|$(PREFIX)|" \
|
||||
-e "s|@LIBDIR@|$(LIBDIR_PC)|" \
|
||||
-e "s|@VERSION@|$(LIBBPF_VERSION)|" \
|
||||
< libbpf.pc.template > $@
|
||||
|
||||
$(STATIC_OBJDIR) $(SHARED_OBJDIR):
|
||||
$(OBJDIR) $(STATIC_OBJDIR) $(SHARED_OBJDIR):
|
||||
$(call msg,MKDIR,$@)
|
||||
$(Q)mkdir -p $@
|
||||
|
||||
|
||||
@@ -996,6 +996,7 @@ static struct btf *btf_new_empty(struct btf *base_btf)
|
||||
btf->base_btf = base_btf;
|
||||
btf->start_id = btf__type_cnt(base_btf);
|
||||
btf->start_str_off = base_btf->hdr->str_len;
|
||||
btf->swapped_endian = base_btf->swapped_endian;
|
||||
}
|
||||
|
||||
/* +1 for empty string at offset 0 */
|
||||
@@ -5394,6 +5395,9 @@ int btf__distill_base(const struct btf *src_btf, struct btf **new_base_btf,
|
||||
new_base = btf__new_empty();
|
||||
if (!new_base)
|
||||
return libbpf_err(-ENOMEM);
|
||||
|
||||
btf__set_endianness(new_base, btf__endianness(src_btf));
|
||||
|
||||
dist.id_map = calloc(n, sizeof(*dist.id_map));
|
||||
if (!dist.id_map) {
|
||||
err = -ENOMEM;
|
||||
|
||||
@@ -1559,10 +1559,12 @@ static void btf_dump_emit_type_chain(struct btf_dump *d,
|
||||
* Clang for BPF target generates func_proto with no
|
||||
* args as a func_proto with a single void arg (e.g.,
|
||||
* `int (*f)(void)` vs just `int (*f)()`). We are
|
||||
* going to pretend there are no args for such case.
|
||||
* going to emit valid empty args (void) syntax for
|
||||
* such case. Similarly and conveniently, valid
|
||||
* no args case can be special-cased here as well.
|
||||
*/
|
||||
if (vlen == 1 && p->type == 0) {
|
||||
btf_dump_printf(d, ")");
|
||||
if (vlen == 0 || (vlen == 1 && p->type == 0)) {
|
||||
btf_dump_printf(d, "void)");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
|
||||
/* Copyright (c) 2024, Oracle and/or its affiliates. */
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
|
||||
@@ -28,6 +28,9 @@ int elf_open(const char *binary_path, struct elf_fd *elf_fd)
|
||||
int fd, ret;
|
||||
Elf *elf;
|
||||
|
||||
elf_fd->elf = NULL;
|
||||
elf_fd->fd = -1;
|
||||
|
||||
if (elf_version(EV_CURRENT) == EV_NONE) {
|
||||
pr_warn("elf: failed to init libelf for %s\n", binary_path);
|
||||
return -LIBBPF_ERRNO__LIBELF;
|
||||
|
||||
75
src/libbpf.c
75
src/libbpf.c
@@ -496,8 +496,6 @@ struct bpf_program {
|
||||
};
|
||||
|
||||
struct bpf_struct_ops {
|
||||
const char *tname;
|
||||
const struct btf_type *type;
|
||||
struct bpf_program **progs;
|
||||
__u32 *kern_func_off;
|
||||
/* e.g. struct tcp_congestion_ops in bpf_prog's btf format */
|
||||
@@ -1083,11 +1081,14 @@ static int bpf_object_adjust_struct_ops_autoload(struct bpf_object *obj)
|
||||
continue;
|
||||
|
||||
for (j = 0; j < obj->nr_maps; ++j) {
|
||||
const struct btf_type *type;
|
||||
|
||||
map = &obj->maps[j];
|
||||
if (!bpf_map__is_struct_ops(map))
|
||||
continue;
|
||||
|
||||
vlen = btf_vlen(map->st_ops->type);
|
||||
type = btf__type_by_id(obj->btf, map->st_ops->type_id);
|
||||
vlen = btf_vlen(type);
|
||||
for (k = 0; k < vlen; ++k) {
|
||||
slot_prog = map->st_ops->progs[k];
|
||||
if (prog != slot_prog)
|
||||
@@ -1121,8 +1122,8 @@ static int bpf_map__init_kern_struct_ops(struct bpf_map *map)
|
||||
int err;
|
||||
|
||||
st_ops = map->st_ops;
|
||||
type = st_ops->type;
|
||||
tname = st_ops->tname;
|
||||
type = btf__type_by_id(btf, st_ops->type_id);
|
||||
tname = btf__name_by_offset(btf, type->name_off);
|
||||
err = find_struct_ops_kern_types(obj, tname, &mod_btf,
|
||||
&kern_type, &kern_type_id,
|
||||
&kern_vtype, &kern_vtype_id,
|
||||
@@ -1423,8 +1424,6 @@ static int init_struct_ops_maps(struct bpf_object *obj, const char *sec_name,
|
||||
memcpy(st_ops->data,
|
||||
data->d_buf + vsi->offset,
|
||||
type->size);
|
||||
st_ops->tname = tname;
|
||||
st_ops->type = type;
|
||||
st_ops->type_id = type_id;
|
||||
|
||||
pr_debug("struct_ops init: struct %s(type_id=%u) %s found at offset %u\n",
|
||||
@@ -7906,16 +7905,19 @@ static int bpf_object_init_progs(struct bpf_object *obj, const struct bpf_object
|
||||
}
|
||||
|
||||
static struct bpf_object *bpf_object_open(const char *path, const void *obj_buf, size_t obj_buf_sz,
|
||||
const char *obj_name,
|
||||
const struct bpf_object_open_opts *opts)
|
||||
{
|
||||
const char *obj_name, *kconfig, *btf_tmp_path, *token_path;
|
||||
const char *kconfig, *btf_tmp_path, *token_path;
|
||||
struct bpf_object *obj;
|
||||
char tmp_name[64];
|
||||
int err;
|
||||
char *log_buf;
|
||||
size_t log_size;
|
||||
__u32 log_level;
|
||||
|
||||
if (obj_buf && !obj_name)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
if (elf_version(EV_CURRENT) == EV_NONE) {
|
||||
pr_warn("failed to init libelf for %s\n",
|
||||
path ? : "(mem buf)");
|
||||
@@ -7925,16 +7927,12 @@ static struct bpf_object *bpf_object_open(const char *path, const void *obj_buf,
|
||||
if (!OPTS_VALID(opts, bpf_object_open_opts))
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
obj_name = OPTS_GET(opts, object_name, NULL);
|
||||
obj_name = OPTS_GET(opts, object_name, NULL) ?: obj_name;
|
||||
if (obj_buf) {
|
||||
if (!obj_name) {
|
||||
snprintf(tmp_name, sizeof(tmp_name), "%lx-%lx",
|
||||
(unsigned long)obj_buf,
|
||||
(unsigned long)obj_buf_sz);
|
||||
obj_name = tmp_name;
|
||||
}
|
||||
path = obj_name;
|
||||
pr_debug("loading object '%s' from buffer\n", obj_name);
|
||||
} else {
|
||||
pr_debug("loading object from %s\n", path);
|
||||
}
|
||||
|
||||
log_buf = OPTS_GET(opts, kernel_log_buf, NULL);
|
||||
@@ -8018,9 +8016,7 @@ bpf_object__open_file(const char *path, const struct bpf_object_open_opts *opts)
|
||||
if (!path)
|
||||
return libbpf_err_ptr(-EINVAL);
|
||||
|
||||
pr_debug("loading %s\n", path);
|
||||
|
||||
return libbpf_ptr(bpf_object_open(path, NULL, 0, opts));
|
||||
return libbpf_ptr(bpf_object_open(path, NULL, 0, NULL, opts));
|
||||
}
|
||||
|
||||
struct bpf_object *bpf_object__open(const char *path)
|
||||
@@ -8032,10 +8028,15 @@ struct bpf_object *
|
||||
bpf_object__open_mem(const void *obj_buf, size_t obj_buf_sz,
|
||||
const struct bpf_object_open_opts *opts)
|
||||
{
|
||||
char tmp_name[64];
|
||||
|
||||
if (!obj_buf || obj_buf_sz == 0)
|
||||
return libbpf_err_ptr(-EINVAL);
|
||||
|
||||
return libbpf_ptr(bpf_object_open(NULL, obj_buf, obj_buf_sz, opts));
|
||||
/* create a (quite useless) default "name" for this memory buffer object */
|
||||
snprintf(tmp_name, sizeof(tmp_name), "%lx-%zx", (unsigned long)obj_buf, obj_buf_sz);
|
||||
|
||||
return libbpf_ptr(bpf_object_open(NULL, obj_buf, obj_buf_sz, tmp_name, opts));
|
||||
}
|
||||
|
||||
static int bpf_object_unload(struct bpf_object *obj)
|
||||
@@ -8445,11 +8446,13 @@ static int bpf_object__resolve_externs(struct bpf_object *obj,
|
||||
|
||||
static void bpf_map_prepare_vdata(const struct bpf_map *map)
|
||||
{
|
||||
const struct btf_type *type;
|
||||
struct bpf_struct_ops *st_ops;
|
||||
__u32 i;
|
||||
|
||||
st_ops = map->st_ops;
|
||||
for (i = 0; i < btf_vlen(st_ops->type); i++) {
|
||||
type = btf__type_by_id(map->obj->btf, st_ops->type_id);
|
||||
for (i = 0; i < btf_vlen(type); i++) {
|
||||
struct bpf_program *prog = st_ops->progs[i];
|
||||
void *kern_data;
|
||||
int prog_fd;
|
||||
@@ -9712,6 +9715,7 @@ static struct bpf_map *find_struct_ops_map_by_offset(struct bpf_object *obj,
|
||||
static int bpf_object__collect_st_ops_relos(struct bpf_object *obj,
|
||||
Elf64_Shdr *shdr, Elf_Data *data)
|
||||
{
|
||||
const struct btf_type *type;
|
||||
const struct btf_member *member;
|
||||
struct bpf_struct_ops *st_ops;
|
||||
struct bpf_program *prog;
|
||||
@@ -9771,13 +9775,14 @@ static int bpf_object__collect_st_ops_relos(struct bpf_object *obj,
|
||||
}
|
||||
insn_idx = sym->st_value / BPF_INSN_SZ;
|
||||
|
||||
member = find_member_by_offset(st_ops->type, moff * 8);
|
||||
type = btf__type_by_id(btf, st_ops->type_id);
|
||||
member = find_member_by_offset(type, moff * 8);
|
||||
if (!member) {
|
||||
pr_warn("struct_ops reloc %s: cannot find member at moff %u\n",
|
||||
map->name, moff);
|
||||
return -EINVAL;
|
||||
}
|
||||
member_idx = member - btf_members(st_ops->type);
|
||||
member_idx = member - btf_members(type);
|
||||
name = btf__name_by_offset(btf, member->name_off);
|
||||
|
||||
if (!resolve_func_ptr(btf, member->type, NULL)) {
|
||||
@@ -13758,29 +13763,13 @@ static int populate_skeleton_progs(const struct bpf_object *obj,
|
||||
int bpf_object__open_skeleton(struct bpf_object_skeleton *s,
|
||||
const struct bpf_object_open_opts *opts)
|
||||
{
|
||||
DECLARE_LIBBPF_OPTS(bpf_object_open_opts, skel_opts,
|
||||
.object_name = s->name,
|
||||
);
|
||||
struct bpf_object *obj;
|
||||
int err;
|
||||
|
||||
/* Attempt to preserve opts->object_name, unless overriden by user
|
||||
* explicitly. Overwriting object name for skeletons is discouraged,
|
||||
* as it breaks global data maps, because they contain object name
|
||||
* prefix as their own map name prefix. When skeleton is generated,
|
||||
* bpftool is making an assumption that this name will stay the same.
|
||||
*/
|
||||
if (opts) {
|
||||
memcpy(&skel_opts, opts, sizeof(*opts));
|
||||
if (!opts->object_name)
|
||||
skel_opts.object_name = s->name;
|
||||
}
|
||||
|
||||
obj = bpf_object__open_mem(s->data, s->data_sz, &skel_opts);
|
||||
err = libbpf_get_error(obj);
|
||||
if (err) {
|
||||
pr_warn("failed to initialize skeleton BPF object '%s': %d\n",
|
||||
s->name, err);
|
||||
obj = bpf_object_open(NULL, s->data, s->data_sz, s->name, opts);
|
||||
if (IS_ERR(obj)) {
|
||||
err = PTR_ERR(obj);
|
||||
pr_warn("failed to initialize skeleton BPF object '%s': %d\n", s->name, err);
|
||||
return libbpf_err(err);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user