From: Jiri Olsa <jolsa@redhat.com> To: Andrii Nakryiko <andrii@kernel.org> Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, ast@fb.com, daniel@iogearbox.net, kernel-team@fb.com Subject: Re: [PATCH v4 bpf-next 07/12] libbpf: add BPF static linker BTF and BTF.ext support Date: Fri, 19 Mar 2021 17:23:47 +0100 [thread overview] Message-ID: <YFTQExmhNhMcmNOb@krava> (raw) In-Reply-To: <20210318194036.3521577-8-andrii@kernel.org> On Thu, Mar 18, 2021 at 12:40:31PM -0700, Andrii Nakryiko wrote: SNIP > + > + return NULL; > +} > + > +static int linker_fixup_btf(struct src_obj *obj) > +{ > + const char *sec_name; > + struct src_sec *sec; > + int i, j, n, m; > + > + n = btf__get_nr_types(obj->btf); hi, I'm getting bpftool crash when building tests, looks like above obj->btf can be NULL: (gdb) r gen object /home/jolsa/linux/tools/testing/selftests/bpf/btf_data2.linked1.o /home/jolsa/linux/tools/testing/selftests/bpf/btf_data2.o Starting program: /home/jolsa/linux/tools/testing/selftests/bpf/tools/sbin/bpftool gen object /home/jolsa/linux/tools/testing/selftests/bpf/btf_data2.linked1.o /home/jolsa/linux/tools/testing/selftests/bpf/btf_data2.o Program received signal SIGSEGV, Segmentation fault. btf__get_nr_types (btf=0x0) at btf.c:425 425 return btf->start_id + btf->nr_types - 1; Missing separate debuginfos, use: dnf debuginfo-install elfutils-libelf-0.182-1.fc33.x86_64 libcap-2.48-2.fc33.x86_64 zlib-1.2.11-23.fc33.x86_64 (gdb) (gdb) bt #0 btf__get_nr_types (btf=0x0) at btf.c:425 #1 0x000000000043c4ba in linker_fixup_btf (obj=obj@entry=0x7fffffffda50) at linker.c:1316 #2 0x000000000043caf7 in linker_load_obj_file (linker=linker@entry=0x8612a0, filename=filename@entry=0x7fffffffe0db "/home/jolsa/linux/tools/testing/selftests/bpf/btf_data2.o", obj=obj@entry=0x7fffffffda50) at linker.c:653 #3 0x000000000043df43 in bpf_linker__add_file (linker=linker@entry=0x8612a0, filename=filename@entry=0x7fffffffe0db "/home/jolsa/linux/tools/testing/selftests/bpf/btf_data2.o") at linker.c:412 #4 0x000000000040d710 in do_object (argc=0, argv=0x7fffffffdce0) at gen.c:639 #5 0x000000000040efd7 in cmd_select (cmds=cmds@entry=0x50a600 <cmds>, argc=3, argv=0x7fffffffdcc8, help=help@entry=0x40c6f7 <do_help>) at main.c:134 #6 0x000000000040d7c4 in do_gen (argc=<optimized out>, argv=<optimized out>) at gen.c:686 #7 0x000000000040efd7 in cmd_select (cmds=cmds@entry=0x50b400 <cmds>, argc=4, argv=0x7fffffffdcc0, help=help@entry=0x40ee93 <do_help>) at main.c:134 #8 0x000000000040f88e in main (argc=<optimized out>, argv=<optimized out>) at main.c:469 I'm on current bpf-next/master jirka > + for (i = 1; i <= n; i++) { > + struct btf_var_secinfo *vi; > + struct btf_type *t; > + > + t = btf_type_by_id(obj->btf, i); > + if (btf_kind(t) != BTF_KIND_DATASEC) > + continue; > + > + sec_name = btf__str_by_offset(obj->btf, t->name_off); > + sec = find_src_sec_by_name(obj, sec_name); > + if (sec) { > + /* record actual section size, unless ephemeral */ > + if (sec->shdr) > + t->size = sec->shdr->sh_size; > + } else { > + /* BTF can have some sections that are not represented > + * in ELF, e.g., .kconfig and .ksyms, which are used > + * for special extern variables. Here we'll > + * pre-create "section shells" for them to be able to > + * keep track of extra per-section metadata later > + * (e.g., BTF variables). > + */ > + sec = add_src_sec(obj, sec_name); > + if (!sec) > + return -ENOMEM; > + > + sec->ephemeral = true; > + sec->sec_idx = 0; /* will match UNDEF shndx in ELF */ > + } > + > + /* remember ELF section and its BTF type ID match */ > + sec->sec_type_id = i; > + > + /* fix up variable offsets */ > + vi = btf_var_secinfos(t); > + for (j = 0, m = btf_vlen(t); j < m; j++, vi++) { > + const struct btf_type *vt = btf__type_by_id(obj->btf, vi->type); > + const char *var_name = btf__str_by_offset(obj->btf, vt->name_off); > + int var_linkage = btf_var(vt)->linkage; > + Elf64_Sym *sym; > + > + /* no need to patch up static or extern vars */ > + if (var_linkage != BTF_VAR_GLOBAL_ALLOCATED) > + continue; > + > + sym = find_sym_by_name(obj, sec->sec_idx, STT_OBJECT, var_name); > + if (!sym) { > + pr_warn("failed to find symbol for variable '%s' in section '%s'\n", var_name, sec_name); > + return -ENOENT; > + } > + > + vi->offset = sym->st_value; > + } > + } > + > + return 0; > +} SNIP
next prev parent reply other threads:[~2021-03-19 16:24 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-03-18 19:40 [PATCH v4 bpf-next 00/12] BPF static linking Andrii Nakryiko 2021-03-18 19:40 ` [PATCH v4 bpf-next 01/12] libbpf: expose btf_type_by_id() internally Andrii Nakryiko 2021-03-18 19:40 ` [PATCH v4 bpf-next 02/12] libbpf: generalize BTF and BTF.ext type ID and strings iteration Andrii Nakryiko 2021-03-18 19:40 ` [PATCH v4 bpf-next 03/12] libbpf: rename internal memory-management helpers Andrii Nakryiko 2021-03-18 19:40 ` [PATCH v4 bpf-next 04/12] libbpf: extract internal set-of-strings datastructure APIs Andrii Nakryiko 2021-03-18 19:40 ` [PATCH v4 bpf-next 05/12] libbpf: add generic BTF type shallow copy API Andrii Nakryiko 2021-03-18 19:40 ` [PATCH v4 bpf-next 06/12] libbpf: add BPF static linker APIs Andrii Nakryiko 2021-03-18 19:40 ` [PATCH v4 bpf-next 07/12] libbpf: add BPF static linker BTF and BTF.ext support Andrii Nakryiko 2021-03-19 16:23 ` Jiri Olsa [this message] 2021-03-19 18:39 ` Andrii Nakryiko 2021-03-19 18:58 ` Jiri Olsa 2021-03-28 12:03 ` Jiri Olsa 2021-03-28 18:29 ` Andrii Nakryiko 2021-03-29 11:16 ` Jiri Olsa 2021-03-18 19:40 ` [PATCH v4 bpf-next 08/12] bpftool: add ability to specify custom skeleton object name Andrii Nakryiko 2021-03-18 19:40 ` [PATCH v4 bpf-next 09/12] bpftool: add `gen object` command to perform BPF static linking Andrii Nakryiko 2021-03-18 19:40 ` [PATCH v4 bpf-next 10/12] selftests/bpf: re-generate vmlinux.h and BPF skeletons if bpftool changed Andrii Nakryiko 2021-03-18 19:40 ` [PATCH v4 bpf-next 11/12] selftests/bpf: pass all BPF .o's through BPF static linker Andrii Nakryiko 2021-03-18 19:40 ` [PATCH v4 bpf-next 12/12] selftests/bpf: add multi-file statically linked BPF object file test Andrii Nakryiko 2021-03-18 23:29 ` [PATCH v4 bpf-next 00/12] BPF static linking Alexei Starovoitov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=YFTQExmhNhMcmNOb@krava \ --to=jolsa@redhat.com \ --cc=andrii@kernel.org \ --cc=ast@fb.com \ --cc=bpf@vger.kernel.org \ --cc=daniel@iogearbox.net \ --cc=kernel-team@fb.com \ --cc=netdev@vger.kernel.org \ --subject='Re: [PATCH v4 bpf-next 07/12] libbpf: add BPF static linker BTF and BTF.ext support' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).