public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Jianlin Lv <Jianlin.Lv@arm.com>
Cc: john.garry@huawei.com, will@kernel.org,
	mathieu.poirier@linaro.org, leo.yan@linaro.org,
	peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
	mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
	namhyung@kernel.org, irogers@google.com, agerstmayr@redhat.com,
	kan.liang@linux.intel.com, adrian.hunter@intel.com,
	iecedge@gmail.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] perf tools: Fix arm64 build error with gcc-11
Date: Mon, 15 Feb 2021 13:22:38 +0100	[thread overview]
Message-ID: <YCpnji8ukXa06iBU@krava> (raw)
In-Reply-To: <20210213050516.1221523-1-Jianlin.Lv@arm.com>

On Sat, Feb 13, 2021 at 01:05:16PM +0800, Jianlin Lv wrote:
> gcc version: 11.0.0 20210208 (experimental) (GCC)
> 
> Following build error on arm64:
> 
> .......
> In function ‘printf’,
>     inlined from ‘regs_dump__printf’ at util/session.c:1141:3,
>     inlined from ‘regs__printf’ at util/session.c:1169:2:
> /usr/include/aarch64-linux-gnu/bits/stdio2.h:107:10: \
>   error: ‘%-5s’ directive argument is null [-Werror=format-overflow=]
> 
> 107 |   return __printf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, \
>                 __va_arg_pack ());
> 
> ......
> In function ‘fprintf’,
>   inlined from ‘perf_sample__fprintf_regs.isra’ at \
>     builtin-script.c:622:14:
> /usr/include/aarch64-linux-gnu/bits/stdio2.h:100:10: \
>     error: ‘%5s’ directive argument is null [-Werror=format-overflow=]
>   100 |   return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,
>   101 |                         __va_arg_pack ());
> 
> cc1: all warnings being treated as errors
> .......
> 
> This patch fixes Wformat-overflow warnings. Add ternary operator,
> The statement evaluates to "Unknown" if reg_name==NULL is met.
> 
> Signed-off-by: Jianlin Lv <Jianlin.Lv@arm.com>

Acked-by: Jiri Olsa <jolsa@redhat.com>

thanks,
jirka

> ---
> v2: Add ternary operator to avoid similar errors in other arch.
> v3: Declared reg_name in inner block.
> ---
>  tools/perf/builtin-script.c                            | 4 +++-
>  tools/perf/util/scripting-engines/trace-event-python.c | 3 ++-
>  tools/perf/util/session.c                              | 3 ++-
>  3 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index 42dad4a0f8cf..0d52dc45b1c7 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -643,7 +643,9 @@ static int perf_sample__fprintf_regs(struct regs_dump *regs, uint64_t mask,
>  
>  	for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) {
>  		u64 val = regs->regs[i++];
> -		printed += fprintf(fp, "%5s:0x%"PRIx64" ", perf_reg_name(r), val);
> +		const char *reg_name = perf_reg_name(r);
> +
> +		printed += fprintf(fp, "%5s:0x%"PRIx64" ", reg_name ?: "unknown", val);
>  	}
>  
>  	return printed;
> diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
> index c83c2c6564e0..768bdd4240f4 100644
> --- a/tools/perf/util/scripting-engines/trace-event-python.c
> +++ b/tools/perf/util/scripting-engines/trace-event-python.c
> @@ -699,10 +699,11 @@ static int regs_map(struct regs_dump *regs, uint64_t mask, char *bf, int size)
>  
>  	for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) {
>  		u64 val = regs->regs[i++];
> +		const char *reg_name = perf_reg_name(r);
>  
>  		printed += scnprintf(bf + printed, size - printed,
>  				     "%5s:0x%" PRIx64 " ",
> -				     perf_reg_name(r), val);
> +				     reg_name ?: "unknown", val);
>  	}
>  
>  	return printed;
> diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
> index 25adbcce0281..2b40f1c431a3 100644
> --- a/tools/perf/util/session.c
> +++ b/tools/perf/util/session.c
> @@ -1138,9 +1138,10 @@ static void regs_dump__printf(u64 mask, u64 *regs)
>  
>  	for_each_set_bit(rid, (unsigned long *) &mask, sizeof(mask) * 8) {
>  		u64 val = regs[i++];
> +		const char *reg_name = perf_reg_name(rid);
>  
>  		printf(".... %-5s 0x%016" PRIx64 "\n",
> -		       perf_reg_name(rid), val);
> +		       reg_name ?: "unknown", val);
>  	}
>  }
>  
> -- 
> 2.25.1
> 


  reply	other threads:[~2021-02-15 12:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-13  5:05 [PATCH v3] perf tools: Fix arm64 build error with gcc-11 Jianlin Lv
2021-02-15 12:22 ` Jiri Olsa [this message]
2021-02-16  9:22   ` John Garry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YCpnji8ukXa06iBU@krava \
    --to=jolsa@redhat.com \
    --cc=Jianlin.Lv@arm.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=agerstmayr@redhat.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=iecedge@gmail.com \
    --cc=irogers@google.com \
    --cc=john.garry@huawei.com \
    --cc=kan.liang@linux.intel.com \
    --cc=leo.yan@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.poirier@linaro.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox