Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Feb 2015 09:25:38 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Gleb Smirnoff <glebius@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r278913 - in head/sys: conf modules/cxgbe/if_cxgbe modules/drm2/radeonkms modules/ibcore modules/ipoib modules/mlx4 modules/mlx4ib modules/mlxen modules/mthca ofed/drivers/net/mlx4
Message-ID:  <20150218081602.C3182@besplex.bde.org>
In-Reply-To: <201502171927.t1HJRFVV088172@svn.freebsd.org>
References:  <201502171927.t1HJRFVV088172@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 17 Feb 2015, Gleb Smirnoff wrote:

> Author: glebius
> Date: Tue Feb 17 19:27:14 2015
> New Revision: 278913
> URL: https://svnweb.freebsd.org/changeset/base/278913
>
> Log:
>    Globally enable -fms-extensions when building kernel with gcc, and remove
>  this option from all modules that enable it theirselves.
>    In C mode -fms-extensions option enables anonymous structs and unions,
>  allowing us to use this C11 feature in kernel. Of course, clang supports
>  it without any extra options.

Anonymous unions have been a standard gcc extension for more than 20 years.
It shouldn't take a ms extensions flag to get them, except possibly for
C++.

Indeed, the bugs are mostly in extra options that are already present.
Of course, clang handles these options incorrectly:

- the default CFLAGS for kernels include the foot-shooting flag -std=c99.
   The feature isn't in C99, so this should make the feature unavailable
   in kernels.  This works for gcc-4.2, but not for clang or gcc-4.8.  It
   takes -pedantic as well as -std=c99 to kill the feature for these
   compilers.

- the default CFLAGS for userland include -std=gnu99.  This of course
   doesn't kill 20+ year old gcc extensions, so userland doesn't have the
   problem.

I recently noticed several other bugs involving -std:

- -std sets __STDC_VERSION__, but sys/cdefs.h mostly ignores that.  It
   sets __ISO_C_VISIBLE based mainly on _POSIX_C_SOURCE, so
   __ISO_C_VISIBLE defaults to 2011 and is thus inconsistent with
   __STDC_VERSION__ in all cases where -std=c11 is not used -- that is,
   in almost all cases since everything defaults to -std=c99 or
   -std-gnu99 which give __STDC_VERSION__ = 199901L.

   Compiling with an old makefile or script that doesn't use -std gives
   larger inconsistencies -- it gives C90 for gcc but C99 for clang.
   gcc-4.8 remains compatible with gcc-4.2 (and gcc-1?) here.

- most FreeBSD header files use __ISO_C_VISIBLE and not __STDC_VERSION__,
   so they give C11 symbols by default.  They are supposed to give
   maximal symbols by default, but this is wrong if the symbols are
   related to language features that are turned off by -std.

- gcc-4.8 uses some private header files.  It doesn't use FreeBSD's
   __ISO_C_VISBLE of course, so it gives inconsistent symbols.

- lib/msun used to depend on __ISO_C_VISIBLE being wrong when it was
   compiled with defaults.  Now it depends on -std=*99 being in the
   defaults.  Both conditions are satisifed when the system headers
   are used.  But when gcc's float.h is used and -std is either not
   used or is *89, then the compile breaks.

- gcc's private header for float.h also has incompatibilities unrelated
   to -std.  These break lib/msun more seriously on i386.

- -std=c99 in gcc-4.8 gives large pessimizations in floating point code
   on i386.  -std=gnu99 gives compatible FP code (not perfectly pessimized
   to Standards spec).  clang is just missing support for Standards here.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150218081602.C3182>