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 10/7/21 5:02 PM, andrii.nakryiko@xxxxxxxxx wrote:

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.

Could you explain what would be the difference vs existing bpf_printk macro?
Why these patches enable above to work ?

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.

What is the example of "compile with no warning and not work at runtime" ?



[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