public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/3] build: Check for -Wimplicit-fallthrough=5 separately
@ 2021-02-17  9:27 tbaeder
  2021-02-17  9:27 ` [PATCH 2/3] build: Check for -Wtrampolines support tbaeder
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: tbaeder @ 2021-02-17  9:27 UTC (permalink / raw)
  To: elfutils-devel

From: Timm Bäder <tbaeder@redhat.com>

GCC accepts the =5, which means it doesn't try to parse any comments
and only accepts the fallthrough attribute in code. Clang does not ever
parse any comments and always wants the fallthrough attribute anyway.
Clang also doesn't accept the =n parameter for -Wimplicit-fallthrough.

Test for =5 separately and use it if supported and fall back to just
-Wimplicit-fallthrough otherwise.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
---
 config/eu.am |  4 ++++
 configure.ac | 12 ++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/config/eu.am b/config/eu.am
index 6c3c444f..e109ffd3 100644
--- a/config/eu.am
+++ b/config/eu.am
@@ -64,8 +64,12 @@ endif
 if HAVE_IMPLICIT_FALLTHROUGH_WARNING
 # Use strict fallthrough. Only __attribute__((fallthrough)) will prevent the
 # warning
+if HAVE_IMPLICIT_FALLTHROUGH_5_WARNING
 IMPLICIT_FALLTHROUGH_WARNING=-Wimplicit-fallthrough=5
 else
+IMPLICIT_FALLTHROUGH_WARNING=-Wimplicit-fallthrough
+endif
+else
 IMPLICIT_FALLTHROUGH_WARNING=
 endif
 
diff --git a/configure.ac b/configure.ac
index d345495d..e56aeb6a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -519,6 +519,18 @@ CFLAGS="$old_CFLAGS"])
 AM_CONDITIONAL(HAVE_IMPLICIT_FALLTHROUGH_WARNING,
 	       [test "x$ac_cv_implicit_fallthrough" != "xno"])
 
+# Check whether the compiler additionally accepts -Wimplicit-fallthrough=5
+# GCC accepts this and 5 means "don't parse any fallthrough comments and
+# only accept the fallthrough attribute"
+AC_CACHE_CHECK([whether the compiler accepts -Wimplicit-fallthrough=5], ac_cv_implicit_fallthrough_5, [dnl
+old_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -Wimplicit-fallthrough=5 -Werror"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
+		  ac_cv_implicit_fallthrough_5=yes, ac_cv_implicit_fallthrough_5=no)
+CFLAGS="$old_CFLAGS"])
+AM_CONDITIONAL(HAVE_IMPLICIT_FALLTHROUGH_5_WARNING,
+	       [test "x$ac_cv_implicit_fallthrough_5" != "xno"])
+
 # Assume the fallthrough attribute is supported if -Wimplict-fallthrough is supported
 if test "$ac_cv_implicit_fallthrough" = "yes"; then
 	AC_DEFINE([HAVE_FALLTHROUGH], [1],
-- 
2.26.2


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

* [PATCH 2/3] build: Check for -Wtrampolines support
  2021-02-17  9:27 [PATCH 1/3] build: Check for -Wimplicit-fallthrough=5 separately tbaeder
@ 2021-02-17  9:27 ` tbaeder
  2021-03-06  2:07   ` Mark Wielaard
  2021-02-17  9:27 ` [PATCH 3/3] build: Check for -Wno-packed-not-aligned support tbaeder
  2021-03-06  1:25 ` [PATCH 1/3] build: Check for -Wimplicit-fallthrough=5 separately Mark Wielaard
  2 siblings, 1 reply; 6+ messages in thread
From: tbaeder @ 2021-02-17  9:27 UTC (permalink / raw)
  To: elfutils-devel

From: Timm Bäder <tbaeder@redhat.com>

Clang does not support -Wtrampolines, so check if the compiler supports
it before using it.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
---
 config/eu.am | 10 ++++++++--
 configure.ac |  9 +++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/config/eu.am b/config/eu.am
index e109ffd3..02512570 100644
--- a/config/eu.am
+++ b/config/eu.am
@@ -73,8 +73,14 @@ else
 IMPLICIT_FALLTHROUGH_WARNING=
 endif
 
+if HAVE_TRAMPOLINES_WARNING
+TRAMPOLINES_WARNING=-Wtrampolines
+else
+TRAMPOLINES_WARNING=
+endif
+
 AM_CFLAGS = -std=gnu99 -Wall -Wshadow -Wformat=2 \
-	    -Wold-style-definition -Wstrict-prototypes -Wtrampolines \
+	    -Wold-style-definition -Wstrict-prototypes $(TRAMPOLINES_WARNING) \
 	    $(LOGICAL_OP_WARNING) $(DUPLICATED_COND_WARNING) \
 	    $(NULL_DEREFERENCE_WARNING) $(IMPLICIT_FALLTHROUGH_WARNING) \
 	    $(if $($(*F)_no_Werror),,-Werror) \
@@ -84,7 +90,7 @@ AM_CFLAGS = -std=gnu99 -Wall -Wshadow -Wformat=2 \
 	    $($(*F)_CFLAGS)
 
 AM_CXXFLAGS = -std=c++11 -Wall -Wshadow \
-	   -Wtrampolines \
+	   $(TRAMPOLINES_WARNING) \
 	   $(LOGICAL_OP_WARNING) $(DUPLICATED_COND_WARNING) \
 	   $(NULL_DEREFERENCE_WARNING) $(IMPLICIT_FALLTHROUGH_WARNING) \
 	   $(if $($(*F)_no_Werror),,-Werror) \
diff --git a/configure.ac b/configure.ac
index e56aeb6a..5f3321aa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -537,6 +537,15 @@ if test "$ac_cv_implicit_fallthrough" = "yes"; then
 		  [Defined if __attribute__((fallthrough)) is supported])
 fi
 
+AC_CACHE_CHECK([whether the compiler accepts -Wtrampolines], ac_cv_trampolines, [dnl
+old_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -Wtrampolines -Werror"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
+		  ac_cv_trampolines=yes, ac_cv_trampolines=no)
+CFLAGS="$old_CFLAGS"])
+AM_CONDITIONAL(HAVE_TRAMPOLINES_WARNING,
+	       [test "x$ac_cv_trampolines" != "xno"])
+
 saved_LIBS="$LIBS"
 AC_SEARCH_LIBS([argp_parse], [argp])
 LIBS="$saved_LIBS"
-- 
2.26.2


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

* [PATCH 3/3] build: Check for -Wno-packed-not-aligned support
  2021-02-17  9:27 [PATCH 1/3] build: Check for -Wimplicit-fallthrough=5 separately tbaeder
  2021-02-17  9:27 ` [PATCH 2/3] build: Check for -Wtrampolines support tbaeder
@ 2021-02-17  9:27 ` tbaeder
  2021-03-06  2:17   ` Mark Wielaard
  2021-03-06  1:25 ` [PATCH 1/3] build: Check for -Wimplicit-fallthrough=5 separately Mark Wielaard
  2 siblings, 1 reply; 6+ messages in thread
From: tbaeder @ 2021-02-17  9:27 UTC (permalink / raw)
  To: elfutils-devel

From: Timm Bäder <tbaeder@redhat.com>

Clang does not support this warning, so check for compiler support
before using it.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
---
 config/eu.am | 10 ++++++++--
 configure.ac |  9 +++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/config/eu.am b/config/eu.am
index 02512570..2c3e4571 100644
--- a/config/eu.am
+++ b/config/eu.am
@@ -79,6 +79,12 @@ else
 TRAMPOLINES_WARNING=
 endif
 
+if HAVE_NO_PACKED_NOT_ALIGNED_WARNING
+NO_PACKED_NOT_ALIGNED_WARNING=-Wno-packed-not-aligned
+else
+NO_PACKED_NOT_ALIGNED_WARNING=
+endif
+
 AM_CFLAGS = -std=gnu99 -Wall -Wshadow -Wformat=2 \
 	    -Wold-style-definition -Wstrict-prototypes $(TRAMPOLINES_WARNING) \
 	    $(LOGICAL_OP_WARNING) $(DUPLICATED_COND_WARNING) \
@@ -86,7 +92,7 @@ AM_CFLAGS = -std=gnu99 -Wall -Wshadow -Wformat=2 \
 	    $(if $($(*F)_no_Werror),,-Werror) \
 	    $(if $($(*F)_no_Wunused),,-Wunused -Wextra) \
 	    $(if $($(*F)_no_Wstack_usage),,$(STACK_USAGE_WARNING)) \
-	    $(if $($(*F)_no_Wpacked_not_aligned),-Wno-packed-not-aligned,) \
+	    $(if $($(*F)_no_Wpacked_not_aligned),$(NO_PACKED_NOT_ALIGNED_WARNING),) \
 	    $($(*F)_CFLAGS)
 
 AM_CXXFLAGS = -std=c++11 -Wall -Wshadow \
@@ -96,7 +102,7 @@ AM_CXXFLAGS = -std=c++11 -Wall -Wshadow \
 	   $(if $($(*F)_no_Werror),,-Werror) \
 	   $(if $($(*F)_no_Wunused),,-Wunused -Wextra) \
 	   $(if $($(*F)_no_Wstack_usage),,$(STACK_USAGE_WARNING)) \
-	   $(if $($(*F)_no_Wpacked_not_aligned),-Wno-packed-not-aligned,) \
+	   $(if $($(*F)_no_Wpacked_not_aligned),$(NO_PACKED_NOT_ALIGNED_WARNING),) \
 	   $($(*F)_CXXFLAGS)
 
 COMPILE.os = $(filter-out -fprofile-arcs -ftest-coverage, $(COMPILE))
diff --git a/configure.ac b/configure.ac
index 5f3321aa..aa8439e8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -546,6 +546,15 @@ CFLAGS="$old_CFLAGS"])
 AM_CONDITIONAL(HAVE_TRAMPOLINES_WARNING,
 	       [test "x$ac_cv_trampolines" != "xno"])
 
+AC_CACHE_CHECK([whether the compiler accepts -Wno-packed-not-aligned], ac_cv_no_packed_not_aligned, [dnl
+old_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -Wno-packed-not-aligned -Werror"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
+		  ac_cv_no_packed_not_aligned=yes, ac_cv_no_packed_not_aligned=no)
+CFLAGS="$old_CFLAGS"])
+AM_CONDITIONAL(HAVE_NO_PACKED_NOT_ALIGNED_WARNING,
+	       [test "x$ac_cv_no_packed_not_aligned" != "xno"])
+
 saved_LIBS="$LIBS"
 AC_SEARCH_LIBS([argp_parse], [argp])
 LIBS="$saved_LIBS"
-- 
2.26.2


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

* Re: [PATCH 1/3] build: Check for -Wimplicit-fallthrough=5 separately
  2021-02-17  9:27 [PATCH 1/3] build: Check for -Wimplicit-fallthrough=5 separately tbaeder
  2021-02-17  9:27 ` [PATCH 2/3] build: Check for -Wtrampolines support tbaeder
  2021-02-17  9:27 ` [PATCH 3/3] build: Check for -Wno-packed-not-aligned support tbaeder
@ 2021-03-06  1:25 ` Mark Wielaard
  2 siblings, 0 replies; 6+ messages in thread
From: Mark Wielaard @ 2021-03-06  1:25 UTC (permalink / raw)
  To: tbaeder, elfutils-devel

Hi Timm,

On Wed, 2021-02-17 at 10:27 +0100, Timm Bäder via Elfutils-devel wrote:
> GCC accepts the =5, which means it doesn't try to parse any comments
> and only accepts the fallthrough attribute in code. Clang does not ever
> parse any comments and always wants the fallthrough attribute anyway.
> Clang also doesn't accept the =n parameter for -Wimplicit-fallthrough.
> 
> Test for =5 separately and use it if supported and fall back to just
> -Wimplicit-fallthrough otherwise.

Looks good, pushed.

Thanks,

Mark


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

* Re: [PATCH 2/3] build: Check for -Wtrampolines support
  2021-02-17  9:27 ` [PATCH 2/3] build: Check for -Wtrampolines support tbaeder
@ 2021-03-06  2:07   ` Mark Wielaard
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Wielaard @ 2021-03-06  2:07 UTC (permalink / raw)
  To: tbaeder, elfutils-devel

Hi Timm,

On Wed, 2021-02-17 at 10:27 +0100, Timm Bäder via Elfutils-devel wrote:
> From: Timm Bäder <tbaeder@redhat.com>
> 
> Clang does not support -Wtrampolines, so check if the compiler
> supports
> it before using it.

Grin. If you don't support creating trampolines, then having a warning
for them (or at least the variant that needs executable stack, which is
really what we are trying to prevent) is probably not a high priority.

Added ChangeLog entries and pushed.

Thanks,

Mark

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

* Re: [PATCH 3/3] build: Check for -Wno-packed-not-aligned support
  2021-02-17  9:27 ` [PATCH 3/3] build: Check for -Wno-packed-not-aligned support tbaeder
@ 2021-03-06  2:17   ` Mark Wielaard
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Wielaard @ 2021-03-06  2:17 UTC (permalink / raw)
  To: tbaeder, elfutils-devel

Hi Timm,

On Wed, 2021-02-17 at 10:27 +0100, Timm Bäder via Elfutils-devel wrote:
> From: Timm Bäder <tbaeder@redhat.com>
> 
> Clang does not support this warning, so check for compiler support
> before using it.

It is somewhat unfortunate that we need to check for -Wno- acceptance
with clang. gcc also doesn't support this warning in all versions, in
the versions that do, it is enabled by -Wall. gcc -Wno-foobarbaz
however is always accepted. The idea is that it is easy to not warn for
something, even if you don't know what something is :)

Anyway, if it is necessary for some compilers then lets add the extra
check. Added ChangeLog entries and pushed.

Cheers,

Mark

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

end of thread, other threads:[~2021-03-06  2:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-17  9:27 [PATCH 1/3] build: Check for -Wimplicit-fallthrough=5 separately tbaeder
2021-02-17  9:27 ` [PATCH 2/3] build: Check for -Wtrampolines support tbaeder
2021-03-06  2:07   ` Mark Wielaard
2021-02-17  9:27 ` [PATCH 3/3] build: Check for -Wno-packed-not-aligned support tbaeder
2021-03-06  2:17   ` Mark Wielaard
2021-03-06  1:25 ` [PATCH 1/3] build: Check for -Wimplicit-fallthrough=5 separately Mark Wielaard

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