Skip to content

Commit 6709a91

Browse files
anakryikoAlexei Starovoitov
authored and
Alexei Starovoitov
committed
libbpf: Support BTF_KIND_FLOAT during type compatibility checks in CO-RE
Add BTF_KIND_FLOAT support when doing CO-RE field type compatibility check. Without this, relocations against float/double fields will fail. Also adjust one error message to emit instruction index instead of less convenient instruction byte offset. Fixes: 22541a9 ("libbpf: Add BTF_KIND_FLOAT support") Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Lorenz Bauer <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 7a2fa70 commit 6709a91

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tools/lib/bpf/libbpf.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -5115,6 +5115,7 @@ bpf_core_find_cands(struct bpf_object *obj, const struct btf *local_btf, __u32 l
51155115
* least one of enums should be anonymous;
51165116
* - for ENUMs, check sizes, names are ignored;
51175117
* - for INT, size and signedness are ignored;
5118+
* - any two FLOATs are always compatible;
51185119
* - for ARRAY, dimensionality is ignored, element types are checked for
51195120
* compatibility recursively;
51205121
* - everything else shouldn't be ever a target of relocation.
@@ -5141,6 +5142,7 @@ static int bpf_core_fields_are_compat(const struct btf *local_btf,
51415142

51425143
switch (btf_kind(local_type)) {
51435144
case BTF_KIND_PTR:
5145+
case BTF_KIND_FLOAT:
51445146
return 1;
51455147
case BTF_KIND_FWD:
51465148
case BTF_KIND_ENUM: {
@@ -6245,8 +6247,8 @@ static int bpf_core_apply_relo(struct bpf_program *prog,
62456247
/* bpf_core_patch_insn() should know how to handle missing targ_spec */
62466248
err = bpf_core_patch_insn(prog, relo, relo_idx, &targ_res);
62476249
if (err) {
6248-
pr_warn("prog '%s': relo #%d: failed to patch insn at offset %d: %d\n",
6249-
prog->name, relo_idx, relo->insn_off, err);
6250+
pr_warn("prog '%s': relo #%d: failed to patch insn #%zu: %d\n",
6251+
prog->name, relo_idx, relo->insn_off / BPF_INSN_SZ, err);
62506252
return -EINVAL;
62516253
}
62526254

0 commit comments

Comments
 (0)