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.
This commit is contained in:
Vladimir Mezentsev 2022-06-16 12:31:05 -07:00
parent 97032db708
commit 14e283ff4e
7 changed files with 27 additions and 115 deletions

View File

@ -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;
}

59
gprofng/configure vendored
View File

@ -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'

View File

@ -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=

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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;