Re: [PATCH v2 00/14] perf: Stream comparison

From: Jin, Yao
Date: Mon Mar 23 2020 - 09:59:20 EST


Hi Jiri,

On 3/23/2020 7:05 PM, Jiri Olsa wrote:
On Fri, Mar 13, 2020 at 03:11:04PM +0800, Jin Yao wrote:
Sometimes, a small change in a hot function reducing the cycles of
this function, but the overall workload doesn't get faster. It is
interesting where the cycles are moved to.

I'm getting compilation fail:

BUILD: Doing 'make -j1' parallel build
CC util/srclist.o
util/srclist.c: In function âsrclist__node_newâ:
util/srclist.c:388:35: error: â%sâ directive output may be truncated writing up to 4095 bytes into a region of size 4091 [-Werror=format-truncation=]
388 | snprintf(cmd, sizeof(cmd), "diff %s %s",
| ^~
......
456 | ret = init_src_info(b_path, a_path, rel_path, &node->info);
| ~~~~~~
In file included from /usr/include/stdio.h:867,
from util/srclist.c:8:
/usr/include/bits/stdio2.h:67:10: note: â__builtin___snprintf_chkâ output between 7 and 8197 bytes into a destination of size 4096
67 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68 | __bos (__s), __fmt, __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
mv: cannot stat 'util/.srclist.o.tmp': No such file or directory
make[4]: *** [/home/jolsa/kernel/linux-perf/tools/build/Makefile.build:97: util/srclist.o] Error 1
make[3]: *** [/home/jolsa/kernel/linux-perf/tools/build/Makefile.build:139: util] Error 2
make[2]: *** [Makefile.perf:617: perf-in.o] Error 2
make[1]: *** [Makefile.perf:225: sub-make] Error 2
make: *** [Makefile:70: all] Error 2


[jolsa@krava ~]$ gcc --version
gcc (GCC) 9.3.1 20200317 (Red Hat 9.3.1-1)

jirka


Can you help to add following patch on top of the patch-set? Looks we need to check the return value of snprintf for truncation checking.

jinyao@kbl:~/kbl-ws/perf-dev/lck-7589/acme/tools/perf$ git diff
diff --git a/tools/perf/util/srclist.c b/tools/perf/util/srclist.c
index 8060e4855d11..51ca69eaa9fd 100644
--- a/tools/perf/util/srclist.c
+++ b/tools/perf/util/srclist.c
@@ -385,8 +385,12 @@ static int src_info__create_line_mapping(struct src_info *info, char *b_path,
goto out;
}

- snprintf(cmd, sizeof(cmd), "diff %s %s",
- b_path, a_path);
+ ret = snprintf(cmd, PATH_MAX, "diff %s %s",
+ b_path, a_path);
+ if (ret == PATH_MAX) {
+ ret = -1;
+ goto out;
+ }

pr_debug("Execute '%s'\n", cmd);

Thanks
Jin Yao