Skip to contentSkip to conversation

Fix ACL_CHECK_ADD_COMPILE_FLAGS to work with clang

PATCH Superseded [email protected]... 6 participants 12 messages Nov 14, 2019 – Nov 27, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix ACL_CHECK_ADD_COMPILE_FLAGS to work with clang

From: Selva Nair <[email protected]...>

Some compilers (e.g., clang) only issue a warning for unsupported options unless additional flags such as -Werror are used to convert the warning to an error.

Add support for extra flags in ACL_CHECK_ADD_COMPILE_FLAGS.

Note: a similar approach is used in AX_CHECK_COMPILE_FLAG in autoconf archives.

---

For successful travis build result see
https://travis-ci.org/selvanair/openvpn/builds/612019849

But this + https://patchwork.openvpn.net/patch/908/
alone does not fix the travis build as clang is not happy with struct initializers: Like this

crypto.c:1860:31: error: suggest braces around initialization of subobject

      [-Werror,-Wmissing-braces]
    struct key server_key = { 0 };

I think clang wants {{0}} there.

Darn compilers and darn -Werror :)

 configure.ac | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
configure.ac +10 -7
index 807804e5..e59bd91b 100644
@@ -1275,18 +1275,21 @@ if test "${enable_pkcs11}" = "yes"; then
 	)
 fi
 
+# Usage: ACL_CHECK_ADD_COMPILE_FLAGS(flag, [extra-flags])
+# Some compilers require extra flags to trigger an error on
+# unsupported options. E.g., clang requires -Werror.
 AC_DEFUN([ACL_CHECK_ADD_COMPILE_FLAGS], [
     old_cflags="$CFLAGS"
-    CFLAGS="$1 $CFLAGS"
-    AC_MSG_CHECKING([whether the compiler acceppts $1])
-    AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [AC_MSG_RESULT([yes])],
+    CFLAGS="$2 $1 $CFLAGS"
+    AC_MSG_CHECKING([whether the compiler accepts $1])
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [AC_MSG_RESULT([yes])]; CFLAGS="$1 $old_cflags",
         [AC_MSG_RESULT([no]); CFLAGS="$old_cflags"])]
 )
 
-ACL_CHECK_ADD_COMPILE_FLAGS([-Wno-stringop-truncation])
-ACL_CHECK_ADD_COMPILE_FLAGS([-Wno-unused-function])
-ACL_CHECK_ADD_COMPILE_FLAGS([-Wno-unused-parameter])
-ACL_CHECK_ADD_COMPILE_FLAGS([-Wall])
+ACL_CHECK_ADD_COMPILE_FLAGS([-Wno-stringop-truncation], [-Werror])
+ACL_CHECK_ADD_COMPILE_FLAGS([-Wno-unused-function], [-Werror])
+ACL_CHECK_ADD_COMPILE_FLAGS([-Wno-unused-parameter], [-Werror])
+ACL_CHECK_ADD_COMPILE_FLAGS([-Wall], [-Werror])
 
 if test "${enable_pedantic}" = "yes"; then
 	enable_strict="yes"
Signature · 1 line
2.20.1
#1 lore raw

Thank you for your efforts.
As you are touching this, can you try "dist: bionic" ? It might bring newer compilers

Quoted 76 lines · On Thu, Nov 14, 2019, 8:41 PM <[email protected]...> wrote:

From: Selva Nair <[email protected]...>

Some compilers (e.g., clang) only issue a warning for unsupported options unless additional flags such as -Werror are used to convert the warning to an error.

Add support for extra flags in ACL_CHECK_ADD_COMPILE_FLAGS.

Note: a similar approach is used in AX_CHECK_COMPILE_FLAG in autoconf archives.

---

For successful travis build result see
https://travis-ci.org/selvanair/openvpn/builds/612019849

But this + https://patchwork.openvpn.net/patch/908/
alone does not fix the travis build as clang is not happy with struct initializers: Like this

crypto.c:1860:31: error: suggest braces around initialization of subobject

      [-Werror,-Wmissing-braces]
    struct key server_key = { 0 };

I think clang wants {{0}} there.

Darn compilers and darn -Werror :)

 configure.ac | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
configure.ac +10 -7
index 807804e5..e59bd91b 100644
@@ -1275,18 +1275,21 @@ if test "${enable_pkcs11}" = "yes"; then
        )
 fi
 
+# Usage: ACL_CHECK_ADD_COMPILE_FLAGS(flag, [extra-flags])
+# Some compilers require extra flags to trigger an error on
+# unsupported options. E.g., clang requires -Werror.
 AC_DEFUN([ACL_CHECK_ADD_COMPILE_FLAGS], [
     old_cflags="$CFLAGS"
-    CFLAGS="$1 $CFLAGS"
-    AC_MSG_CHECKING([whether the compiler acceppts $1])
-    AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [AC_MSG_RESULT([yes])],
+    CFLAGS="$2 $1 $CFLAGS"
+    AC_MSG_CHECKING([whether the compiler accepts $1])
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [AC_MSG_RESULT([yes])];
 CFLAGS="$1 $old_cflags",
         [AC_MSG_RESULT([no]); CFLAGS="$old_cflags"])]
 )
 
-ACL_CHECK_ADD_COMPILE_FLAGS([-Wno-stringop-truncation])
-ACL_CHECK_ADD_COMPILE_FLAGS([-Wno-unused-function])
-ACL_CHECK_ADD_COMPILE_FLAGS([-Wno-unused-parameter])
-ACL_CHECK_ADD_COMPILE_FLAGS([-Wall])
+ACL_CHECK_ADD_COMPILE_FLAGS([-Wno-stringop-truncation], [-Werror])
+ACL_CHECK_ADD_COMPILE_FLAGS([-Wno-unused-function], [-Werror])
+ACL_CHECK_ADD_COMPILE_FLAGS([-Wno-unused-parameter], [-Werror])
+ACL_CHECK_ADD_COMPILE_FLAGS([-Wall], [-Werror])
 
 if test "${enable_pedantic}" = "yes"; then

enable_strict="yes"
--
2.20.1

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

author
#2 lore raw

Hi,

Quoted 4 lines · Илья Шипицин

Thank you for your efforts.
As you are touching this, can you try "dist: bionic" ? It might bring newer compilers

I don't expect newer compilers on bionic break this patch. But fwiw, I've started a travis build with dist: bionic. For results see
https://travis-ci.org/selvanair/openvpn/jobs/612099524

Selva

#3 lore raw
In reply to [email protected]...
Quoted 10 lines · On 14/11/2019 20:40, [email protected]... wrote:

From: Selva Nair <[email protected]...>

Some compilers (e.g., clang) only issue a warning for unsupported options unless additional flags such as -Werror are used to convert the warning to an error.

Add support for extra flags in ACL_CHECK_ADD_COMPILE_FLAGS.

Note: a similar approach is used in AX_CHECK_COMPILE_FLAG in autoconf archives.

I'm glad I didn't spend more time on thinking about this earlier today, as you have almost the same ideas as I had :)

[...snip...]

configure.ac if test "${enable_pkcs11}" = "yes"; then · line 1285

Quoted 12 lines
configure.ac +6 -3
+# Usage: ACL_CHECK_ADD_COMPILE_FLAGS(flag, [extra-flags])
+# Some compilers require extra flags to trigger an error on
+# unsupported options. E.g., clang requires -Werror.
 AC_DEFUN([ACL_CHECK_ADD_COMPILE_FLAGS], [
     old_cflags="$CFLAGS"
-    CFLAGS="$1 $CFLAGS"
-    AC_MSG_CHECKING([whether the compiler acceppts $1])
-    AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [AC_MSG_RESULT([yes])],
+    CFLAGS="$2 $1 $CFLAGS"
+    AC_MSG_CHECKING([whether the compiler accepts $1])
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [AC_MSG_RESULT([yes])]; CFLAGS="$1 $old_cflags",

My idea was just to add -Werror right in the line above, and not extend the ACL_CHECK_ADD_COMPILE_FLAGS macro with another argument.

But I stopped when I realized that GCC has some quirks as well, as I needed to ponder about this a bit.

Clang is fairly consistent:

* first with an unknown -Wno-* argument

$ clang-6.0 -o test test.c -Wall -Wno-non-existing-flag
warning: unknown warning option '-Wno-non-existing-flag'; did you mean
      '-Wno-non-virtual-dtor'? [-Wunknown-warning-option]
$ clang-6.0 -o test test.c -Wall -Wno-non-existing-flag  -Werror
error: unknown warning option '-Wno-non-existing-flag'; did you mean
      '-Wno-non-virtual-dtor'? [-Werror,-Wunknown-warning-option]

* then with an unknown -W* argument (without the no- prefix)

$ clang-6.0 -o test test.c -Wall -Wnon-existing-flag
warning: unknown warning option '-Wnon-existing-flag'; did you mean
      '-Wnon-virtual-dtor'? [-Wunknown-warning-option]
$ clang-6.0 -o test test.c -Wall -Wnon-existing-flag  -Werror
error: unknown warning option '-Wnon-existing-flag'; did you mean
      '-Wnon-virtual-dtor'? [-Werror,-Wunknown-warning-option]

This is consistent and I can live with this behavior, using -Werror to bail out on warnings.

So lets running the same tests with GCC:

* first with an unknown -Wno-* argument

$ gcc -o test test.c -Wall -Wno-non-existing-flag
(no error nor warning)
$ gcc -o test test.c -Wall -Wno-non-existing-flag -Werror
(no error nor warning)

* then with an unknown -W* argument (without the no- prefix)

$ gcc -o test test.c -Wall -Wnon-existing-flag
gcc: error: unrecognized command line option ‘-Wnon-existing-flag’

I think you said it pretty well in your mail:

Quoted 1 line

Darn compilers and darn -Werror

So your change does improve Clang ... I dunno what we will do with GCC.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
author
#4 lore raw

Hi David

Thanks for the comments

My idea was just to add -Werror right in the line above, and not extend the

Quoted 2 lines

ACL_CHECK_ADD_COMPILE_FLAGS macro with another argument.

I'm fine with that approach as well. Let me know if you want a v2.

Quoted 7 lines

I think you said it pretty well in your mail:

Quoted 1 line

Darn compilers and darn -Werror

So your change does improve Clang ... I dunno what we will do with GCC.

It doesn't affect gcc as gcc does error (or ignore -- see below) unsupported options with or without -Werror. So I think we are okay. travis build on my fork confirms that:
https://travis-ci.org/selvanair/openvpn/builds/612019849

However, gcc does have quirky behaviour when it comes to options like -Wno-xx-yy. It just accepts them silently[*] with or without -Werror. That works fine for us, but it does generate an error about that unsupported option if any other error is encountered during the build. As other errors are anyway a show-stopper, I think we can live with that.

Selva

[*] I think their reasoning is that -Wno-xx-yy can be thus used to suppress warnings added to newer versions without breaking builds with older ones. But clang doesn't share that view.

Acked-by
#5 lore raw

Am 14.11.19 um 22:58 schrieb Selva Nair:

Quoted 31 lines

Hi David

Thanks for the comments

My idea was just to add -Werror right in the line above, and not extend the
ACL_CHECK_ADD_COMPILE_FLAGS macro with another argument.

I'm fine with that approach as well. Let me know if you want a v2.

I think you said it pretty well in your mail:

> Darn compilers and darn -Werror

So your change does improve Clang ... I dunno what we will do with GCC.

It doesn't affect gcc as gcc does error (or ignore -- see below) unsupported options with or without -Werror. So I think we are okay. travis build on my fork confirms that:
https://travis-ci.org/selvanair/openvpn/builds/612019849

However, gcc does have quirky behaviour when it comes to options like -Wno-xx-yy. It just accepts them silently[*] with or without -Werror. That works fine for us, but it does generate an error about that unsupported option if any other error is encountered during the build. As other errors are anyway a show-stopper, I think we can live with that.

Quoted 5 lines

Selva

[*] I think their reasoning is that -Wno-xx-yy can be thus used to suppress warnings added to newer versions without breaking builds with older ones. But clang doesn't share that view.

I agree with Selva here. If we cannot get rid of the warnings themselves this seems to be the only sane way. So I am not totally with this stuff but it is better than the altneratives at the moment. And I really annoyed by all these new warnings of Clang

Arne

#6 lore raw
In reply to Selva Nair
Quoted 9 lines · Selva Nair

Hi David

Thanks for the comments

My idea was just to add -Werror right in the line above, and not extend the ACL_CHECK_ADD_COMPILE_FLAGS macro with another argument.

I'm fine with that approach as well. Let me know if you want a v2.

Sorry for the delay responding. I've done some pondering, and I have come to the same conclusion as Arne, so this is a reasonable approach to add -Werror.

That said, is there any specific reasons why adding the [-Werror] to essentially all ACL_CHECK_ADD_COMPILE_FLAGS() calls? Our ./configure script is the only one implementing and supporting and using this macro, and it is defined in configure.ac.

If there are no foreseeable reason for that now, I think it's just fine to change the AC_COMPILE_IFELSE() call to use CFLAGS="$1 -Werror $old_cflags". Just add a comment in that area why we add the -Werror explicitly. This makes the whole change smaller and clearer. If we need the flexibility later on, we can adjust this when that time arrives.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
author
#7 lore raw

Hi,

Quoted 23 lines · David Sommerseth
Quoted 5 lines · Selva Nair

Hi David

Thanks for the comments

My idea was just to add -Werror right in the line above, and not

extend the

Quoted 4 lines

ACL_CHECK_ADD_COMPILE_FLAGS macro with another argument.

I'm fine with that approach as well. Let me know if you want a v2.

Sorry for the delay responding. I've done some pondering, and I have come to
the same conclusion as Arne, so this is a reasonable approach to add -Werror.

That said, is there any specific reasons why adding the [-Werror] to essentially all ACL_CHECK_ADD_COMPILE_FLAGS() calls? Our ./configure script
is the only one implementing and supporting and using this macro, and it is defined in configure.ac.

Quoted 8 lines

If there are no foreseeable reason for that now, I think it's just fine to change the AC_COMPILE_IFELSE() call to use CFLAGS="$1 -Werror $old_cflags". Just add a comment in that area why we add the -Werror explicitly. This makes
the whole change smaller and clearer. If we need the flexibility later on, we
can adjust this when that time arrives.

Agreed. v2 follows.

Selva

#8 lore raw

PATCH v2 1/1 Fix ACL_CHECK_ADD_COMPILE_FLAGS to work with clang

In reply to [email protected]...

From: Selva Nair <[email protected]...>

Some compilers (e.g., clang) only issue a warning for unsupported options unless an additional flag such as -Werror is used to convert the warning to an error.

The behaviour is unchanged when using gcc as it either errors or ignores unknown options whether or not -Werror is present.

---
v2: Do not extend the macro to take an extra argument. Instead, add -Werror while doing the test.

The commit message and comment changed to match this.

 configure.ac | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
configure.ac +6 -3
index 807804e5..f4a947d2 100644
@@ -1275,11 +1275,14 @@ if test "${enable_pkcs11}" = "yes"; then
 	)
 fi
 
+# When testing a compiler option, we add -Werror to force
+# an error when the option is unsupported. This is not
+# required for gcc, but come compilers such as clang needs it.
 AC_DEFUN([ACL_CHECK_ADD_COMPILE_FLAGS], [
     old_cflags="$CFLAGS"
-    CFLAGS="$1 $CFLAGS"
-    AC_MSG_CHECKING([whether the compiler acceppts $1])
-    AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [AC_MSG_RESULT([yes])],
+    CFLAGS="$1 -Werror $CFLAGS"
+    AC_MSG_CHECKING([whether the compiler accepts $1])
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [AC_MSG_RESULT([yes])]; CFLAGS="$1 $old_cflags",
         [AC_MSG_RESULT([no]); CFLAGS="$old_cflags"])]
 )
 
Signature · 1 line
2.20.1
Acked-by on v2 1/1
#9 lore raw
Quoted 11 lines · On 19/11/2019 18:03, [email protected]... wrote:

From: Selva Nair <[email protected]...>

Some compilers (e.g., clang) only issue a warning for unsupported options unless an additional flag such as -Werror is used to convert the warning to an error.

The behaviour is unchanged when using gcc as it either errors or ignores unknown options whether or not -Werror is present.

Quoted 9 lines

---
v2: Do not extend the macro to take an extra argument. Instead, add -Werror while doing the test.

The commit message and comment changed to match this.

 configure.ac | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Tested running ./configure and 'make' using gcc-4.3.8, gcc-8.3.1 and clang-5.0.1. With patch applied, everything works as expected and no
unexpected halts during these two steps. Without this patch, clang-5.0.1
spits out lots of warnings related to -Wno-stringop-truncation.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#10 lore raw
In reply to [email protected]...

Typo below,

Quoted 25 lines · On 19/11/2019 17:03, [email protected]... wrote:

From: Selva Nair <[email protected]...>

Some compilers (e.g., clang) only issue a warning for unsupported options unless an additional flag such as -Werror is used to convert the warning to an error.

The behaviour is unchanged when using gcc as it either errors or ignores unknown options whether or not -Werror is present.

---
v2: Do not extend the macro to take an extra argument. Instead, add -Werror while doing the test.

The commit message and comment changed to match this.

  configure.ac | 9 ++++++---
  1 file changed, 6 insertions(+), 3 deletions(-)
configure.ac +0 -0
index 807804e5..f4a947d2 100644

configure.ac if test "${enable_pkcs11}" = "yes"; then · line 1280

Quoted 6 lines
configure.ac +3 -0
@@ -1275,11 +1275,14 @@ if test "${enable_pkcs11}" = "yes"; then
  	)
  fi
 
+# When testing a compiler option, we add -Werror to force
+# an error when the option is unsupported. This is not
+# required for gcc, but come compilers such as clang needs it.

come compilers --> some compilers

Quoted 12 lines
configure.ac +3 -3
  AC_DEFUN([ACL_CHECK_ADD_COMPILE_FLAGS], [
      old_cflags="$CFLAGS"
-    CFLAGS="$1 $CFLAGS"
-    AC_MSG_CHECKING([whether the compiler acceppts $1])
-    AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [AC_MSG_RESULT([yes])],
+    CFLAGS="$1 -Werror $CFLAGS"
+    AC_MSG_CHECKING([whether the compiler accepts $1])
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [AC_MSG_RESULT([yes])]; CFLAGS="$1 $old_cflags",
          [AC_MSG_RESULT([no]); CFLAGS="$old_cflags"])]
  )
 
#11 lore raw
In reply to [email protected]...

Your patch has been applied to the master branch. Thanks :-)

I have fixed the "come compilers" typo on the fly.

Very lightly tested (Linux/gcc 8.3.0, and FreeBSD/clang 6.0.0).

commit acc18e8842570e66ef12ffee591968777ed5be6a

Author: Selva Nair
Date:   Tue Nov 19 12:03:43 2019 -0500
     Fix ACL_CHECK_ADD_COMPILE_FLAGS to work with clang

     Signed-off-by: Selva Nair <[email protected]...>
     Acked-by: David Sommerseth <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg19170.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering