From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2041) id BBA4C386C58C; Fri, 17 Jun 2022 03:47:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBA4C386C58C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Vladimir Mezentsev To: bfd-cvs@sourceware.org, gdb-cvs@sourceware.org Subject: [binutils-gdb] gprofng: fix build with -Werror=format-truncation X-Act-Checkin: binutils-gdb X-Git-Author: Vladimir Mezentsev X-Git-Refname: refs/heads/master X-Git-Oldrev: 97032db708aa116191269ddbe51fe032e86742b7 X-Git-Newrev: 14e283ff4e0656327179a5b69954796af3807b66 Message-Id: <20220617034714.BBA4C386C58C@sourceware.org> Date: Fri, 17 Jun 2022 03:47:14 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Jun 2022 03:47:14 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D14e283ff4e06= 56327179a5b69954796af3807b66 commit 14e283ff4e0656327179a5b69954796af3807b66 Author: Vladimir Mezentsev Date: Thu Jun 16 12:31:05 2022 -0700 gprofng: fix build with -Werror=3Dformat-truncation =20 gprofng/ChangeLog 2022-06-16 Vladimir Mezentsev =20 * configure.ac: Remove -Wno-format-truncation. * src/Makefile.am: Likewise. * configure: Rebuild. * src/Makefile.in: Rebuild. * common/hwctable.c: Fix -Werror=3Dformat-truncation errors. * src/ipc.cc: Likewise. * src/parse.cc: Likewise. Diff: --- gprofng/common/hwctable.c | 28 +++++++--------------- gprofng/configure | 59 +------------------------------------------= ---- gprofng/configure.ac | 1 - gprofng/src/Makefile.am | 1 - gprofng/src/Makefile.in | 1 - gprofng/src/ipc.cc | 45 +++++++++++------------------------- gprofng/src/parse.cc | 7 ++++-- 7 files changed, 27 insertions(+), 115 deletions(-) diff --git a/gprofng/common/hwctable.c b/gprofng/common/hwctable.c index a1422b63c11..61101baed2b 100644 --- a/gprofng/common/hwctable.c +++ b/gprofng/common/hwctable.c @@ -4520,29 +4520,23 @@ static char * hwc_hwcentry_string_internal (char *buf, size_t buflen, const Hwcentry *ct= r, int show_short_desc) { - char stderrbuf[1024]; char regnolist[256]; if (!buf || !buflen) return buf; - buf[0] =3D 0; if (ctr =3D=3D NULL) { - snprintf (stderrbuf, sizeof (stderrbuf), GTXT ("HW counter not avail= able")); - goto hwc_hwcentry_string_done; + snprintf (buf, buflen, GTXT ("HW counter not available")); + return buf; } char *desc =3D NULL; if (show_short_desc) desc =3D ctr->short_desc; if (desc =3D=3D NULL) desc =3D ctr->metric ? hwc_i18n_metric (ctr) : NULL; - format_columns (stderrbuf, sizeof (stderrbuf), ctr->name, ctr->int_name, + format_columns (buf, buflen, ctr->name, ctr->int_name, hwc_memop_string (ctr->memop), timecvt_string (ctr->timecvt), get_regnolist (regnolist, sizeof (regnolist), ctr->reg_list, 2), desc); - -hwc_hwcentry_string_done: - strncpy (buf, stderrbuf, buflen - 1); - buf[buflen - 1] =3D 0; return buf; } =20 @@ -4557,16 +4551,14 @@ hwc_hwcentry_string (char *buf, size_t buflen, cons= t Hwcentry *ctr) extern char * hwc_hwcentry_specd_string (char *buf, size_t buflen, const Hwcentry *ctr) { - char stderrbuf[1024]; const char *memop, *timecvt; char descstr[1024]; if (!buf || !buflen) return buf; - buf[0] =3D 0; if (ctr =3D=3D NULL) { - snprintf (stderrbuf, sizeof (stderrbuf), GTXT ("HW counter not avail= able")); - goto hwc_hwcentry_specd_string_done; + snprintf (buf, buflen, GTXT ("HW counter not available")); + return buf; } timecvt =3D timecvt_string (ctr->timecvt); if (ctr->memop) @@ -4574,19 +4566,15 @@ hwc_hwcentry_specd_string (char *buf, size_t buflen= , const Hwcentry *ctr) else memop =3D ""; if (ctr->metric !=3D NULL) /* a standard counter for a specific registe= r */ - snprintf (descstr, sizeof (descstr), GTXT (" (`%s'; %s%s)"), + snprintf (descstr, sizeof (descstr), " (`%s'; %s%s)", hwc_i18n_metric (ctr), memop, timecvt); else /* raw counter */ - snprintf (descstr, sizeof (descstr), GTXT (" (%s%s)"), memop, timecvt); + snprintf (descstr, sizeof (descstr), " (%s%s)", memop, timecvt); =20 char *rateString =3D hwc_rate_string (ctr, 1); - snprintf (stderrbuf, sizeof (stderrbuf), NTXT ("%s,%s%s"), ctr->name, + snprintf (buf, buflen, "%s,%s%s", ctr->name, rateString ? rateString : "", descstr); free (rateString); - -hwc_hwcentry_specd_string_done: - strncpy (buf, stderrbuf, buflen - 1); - buf[buflen - 1] =3D 0; return buf; } =20 diff --git a/gprofng/configure b/gprofng/configure index d0345ecdfbc..a0d723990bf 100755 --- a/gprofng/configure +++ b/gprofng/configure @@ -636,6 +636,7 @@ LIBOBJS BUILD_SUBDIRS CLOCK_GETTIME_LINK GPROFNG_CPPFLAGS +GPROFNG_NO_FORMAT_TRUNCATION_CFLAGS GPROFNG_CFLAGS LD_NO_AS_NEEDED BUILD_MAN_FALSE @@ -662,7 +663,6 @@ BUILD_SRC_TRUE BUILD_COLLECTOR_FALSE BUILD_COLLECTOR_TRUE GPROFNG_NO_SWITCH_CFLAGS -GPROFNG_NO_FORMAT_TRUNCATION_CFLAGS gprofng_cflags WERROR GPROFNG_LIBADD @@ -15662,63 +15662,6 @@ ac_link=3D'$CC -o conftest$ac_exeext $CFLAGS $CPPF= LAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=3D$ac_cv_c_compiler_gnu =20 =20 -ac_ext=3Dc -ac_cpp=3D'$CPP $CPPFLAGS' -ac_compile=3D'$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link=3D'$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$= ac_ext $LIBS >&5' -ac_compiler_gnu=3D$ac_cv_c_compiler_gnu - -GPROFNG_NO_FORMAT_TRUNCATION_CFLAGS=3D -save_CFLAGS=3D"$CFLAGS" -for real_option in -Wno-format-truncation; do - # Do the check with the no- prefix removed since gcc silently - # accepts any -Wno-* option on purpose - case $real_option in - -Wno-*) option=3D-W`expr x$real_option : 'x-Wno-\(.*\)'` ;; - *) option=3D$real_option ;; - esac - as_acx_Woption=3D`$as_echo "acx_cv_prog_cc_warning_$option" | $as_tr_sh` - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports $= option" >&5 -$as_echo_n "checking whether $CC supports $option... " >&6; } -if eval \${$as_acx_Woption+:} false; then : - $as_echo_n "(cached) " >&6 -else - CFLAGS=3D"$option" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - eval "$as_acx_Woption=3Dyes" -else - eval "$as_acx_Woption=3Dno" -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -fi -eval ac_res=3D\$$as_acx_Woption - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - if test `eval 'as_val=3D${'$as_acx_Woption'};$as_echo "$as_val"'` =3D ye= s; then : - GPROFNG_NO_FORMAT_TRUNCATION_CFLAGS=3D"$GPROFNG_NO_FORMAT_TRUNCATION_CFL= AGS${GPROFNG_NO_FORMAT_TRUNCATION_CFLAGS:+ }$real_option" -fi - done -CFLAGS=3D"$save_CFLAGS" -ac_ext=3Dc -ac_cpp=3D'$CPP $CPPFLAGS' -ac_compile=3D'$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link=3D'$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$= ac_ext $LIBS >&5' -ac_compiler_gnu=3D$ac_cv_c_compiler_gnu - - ac_ext=3Dc ac_cpp=3D'$CPP $CPPFLAGS' ac_compile=3D'$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' diff --git a/gprofng/configure.ac b/gprofng/configure.ac index 63b505c5e14..5a0fe1ea477 100644 --- a/gprofng/configure.ac +++ b/gprofng/configure.ac @@ -48,7 +48,6 @@ AC_SUBST(GPROFNG_LIBADD) =20 ACX_PROG_CC_WARNINGS_ARE_ERRORS([manual]) ACX_PROG_CC_WARNING_OPTS([-Wall], [gprofng_cflags]) -ACX_PROG_CC_WARNING_OPTS([-Wno-format-truncation], [GPROFNG_NO_FORMAT_TRUN= CATION_CFLAGS]) ACX_PROG_CC_WARNING_OPTS([-Wno-switch], [GPROFNG_NO_SWITCH_CFLAGS]) gprofng_cppflags=3D"-U_ASM" build_collector=3D diff --git a/gprofng/src/Makefile.am b/gprofng/src/Makefile.am index 0718ab61162..f2bd0a04a9a 100644 --- a/gprofng/src/Makefile.am +++ b/gprofng/src/Makefile.am @@ -109,7 +109,6 @@ AM_CPPFLAGS =3D $(GPROFNG_CPPFLAGS) -DLOCALEDIR=3D\"@lo= caledir@\" -I.. -I$(srcdir) \ -I$(srcdir)/../../include -I$(srcdir)/../../opcodes \ -I../../bfd -I$(srcdir)/../../bfd $(ZLIBINC) AM_CFLAGS =3D $(GPROFNG_CFLAGS) $(PTHREAD_CFLAGS) \ - $(GPROFNG_NO_FORMAT_TRUNCATION_CFLAGS) \ $(GPROFNG_NO_SWITCH_CFLAGS) AM_CXXFLAGS =3D $(AM_CFLAGS) =20 diff --git a/gprofng/src/Makefile.in b/gprofng/src/Makefile.in index 1de9b36c2b7..5101b3930fa 100644 --- a/gprofng/src/Makefile.in +++ b/gprofng/src/Makefile.in @@ -540,7 +540,6 @@ AM_CPPFLAGS =3D $(GPROFNG_CPPFLAGS) -DLOCALEDIR=3D\"@lo= caledir@\" -I.. -I$(srcdir) \ -I../../bfd -I$(srcdir)/../../bfd $(ZLIBINC) =20 AM_CFLAGS =3D $(GPROFNG_CFLAGS) $(PTHREAD_CFLAGS) \ - $(GPROFNG_NO_FORMAT_TRUNCATION_CFLAGS) \ $(GPROFNG_NO_SWITCH_CFLAGS) =20 AM_CXXFLAGS =3D $(AM_CFLAGS) diff --git a/gprofng/src/ipc.cc b/gprofng/src/ipc.cc index edc70256a68..06ba33d5b69 100644 --- a/gprofng/src/ipc.cc +++ b/gprofng/src/ipc.cc @@ -95,11 +95,6 @@ extern "C" /* * Fatal error handlers */ -extern "C" void fatalErrorHadler (int sig, siginfo_t *info, void *context); -extern "C" void sigSEGV_handler (int sig, siginfo_t *info, void *context); -extern "C" void sigABRT_handler (int sig, siginfo_t *info, void *context); -static char fatalErrorBuffer1[1024 * 8]; -static char fatalErrorBuffer2[1024 * 8]; static int fatalErrorCode =3D 1; static int fatalErrorCounter =3D 0; static void *fatalErrorContext =3D 0; @@ -127,38 +122,24 @@ fatalErrorHadler (int sig, siginfo_t *info, void *con= text) // Get process ID pid_t pid =3D getpid (); // Create dump file - snprintf (fatalErrorBuffer1, sizeof (fatalErrorBuffer1), "/tmp/analyzer.= %lld", - (long long) pid); - mkdir (fatalErrorBuffer1, 0700); - snprintf (fatalErrorBuffer1, sizeof (fatalErrorBuffer1), - "/tmp/analyzer.%lld/crash.sig%d.%lld", (long long) pid, sig, - (long long) pid); + char fname[128]; + snprintf (fname, sizeof (fname), "/tmp/gprofng.%lld", (long long) pid); + mkdir (fname, 0700); + snprintf (fname, sizeof (fname), "/tmp/gprofng.%lld/crash.sig%d.%lld", + (long long) pid, sig, (long long) pid); // Dump stack trace in background using pstack - snprintf (fatalErrorBuffer2, sizeof (fatalErrorBuffer2), - "/usr/bin/pstack %lld > %s.pstack", (long long) pid, fatalErrorBuffer= 1); - system (fatalErrorBuffer2); - int fd =3D creat (fatalErrorBuffer1, 0600); + char buf[256]; + snprintf (buf, sizeof (buf), "/usr/bin/pstack %lld > %s.pstack", + (long long) pid, fname); + system (buf); + int fd =3D creat (fname, 0600); if (fd >=3D 0) { // Write error message - snprintf (fatalErrorBuffer2, sizeof (fatalErrorBuffer2), - "A fatal error has been detected by er_print: Signal %lld\n", - (long long) sig); - write (fd, fatalErrorBuffer2, strlen (fatalErrorBuffer2)); -// snprintf (fatalErrorBuffer2, sizeof (fatalErrorBuffer2), -// "If you would like to submit a bug report, please use yo= ur support contract.\n")); -// write(fd, fatalErrorBuffer2, strlen(fatalErrorBuffer2)); - snprintf (fatalErrorBuffer2, sizeof (fatalErrorBuffer2), - "Protocol Version: %d\n", IPC_VERSION_NUMBER); - write (fd, fatalErrorBuffer2, strlen (fatalErrorBuffer2)); + dbe_write (fd, "A fatal error has been detected by er_print: Signal = %d\n", + sig); + dbe_write (fd, "Protocol Version: %d\n", IPC_VERSION_NUMBER); close (fd); - // Send postmortem error message to the GUI - // snprintf(fatalErrorBuffer1, sizeof (fatalErrorBuffer1), - // "%s: %s: /tmp/analyzer.%lld", - // "Unexpected signal in er_print", - // "Crash dump", - // (long long) pid); - // res =3D write(2, fatalErrorBuffer2, strlen(fatalErrorBuffer1)); } wait (0); // wait for pstack //sleep(10); // Wait 10 seconds to make sure processing of fatal error i= s done diff --git a/gprofng/src/parse.cc b/gprofng/src/parse.cc index eaed8ee7349..cdbe0cea9a5 100644 --- a/gprofng/src/parse.cc +++ b/gprofng/src/parse.cc @@ -33,6 +33,7 @@ #include "PRBTree.h" #include "Sample.h" #include "Elf.h" +#include "StringBuilder.h" =20 void Experiment::mrec_insert (MapRecord *mrec) @@ -883,10 +884,12 @@ Experiment::process_Linux_kernel_cmd (hrtime_t ts) =20 if (sym_text) { - char fname[128]; - snprintf (fname, sizeof (fname), "%s`%s", mod_name, sym_name); + StringBuilder sb; + sb.appendf ("%s`%s", mod_name, sym_name); + char *fname =3D sb.toString (); Function *func =3D dbeSession->createFunction (); func->set_name (fname); + free (fname); func->size =3D sym_size; func->img_offset =3D sym_addr; func->module =3D mod;