configure tests for gcc builtins with CFLAGS=-Werror

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

configure tests for gcc builtins with CFLAGS=-Werror

Chris Packham
Hi,

We've run into a problem trying to compile openvswitch with CFLAGS=-Werror.

I don't think it's an openvswitch problem. It appears to be a
autoconf/gcc issue.

openvswitch has a test to detect the library that implements
__atomic_load_8 which boils down to "AC_SEARCH_LIBS([__atomic_load_8],
[atomic])". The problem is when configure is invoked with
"CFLAGS=-Werror ./configure" conftest.c fails to compile because the
dummy prototype used doesn't match the builtin definition. This in turn
causes openvswitch to fail to link because -latomic isn't included in LIBS.

Here is a small patch that illustrates the problem

--- 8< ---
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..e69de29
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..0607b5b
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,10 @@
+AC_INIT([test], [0.1])
+AM_INIT_AUTOMAKE([-Wall -Werror foreign])
+AC_CONFIG_HEADERS([config.h])
+AC_PROG_CC
+AC_SEARCH_LIBS([__atomic_load_8], [atomic])
+AC_CONFIG_FILES([
+ Makefile
+])
+AC_OUTPUT
+
--- 8< ---

When invoked without specifying CFLAGS I get the following

   $ autoreconf -fvi
   $ ./configure | grep atomic_load
   checking for library containing __atomic_load_8... -latomic

When specifing -Werror I get

   $ autoreconf -fvi
   $ CFLAGS=-Werror ./configure | grep atomic_load
   checking for library containing __atomic_load_8... no

Looking at config.log we can see the following

generated by GNU Autoconf 2.69.
...
configure:2742: checking for C compiler version
configure:2751: gcc --version >&5
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
...
configure:3478: checking for library containing __atomic_load_8
configure:3509: gcc -o conftest -Werror   conftest.c  >&5
conftest.c:18:6: error: conflicting types for built-in function
'__atomic_load_8' [-Werror]
  char __atomic_load_8 ();
       ^
cc1: all warnings being treated as errors

Any thoughts on how we can get -latomic detected and -Werror passed
through to the build?

Reply | Threaded
Open this post in threaded view
|

Re: configure tests for gcc builtins with CFLAGS=-Werror

Eric Blake-3
On 05/25/2016 02:05 AM, Chris Packham wrote:
> Hi,
>
> We've run into a problem trying to compile openvswitch with CFLAGS=-Werror.

That's never a good thing to do. We explicitly recommend that you avoid
CFLAGS=-Werror during configure tests, and that configure files that
WANT to (possibly conditionally) enable error flags during the main
compile should probe that setting independently during configure.ac.
GNU Coreutils is a good example for how to do this, using gnulib's
gl_WARN_ADD macro

http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=blob;f=configure.ac;h=a4846011#l108

http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob;f=src/local.mk;h=12a0d55d#l20

>
> I don't think it's an openvswitch problem. It appears to be a
> autoconf/gcc issue.

On the contrary, it IS an openvswitch problem, as you should never run
configure with -Werror set for the majority of the probes.

>
> Any thoughts on how we can get -latomic detected and -Werror passed
> through to the build?

As suggested above, make the probing of whether -Werror works
independent from the rest of configure, and set it in a separate
variable (not CFLAGS), then use that separate variable in your Makefiles
but not the rest of configure.

That said, there is an open patch to autoconf to promote gnulib's
gl_WARN_ADD logic into a formal autoconf macro, and that's one of the
remaining things that needs to be merged in before I can release
autoconf 2.70.

--
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


signature.asc (617 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [ovs-discuss] configure tests for gcc builtins with CFLAGS=-Werror

Ben Pfaff-2
In reply to this post by Chris Packham
On Wed, May 25, 2016 at 08:05:38AM +0000, Chris Packham wrote:
> We've run into a problem trying to compile openvswitch with CFLAGS=-Werror.

Use "configure --enable-Werror", as documented in Open vSwitch's
INSTALL.md file.

Reply | Threaded
Open this post in threaded view
|

Re: [ovs-discuss] configure tests for gcc builtins with CFLAGS=-Werror

Chris Packham
On 05/26/2016 11:58 AM, Ben Pfaff wrote:
> On Wed, May 25, 2016 at 08:05:38AM +0000, Chris Packham wrote:
>> We've run into a problem trying to compile openvswitch with CFLAGS=-Werror.
>
> Use "configure --enable-Werror", as documented in Open vSwitch's
> INSTALL.md file.
>

Hi Ben,

Thanks for pointing this out.