Re: Forcing compiler to "respect" verifier needs


Gianluca Borello <g.borello@...>
 

On Fri, Nov 3, 2017 at 11:36 AM, Gianluca Borello <g.borello@...> wrote:

And I couldn't find a way to force the compiler into emitting those
instructions.
FYI, it's definitely controversial and ugly but I have a dirty
workaround after a few hours of experiments that temporarily allows me
to do what I want.

By declaring the variable where I keep offsets for range accesses
"volatile" (e.g. "len" in my previous example), I can force them to be
spilled/restored at every access and thus force the compiler into not
making any assumption about the variable afterwards.

This causes a whole lot more instructions to be generated and it's
inefficient, but as a byproduct the compiler will now not assume it
knows the value of the variable anymore, so I can do range checks
again using &= for each access and be deterministically sure they'll
not be removed or shuffled around at compile time, and the verifier
will be happy.

I'm sure this bloated code will have other disadvantages (and haven't
seen any such usage in bcc), so if there are other cleaner suggestions
I'll eagerly hear them, but in the meantime using volatile
fundamentally fixes both the examples I sent earlier and it's been a
joy writing BPF programs for the past couple hours.

Thanks

Join iovisor-dev@lists.iovisor.org to automatically receive all group messages.