misc/158418: /usr/include librarys broken by unnecessary extra macro indirection.

Bruce Evans brde at optusnet.com.au
Thu Jun 30 02:40:08 UTC 2011


On Tue, 28 Jun 2011, Alan Larson wrote:

>> Description:
>
>  The macro  __aligned(x)  is used several places in files in /usr/include, but is only
> defined if using a sufficiently new version of GCC, or an Intel compiler.
> The definitions are inside an  #if __GNUC_PREREQ__(2, 7)  and  #if defined(__INTEL_COMPILER)
>
>  This breaks things when compiled with PCC or TCC.  ( http://pcc.ludd.ltu.se/jira/browse/PCC-18 )

Unfortunately, breaking is the correct behaviour since the ABI depends on
the struct layout, so only compilers that support packing and alignment
can work.  Structs should be layed out more carefully so that packing and
alignment directives are never needed, but this is sometimes impossible.

>> How-To-Repeat:
>
>  Attempt to compile something that has an #include <signal.h> with TCC (or presumably, PCC).
>
>  Inspection of the code indicates that the same problem is true for __packed  .
>
>  Other values are also redefined in those same conditionals, and they probably have
> the same problems.

The problem outside the kernel doesn't seem to affect much more than
<signal.h>, though relatively recently it has spread to some networking
headers, especially ipv6 ones.

>> Fix:
>
>
>  Two likely fixes come to mind:
>
>    1.  Don't use these macro shortcuts, use the __attribute__ form directly.
>        Many of the files in /usr/include do this, so fixing the remaining ones
>        would simplify things.  It should only take a few minutes to fix them.
>        There are still lots of places using the __attribute__ form, so this
>        is a proven safe and reasonable solution.

That would enlarge the bug.  Doing it for an old version of tcc -Ysystem
gives:

% "/usr/include/machine/signal.h", line 122: Error:
%   [Syntax]: Parse error before '__attribute__'.
%   [Syntax]: Can't recover from this error.

since old versions of tcc don't support __attribute__ any more than they
support the newer types of attributes like the one for alignment.

>    2.  If you absolutely must include macros for this, define the macro all the
>        time.
>        But seriously, you should take solution #1.

The macros are not just shortcuts, but exist primarily to avoid hard-coding
gccisms like __attribute__ in lots of places.

Bruce


More information about the freebsd-bugs mailing list