clang and static linking?
jilles at stack.nl
Sat Nov 10 21:39:46 UTC 2012
On Sat, Nov 10, 2012 at 01:33:40AM +0100, Dimitry Andric wrote:
> On 2012-11-10 00:25, Dimitry Andric wrote:
> > The more difficult way out is to not define any duplicate functions in
> > libc.a and libm.a. For the shared libraries, this should not be a
> > problem, since the dynamic linker will figure out which of the two
> > copies will get precedence. The functions must stay available for
> > backwards compatibility reasons anyway.
> > For static libraries, this compatibility seems to be unnecessary, as
> > they will only be used to link new programs. Therefore, it would
> > probably be best to remove the whole isnan.o member from libc.a, and
> > move all the isnan functions to libm.a instead.
> > Currently, isnan() is commented out in lib/msun/src/s_isnan.c, maybe we
> > can enable it whenever PIC is not defined? Then we could simply skip
> > building lib/libc/gen/isnan.c for libc.a.
> More concretely, here is a patch that seems to achieve the above:
I see this has already been committed, but anyway...
> - Only define isnan, isnanf, __isnan and __isnanf in libc.so, not in
> libc.a and libc_p.a.
OK, but please add a comment about this.
> - Define isnan in libm.a and libm_p.a, not in libm.so. I don't think
> there is a need to define __isnan in the .a files, so I left that out.
Removing symbols from a .so causes subtle ABI breakage and is not needed
for fixing static linking.
More concretely, dlsym of isnan on libm.so will stop working and a
different version of isnan will be chosen if the search list is libm.so,
libother.so, libc.so and libother.so contains another isnan.
> Index: lib/libc/gen/isnan.c
> --- lib/libc/gen/isnan.c (revision 242841)
> +++ lib/libc/gen/isnan.c (working copy)
> @@ -35,6 +35,7 @@
> * binary compat until we can bump libm's major version number.
> +#ifdef PIC
> __weak_reference(__isnan, isnan);
> __weak_reference(__isnanf, isnanf);
> @@ -55,3 +56,4 @@ __isnanf(float f)
> u.f = f;
> return (u.bits.exp == 255 && u.bits.man != 0);
> +#endif /* PIC */
> Index: lib/msun/src/s_isnan.c
> --- lib/msun/src/s_isnan.c (revision 242841)
> +++ lib/msun/src/s_isnan.c (working copy)
> @@ -30,8 +30,9 @@
> #include "fpmath.h"
> -/* Provided by libc */
> -#if 0
> +/* Provided by libc.so */
> +#ifndef PIC
> +#undef isnan
> isnan(double d)
> @@ -40,7 +41,7 @@ isnan(double d)
> u.d = d;
> return (u.bits.exp == 2047 && (u.bits.manl != 0 || u.bits.manh != 0));
> +#endif /* !PIC */
> __isnanf(float f)
More information about the freebsd-current