Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Jun 2011 02:50:08 GMT
From:      Bruce Evans <brde@optusnet.com.au>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: misc/158418: /usr/include librarys broken by unnecessary extra macro indirection.
Message-ID:  <201106300250.p5U2o8Ll093993@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/158418; it has been noted by GNATS.

From: Bruce Evans <brde@optusnet.com.au>
To: Alan Larson <larson@w6yx.stanford.edu>
Cc: FreeBSD-gnats-submit@freebsd.org, freebsd-bugs@freebsd.org
Subject: Re: misc/158418: /usr/include librarys broken by unnecessary extra
 macro indirection.
Date: Thu, 30 Jun 2011 09:55:47 +1000 (EST)

 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



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