Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Sep 2016 15:59:34 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        John Baldwin <jhb@freebsd.org>
Cc:        "Ngie Cooper (yaneurabeya)" <yaneurabeya@gmail.com>,  "Conrad E. Meyer" <cem@freebsd.org>,  src-committers <src-committers@freebsd.org>, svn-src-all@freebsd.org,  svn-src-head@freebsd.org
Subject:   Re: svn commit: r305998 - in head/usr.bin: cmp indent tr
Message-ID:  <20160920154629.K1129@besplex.bde.org>
In-Reply-To: <8333248.dV1m5xp1ki@ralph.baldwin.cx>
References:  <201609192043.u8JKh3jv040006@repo.freebsd.org> <E52FB33D-0921-404F-8457-0E2CB957556B@gmail.com> <8333248.dV1m5xp1ki@ralph.baldwin.cx>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 19 Sep 2016, John Baldwin wrote:

> On Monday, September 19, 2016 01:45:01 PM Ngie Cooper wrote:
>>
>>> On Sep 19, 2016, at 1:43 PM, Conrad E. Meyer <cem@FreeBSD.org> wrote:
>>> Log:
>>>  Move sys/capsicum.h includes after types.h or param.h
>>>
>>>  This is not actually documented or even implied in style(9).  Make the=
 change
>>>  to match convention.  Someone should document this convention in style=
(9).
>>>
>>>  Reported by:=09jhb
>>>  Sponsored by:=09EMC Dell Isilon
>>
>> Uh=E2=80=A6 yes it clearly states it in style(9). From https://www.freeb=
sd.org/cgi/man.cgi?query=3Dstyle&sektion=3D9 :
>>      Kernel include files (i.e. sys/*.h) come first; normally, include
>>      <sys/types.h> OR <sys/param.h>, but not both.  <sys/types.h> includ=
es
>>      <sys/cdefs.h>, and it is okay to depend on that.
>
> It doesn't actually say that types.h/param.h has to come before other sys=
/*.h
> headers though.  Normally sys/foo.h requires sys/types.h to compile hence=
 the
> rule, but sys/capsicum.h gets around this by a nested include of sys/para=
m.h
> (which is itself probably dubious).

This and other nested includes make sys/capsicum.h of rmrf quality.

It is now not so normal to require sys/types or sys/param.h first, since
too many headers have been broken using nested includes.  Only a few have
correct fixes for pollution.  Almost none have documentation for either
their non-pollution or pollution, except possibly with directives like
-D_POSIX_SOURCE (restrict to ~1988 POSIX.1) where the standard has such
documentation and the standard is supported.  E.g., cap_enter(2) only
mentions a couple of symbols and no namespaces.  Its SYNOPSIS uses the
undocumented symbol u_int, and doesn't mention sys/types.h or _BSD_VISIBLE,
so by knowing undocumented things we can tell that its #include of
<sys/capsicum.h> is either incomplete or that it has namespace pollution
including at least u_int and probably all the undocumented symbols in
sys/types.h, but that is just the start of the pollution.

> I do think we should explicitly add a note to style.9 though to say that
> types.h|param.h comes first.

I use the following:

X Index: style.9
X =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
X RCS file: /home/ncvs/src/share/man/man9/style.9,v
X retrieving revision 1.110
X diff -u -2 -r1.110 style.9
X --- style.9=093 Jul 2004 18:29:24 -0000=091.110
X +++ style.9=097 Jul 2004 11:47:22 -0000
X @@ -90,17 +130,22 @@
X  .Ed
X  .Pp
X -Leave another blank line before the header files.
X +Leave one blank line before the header files.
X  .Pp
X -Kernel include files (i.e.\&
X +Kernel include files (i.e.,\&
X  .Pa sys/*.h )
X -come first; normally, include
X -.In sys/types.h
X -OR
X -.In sys/param.h ,
X -but not both.
X +come first; normally,
X  .In sys/types.h
X +or
X +.In sys/param.h
X +will be needed before any others.
X +.In sys/param.h
X  includes
X +.In sys/types.h .
X +Do not include both.
X +Many headers, including
X +.In sys/types.h ,
X +include
X  .In sys/cdefs.h ,
X -and it is okay to depend on that.
X +and it is OK to depend on that.
X  .Bd -literal
X  #include <sys/types.h>=09/* Non-local includes in angle brackets. */
X @@ -116,12 +161,11 @@
X  .Ed
X  .Pp
X -Do not use files in
X +Do not include files in
X  .Pa /usr/include
X  for files in the kernel.
X  .Pp
X -Leave a blank line before the next group, the
X -.Pa /usr/include
X -files,
X -which should be sorted alphabetically by name.
X +Leave a blank line before the next group (XXX nah, all groups),
X +the <*.h> include files.
X +Sort the <*.h> include files (XXX nah, all groups) alphabetically.
X  .Bd -literal
X  #include <stdio.h>
X @@ -138,5 +182,6 @@
X  .Ed
X  .Pp
X -Leave another blank line before the user include files.
X +Leave another blank line before the local include files.
X +XXX nah, leave it before all groups.
X  .Bd -literal
X  #include "pathnames.h"=09=09/* Local includes in double quotes. */

Bruce
From owner-svn-src-all@freebsd.org  Tue Sep 20 06:15:03 2016
Return-Path: <owner-svn-src-all@freebsd.org>
Delivered-To: svn-src-all@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 19A29BE1436;
 Tue, 20 Sep 2016 06:15:03 +0000 (UTC)
 (envelope-from brde@optusnet.com.au)
Received: from mail109.syd.optusnet.com.au (mail109.syd.optusnet.com.au
 [211.29.132.80]) by mx1.freebsd.org (Postfix) with ESMTP id A1663FF5;
 Tue, 20 Sep 2016 06:15:01 +0000 (UTC)
 (envelope-from brde@optusnet.com.au)
Received: from c122-106-149-109.carlnfd1.nsw.optusnet.com.au
 (c122-106-149-109.carlnfd1.nsw.optusnet.com.au [122.106.149.109])
 by mail109.syd.optusnet.com.au (Postfix) with ESMTPS id EECC6D60C24;
 Tue, 20 Sep 2016 15:46:20 +1000 (AEST)
Date: Tue, 20 Sep 2016 15:46:19 +1000 (EST)
From: Bruce Evans <brde@optusnet.com.au>
X-X-Sender: bde@besplex.bde.org
To: Ed Schouten <ed@nuxi.nl>
cc: Bruce Evans <bde@freebsd.org>, src-committers <src-committers@freebsd.org>,
 svn-src-all@freebsd.org, svn-src-stable@freebsd.org, 
 svn-src-stable-11@freebsd.org
Subject: Re: svn commit: r305971 - stable/11/lib/msun/src
In-Reply-To: <CABh_MKneVefUX=buhi1TOtu5keQO3BW_zSBvVHHqM8a+As3Nag@mail.gmail.com>
Message-ID: <20160920144731.P1129@besplex.bde.org>
References: <201609191234.u8JCYTUo052934@repo.freebsd.org>
 <CABh_MKneVefUX=buhi1TOtu5keQO3BW_zSBvVHHqM8a+As3Nag@mail.gmail.com>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
X-Optus-CM-Score: 0
X-Optus-CM-Analysis: v=2.1 cv=CoZCCSMD c=1 sm=1 tr=0
 a=R/f3m204ZbWUO/0rwPSMPw==:117 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10
 a=s5jvgZ67dGcA:10 a=kj9zAlcOel0A:10 a=6I5d2MoRAAAA:8
 a=6kdLHU8h-LnCs2dJQkkA:9 a=CjuIK1q_8ugA:10 a=IjZwj45LgO3ly-622nXo:22
X-BeenThere: svn-src-all@freebsd.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: "SVN commit messages for the entire src tree \(except for &quot;
 user&quot; and &quot; projects&quot; \)" <svn-src-all.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/svn-src-all>,
 <mailto:svn-src-all-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-all/>;
List-Post: <mailto:svn-src-all@freebsd.org>
List-Help: <mailto:svn-src-all-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/svn-src-all>,
 <mailto:svn-src-all-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Tue, 20 Sep 2016 06:15:03 -0000

On Mon, 19 Sep 2016, Ed Schouten wrote:

> 2016-09-19 14:34 GMT+02:00 Bruce Evans <bde@freebsd.org>:
>> +#if (LDBL_MANT_DIG == 53)
>> +__weak_reference(fmod, fmodl);
>> +#endif
>
> I've noticed that libm uses __weak_reference() all over the place, but
> I guess that in this specific case there is no reason to use them,
> right? Wouldn't it make more sense to use strong references here, so
> that they are consistent with other architectures?

I just copied what das did here.

Weak symbols are less portable in theory but more portable in practice:
- the ifdefs depend on compiler support for __strong_reference() but
   not for __weak_reference
- there was apparently no compiler support for __strong_reference() in
   icc, and it is still not defined if __INTEL_COMPILER (so the hundreds
   of other __INTEL_COMPILER ifdefs are nonsense, since __strong_reference()
   is now used all over the place)
- __weak_reference() was implemented in FreeBSD in 1994 but
   __strong_reference() was not implemented until 2000 -- it is barely in
   FreeBSD-4
- however, it is __strong_reference() that requires less toolchain support.
   I think just asm() with ".globl" and ".equ" or ".set" would work for
   it.  __weak_reference() needs the less portable ".weak" instead of
   ".globl".  The compiler __alias__ attribute used to define
   __strong_reference() just generates these directives on x86, except
   clang spells ".equ" worse as "=" (it even rewrites ".equ" in the asm
   to "=") and also generates ".type", and gcc-4.2.1 generates ".set"
   instead of ".equ" (it doesn't rewrite the asm).
- at least, with ELF.  Old versions of FreeBSD including FreeBSD-3 have
   even uglier ifdefs for this involving AOUT.  Apparently, a magic ".stab"
   was needed instead of ".weak".  A magic ".stab" was also used for
   aliasing.  Perhaps ".equ" was not powerful enough, and IIRC it indeed
   isn't in my aout implementation (IIRC it is not exported).  In direct
   asm, it is not needed for mere aliases for functions since you can
   just duplicate labels as needed.

The strong reference is also technically more correct in theory but less
useful in practice.  With non-broken (static) linkers, it gives an error
if the user tries to replace the library function by his own function.
An error is technically correct.  But the user should be allowed to do
this.  Libraries should have only one API per object file, to allow the
user to replace one function at a time (and to not bloat the linked
executable with unused functions).  libm mostly does this.  However, for
these aliases, it puts the alias in the same file as the main function
for convenience.  With strong aliases, this would prevent the user from
replacing the alias without also replacing the main function.

Compiler support for aliases gives mere aliases.  It doesn't generate
extra code like the kernel ALTENTRY() macros to disambiguate the aliases
for -pg.  Compilers should optionally also generate such code (or
duplicate the function for small functions) for -g and -finstrument-
functions (so that you can put a breakpoint in fmodl() without hitting
in when you only call fmod() ...).  ALTENTRY() and END() are perhaps
not careful enough with ".type" and ".size" directives for the not-quite-
alias.  Compilers don't generate ".size" for the alias.

Bruce



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