public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Vladimir Mezentsev <vmezents@sourceware.org>
To: bfd-cvs@sourceware.org, gdb-cvs@sourceware.org
Subject: [binutils-gdb] gprofng: fix build with -Werror=format-truncation
Date: Fri, 17 Jun 2022 03:47:14 +0000 (GMT)	[thread overview]
Message-ID: <20220617034714.BBA4C386C58C@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=14e283ff4e0656327179a5b69954796af3807b66

commit 14e283ff4e0656327179a5b69954796af3807b66
Author: Vladimir Mezentsev <vladimir.mezentsev@oracle.com>
Date:   Thu Jun 16 12:31:05 2022 -0700

    gprofng: fix build with -Werror=format-truncation
    
    gprofng/ChangeLog
    2022-06-16  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>
    
            * configure.ac: Remove -Wno-format-truncation.
            * src/Makefile.am: Likewise.
            * configure: Rebuild.
            * src/Makefile.in: Rebuild.
            * common/hwctable.c: Fix -Werror=format-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 *ctr,
 			      int show_short_desc)
 {
-  char stderrbuf[1024];
   char regnolist[256];
   if (!buf || !buflen)
     return buf;
-  buf[0] = 0;
   if (ctr == NULL)
     {
-      snprintf (stderrbuf, sizeof (stderrbuf), GTXT ("HW counter not available"));
-      goto hwc_hwcentry_string_done;
+      snprintf (buf, buflen, GTXT ("HW counter not available"));
+      return buf;
     }
   char *desc = NULL;
   if (show_short_desc)
     desc = ctr->short_desc;
   if (desc == NULL)
     desc = 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] = 0;
   return buf;
 }
 
@@ -4557,16 +4551,14 @@ hwc_hwcentry_string (char *buf, size_t buflen, const 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] = 0;
   if (ctr == NULL)
     {
-      snprintf (stderrbuf, sizeof (stderrbuf), GTXT ("HW counter not available"));
-      goto hwc_hwcentry_specd_string_done;
+      snprintf (buf, buflen, GTXT ("HW counter not available"));
+      return buf;
     }
   timecvt = 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 = "";
   if (ctr->metric != NULL)  /* a standard counter for a specific register */
-    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);
 
   char *rateString = 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] = 0;
   return buf;
 }
 
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='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
-GPROFNG_NO_FORMAT_TRUNCATION_CFLAGS=
-save_CFLAGS="$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=-W`expr x$real_option : 'x-Wno-\(.*\)'` ;;
-    *) option=$real_option ;;
-  esac
-  as_acx_Woption=`$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="$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=yes"
-else
-  eval "$as_acx_Woption=no"
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-
-fi
-eval ac_res=\$$as_acx_Woption
-	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
-$as_echo "$ac_res" >&6; }
-  if test `eval 'as_val=${'$as_acx_Woption'};$as_echo "$as_val"'` = yes; then :
-  GPROFNG_NO_FORMAT_TRUNCATION_CFLAGS="$GPROFNG_NO_FORMAT_TRUNCATION_CFLAGS${GPROFNG_NO_FORMAT_TRUNCATION_CFLAGS:+ }$real_option"
-fi
-  done
-CFLAGS="$save_CFLAGS"
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
-
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='$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)
 
 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_TRUNCATION_CFLAGS])
 ACX_PROG_CC_WARNING_OPTS([-Wno-switch], [GPROFNG_NO_SWITCH_CFLAGS])
 gprofng_cppflags="-U_ASM"
 build_collector=
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 = $(GPROFNG_CPPFLAGS) -DLOCALEDIR=\"@localedir@\" -I.. -I$(srcdir) \
 	-I$(srcdir)/../../include -I$(srcdir)/../../opcodes \
 	-I../../bfd -I$(srcdir)/../../bfd $(ZLIBINC)
 AM_CFLAGS = $(GPROFNG_CFLAGS) $(PTHREAD_CFLAGS) \
-	$(GPROFNG_NO_FORMAT_TRUNCATION_CFLAGS) \
 	$(GPROFNG_NO_SWITCH_CFLAGS)
 AM_CXXFLAGS = $(AM_CFLAGS)
 
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 = $(GPROFNG_CPPFLAGS) -DLOCALEDIR=\"@localedir@\" -I.. -I$(srcdir) \
 	-I../../bfd -I$(srcdir)/../../bfd $(ZLIBINC)
 
 AM_CFLAGS = $(GPROFNG_CFLAGS) $(PTHREAD_CFLAGS) \
-	$(GPROFNG_NO_FORMAT_TRUNCATION_CFLAGS) \
 	$(GPROFNG_NO_SWITCH_CFLAGS)
 
 AM_CXXFLAGS = $(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 = 1;
 static int fatalErrorCounter = 0;
 static void *fatalErrorContext = 0;
@@ -127,38 +122,24 @@ fatalErrorHadler (int sig, siginfo_t *info, void *context)
   // Get process ID
   pid_t pid = 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, fatalErrorBuffer1);
-  system (fatalErrorBuffer2);
-  int fd = creat (fatalErrorBuffer1, 0600);
+  char buf[256];
+  snprintf (buf, sizeof (buf), "/usr/bin/pstack %lld > %s.pstack",
+	    (long long) pid, fname);
+  system (buf);
+  int fd = creat (fname, 0600);
   if (fd >= 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 your 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 = write(2, fatalErrorBuffer2, strlen(fatalErrorBuffer1));
     }
   wait (0); // wait for pstack
   //sleep(10); // Wait 10 seconds to make sure processing of fatal error is 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"
 
 void
 Experiment::mrec_insert (MapRecord *mrec)
@@ -883,10 +884,12 @@ Experiment::process_Linux_kernel_cmd (hrtime_t ts)
 
 	  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 = sb.toString ();
 	      Function *func = dbeSession->createFunction ();
 	      func->set_name (fname);
+	      free (fname);
 	      func->size = sym_size;
 	      func->img_offset = sym_addr;
 	      func->module = mod;


                 reply	other threads:[~2022-06-17  3:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220617034714.BBA4C386C58C@sourceware.org \
    --to=vmezents@sourceware.org \
    --cc=bfd-cvs@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).