On Wed, Mar 6, 2024 at 2:45 AM Eduard Zingerman <eddyz87@xxxxxxxxx> wrote: > > The intent is to allow libbpf to use SEC("?.struct_ops") to identify > struct_ops maps that are optional, e.g. like in the following BPF code: > > SEC("?.struct_ops") > struct test_ops optional_map = { ... }; > > Which yields the following BTF: > > ... > [13] DATASEC '?.struct_ops' size=0 vlen=... > ... > > To load such BTF libbpf rewrites DATASEC name before load. > After this patch the rewrite won't be necessary. > > Signed-off-by: Eduard Zingerman <eddyz87@xxxxxxxxx> > --- > kernel/bpf/btf.c | 16 +++++++++++++++- > 1 file changed, 15 insertions(+), 1 deletion(-) > > diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c > index 6ff0bd1a91d5..170d017e8e4a 100644 > --- a/kernel/bpf/btf.c > +++ b/kernel/bpf/btf.c > @@ -809,9 +809,23 @@ static bool btf_name_valid_identifier(const struct btf *btf, u32 offset) > return __btf_name_valid(btf, offset); We should just rename __btf_name_valid() into btf_name_valid_indentifier() and use that everywhere. Please consider a clean up patch as a follow up, thanks! > } > > +/* Allow any printable character in DATASEC names */ > static bool btf_name_valid_section(const struct btf *btf, u32 offset) > { > - return __btf_name_valid(btf, offset); > + /* offset must be valid */ > + const char *src = btf_str_by_offset(btf, offset); > + const char *src_limit; > + > + /* set a limit on identifier length */ > + src_limit = src + KSYM_NAME_LEN; > + src++; > + while (*src && src < src_limit) { > + if (!isprint(*src)) > + return false; > + src++; > + } > + > + return !*src; > } > > static const char *__btf_name_by_offset(const struct btf *btf, u32 offset) > -- > 2.43.0 >