This reverts commit 9abe2c42ecab6c86b54838d2d645ca2e10204606. The commit made btf_rewrite_str() make every base of the destination modifiable before taking a pointer to the source string, because looking the string up in a base made it modifiable and freed its raw data. Since commit efeb5ab5753d ("libbpf: Look up BTF strings without making BTF modifiable"), the lookup leaves the raw data in place, so the pointer stays valid. Making a base modifiable fails for BTF with unknown header-extension bytes. With the loop in place, btf__add_type() and btf__add_btf() into a split over such a base fail with -EOPNOTSUPP, and so does bpftool when it merges module BTFs over it: $ bpftool -B base.btf btf dump file mod1.btf file mod2.btf format raw Error: failed to merge BTF from mod1.btf: Operation not supported Suggested-by: BPF CI bot Link: https://lore.kernel.org/bpf/e0df4fa9e17514c79de41ee9fd2eb610d43a95741fb994db160b35fd488f054a@mail.kernel.org/ Signed-off-by: Ihor Solodrai --- tools/lib/bpf/btf.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 0984a8ccb526..448ee6acf519 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -2232,7 +2232,6 @@ struct btf_pipe { static int btf_rewrite_str(struct btf_pipe *p, __u32 *str_off) { - struct btf *base; long mapped_off; int off, err; @@ -2245,19 +2244,6 @@ static int btf_rewrite_str(struct btf_pipe *p, __u32 *str_off) return 0; } - /* - * btf__add_str() first looks the string up in the base BTFs of dst, - * which makes each of them modifiable and frees its raw data. If src - * shares a base with dst and the string lives in that base, the - * pointer taken below would be left dangling. So make the bases - * modifiable before the pointer is taken. - */ - for (base = p->dst->base_btf; base; base = base->base_btf) { - err = btf_ensure_modifiable(base); - if (err) - return err; - } - off = btf__add_str(p->dst, btf__str_by_offset(p->src, *str_off)); if (off < 0) return off; base-commit: 3e18218484126afb9da722080659c038cb2256ab -- 2.56.0