On Mon, Sep 16, 2024 at 2:18 AM Eduard Zingerman <eddyz87@xxxxxxxxx> wrote: > > Allow a new optional 'Attributes' section to be specified for helper > functions description, e.g.: > > * u32 bpf_get_smp_processor_id(void) > * ... > * Return > * ... > * Attributes > * __bpf_fastcall > * > > Generated header for the example above: > > #ifndef __bpf_fastcall > #if __has_attribute(__bpf_fastcall) > #define __bpf_fastcall __attribute__((bpf_fastcall)) > #else > #define __bpf_fastcall > #endif > #endif > ... > __bpf_fastcall I found it a bit annoying that bpf_helper_defs.h uses __bpf_fastcall static __u32 .... format, while in vmlinux we have single-line (and yeah, note that I put extern in front) extern __bpf_fastcall __u32 ... So I slightly modified bpf_doc.py with my weak Python-fu: diff --git a/scripts/bpf_doc.py b/scripts/bpf_doc.py index db50c8d7d112..f98933a5d38c 100755 --- a/scripts/bpf_doc.py +++ b/scripts/bpf_doc.py @@ -871,9 +871,10 @@ class PrinterHelpers(Printer): print(' *{}{}'.format(' \t' if line else '', line)) print(' */') + print('static ', end='') if helper.attrs: - print(" ".join(helper.attrs)) - print('static %s %s(* const %s)(' % (self.map_type(proto['ret_type']), + print('%s ' % (" ".join(helper.attrs)), end='') + print('%s %s(* const %s)(' % (self.map_type(proto['ret_type']), proto['ret_star'], proto['name']), end='') comma = '' for i, a in enumerate(proto['args']): But now I have: static __bpf_fastcall __u32 (* const bpf_get_smp_processor_id)(void) = (void *) 8; and extern __bpf_fastcall void *bpf_rdonly_cast(const void *obj__ign, u32 btf_id__k) __weak __ksym; and that makes me a touch happier. I hope you don't mind. > static __u32 (* const bpf_get_smp_processor_id)(void) = (void *) 8; > > The following rules apply: > - when present, section must follow 'Return' section; > - attribute names are specified on the line following 'Attribute' > keyword; > - attribute names are separated by spaces; > - section ends with an "empty" line (" *\n"). > > Valid attribute names are recorded in the ATTRS map. > ATTRS maps shortcut attribute name to correct C syntax. > > Signed-off-by: Eduard Zingerman <eddyz87@xxxxxxxxx> > --- > scripts/bpf_doc.py | 50 ++++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 48 insertions(+), 2 deletions(-) > Looks good to me, and I'm not sure there is anything too controversial here, so I went ahead and applied to bpf-next, thanks.