Hi all,

As I did not get a reply from Stephane I would like to turn this to the 
perfmon2-devel mailing list.
Please see the text below:

Hi Stephane,

I would like to ask for your help.
There is a build problem of PAPI when using gcc/8.

See open issue here:
https://bitbucket.org/icl/papi/issues/51/build-failed-using-gcc-810 
<https://bitbucket.org/icl/papi/issues/51/build-failed-using-gcc-810>


This issue can be fixed very easily by just increasing the buffer size.
As this is part of libpfm4 I would like to address this to you.

The main reason for the build failure is that PAPI converts warnings to errors, 
see:

-Werror (Make the specified warning into an error)
-Wformat-truncation (Warn about calls to formatted input/output functions such 
as snprintf and vsnprintf that might result in output truncation)

And the latest gcc versions message warnings for snprintf if the buffer is too 
small and output might be truncated.


Here a small example:

cat test.c:

int main()
{
  char dirname[256];
  char filename[256];

  strcpy(dirname,"/ccs/home/winklerf/sources");
  strcpy(filename,"frank.txt");
  char pathname[256];

  snprintf(pathname, sizeof(pathname), "%s/%s", dirname, filename);

  puts(pathname);
  return 0;
}

gcc -Werror -Wformat-truncation test.c -o test
[winklerf@login3.summit <mailto:winklerf@login3.summit> sources]$ gcc -Werror 
-Wformat-truncation test.c -o test
test.c: In function 'main':
test.c:17:43: error: '%s' directive output may be truncated writing up to 255 
bytes into a region of size between 0 and 255 [-Werror=format-truncation=]
   snprintf(pathname, sizeof pathname, "%s/%s", dirname, filename);
                                           ^~            ~~~~~~~~
test.c:17:3: note: 'snprintf' output between 2 and 512 bytes into a destination 
of size 256
   snprintf(pathname, sizeof pathname, "%s/%s", dirname, filename);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors


The same happens with PAPI when building with gcc/8:

make[2]: Entering directory 
`/autofs/nccs-svm1_home2/winklerf/sources/papi-5.6.0/src/libpfm4/lib'
gcc  -Wno-override-init  -g -Wall -Werror -Wextra -Wno-unused-parameter -I. 
-I/autofs/nccs-svm1_home2/winklerf/sources/papi-5.6.0/src/libpfm4/lib/../include
 -DCONFIG_PFMLIB_DEBUG -DCONFIG_PFMLIB_OS_LINUX -D_REENTRANT -I. 
-fvisibility=hidden -DCONFIG_PFMLIB_ARCH_POWERPC -I. -c pfmlib_common.c
gcc  -Wno-override-init  -g -Wall -Werror -Wextra -Wno-unused-parameter -I. 
-I/autofs/nccs-svm1_home2/winklerf/sources/papi-5.6.0/src/libpfm4/lib/../include
 -DCONFIG_PFMLIB_DEBUG -DCONFIG_PFMLIB_OS_LINUX -D_REENTRANT -I. 
-fvisibility=hidden -DCONFIG_PFMLIB_ARCH_POWERPC -I. -c pfmlib_perf_event_pmu.c
pfmlib_perf_event_pmu.c: In function 'gen_tracepoint_table':
pfmlib_perf_event_pmu.c:349:36: error: '%s' directive output may be truncated 
writing up to 255 bytes into a region of size between 0 and 4095 
[-Werror=format-truncation=]
   snprintf(d2path, MAXPATHLEN, "%s/%s", debugfs_mnt, d1->d_name);
                                    ^~
pfmlib_perf_event_pmu.c:349:3: note: 'snprintf' output between 2 and 4352 bytes 
into a destination of size 4096
   snprintf(d2path, MAXPATHLEN, "%s/%s", debugfs_mnt, d1->d_name);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pfmlib_perf_event_pmu.c:399:58: error: '%s' directive output may be truncated 
writing up to 255 bytes into a region of size between 0 and 4095 
[-Werror=format-truncation=]
                         snprintf(idpath, MAXPATHLEN, "%s/%s/id", d2path, 
d2->d_name);
                                                          ^~
pfmlib_perf_event_pmu.c:399:25: note: 'snprintf' output between 5 and 4355 
bytes into a destination of size 4096
                         snprintf(idpath, MAXPATHLEN, "%s/%s/id", d2path, 
d2->d_name);
                         
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors


The 2 lines of the following file have to be fixed:

vi src/libpfm4/lib/pfmlib_perf_event_pmu.c

349         snprintf(d2path, MAXPATHLEN + 256, "%s/%s", debugfs_mnt, 
d1->d_name);


399                         snprintf(idpath, MAXPATHLEN + 3 + 256, "%s/%s/id", 
d2path, d2->d_name);

There should be a more general fix, of course. But this is up to you, maybe 
just increase MAXPATHLEN...

Thanks
Frank
_______________________________________________
perfmon2-devel mailing list
perfmon2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perfmon2-devel

Reply via email to