Re: [PATCH v2 10/10] objtool: More complex static jump implementation

From: Peter Zijlstra
Date: Tue Jan 16 2018 - 10:20:56 EST


On Tue, Jan 16, 2018 at 03:28:35PM +0100, Peter Zijlstra wrote:
> +static int grow_static_blocks(struct objtool_file *file)
> +{
> + struct instruction *insn;
> + bool static_block = false;
> +
> + for_each_insn(file, insn) {
> + if (!static_block && !insn->static_jump_dest)
> + continue;
> +
> + if (insn->static_jump_dest) {
> + static_block = true;
> + continue;
> + }
> +
> + if (insn->branch_target) {
> + static_block = false;
> + continue;
> + } else switch (insn->type) {
> + case INSN_JUMP_CONDITIONAL:
> + case INSN_JUMP_DYNAMIC:

Hmm, I think I also should have added INSN_JUMP_UNCONDITIONAL here,
because the for_each_insn() iteration simply iterates through the entire
file in linear order, it doesn't actually _follow_ the jumps.

So this would result in code after the unconditional jump also being
marked static (although very likely it ends up being a branch target and
thus stops it through that).

/me updates.

> + case INSN_CALL:
> + case INSN_CALL_DYNAMIC:
> + case INSN_RETURN:
> + case INSN_BUG:
> + static_block = false;
> + continue;
> + }
> +
> + insn->static_jump_dest = static_block;
> + }
> +
> + return 0;
> +}