public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/3] gprofng: Support build with older versions of GCC
@ 2022-03-15 16:22 H.J. Lu
  2022-03-15 16:22 ` [PATCH 1/3] gprofng: Define ATTRIBUTE_FALLTHROUGH H.J. Lu
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: H.J. Lu @ 2022-03-15 16:22 UTC (permalink / raw)
  To: binutils

Don't hardcode __attribute__ ((fallthrough)), -Wno-nonnull-compare,
-Wno-format-truncation nor -Wno-switch.  Use them only if they are
supported.

H.J. Lu (3):
  gprofng: Define ATTRIBUTE_FALLTHROUGH
  gprofng: Don't hardcode -Wno-nonnull-compare
  gprofng: Don't hardcode -Wno-format-truncation/-Wno-switch

 gprofng/Makefile.in               |   2 +
 gprofng/common/gp-defs.h          |   8 ++
 gprofng/configure                 | 122 +++++++++++++++++++++++++++++-
 gprofng/configure.ac              |   4 +
 gprofng/libcollector/Makefile.am  |   2 +-
 gprofng/libcollector/Makefile.in  |   3 +-
 gprofng/libcollector/aclocal.m4   |   1 +
 gprofng/libcollector/configure    |  64 +++++++++++++++-
 gprofng/libcollector/configure.ac |   3 +
 gprofng/src/Makefile.am           |   5 +-
 gprofng/src/Makefile.in           |   8 +-
 gprofng/src/gp-collect-app.cc     |   2 +-
 12 files changed, 213 insertions(+), 11 deletions(-)

-- 
2.35.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] gprofng: Define ATTRIBUTE_FALLTHROUGH
  2022-03-15 16:22 [PATCH 0/3] gprofng: Support build with older versions of GCC H.J. Lu
@ 2022-03-15 16:22 ` H.J. Lu
  2022-03-15 20:10   ` Jose E. Marchesi
  2022-03-15 16:22 ` [PATCH 2/3] gprofng: Don't hardcode -Wno-nonnull-compare H.J. Lu
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: H.J. Lu @ 2022-03-15 16:22 UTC (permalink / raw)
  To: binutils

Define ATTRIBUTE_FALLTHROUGH to __attribute__ ((fallthrough)) only for
GCC 7 or above.

	PR gprof/28969
	* common/gp-defs.h (ATTRIBUTE_FALLTHROUGH): New.
	* src/gp-collect-app.cc (collect::check_args): Replace
	__attribute__ ((fallthrough)) with ATTRIBUTE_FALLTHROUGH.
---
 gprofng/common/gp-defs.h      | 8 ++++++++
 gprofng/src/gp-collect-app.cc | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/gprofng/common/gp-defs.h b/gprofng/common/gp-defs.h
index 440bfb1c5e2..e92c33e101b 100644
--- a/gprofng/common/gp-defs.h
+++ b/gprofng/common/gp-defs.h
@@ -55,4 +55,12 @@
 #define WSIZE_32            1
 #endif
 
+#ifndef ATTRIBUTE_FALLTHROUGH
+# if (GCC_VERSION >= 7000)
+#  define ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__))
+# else
+#  define ATTRIBUTE_FALLTHROUGH	/* Fall through */
+# endif
+#endif
+
 #endif
diff --git a/gprofng/src/gp-collect-app.cc b/gprofng/src/gp-collect-app.cc
index afaae70bc2b..34874b8c296 100644
--- a/gprofng/src/gp-collect-app.cc
+++ b/gprofng/src/gp-collect-app.cc
@@ -848,7 +848,7 @@ collect::check_args (int argc, char *argv[])
 	  }
 	case 'O':
 	  overwriteExp = true;
-	  __attribute__ ((fallthrough));
+	  ATTRIBUTE_FALLTHROUGH
 	case 'o':
 	  if (precheck == 1)
 	    {
-- 
2.35.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/3] gprofng: Don't hardcode -Wno-nonnull-compare
  2022-03-15 16:22 [PATCH 0/3] gprofng: Support build with older versions of GCC H.J. Lu
  2022-03-15 16:22 ` [PATCH 1/3] gprofng: Define ATTRIBUTE_FALLTHROUGH H.J. Lu
@ 2022-03-15 16:22 ` H.J. Lu
  2022-03-15 16:22 ` [PATCH 3/3] gprofng: Don't hardcode -Wno-format-truncation/-Wno-switch H.J. Lu
  2022-03-16  0:49 ` [PATCH 0/3] gprofng: Support build with older versions of GCC Alan Modra
  3 siblings, 0 replies; 6+ messages in thread
From: H.J. Lu @ 2022-03-15 16:22 UTC (permalink / raw)
  To: binutils

Use -Wno-nonnull-compare only if it is supported.

	PR gprof/28969
	* libcollector/Makefile.am (AM_CFLAGS): Replace
	-Wno-nonnull-compare with GPROFNG_NO_NONNULL_COMPARE_CFLAGS.
	* libcollector/configure.ac (GPROFNG_NO_NONNULL_COMPARE_CFLAGS):
	New AC_SUBST for -Wno-nonnull-compare.
	* libcollector/Makefile.in: Regenerate.
	* libcollector/aclocal.m4: Likewise.
	* libcollector/configure: Likewise.
---
 gprofng/libcollector/Makefile.am  |  2 +-
 gprofng/libcollector/Makefile.in  |  3 +-
 gprofng/libcollector/aclocal.m4   |  1 +
 gprofng/libcollector/configure    | 64 ++++++++++++++++++++++++++++++-
 gprofng/libcollector/configure.ac |  3 ++
 5 files changed, 69 insertions(+), 4 deletions(-)

diff --git a/gprofng/libcollector/Makefile.am b/gprofng/libcollector/Makefile.am
index bd86e97753d..2827963b7ed 100644
--- a/gprofng/libcollector/Makefile.am
+++ b/gprofng/libcollector/Makefile.am
@@ -41,7 +41,7 @@ CSOURCES = \
 	collector.c \
 	$(NULL)
 
-AM_CFLAGS = $(GPROFNG_CFLAGS) -Wno-nonnull-compare
+AM_CFLAGS = $(GPROFNG_CFLAGS) $(GPROFNG_NO_NONNULL_COMPARE_CFLAGS)
 AM_CPPFLAGS = $(GPROFNG_CPPFLAGS) -I.. -I$(srcdir) \
 	-I$(srcdir)/../common -I$(srcdir)/../src \
 	-I$(srcdir)/../../include
diff --git a/gprofng/libcollector/Makefile.in b/gprofng/libcollector/Makefile.in
index 920c7a7ad11..3e5030d76ad 100644
--- a/gprofng/libcollector/Makefile.in
+++ b/gprofng/libcollector/Makefile.in
@@ -322,6 +322,7 @@ ECHO_T = @ECHO_T@
 EGREP = @EGREP@
 EXEEXT = @EXEEXT@
 FGREP = @FGREP@
+GPROFNG_NO_NONNULL_COMPARE_CFLAGS = @GPROFNG_NO_NONNULL_COMPARE_CFLAGS@
 GPROFNG_VARIANT = @GPROFNG_VARIANT@
 GREP = @GREP@
 INSTALL = @INSTALL@
@@ -435,7 +436,7 @@ CSOURCES = \
 	collector.c \
 	$(NULL)
 
-AM_CFLAGS = $(GPROFNG_CFLAGS) -Wno-nonnull-compare
+AM_CFLAGS = $(GPROFNG_CFLAGS) $(GPROFNG_NO_NONNULL_COMPARE_CFLAGS)
 AM_CPPFLAGS = $(GPROFNG_CPPFLAGS) -I.. -I$(srcdir) \
 	-I$(srcdir)/../common -I$(srcdir)/../src \
 	-I$(srcdir)/../../include
diff --git a/gprofng/libcollector/aclocal.m4 b/gprofng/libcollector/aclocal.m4
index b269c739e73..2d13dba8c20 100644
--- a/gprofng/libcollector/aclocal.m4
+++ b/gprofng/libcollector/aclocal.m4
@@ -1230,6 +1230,7 @@ AC_SUBST([am__untar])
 m4_include([../../config/depstand.m4])
 m4_include([../../config/lead-dot.m4])
 m4_include([../../config/override.m4])
+m4_include([../../config/warnings.m4])
 m4_include([../../libtool.m4])
 m4_include([../../ltoptions.m4])
 m4_include([../../ltsugar.m4])
diff --git a/gprofng/libcollector/configure b/gprofng/libcollector/configure
index ed23350d7b6..40ab929857b 100755
--- a/gprofng/libcollector/configure
+++ b/gprofng/libcollector/configure
@@ -633,6 +633,7 @@ ac_subst_vars='am__EXEEXT_FALSE
 am__EXEEXT_TRUE
 LTLIBOBJS
 LIBOBJS
+GPROFNG_NO_NONNULL_COMPARE_CFLAGS
 GPROFNG_VARIANT
 CXXCPP
 OTOOL64
@@ -12013,7 +12014,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12016 "configure"
+#line 12017 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12119,7 +12120,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12122 "configure"
+#line 12123 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -15437,6 +15438,65 @@ case "${target}" in
 esac
 
 
+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_NONNULL_COMPARE_CFLAGS=
+save_CFLAGS="$CFLAGS"
+for real_option in -Wno-nonnull-compare; 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_NONNULL_COMPARE_CFLAGS="$GPROFNG_NO_NONNULL_COMPARE_CFLAGS${GPROFNG_NO_NONNULL_COMPARE_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_config_files="$ac_config_files Makefile"
 
 ac_config_headers="$ac_config_headers lib-config.h:../common/config.h.in"
diff --git a/gprofng/libcollector/configure.ac b/gprofng/libcollector/configure.ac
index 8acd66f6977..e12d6917148 100644
--- a/gprofng/libcollector/configure.ac
+++ b/gprofng/libcollector/configure.ac
@@ -54,6 +54,9 @@ case "${target}" in
 esac
 AC_SUBST(GPROFNG_VARIANT)
 
+ACX_PROG_CC_WARNING_OPTS([-Wno-nonnull-compare], [GPROFNG_NO_NONNULL_COMPARE_CFLAGS])
+AC_SUBST(GPROFNG_NO_NONNULL_COMPARE_CFLAGS)
+
 AC_CONFIG_FILES([Makefile])
 AC_CONFIG_HEADERS([lib-config.h:../common/config.h.in])
 AC_OUTPUT
-- 
2.35.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/3] gprofng: Don't hardcode -Wno-format-truncation/-Wno-switch
  2022-03-15 16:22 [PATCH 0/3] gprofng: Support build with older versions of GCC H.J. Lu
  2022-03-15 16:22 ` [PATCH 1/3] gprofng: Define ATTRIBUTE_FALLTHROUGH H.J. Lu
  2022-03-15 16:22 ` [PATCH 2/3] gprofng: Don't hardcode -Wno-nonnull-compare H.J. Lu
@ 2022-03-15 16:22 ` H.J. Lu
  2022-03-16  0:49 ` [PATCH 0/3] gprofng: Support build with older versions of GCC Alan Modra
  3 siblings, 0 replies; 6+ messages in thread
From: H.J. Lu @ 2022-03-15 16:22 UTC (permalink / raw)
  To: binutils

Use -Wno-format-truncation and -Wno-switch only if they are supported.

	PR gprof/28969
	* configure.ac (GPROFNG_NO_FORMAT_TRUNCATION_CFLAGS): New
	AC_SUBST for -Wno-format-truncation.
	(GPROFNG_NO_SWITCH_CFLAGS): New AC_SUBST for -Wno-switch.
	* Makefile.in: Regenerate.
	* configure: Likewise.
	* src/Makefile.am (AM_CFLAGS): Replace -Wno-format-truncation
	and -Wno-switch with GPROFNG_NO_FORMAT_TRUNCATION_CFLAGS and
	GPROFNG_NO_SWITCH_CFLAGS.
	* src/Makefile.in: Regenerate.
---
 gprofng/Makefile.in     |   2 +
 gprofng/configure       | 122 +++++++++++++++++++++++++++++++++++++++-
 gprofng/configure.ac    |   4 ++
 gprofng/src/Makefile.am |   5 +-
 gprofng/src/Makefile.in |   8 ++-
 5 files changed, 135 insertions(+), 6 deletions(-)

diff --git a/gprofng/configure.ac b/gprofng/configure.ac
index 394e8b8837c..54a4279d6f5 100644
--- a/gprofng/configure.ac
+++ b/gprofng/configure.ac
@@ -42,6 +42,8 @@ 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=
 build_src=
@@ -190,6 +192,8 @@ AM_CONDITIONAL([BUILD_MAN], [test x$build_man = xtrue])
 
 AC_SUBST(LD_NO_AS_NEEDED, [${no_as_needed}])
 AC_SUBST(GPROFNG_CFLAGS, [${gprofng_cflags}])
+AC_SUBST(GPROFNG_NO_FORMAT_TRUNCATION_CFLAGS)
+AC_SUBST(GPROFNG_NO_SWITCH_CFLAGS)
 AC_SUBST(GPROFNG_CPPFLAGS, [${gprofng_cppflags}])
 AC_SUBST(GPROFNG_LIBDIR, [${libdir}])
 
diff --git a/gprofng/src/Makefile.am b/gprofng/src/Makefile.am
index b874b5b32aa..84fd1df9a44 100644
--- a/gprofng/src/Makefile.am
+++ b/gprofng/src/Makefile.am
@@ -102,8 +102,9 @@ AM_CPPFLAGS = $(GPROFNG_CPPFLAGS) -DLOCALEDIR=\"@localedir@\" -I.. -I$(srcdir) \
 	-I$(srcdir)/../common \
 	-I$(srcdir)/../../include -I$(srcdir)/../../opcodes \
 	-I../../bfd -I$(srcdir)/../../bfd
-AM_CFLAGS = $(GPROFNG_CFLAGS) $(PTHREAD_CFLAGS) -Wno-switch \
-	-Wno-format-truncation
+AM_CFLAGS = $(GPROFNG_CFLAGS) $(PTHREAD_CFLAGS) \
+	$(GPROFNG_NO_FORMAT_TRUNCATION_CFLAGS) \
+	$(GPROFNG_NO_SWITCH_CFLAGS)
 AM_CXXFLAGS = $(AM_CFLAGS)
 
 man_MANS = gprofng.1 \
-- 
2.35.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] gprofng: Define ATTRIBUTE_FALLTHROUGH
  2022-03-15 16:22 ` [PATCH 1/3] gprofng: Define ATTRIBUTE_FALLTHROUGH H.J. Lu
@ 2022-03-15 20:10   ` Jose E. Marchesi
  0 siblings, 0 replies; 6+ messages in thread
From: Jose E. Marchesi @ 2022-03-15 20:10 UTC (permalink / raw)
  To: H.J. Lu via Binutils



> Define ATTRIBUTE_FALLTHROUGH to __attribute__ ((fallthrough)) only for
> GCC 7 or above.
>
> 	PR gprof/28969
> 	* common/gp-defs.h (ATTRIBUTE_FALLTHROUGH): New.
> 	* src/gp-collect-app.cc (collect::check_args): Replace
> 	__attribute__ ((fallthrough)) with ATTRIBUTE_FALLTHROUGH.

Oh sorry HJ I just pushed the patch below as obvious because I couldn't
build gprofng with GCC 6.  Didnt see your patch here which is better.

commit 6aa03e9c1769c8d925f4d23d72af93483bfd31f3
Author: Jose E. Marchesi <jose.marchesi@oracle.com>
Date:   Tue Mar 15 21:04:57 2022 +0100

    gprofng: avoid using `fallthrough' attributes
    
    gprofng didn't build with gcc 6.3 due to the usage of __attribute__
    ((fallthrough)).  This patch uses /* FALLTHROUGH */ instead.
    
    2022-03-15  Jose E. Marchesi  <jose.marchesi@oracle.com>
    
            * gprofng/src/gp-collect-app.cc (collect::check_args): Use
            fallthrough comment instead of attribute.

diff --git a/ChangeLog b/ChangeLog
index 73b6085d6ef..dfe468c0af4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2022-03-15  Jose E. Marchesi  <jose.marchesi@oracle.com>
+
+	* gprofng/src/gp-collect-app.cc (collect::check_args): Use
+	fallthrough comment instead of attribute.
+
 2022-03-11  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>
 
 	* Makefile.def: Add gprofng module.
diff --git a/gprofng/src/gp-collect-app.cc b/gprofng/src/gp-collect-app.cc
index afaae70bc2b..a40cf8fb9be 100644
--- a/gprofng/src/gp-collect-app.cc
+++ b/gprofng/src/gp-collect-app.cc
@@ -848,7 +848,7 @@ collect::check_args (int argc, char *argv[])
 	  }
 	case 'O':
 	  overwriteExp = true;
-	  __attribute__ ((fallthrough));
+          /* FALLTHROUGH */
 	case 'o':
 	  if (precheck == 1)
 	    {

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] gprofng: Support build with older versions of GCC
  2022-03-15 16:22 [PATCH 0/3] gprofng: Support build with older versions of GCC H.J. Lu
                   ` (2 preceding siblings ...)
  2022-03-15 16:22 ` [PATCH 3/3] gprofng: Don't hardcode -Wno-format-truncation/-Wno-switch H.J. Lu
@ 2022-03-16  0:49 ` Alan Modra
  3 siblings, 0 replies; 6+ messages in thread
From: Alan Modra @ 2022-03-16  0:49 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On Tue, Mar 15, 2022 at 09:22:01AM -0700, H.J. Lu via Binutils wrote:
> Don't hardcode __attribute__ ((fallthrough)), -Wno-nonnull-compare,
> -Wno-format-truncation nor -Wno-switch.  Use them only if they are
> supported.

Looks fine to me.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-03-16  0:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-15 16:22 [PATCH 0/3] gprofng: Support build with older versions of GCC H.J. Lu
2022-03-15 16:22 ` [PATCH 1/3] gprofng: Define ATTRIBUTE_FALLTHROUGH H.J. Lu
2022-03-15 20:10   ` Jose E. Marchesi
2022-03-15 16:22 ` [PATCH 2/3] gprofng: Don't hardcode -Wno-nonnull-compare H.J. Lu
2022-03-15 16:22 ` [PATCH 3/3] gprofng: Don't hardcode -Wno-format-truncation/-Wno-switch H.J. Lu
2022-03-16  0:49 ` [PATCH 0/3] gprofng: Support build with older versions of GCC Alan Modra

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