Skip to content

Commit fbbb68d

Browse files
olsajiriAlexei Starovoitov
authored andcommitted
bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object
The resolve_btfids tool scans elf object for .BTF_ids section and resolves its symbols with BTF ID values. It will be used to during linking time to resolve arrays of BTF ID values used in verifier, so these IDs do not need to be resolved in runtime. The expected layout of .BTF_ids section is described in main.c header. Related kernel changes are coming in following changes. Build issue reported by 0-DAY CI Kernel Test Service. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20200711215329.41165-2-jolsa@kernel.org
1 parent eef8a42 commit fbbb68d

3 files changed

Lines changed: 808 additions & 0 deletions

File tree

‎tools/bpf/resolve_btfids/Build‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
resolve_btfids-y += main.o
2+
resolve_btfids-y += rbtree.o
3+
resolve_btfids-y += zalloc.o
4+
resolve_btfids-y += string.o
5+
resolve_btfids-y += ctype.o
6+
resolve_btfids-y += str_error_r.o
7+
8+
$(OUTPUT)%.o: ../../lib/%.c FORCE
9+
$(call rule_mkdir)
10+
$(call if_changed_dep,cc_o_c)

‎tools/bpf/resolve_btfids/Makefile‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
include ../../scripts/Makefile.include
3+
4+
ifeq ($(srctree),)
5+
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
6+
srctree := $(patsubst %/,%,$(dir $(srctree)))
7+
srctree := $(patsubst %/,%,$(dir $(srctree)))
8+
endif
9+
10+
ifeq ($(V),1)
11+
Q =
12+
msg =
13+
else
14+
Q = @
15+
msg = @printf ' %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))";
16+
MAKEFLAGS=--no-print-directory
17+
endif
18+
19+
OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/
20+
21+
LIBBPF_SRC := $(srctree)/tools/lib/bpf/
22+
SUBCMD_SRC := $(srctree)/tools/lib/subcmd/
23+
24+
BPFOBJ := $(OUTPUT)/libbpf.a
25+
SUBCMDOBJ := $(OUTPUT)/libsubcmd.a
26+
27+
BINARY := $(OUTPUT)/resolve_btfids
28+
BINARY_IN := $(BINARY)-in.o
29+
30+
all: $(BINARY)
31+
32+
$(OUTPUT):
33+
$(call msg,MKDIR,,$@)
34+
$(Q)mkdir -p $(OUTPUT)
35+
36+
$(SUBCMDOBJ): fixdep FORCE
37+
$(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(OUTPUT)
38+
39+
$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)
40+
$(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
41+
42+
CFLAGS := -g \
43+
-I$(srctree)/tools/include \
44+
-I$(srctree)/tools/include/uapi \
45+
-I$(LIBBPF_SRC) \
46+
-I$(SUBCMD_SRC)
47+
48+
LIBS = -lelf -lz
49+
50+
export srctree OUTPUT CFLAGS Q
51+
include $(srctree)/tools/build/Makefile.include
52+
53+
$(BINARY_IN): fixdep FORCE
54+
$(Q)$(MAKE) $(build)=resolve_btfids
55+
56+
$(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN)
57+
$(call msg,LINK,$@)
58+
$(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS)
59+
60+
libsubcmd-clean:
61+
$(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(OUTPUT) clean
62+
63+
libbpf-clean:
64+
$(Q)$(MAKE) -C $(LIBBPF_SRC) OUTPUT=$(OUTPUT) clean
65+
66+
clean: libsubcmd-clean libbpf-clean fixdep-clean
67+
$(call msg,CLEAN,$(BINARY))
68+
$(Q)$(RM) -f $(BINARY); \
69+
find $(if $(OUTPUT),$(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
70+
71+
tags:
72+
$(call msg,GEN,,tags)
73+
$(Q)ctags -R . $(LIBBPF_SRC) $(SUBCMD_SRC)
74+
75+
FORCE:
76+
77+
.PHONY: all FORCE clean tags

0 commit comments

Comments
 (0)