From owner-svn-src-stable@freebsd.org Tue Sep 20 06:15:03 2016 Return-Path: Delivered-To: svn-src-stable@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 X-X-Sender: bde@besplex.bde.org To: Ed Schouten cc: Bruce Evans , src-committers , 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: Message-ID: <20160920144731.P1129@besplex.bde.org> References: <201609191234.u8JCYTUo052934@repo.freebsd.org> 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-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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 : >> +#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