Re: [PATCH bpf-next 00/10] libbpf: support custom .rodata.*/.data.* sections

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Oct 08, 2021 at 05:32:59AM IST, andrii.nakryiko@xxxxxxxxx wrote:
> From: Andrii Nakryiko <andrii@xxxxxxxxxx>
>
> [...]
> One interesting possibility that is now open by these changes is that it's
> possible to do:
>
>     bpf_trace_printk("My fmt %s", sizeof("My fmt %s"), "blah");
>
> and it will work as expected. I haven't updated libbpf-provided helpers in
> bpf_helpers.h for snprintf, seq_printf, and printk, because using
> `static const char ___fmt[] = fmt;` trick is still efficient and doesn't fill
> out the buffer at runtime (no copying), but it also enforces that format
> string is compile-time string literal:
>
>     const char *s = NULL;
>
>     bpf_printk("hi"); /* works */
>     bpf_printk(s); /* compilation error */
>
> By passing fmt directly to bpf_trace_printk() would actually compile
> bpf_printk(s) above with no warnings and will not work at runtime, which is
> worse user experience, IMO.
>

You could try the following (_Static_assert would probably be preferable, but
IDK if libbpf can use it).

#define IS_ARRAY(x) ({ sizeof(int[-__builtin_types_compatible_p(typeof(x), typeof(&*(x)))]); 1; })

In action: https://godbolt.org/z/4d4W61YPf

--
Kartikeya



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux