[PATCH V3] gprofng: a new GNU profiler

Sergei Trofimovich slyich@gmail.com
Sat May 21 08:30:57 GMT 2022


On Wed, 1 Sep 2021 11:45:01 -0700
Vladimir Mezentsev via Binutils <binutils@sourceware.org> wrote:

> Hi people!
> 
> 
> 09/01/2021: Changes from V2
> ===========================
> 
>    - Renamed experiment.h to gp-experiment.h (Hannes Domani reported 
> problem on Windows).
>    - Fixed regression in build on ARM.
>    - Improved gprofng/testsuite.
> 
> 
> Where to get gprofng
> ====================
> 
> Due to the size of the contribution, we thought it would be better to 
> submit it in the form
> of a git branch, instead of a regular emailed patch series.
> 
> Repository: https://www.github.com/oracle/binutils-gdb
> Branch:     oracle/gprofng-v3

Hi Vladimir! [Months later] I noticed that gprofng is doing a bit of
indirection in format strings.

Many distributions (including NixOS) build projects with
    CFLAGS/CXXFLAGS=-Werror=format-security
to avoid trivial format string vulnerabilities.

Today's binutils-gdb master fails to build under such a setup.
The rest of binutils is generally -Werror=format-security clean.

Do you think it's something gprofng could support or workaround?

Currently I see the following failures:

../../../gprofng/src/Print.cc: In function 'int print_one_visible(FILE*, char*, char*, char*, TValue*, int)':
../../../gprofng/src/Print.cc:547:35: error: format not a string literal and no format arguments [-Werror=format-security]
  547 |  nc = fprintf (out_file, fmt_real0);
      |                                   ^
../../../gprofng/src/Print.cc:574:35: error: format not a string literal and no format arguments [-Werror=format-security]
  574 |  nc = fprintf (out_file, fmt_real0);
      |                                   ^
../../../gprofng/src/Print.cc: In function 'int print_one_tvisible(FILE*, char*, char*, TValue*, int, int)':
../../../gprofng/src/Print.cc:596:38: error: format not a string literal and no format arguments [-Werror=format-security]
  596 |     nc = fprintf (out_file, fmt_real0);
      |                                      ^
../../../gprofng/src/Print.cc: In function 'void print_one(FILE*, Hist_data*, Hist_data::HistItem*, char**, char**, char**, MetricList*, Metric::HistMetric*, char*, Histable::NameFormat)':
../../../gprofng/src/Print.cc:692:31: error: format not a string literal and no format arguments [-Werror=format-security]
  692 |      nc += fprintf (out_file, stmp);
      |                               ^~~~
../../../gprofng/src/Print.cc: In member function 'void er_print_histogram::dump_detail(int)':
../../../gprofng/src/Print.cc:1044:24: error: format not a string literal and no format arguments [-Werror=format-security]
 1044 |     fprintf (out_file, fmt_real1);
      |                        ^~~~~~~~~
../../../gprofng/src/Print.cc:1051:24: error: format not a string literal and no format arguments [-Werror=format-security]
 1051 |     fprintf (out_file, fmt_int1);
      |                        ^~~~~~~~
../../../gprofng/src/Print.cc:1062:23: error: format not a string literal and no format arguments [-Werror=format-security]
 1062 |    fprintf (out_file, fmt_real1);
      |                       ^~~~~~~~~
../../../gprofng/src/Print.cc:1066:28: error: format not a string literal and no format arguments [-Werror=format-security]
 1066 |         fprintf (out_file, fmt_long1);
      |                            ^~~~~~~~~
../../../gprofng/src/Print.cc:1105:24: error: format not a string literal and no format arguments [-Werror=format-security]
 1105 |     fprintf (out_file, fmt_real1);
      |                        ^~~~~~~~~
../../../gprofng/src/Print.cc: In member function 'void er_print_experiment::overview_value(Value*, ValueTag, double)':
../../../gprofng/src/Print.cc:2616:26: error: format not a string literal and no format arguments [-Werror=format-security]
 2616 |       fprintf (out_file, fmt3);
      |                          ^~~~
cc1plus: some warnings being treated as errors
make[5]: *** [Makefile:870: Print.lo] Error 1
depbase=`echo parse.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`;\
/nix/store/w61p7kw12h9ppxlfy5lsp2k32hcrwg4z-bash-5.1-p16/bin/bash ../libtool  --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I. -I../../../gprofng/src -I..  -U_ASM -DLOCALEDIR=\"/mnt/archive/big/git/binutils-gdb/outputs/out/share/locale\" -I.. -I../../../gprofng/src -I../../../gprofng/src/../common -I../../../gprofng/src/../../include -I../../../gprofng/src/../../opcodes -I../../bfd -I../../../gprofng/src/../../bfd   -Wall -pthread -Wno-format-truncation -Wno-switch -g -O2     -MT parse.lo -MD -MP -MF $depbase.Tpo -c -o parse.lo ../../../gprofng/src/parse.cc &&\
mv -f $depbase.Tpo $depbase.Plo
libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I../../../gprofng/src -I.. -U_ASM -DLOCALEDIR=\"/mnt/archive/big/git/binutils-gdb/outputs/out/share/locale\" -I.. -I../../../gprofng/src -I../../../gprofng/src/../common -I../../../gprofng/src/../../include -I../../../gprofng/src/../../opcodes -I../../bfd -I../../../gprofng/src/../../bfd -Wall -pthread -Wno-format-truncation -Wno-switch -g -O2 -MT parse.lo -MD -MP -MF .deps/parse.Tpo -c ../../../gprofng/src/parse.cc -o parse.o
../../../gprofng/src/parse.cc: In member function 'virtual int Experiment::process_Linux_kernel_cmd(hrtime_t)':
../../../gprofng/src/parse.cc:909:40: error: format not a string literal and no format arguments [-Werror=format-security]
  909 |    sprintf (last_mod_name, mod_name_ptr);
      |                                        ^

Thanks!

-- 

  Sergei


More information about the Binutils mailing list