Re: [PATCH 3/8] objtool: Rework allocating stack_ops on decode

From: Miroslav Benes
Date: Fri Apr 24 2020 - 05:43:16 EST


On Thu, 23 Apr 2020, Peter Zijlstra wrote:

> On Thu, Apr 23, 2020 at 05:40:38PM +0200, Alexandre Chartre wrote:
> >
> > On 4/23/20 2:47 PM, Peter Zijlstra wrote:
> > > Wrap each stack_op in a macro that allocates and adds it to the list.
> > > This simplifies trying to figure out what to do with the pre-allocated
> > > stack_op at the end.
> > >
> > > Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
> > > ---
> > > tools/objtool/arch/x86/decode.c | 257 +++++++++++++++++++++++-----------------
> > > 1 file changed, 153 insertions(+), 104 deletions(-)
> > >
> > > --- a/tools/objtool/arch/x86/decode.c
> > > +++ b/tools/objtool/arch/x86/decode.c
> > > @@ -77,6 +77,17 @@ unsigned long arch_jump_destination(stru
> > > return insn->offset + insn->len + insn->immediate;
> > > }
> > > +#define PUSH_OP(op) \
> > > +({ \
> > > + list_add_tail(&op->list, ops_list); \
> > > + NULL; \
> > > +})
> > > +
> > > +#define ADD_OP(op) \
> > > + if (!(op = calloc(1, sizeof(*op)))) \
> > > + return -1; \
> > > + else for (; op; op = PUSH_OP(op))
> > > +
> >
> > I would better have a function to alloc+add op instead of weird macros,
> > for example:
>
> I know it'll not make you feel (much) better, but we can write it
> shorter:
>
> +#define ADD_OP(op) \
> + if (!(op = calloc(1, sizeof(*op)))) \
> + return -1; \
> + else for (list_add_tail(&op->list, ops_list); op; op = NULL)

FWIW, I like this version the best.

Miroslav