Big props to you for braving the bowels of the objtool code.

On Mon, Jan 15, 2018 at 05:44:29PM +0100, Peter Zijlstra wrote:
> +static int read_jump_assertions(struct objtool_file *file)

This does more than just _read_ the assertions.  Can you call it
something like assert_static_jumps() or do_static_jump_assertions() and
then call it from the main check() function?

> +{
> +     struct section *sec, *relasec;
> +     struct instruction *insn;
> +     struct rela *rela;
> +     int i;
> +
> +     sec = find_section_by_name(file->elf, ".discard.jump_assert");
> +     if (!sec)
> +             return 0;
> +
> +     relasec = sec->rela;
> +     if (!relasec) {
> +             WARN("missing .rela.discard.jump_assert section");
> +             return -1;
> +     }
> +
> +     if (sec->len % sizeof(unsigned long)) {
> +             WARN("jump_assert size mismatch: %d %ld", sec->len, 
> sizeof(unsigned long));
> +             return -1;
> +     }
> +
> +     for (i = 0; i < sec->len / sizeof(unsigned long); i++) {
> +             rela = find_rela_by_dest(sec, i * sizeof(unsigned long));
> +             if (!rela) {
> +                     WARN("can't find rela for jump_assert[%d]", i);
> +                     return -1;
> +             }
> +
> +             insn = find_insn(file, rela->sym->sec, rela->addend);
> +             if (!insn) {
> +                     WARN("can't find insn for jump_assert[%d]", i);
> +                     return -1;
> +             }
> +
> +             if (!insn->br_static) {
> +                     WARN_FUNC("static assert FAIL", insn->sec, 
> insn->offset);
> +                     return -1;
> +             }
> +     }
> +
> +     return 0;
> +}
> +
>  static int decode_sections(struct objtool_file *file)
>  {
>       int ret;
> @@ -1105,6 +1167,10 @@ static int decode_sections(struct objtoo
>       if (ret)
>               return ret;
>  
> +     ret = read_jump_assertions(file);
> +     if (ret)
> +             return ret;
> +
>       return 0;
>  }
>  
> --- a/tools/objtool/check.h
> +++ b/tools/objtool/check.h
> @@ -45,6 +45,7 @@ struct instruction {
>       unsigned char type;
>       unsigned long immediate;
>       bool alt_group, visited, dead_end, ignore, hint, save, restore, 
> ignore_alts;
> +     bool br_static;

s/br_static/static_jump_dest/?

Also, fellow objtool expert, you forgot the patch to the MAINTAINERS
file ;-)

-- 
Josh

Reply via email to