Re: [PATCH v2 11/10] objtool: Even more complex static block checks

From: Josh Poimboeuf
Date: Tue Jan 16 2018 - 22:12:53 EST


On Tue, Jan 16, 2018 at 08:49:17PM +0100, Peter Zijlstra wrote:
> Subject: objtool: Even more complex static block checks
> From: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Date: Tue Jan 16 20:17:01 CET 2018
>
> I've observed GCC transform:
>
> f()
> {
> if (!static_branch_unlikely())
> return;
>
> static_assert();
> A;
> }
>
> g()
> {
> f();
> }
>
> Into:
>
> f()
> {
> static_assert();
> A;
> }
>
> g()
> {
> if (static_branch_unlikely())
> f();
> }
>
> Which results in the assertion landing at f+0. The transformation is
> valid and useful; it avoids a pointless CALL+RET sequence, so we'll
> have to teach objtool how to deal with this.
>
> Do this by marking all CALL destinations with static_call when called
> from a static_block and non_static_call when called outside a
> static_block. This allows us to identify functions called exclusively
> from a static_block and start them with a static_block.

Ew... where'd you place the assertion to trigger this?

It's late and my brain has already clocked out, so I'll need to revisit
this tomorrow. But now I'm wondering if my basic block idea would be a
better way to solve this.

--
Josh