Skip to content

Commit f86ca3c

Browse files
anakryikoborkmann
authored andcommitted
tools/resolve_btfids: Use libbpf's btf__parse() API
Instead of re-implementing generic BTF parsing logic, use libbpf's API. Also add .gitignore for resolve_btfids's build artifacts. Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 8526df0 commit f86ca3c

File tree

2 files changed

+5
-57
lines changed

2 files changed

+5
-57
lines changed

tools/bpf/resolve_btfids/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/FEATURE-DUMP.libbpf
2+
/bpf_helper_defs.h
3+
/fixdep
4+
/resolve_btfids

tools/bpf/resolve_btfids/main.c

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -403,62 +403,6 @@ static int symbols_collect(struct object *obj)
403403
return 0;
404404
}
405405

406-
static struct btf *btf__parse_raw(const char *file)
407-
{
408-
struct btf *btf;
409-
struct stat st;
410-
__u8 *buf;
411-
FILE *f;
412-
413-
if (stat(file, &st))
414-
return NULL;
415-
416-
f = fopen(file, "rb");
417-
if (!f)
418-
return NULL;
419-
420-
buf = malloc(st.st_size);
421-
if (!buf) {
422-
btf = ERR_PTR(-ENOMEM);
423-
goto exit_close;
424-
}
425-
426-
if ((size_t) st.st_size != fread(buf, 1, st.st_size, f)) {
427-
btf = ERR_PTR(-EINVAL);
428-
goto exit_free;
429-
}
430-
431-
btf = btf__new(buf, st.st_size);
432-
433-
exit_free:
434-
free(buf);
435-
exit_close:
436-
fclose(f);
437-
return btf;
438-
}
439-
440-
static bool is_btf_raw(const char *file)
441-
{
442-
__u16 magic = 0;
443-
int fd, nb_read;
444-
445-
fd = open(file, O_RDONLY);
446-
if (fd < 0)
447-
return false;
448-
449-
nb_read = read(fd, &magic, sizeof(magic));
450-
close(fd);
451-
return nb_read == sizeof(magic) && magic == BTF_MAGIC;
452-
}
453-
454-
static struct btf *btf_open(const char *path)
455-
{
456-
if (is_btf_raw(path))
457-
return btf__parse_raw(path);
458-
else
459-
return btf__parse_elf(path, NULL);
460-
}
461-
462406
static int symbols_resolve(struct object *obj)
463407
{
464408
int nr_typedefs = obj->nr_typedefs;
@@ -469,7 +413,7 @@ static int symbols_resolve(struct object *obj)
469413
struct btf *btf;
470414
__u32 nr;
471415

472-
btf = btf_open(obj->btf ?: obj->path);
416+
btf = btf__parse(obj->btf ?: obj->path, NULL);
473417
err = libbpf_get_error(btf);
474418
if (err) {
475419
pr_err("FAILED: load BTF from %s: %s",

0 commit comments

Comments
 (0)