bpf: libbpf: Add btf_line_info support to libbpf
This patch adds bpf_line_info support to libbpf: 1) Parsing the line_info sec from ".BTF.ext" 2) Relocating the line_info. If the main prog *_info relocation fails, it will ignore the remaining subprog line_info and continue. If the subprog *_info relocation fails, it will bail out. 3) BPF_PROG_LOAD a prog with line_info Signed-off-by: Martin KaFai Lau <kafai@fb.com> Acked-by: Yonghong Song <yhs@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
Родитель
f0187f0b17
Коммит
3d65014146
|
@ -173,11 +173,36 @@ int bpf_create_map_in_map(enum bpf_map_type map_type, const char *name,
|
||||||
-1);
|
-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void *
|
||||||
|
alloc_zero_tailing_info(const void *orecord, __u32 cnt,
|
||||||
|
__u32 actual_rec_size, __u32 expected_rec_size)
|
||||||
|
{
|
||||||
|
__u64 info_len = actual_rec_size * cnt;
|
||||||
|
void *info, *nrecord;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
info = malloc(info_len);
|
||||||
|
if (!info)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
/* zero out bytes kernel does not understand */
|
||||||
|
nrecord = info;
|
||||||
|
for (i = 0; i < cnt; i++) {
|
||||||
|
memcpy(nrecord, orecord, expected_rec_size);
|
||||||
|
memset(nrecord + expected_rec_size, 0,
|
||||||
|
actual_rec_size - expected_rec_size);
|
||||||
|
orecord += actual_rec_size;
|
||||||
|
nrecord += actual_rec_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
int bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr,
|
int bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr,
|
||||||
char *log_buf, size_t log_buf_sz)
|
char *log_buf, size_t log_buf_sz)
|
||||||
{
|
{
|
||||||
|
void *finfo = NULL, *linfo = NULL;
|
||||||
union bpf_attr attr;
|
union bpf_attr attr;
|
||||||
void *finfo = NULL;
|
|
||||||
__u32 name_len;
|
__u32 name_len;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
@ -201,6 +226,9 @@ int bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr,
|
||||||
attr.func_info_rec_size = load_attr->func_info_rec_size;
|
attr.func_info_rec_size = load_attr->func_info_rec_size;
|
||||||
attr.func_info_cnt = load_attr->func_info_cnt;
|
attr.func_info_cnt = load_attr->func_info_cnt;
|
||||||
attr.func_info = ptr_to_u64(load_attr->func_info);
|
attr.func_info = ptr_to_u64(load_attr->func_info);
|
||||||
|
attr.line_info_rec_size = load_attr->line_info_rec_size;
|
||||||
|
attr.line_info_cnt = load_attr->line_info_cnt;
|
||||||
|
attr.line_info = ptr_to_u64(load_attr->line_info);
|
||||||
memcpy(attr.prog_name, load_attr->name,
|
memcpy(attr.prog_name, load_attr->name,
|
||||||
min(name_len, BPF_OBJ_NAME_LEN - 1));
|
min(name_len, BPF_OBJ_NAME_LEN - 1));
|
||||||
|
|
||||||
|
@ -212,36 +240,35 @@ int bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr,
|
||||||
* to give user space a hint how to deal with loading failure.
|
* to give user space a hint how to deal with loading failure.
|
||||||
* Check to see whether we can make some changes and load again.
|
* Check to see whether we can make some changes and load again.
|
||||||
*/
|
*/
|
||||||
if (errno == E2BIG && attr.func_info_cnt &&
|
while (errno == E2BIG && (!finfo || !linfo)) {
|
||||||
attr.func_info_rec_size < load_attr->func_info_rec_size) {
|
if (!finfo && attr.func_info_cnt &&
|
||||||
__u32 actual_rec_size = load_attr->func_info_rec_size;
|
attr.func_info_rec_size < load_attr->func_info_rec_size) {
|
||||||
__u32 expected_rec_size = attr.func_info_rec_size;
|
/* try with corrected func info records */
|
||||||
__u32 finfo_cnt = load_attr->func_info_cnt;
|
finfo = alloc_zero_tailing_info(load_attr->func_info,
|
||||||
__u64 finfo_len = actual_rec_size * finfo_cnt;
|
load_attr->func_info_cnt,
|
||||||
const void *orecord;
|
load_attr->func_info_rec_size,
|
||||||
void *nrecord;
|
attr.func_info_rec_size);
|
||||||
int i;
|
if (!finfo)
|
||||||
|
goto done;
|
||||||
|
|
||||||
finfo = malloc(finfo_len);
|
attr.func_info = ptr_to_u64(finfo);
|
||||||
if (!finfo)
|
attr.func_info_rec_size = load_attr->func_info_rec_size;
|
||||||
/* further try with log buffer won't help */
|
} else if (!linfo && attr.line_info_cnt &&
|
||||||
return fd;
|
attr.line_info_rec_size <
|
||||||
|
load_attr->line_info_rec_size) {
|
||||||
|
linfo = alloc_zero_tailing_info(load_attr->line_info,
|
||||||
|
load_attr->line_info_cnt,
|
||||||
|
load_attr->line_info_rec_size,
|
||||||
|
attr.line_info_rec_size);
|
||||||
|
if (!linfo)
|
||||||
|
goto done;
|
||||||
|
|
||||||
/* zero out bytes kernel does not understand */
|
attr.line_info = ptr_to_u64(linfo);
|
||||||
orecord = load_attr->func_info;
|
attr.line_info_rec_size = load_attr->line_info_rec_size;
|
||||||
nrecord = finfo;
|
} else {
|
||||||
for (i = 0; i < load_attr->func_info_cnt; i++) {
|
break;
|
||||||
memcpy(nrecord, orecord, expected_rec_size);
|
|
||||||
memset(nrecord + expected_rec_size, 0,
|
|
||||||
actual_rec_size - expected_rec_size);
|
|
||||||
orecord += actual_rec_size;
|
|
||||||
nrecord += actual_rec_size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* try with corrected func info records */
|
|
||||||
attr.func_info = ptr_to_u64(finfo);
|
|
||||||
attr.func_info_rec_size = load_attr->func_info_rec_size;
|
|
||||||
|
|
||||||
fd = sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
|
fd = sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
|
||||||
|
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
|
@ -259,6 +286,7 @@ int bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr,
|
||||||
fd = sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
|
fd = sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
|
||||||
done:
|
done:
|
||||||
free(finfo);
|
free(finfo);
|
||||||
|
free(linfo);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,9 @@ struct bpf_load_program_attr {
|
||||||
__u32 func_info_rec_size;
|
__u32 func_info_rec_size;
|
||||||
const void *func_info;
|
const void *func_info;
|
||||||
__u32 func_info_cnt;
|
__u32 func_info_cnt;
|
||||||
|
__u32 line_info_rec_size;
|
||||||
|
const void *line_info;
|
||||||
|
__u32 line_info_cnt;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Flags to direct loading requirements */
|
/* Flags to direct loading requirements */
|
||||||
|
|
|
@ -37,16 +37,26 @@ struct btf {
|
||||||
int fd;
|
int fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct btf_ext {
|
struct btf_ext_info {
|
||||||
void *func_info;
|
/*
|
||||||
__u32 func_info_rec_size;
|
* info points to a deep copy of the individual info section
|
||||||
__u32 func_info_len;
|
* (e.g. func_info and line_info) from the .BTF.ext.
|
||||||
|
* It does not include the __u32 rec_size.
|
||||||
|
*/
|
||||||
|
void *info;
|
||||||
|
__u32 rec_size;
|
||||||
|
__u32 len;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct btf_sec_func_info {
|
struct btf_ext {
|
||||||
|
struct btf_ext_info func_info;
|
||||||
|
struct btf_ext_info line_info;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct btf_ext_info_sec {
|
||||||
__u32 sec_name_off;
|
__u32 sec_name_off;
|
||||||
__u32 num_func_info;
|
__u32 num_info;
|
||||||
/* Followed by num_func_info number of bpf func_info records */
|
/* Followed by num_info * record_size number of bytes */
|
||||||
__u8 data[0];
|
__u8 data[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,6 +66,14 @@ struct bpf_func_info_min {
|
||||||
__u32 type_id;
|
__u32 type_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* The minimum bpf_line_info checked by the loader */
|
||||||
|
struct bpf_line_info_min {
|
||||||
|
__u32 insn_off;
|
||||||
|
__u32 file_name_off;
|
||||||
|
__u32 line_off;
|
||||||
|
__u32 line_col;
|
||||||
|
};
|
||||||
|
|
||||||
static inline __u64 ptr_to_u64(const void *ptr)
|
static inline __u64 ptr_to_u64(const void *ptr)
|
||||||
{
|
{
|
||||||
return (__u64) (unsigned long) ptr;
|
return (__u64) (unsigned long) ptr;
|
||||||
|
@ -486,12 +504,22 @@ exit_free:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int btf_ext_copy_func_info(struct btf_ext *btf_ext,
|
struct btf_ext_sec_copy_param {
|
||||||
__u8 *data, __u32 data_size,
|
__u32 off;
|
||||||
btf_print_fn_t err_log)
|
__u32 len;
|
||||||
|
__u32 min_rec_size;
|
||||||
|
struct btf_ext_info *ext_info;
|
||||||
|
const char *desc;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int btf_ext_copy_info(struct btf_ext *btf_ext,
|
||||||
|
__u8 *data, __u32 data_size,
|
||||||
|
struct btf_ext_sec_copy_param *ext_sec,
|
||||||
|
btf_print_fn_t err_log)
|
||||||
{
|
{
|
||||||
const struct btf_ext_header *hdr = (struct btf_ext_header *)data;
|
const struct btf_ext_header *hdr = (struct btf_ext_header *)data;
|
||||||
const struct btf_sec_func_info *sinfo;
|
const struct btf_ext_info_sec *sinfo;
|
||||||
|
struct btf_ext_info *ext_info;
|
||||||
__u32 info_left, record_size;
|
__u32 info_left, record_size;
|
||||||
/* The start of the info sec (including the __u32 record_size). */
|
/* The start of the info sec (including the __u32 record_size). */
|
||||||
const void *info;
|
const void *info;
|
||||||
|
@ -500,66 +528,69 @@ static int btf_ext_copy_func_info(struct btf_ext *btf_ext,
|
||||||
data = data + hdr->hdr_len;
|
data = data + hdr->hdr_len;
|
||||||
data_size -= hdr->hdr_len;
|
data_size -= hdr->hdr_len;
|
||||||
|
|
||||||
if (hdr->func_info_off & 0x03) {
|
if (ext_sec->off & 0x03) {
|
||||||
elog("BTF.ext func_info section is not aligned to 4 bytes\n");
|
elog(".BTF.ext %s section is not aligned to 4 bytes\n",
|
||||||
|
ext_sec->desc);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data_size < hdr->func_info_off ||
|
if (data_size < ext_sec->off ||
|
||||||
hdr->func_info_len > data_size - hdr->func_info_off) {
|
ext_sec->len > data_size - ext_sec->off) {
|
||||||
elog("func_info section (off:%u len:%u) is beyond the end of the ELF section .BTF.ext\n",
|
elog("%s section (off:%u len:%u) is beyond the end of the ELF section .BTF.ext\n",
|
||||||
hdr->func_info_off, hdr->func_info_len);
|
ext_sec->desc, ext_sec->off, ext_sec->len);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
info = data + hdr->func_info_off;
|
info = data + ext_sec->off;
|
||||||
info_left = hdr->func_info_len;
|
info_left = ext_sec->len;
|
||||||
|
|
||||||
/* At least a func_info record size */
|
/* At least a record size */
|
||||||
if (info_left < sizeof(__u32)) {
|
if (info_left < sizeof(__u32)) {
|
||||||
elog("BTF.ext func_info record size not found");
|
elog(".BTF.ext %s record size not found\n", ext_sec->desc);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The record size needs to meet the minimum standard */
|
/* The record size needs to meet the minimum standard */
|
||||||
record_size = *(__u32 *)info;
|
record_size = *(__u32 *)info;
|
||||||
if (record_size < sizeof(struct bpf_func_info_min) ||
|
if (record_size < ext_sec->min_rec_size ||
|
||||||
record_size & 0x03) {
|
record_size & 0x03) {
|
||||||
elog("BTF.ext func_info invalid record size");
|
elog("%s section in .BTF.ext has invalid record size %u\n",
|
||||||
|
ext_sec->desc, record_size);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sinfo = info + sizeof(__u32);
|
sinfo = info + sizeof(__u32);
|
||||||
info_left -= sizeof(__u32);
|
info_left -= sizeof(__u32);
|
||||||
|
|
||||||
/* If no func_info records, return failure now so .BTF.ext
|
/* If no records, return failure now so .BTF.ext won't be used. */
|
||||||
* won't be used.
|
|
||||||
*/
|
|
||||||
if (!info_left) {
|
if (!info_left) {
|
||||||
elog("BTF.ext no func info records");
|
elog("%s section in .BTF.ext has no records", ext_sec->desc);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (info_left) {
|
while (info_left) {
|
||||||
unsigned int sec_hdrlen = sizeof(struct btf_sec_func_info);
|
unsigned int sec_hdrlen = sizeof(struct btf_ext_info_sec);
|
||||||
__u64 total_record_size;
|
__u64 total_record_size;
|
||||||
__u32 num_records;
|
__u32 num_records;
|
||||||
|
|
||||||
if (info_left < sec_hdrlen) {
|
if (info_left < sec_hdrlen) {
|
||||||
elog("BTF.ext func_info header not found");
|
elog("%s section header is not found in .BTF.ext\n",
|
||||||
|
ext_sec->desc);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
num_records = sinfo->num_func_info;
|
num_records = sinfo->num_info;
|
||||||
if (num_records == 0) {
|
if (num_records == 0) {
|
||||||
elog("incorrect BTF.ext num_func_info");
|
elog("%s section has incorrect num_records in .BTF.ext\n",
|
||||||
|
ext_sec->desc);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
total_record_size = sec_hdrlen +
|
total_record_size = sec_hdrlen +
|
||||||
(__u64)num_records * record_size;
|
(__u64)num_records * record_size;
|
||||||
if (info_left < total_record_size) {
|
if (info_left < total_record_size) {
|
||||||
elog("incorrect BTF.ext num_func_info");
|
elog("%s section has incorrect num_records in .BTF.ext\n",
|
||||||
|
ext_sec->desc);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -567,17 +598,49 @@ static int btf_ext_copy_func_info(struct btf_ext *btf_ext,
|
||||||
sinfo = (void *)sinfo + total_record_size;
|
sinfo = (void *)sinfo + total_record_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
btf_ext->func_info_len = hdr->func_info_len - sizeof(__u32);
|
ext_info = ext_sec->ext_info;
|
||||||
btf_ext->func_info_rec_size = record_size;
|
ext_info->len = ext_sec->len - sizeof(__u32);
|
||||||
btf_ext->func_info = malloc(btf_ext->func_info_len);
|
ext_info->rec_size = record_size;
|
||||||
if (!btf_ext->func_info)
|
ext_info->info = malloc(ext_info->len);
|
||||||
|
if (!ext_info->info)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
memcpy(btf_ext->func_info, info + sizeof(__u32),
|
memcpy(ext_info->info, info + sizeof(__u32), ext_info->len);
|
||||||
btf_ext->func_info_len);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int btf_ext_copy_func_info(struct btf_ext *btf_ext,
|
||||||
|
__u8 *data, __u32 data_size,
|
||||||
|
btf_print_fn_t err_log)
|
||||||
|
{
|
||||||
|
const struct btf_ext_header *hdr = (struct btf_ext_header *)data;
|
||||||
|
struct btf_ext_sec_copy_param param = {
|
||||||
|
.off = hdr->func_info_off,
|
||||||
|
.len = hdr->func_info_len,
|
||||||
|
.min_rec_size = sizeof(struct bpf_func_info_min),
|
||||||
|
.ext_info = &btf_ext->func_info,
|
||||||
|
.desc = "func_info"
|
||||||
|
};
|
||||||
|
|
||||||
|
return btf_ext_copy_info(btf_ext, data, data_size, ¶m, err_log);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int btf_ext_copy_line_info(struct btf_ext *btf_ext,
|
||||||
|
__u8 *data, __u32 data_size,
|
||||||
|
btf_print_fn_t err_log)
|
||||||
|
{
|
||||||
|
const struct btf_ext_header *hdr = (struct btf_ext_header *)data;
|
||||||
|
struct btf_ext_sec_copy_param param = {
|
||||||
|
.off = hdr->line_info_off,
|
||||||
|
.len = hdr->line_info_len,
|
||||||
|
.min_rec_size = sizeof(struct bpf_line_info_min),
|
||||||
|
.ext_info = &btf_ext->line_info,
|
||||||
|
.desc = "line_info",
|
||||||
|
};
|
||||||
|
|
||||||
|
return btf_ext_copy_info(btf_ext, data, data_size, ¶m, err_log);
|
||||||
|
}
|
||||||
|
|
||||||
static int btf_ext_parse_hdr(__u8 *data, __u32 data_size,
|
static int btf_ext_parse_hdr(__u8 *data, __u32 data_size,
|
||||||
btf_print_fn_t err_log)
|
btf_print_fn_t err_log)
|
||||||
{
|
{
|
||||||
|
@ -617,7 +680,8 @@ void btf_ext__free(struct btf_ext *btf_ext)
|
||||||
if (!btf_ext)
|
if (!btf_ext)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
free(btf_ext->func_info);
|
free(btf_ext->func_info.info);
|
||||||
|
free(btf_ext->line_info.info);
|
||||||
free(btf_ext);
|
free(btf_ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -640,25 +704,32 @@ struct btf_ext *btf_ext__new(__u8 *data, __u32 size, btf_print_fn_t err_log)
|
||||||
return ERR_PTR(err);
|
return ERR_PTR(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = btf_ext_copy_line_info(btf_ext, data, size, err_log);
|
||||||
|
if (err) {
|
||||||
|
btf_ext__free(btf_ext);
|
||||||
|
return ERR_PTR(err);
|
||||||
|
}
|
||||||
|
|
||||||
return btf_ext;
|
return btf_ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
int btf_ext__reloc_func_info(struct btf *btf, struct btf_ext *btf_ext,
|
static int btf_ext_reloc_info(const struct btf *btf,
|
||||||
const char *sec_name, __u32 insns_cnt,
|
const struct btf_ext_info *ext_info,
|
||||||
void **func_info, __u32 *cnt)
|
const char *sec_name, __u32 insns_cnt,
|
||||||
|
void **info, __u32 *cnt)
|
||||||
{
|
{
|
||||||
__u32 sec_hdrlen = sizeof(struct btf_sec_func_info);
|
__u32 sec_hdrlen = sizeof(struct btf_ext_info_sec);
|
||||||
__u32 i, record_size, existing_flen, records_len;
|
__u32 i, record_size, existing_len, records_len;
|
||||||
struct btf_sec_func_info *sinfo;
|
struct btf_ext_info_sec *sinfo;
|
||||||
const char *info_sec_name;
|
const char *info_sec_name;
|
||||||
__u64 remain_len;
|
__u64 remain_len;
|
||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
record_size = btf_ext->func_info_rec_size;
|
record_size = ext_info->rec_size;
|
||||||
sinfo = btf_ext->func_info;
|
sinfo = ext_info->info;
|
||||||
remain_len = btf_ext->func_info_len;
|
remain_len = ext_info->len;
|
||||||
while (remain_len > 0) {
|
while (remain_len > 0) {
|
||||||
records_len = sinfo->num_func_info * record_size;
|
records_len = sinfo->num_info * record_size;
|
||||||
info_sec_name = btf__name_by_offset(btf, sinfo->sec_name_off);
|
info_sec_name = btf__name_by_offset(btf, sinfo->sec_name_off);
|
||||||
if (strcmp(info_sec_name, sec_name)) {
|
if (strcmp(info_sec_name, sec_name)) {
|
||||||
remain_len -= sec_hdrlen + records_len;
|
remain_len -= sec_hdrlen + records_len;
|
||||||
|
@ -666,32 +737,52 @@ int btf_ext__reloc_func_info(struct btf *btf, struct btf_ext *btf_ext,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
existing_flen = (*cnt) * record_size;
|
existing_len = (*cnt) * record_size;
|
||||||
data = realloc(*func_info, existing_flen + records_len);
|
data = realloc(*info, existing_len + records_len);
|
||||||
if (!data)
|
if (!data)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
memcpy(data + existing_flen, sinfo->data, records_len);
|
memcpy(data + existing_len, sinfo->data, records_len);
|
||||||
/* adjust insn_off only, the rest data will be passed
|
/* adjust insn_off only, the rest data will be passed
|
||||||
* to the kernel.
|
* to the kernel.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < sinfo->num_func_info; i++) {
|
for (i = 0; i < sinfo->num_info; i++) {
|
||||||
struct bpf_func_info_min *record;
|
__u32 *insn_off;
|
||||||
|
|
||||||
record = data + existing_flen + i * record_size;
|
insn_off = data + existing_len + (i * record_size);
|
||||||
record->insn_off =
|
*insn_off = *insn_off / sizeof(struct bpf_insn) +
|
||||||
record->insn_off / sizeof(struct bpf_insn) +
|
|
||||||
insns_cnt;
|
insns_cnt;
|
||||||
}
|
}
|
||||||
*func_info = data;
|
*info = data;
|
||||||
*cnt += sinfo->num_func_info;
|
*cnt += sinfo->num_info;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int btf_ext__reloc_func_info(const struct btf *btf, const struct btf_ext *btf_ext,
|
||||||
|
const char *sec_name, __u32 insns_cnt,
|
||||||
|
void **func_info, __u32 *cnt)
|
||||||
|
{
|
||||||
|
return btf_ext_reloc_info(btf, &btf_ext->func_info, sec_name,
|
||||||
|
insns_cnt, func_info, cnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
int btf_ext__reloc_line_info(const struct btf *btf, const struct btf_ext *btf_ext,
|
||||||
|
const char *sec_name, __u32 insns_cnt,
|
||||||
|
void **line_info, __u32 *cnt)
|
||||||
|
{
|
||||||
|
return btf_ext_reloc_info(btf, &btf_ext->line_info, sec_name,
|
||||||
|
insns_cnt, line_info, cnt);
|
||||||
|
}
|
||||||
|
|
||||||
__u32 btf_ext__func_info_rec_size(const struct btf_ext *btf_ext)
|
__u32 btf_ext__func_info_rec_size(const struct btf_ext *btf_ext)
|
||||||
{
|
{
|
||||||
return btf_ext->func_info_rec_size;
|
return btf_ext->func_info.rec_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
__u32 btf_ext__line_info_rec_size(const struct btf_ext *btf_ext)
|
||||||
|
{
|
||||||
|
return btf_ext->line_info.rec_size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,8 @@ struct btf_ext_header {
|
||||||
/* All offsets are in bytes relative to the end of this header */
|
/* All offsets are in bytes relative to the end of this header */
|
||||||
__u32 func_info_off;
|
__u32 func_info_off;
|
||||||
__u32 func_info_len;
|
__u32 func_info_len;
|
||||||
|
__u32 line_info_off;
|
||||||
|
__u32 line_info_len;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef int (*btf_print_fn_t)(const char *, ...)
|
typedef int (*btf_print_fn_t)(const char *, ...)
|
||||||
|
@ -70,10 +72,16 @@ LIBBPF_API int btf__get_from_id(__u32 id, struct btf **btf);
|
||||||
|
|
||||||
struct btf_ext *btf_ext__new(__u8 *data, __u32 size, btf_print_fn_t err_log);
|
struct btf_ext *btf_ext__new(__u8 *data, __u32 size, btf_print_fn_t err_log);
|
||||||
void btf_ext__free(struct btf_ext *btf_ext);
|
void btf_ext__free(struct btf_ext *btf_ext);
|
||||||
int btf_ext__reloc_func_info(struct btf *btf, struct btf_ext *btf_ext,
|
int btf_ext__reloc_func_info(const struct btf *btf,
|
||||||
|
const struct btf_ext *btf_ext,
|
||||||
const char *sec_name, __u32 insns_cnt,
|
const char *sec_name, __u32 insns_cnt,
|
||||||
void **func_info, __u32 *func_info_len);
|
void **func_info, __u32 *func_info_len);
|
||||||
|
int btf_ext__reloc_line_info(const struct btf *btf,
|
||||||
|
const struct btf_ext *btf_ext,
|
||||||
|
const char *sec_name, __u32 insns_cnt,
|
||||||
|
void **line_info, __u32 *cnt);
|
||||||
__u32 btf_ext__func_info_rec_size(const struct btf_ext *btf_ext);
|
__u32 btf_ext__func_info_rec_size(const struct btf_ext *btf_ext);
|
||||||
|
__u32 btf_ext__line_info_rec_size(const struct btf_ext *btf_ext);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
|
|
|
@ -170,6 +170,10 @@ struct bpf_program {
|
||||||
__u32 func_info_cnt;
|
__u32 func_info_cnt;
|
||||||
|
|
||||||
struct bpf_capabilities *caps;
|
struct bpf_capabilities *caps;
|
||||||
|
|
||||||
|
void *line_info;
|
||||||
|
__u32 line_info_rec_size;
|
||||||
|
__u32 line_info_cnt;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct bpf_map {
|
struct bpf_map {
|
||||||
|
@ -1342,6 +1346,19 @@ bpf_program_reloc_btf_ext(struct bpf_program *prog, struct bpf_object *obj,
|
||||||
prog->func_info_rec_size = btf_ext__func_info_rec_size(obj->btf_ext);
|
prog->func_info_rec_size = btf_ext__func_info_rec_size(obj->btf_ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!insn_offset || prog->line_info) {
|
||||||
|
err = btf_ext__reloc_line_info(obj->btf, obj->btf_ext,
|
||||||
|
section_name, insn_offset,
|
||||||
|
&prog->line_info,
|
||||||
|
&prog->line_info_cnt);
|
||||||
|
if (err)
|
||||||
|
return check_btf_ext_reloc_err(prog, err,
|
||||||
|
prog->line_info,
|
||||||
|
"bpf_line_info");
|
||||||
|
|
||||||
|
prog->line_info_rec_size = btf_ext__line_info_rec_size(obj->btf_ext);
|
||||||
|
}
|
||||||
|
|
||||||
if (!insn_offset)
|
if (!insn_offset)
|
||||||
prog->btf_fd = btf__fd(obj->btf);
|
prog->btf_fd = btf__fd(obj->btf);
|
||||||
|
|
||||||
|
@ -1526,6 +1543,9 @@ load_program(struct bpf_program *prog, struct bpf_insn *insns, int insns_cnt,
|
||||||
load_attr.func_info = prog->func_info;
|
load_attr.func_info = prog->func_info;
|
||||||
load_attr.func_info_rec_size = prog->func_info_rec_size;
|
load_attr.func_info_rec_size = prog->func_info_rec_size;
|
||||||
load_attr.func_info_cnt = prog->func_info_cnt;
|
load_attr.func_info_cnt = prog->func_info_cnt;
|
||||||
|
load_attr.line_info = prog->line_info;
|
||||||
|
load_attr.line_info_rec_size = prog->line_info_rec_size;
|
||||||
|
load_attr.line_info_cnt = prog->line_info_cnt;
|
||||||
if (!load_attr.insns || !load_attr.insns_cnt)
|
if (!load_attr.insns || !load_attr.insns_cnt)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче