Re: [PATCH 3/8] objtool: Rework allocating stack_ops on decode
From: Peter Zijlstra
Date: Thu Apr 23 2020 - 12:17:26 EST
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)
Also, the kernel is full of funny macros like this ;-)