Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Fix arm64 build error with gcc-11

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 helper function to
convert NULL to "unknown".

Signed-off-by: Jianlin Lv <Jianlin.Lv@arm.com>
Reviewed-by: John Garry <john.garry@huawei.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Anju T Sudhakar <anju@linux.vnet.ibm.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: Guo Ren <guoren@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: iecedge@gmail.com
Cc: linux-csky@vger.kernel.org
Cc: linux-riscv@lists.infradead.org
Link: http://lore.kernel.org/lkml/20210218031245.2078492-1-Jianlin.Lv@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jianlin Lv and committed by
Arnaldo Carvalho de Melo
06701297 865eb3fb

+14 -7
+1 -1
tools/perf/arch/arm/include/perf_regs.h
··· 15 15 #define PERF_REG_IP PERF_REG_ARM_PC 16 16 #define PERF_REG_SP PERF_REG_ARM_SP 17 17 18 - static inline const char *perf_reg_name(int id) 18 + static inline const char *__perf_reg_name(int id) 19 19 { 20 20 switch (id) { 21 21 case PERF_REG_ARM_R0:
+1 -1
tools/perf/arch/arm64/include/perf_regs.h
··· 15 15 #define PERF_REG_IP PERF_REG_ARM64_PC 16 16 #define PERF_REG_SP PERF_REG_ARM64_SP 17 17 18 - static inline const char *perf_reg_name(int id) 18 + static inline const char *__perf_reg_name(int id) 19 19 { 20 20 switch (id) { 21 21 case PERF_REG_ARM64_X0:
+1 -1
tools/perf/arch/csky/include/perf_regs.h
··· 15 15 #define PERF_REG_IP PERF_REG_CSKY_PC 16 16 #define PERF_REG_SP PERF_REG_CSKY_SP 17 17 18 - static inline const char *perf_reg_name(int id) 18 + static inline const char *__perf_reg_name(int id) 19 19 { 20 20 switch (id) { 21 21 case PERF_REG_CSKY_A0:
+1 -1
tools/perf/arch/powerpc/include/perf_regs.h
··· 79 79 [PERF_REG_POWERPC_PMC6] = "pmc6", 80 80 }; 81 81 82 - static inline const char *perf_reg_name(int id) 82 + static inline const char *__perf_reg_name(int id) 83 83 { 84 84 return reg_names[id]; 85 85 }
+1 -1
tools/perf/arch/riscv/include/perf_regs.h
··· 19 19 #define PERF_REG_IP PERF_REG_RISCV_PC 20 20 #define PERF_REG_SP PERF_REG_RISCV_SP 21 21 22 - static inline const char *perf_reg_name(int id) 22 + static inline const char *__perf_reg_name(int id) 23 23 { 24 24 switch (id) { 25 25 case PERF_REG_RISCV_PC:
+1 -1
tools/perf/arch/s390/include/perf_regs.h
··· 14 14 #define PERF_REG_IP PERF_REG_S390_PC 15 15 #define PERF_REG_SP PERF_REG_S390_R15 16 16 17 - static inline const char *perf_reg_name(int id) 17 + static inline const char *__perf_reg_name(int id) 18 18 { 19 19 switch (id) { 20 20 case PERF_REG_S390_R0:
+1 -1
tools/perf/arch/x86/include/perf_regs.h
··· 23 23 #define PERF_REG_IP PERF_REG_X86_IP 24 24 #define PERF_REG_SP PERF_REG_X86_SP 25 25 26 - static inline const char *perf_reg_name(int id) 26 + static inline const char *__perf_reg_name(int id) 27 27 { 28 28 switch (id) { 29 29 case PERF_REG_X86_AX:
+7
tools/perf/util/perf_regs.h
··· 33 33 34 34 int perf_reg_value(u64 *valp, struct regs_dump *regs, int id); 35 35 36 + static inline const char *perf_reg_name(int id) 37 + { 38 + const char *reg_name = __perf_reg_name(id); 39 + 40 + return reg_name ?: "unknown"; 41 + } 42 + 36 43 #else 37 44 #define PERF_REGS_MASK 0 38 45 #define PERF_REGS_MAX 0