On 25/08/26 04:15PM, Anton Protopopov wrote: > On 25/08/25 05:06PM, Eduard Zingerman wrote: > > On Sat, 2025-08-16 at 18:06 +0000, Anton Protopopov wrote: > > > > [...] > > > > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > > > index fe4fc5438678..a5f04544c09c 100644 > > > --- a/tools/lib/bpf/libbpf.c > > > +++ b/tools/lib/bpf/libbpf.c > > > > [...] > > > > > @@ -6101,6 +6124,60 @@ static void poison_kfunc_call(struct bpf_program *prog, int relo_idx, > > > insn->imm = POISON_CALL_KFUNC_BASE + ext_idx; > > > } > > > > > > +static int create_jt_map(struct bpf_object *obj, int off, int size, int adjust_off) > > > +{ > > > + static union bpf_attr attr = { > > > + .map_type = BPF_MAP_TYPE_INSN_ARRAY, > > > + .key_size = 4, > > > + .value_size = sizeof(struct bpf_insn_array_value), > > > + .max_entries = 0, > > > + }; > > > + struct bpf_insn_array_value val = {}; > > > + int map_fd; > > > + int err; > > > + __u32 i; > > > + __u32 *jt; > > > + > > > + attr.max_entries = size / 8; > > > + > > > + map_fd = syscall(__NR_bpf, BPF_MAP_CREATE, &attr, sizeof(attr)); > > > + if (map_fd < 0) > > > + return map_fd; > > > + > > > + jt = (__u32 *)(obj->efile.jumptables_data.d_buf + off); > > ^^^^^^^^^ > > Jump table entries are u64 now, e.g. see test case: > > https://github.com/llvm/llvm-project/blob/39dc3c41e459e6c847c1e45e7e93c53aaf74c1de/llvm/test/CodeGen/BPF/jump_table_swith_stmt.ll#L68 > > > > [...] > > Yes, thanks, I will change it to u64. (Just in case, it works now > because the code happens to work properly on little-endian: it uses > jt[2*i] for i-th element.) > > > > @@ -6389,36 +6481,58 @@ static int append_subprog_relos(struct bpf_program *main_prog, struct bpf_progra > > > > [...] > > > > > static int > > > bpf_object__append_subprog_code(struct bpf_object *obj, struct bpf_program *main_prog, > > > - struct bpf_program *subprog) > > > + struct bpf_program *subprog) > > > { > > > - struct bpf_insn *insns; > > > - size_t new_cnt; > > > - int err; > > > + struct bpf_insn *insns; > > > + size_t new_cnt; > > > + int err; > > > > Could you please extract spaces vs tabs fix for this function as a separate commit? > > Just to make diff easier to read. > > > > [...] > > Sure, sorry, I haven't noticed it. Just in case, this chunk is @@ -6418,6 +6524,17 @@ bpf_object__append_subprog_code(struct bpf_object *obj, struct bpf_program *main err = append_subprog_relos(main_prog, subprog); if (err) return err; + + /* Save subprogram offsets */ + if (main_prog->subprog_cnt == ARRAY_SIZE(main_prog->subprog_sec_off)) { + pr_warn("prog '%s': number of subprogs exceeds %zu\n", + main_prog->name, ARRAY_SIZE(main_prog->subprog_sec_off)); + return -E2BIG; + } + main_prog->subprog_sec_off[main_prog->subprog_cnt] = subprog->sec_insn_off; + main_prog->subprog_off[main_prog->subprog_cnt] = subprog->sub_insn_off; + main_prog->subprog_cnt += 1; + return 0; } (In v2 it will either change to realloc vs. static allocation, or disappear.)