Thread (32 messages) 32 messages, 4 authors, 2021-02-26

Re: [PATCH bpf-next v3 08/11] libbpf: support subprog address relocation

From: Andrii Nakryiko <hidden>
Date: 2021-02-25 23:05:28

On Thu, Feb 25, 2021 at 1:35 AM Yonghong Song [off-list ref] wrote:
A new relocation RELO_SUBPROG_ADDR is added to capture
subprog addresses loaded with ld_imm64 insns. Such ld_imm64
insns are marked with BPF_PSEUDO_FUNC and will be passed to
kernel. For bpf_for_each_map_elem() case, kernel will
check that the to-be-used subprog address must be a static
function and replace it with proper actual jited func address.

Signed-off-by: Yonghong Song <redacted>
---
 tools/lib/bpf/libbpf.c | 64 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 61 insertions(+), 3 deletions(-)
LGTM. I'll still need to relax it a bit more for static functions, but
it can come as part of static linker work.

Acked-by: Andrii Nakryiko <andrii@kernel.org>

[...]
+static bool sym_is_subprog(const GElf_Sym *sym, int text_shndx)
+{
+       int bind = GELF_ST_BIND(sym->st_info);
+       int type = GELF_ST_TYPE(sym->st_info);
+
+       /* in .text section */
+       if (sym->st_shndx != text_shndx)
+               return false;
+
+       /* local function */
+       if (bind == STB_LOCAL && type == STT_SECTION)
+               return true;
+
+       /* global function */
+       return bind == STB_GLOBAL && type == STT_FUNC;
theoretically STT_FUNC could be STB_LOCAL here, though Clang doesn't
emit it that way today. It will be easy to fix later, though. Just
mentioning, because I intend to have STB_LOCAL + STT_FUNC relocations
with BPF static linker.
+}
+
 static int find_extern_btf_id(const struct btf *btf, const char *ext_name)
 {
        const struct btf_type *t;
[...]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help