Re: [PATCH] perf tools: Replace zero-length array with flexible-array

From: Gustavo A. R. Silva
Date: Wed May 13 2020 - 17:25:34 EST


On Wed, May 13, 2020 at 02:03:56PM -0700, Ian Rogers wrote:
> On Tue, May 12, 2020 at 10:59 AM Gustavo A. R. Silva
> <gustavoars@xxxxxxxxxx> wrote:
> >
> > On Tue, May 12, 2020 at 10:06:07AM +0200, Peter Zijlstra wrote:
> > > On Mon, May 11, 2020 at 07:04:04PM -0500, Gustavo A. R. Silva wrote:
> > > > On Mon, May 11, 2020 at 05:20:08PM -0300, Arnaldo Melo wrote:
> > > > >
> > > > > Thanks, applied
> > > > >
> > > >
> > > > Thanks, Arnaldo.
> > > >
> > > > I wonder if could also take the other two:
> > > >
> > > > 20200511200911.GA13149@embeddedor/">https://lore.kernel.org/lkml/20200511200911.GA13149@embeddedor/
> > > > 20200511201227.GA14041@embeddedor/">https://lore.kernel.org/lkml/20200511201227.GA14041@embeddedor/
> > >
> > > I think I have those, but let me make sure.
> >
> > Great. :)
>
>
> Thanks for the cleanup! It has yielded a clang compiler warning/error
> for me in kernel/git/acme/linux.git branch perf/core:
>
> util/intel-pt.c:1802:24: error: field 'br_stack' with variable sized
> type 'struct branch_stack' not
> at the end of a struct or class is a GNU extension
> [-Werror,-Wgnu-variable-sized-type-not-at-end]
> struct branch_stack br_stack;
>
> I think this can be resolved by reordering the members of the struct,
> and may have been a latent bug exposed by this change. It's
> unfortunate it has broken this build.
>

Yep. The following should resolve the issue:

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index f17b1e769ae4..b34179e3926f 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1799,8 +1799,8 @@ static int intel_pt_synth_pebs_sample(struct intel_pt_queue *ptq)

if (sample_type & PERF_SAMPLE_BRANCH_STACK) {
struct {
- struct branch_stack br_stack;
struct branch_entry entries[LBRS_MAX];
+ struct branch_stack br_stack;
} br;

if (items->mask[INTEL_PT_LBR_0_POS] ||

I'll send a proper patch.

Thanks for the report!
--
Gustavo