Re: clang and static linking?

From: Roman Divacky <rdivacky_at_freebsd.org>
Date: Fri, 9 Nov 2012 14:09:20 +0100
On Fri, Nov 09, 2012 at 02:00:12PM +0200, Konstantin Belousov wrote:
> On Thu, Nov 08, 2012 at 03:49:32PM -0800, Steve Kargl wrote:
> > On Thu, Nov 08, 2012 at 03:13:49PM -0800, Steve Kargl wrote:
> > > Upgraded my amd64 system, yesterday.  Needed to rebuild one
> > > of my projects, and hit
> > > 
> > > /usr/local/openmpi-1.6.3/bin/mpif90 -static -O2 -pipe -march=native -mtune=native -funroll-loops -ftree-vectorize -Wall -rpath /usr/local/lib/gcc46 -I/home/kargl/modules -o sasmp sasmp.f90 -L/home/kargl/lib -L. -L/usr/local/lib -L. -loa -lm90 -llapack -lblas
> > > //usr/lib/libc.a(isnan.o): In function `isnanf':
> > > /usr/src/lib/libc/gen/isnan.c:(.text+0x40): multiple definition of `__isnanf'
> > > //usr/lib/libm.a(s_isnan.o):/usr/src/lib/msun/src/s_isnan.c:(.text+0x0):
> > > first defined here
> > > collect2: ld returned 1 exit status
> > > *** [sasmp] Error code 1
> > > 
> > > Stop in /usr/home/kargl/trunk/oa.
> > > 
> > > Can't rebuild gcc46 due to clang issue.
> > > Rebuilding openmpi does not help as openmpi uses gfortran46.
> > > Maybe there's a library problem.
> > > 
> > > Error   clang        base/gcc
> > > yes    libc,libm
> > > yes    libm          libc
> > > no     libc          libm
> > > no                   libc,libm
> > > 
> > > libm.a compiled with clang
> > > % nm /usr/lib/libm.a | grep isnan
> > >                  U __isnanl
> > >                  U __isnanf
> > >                  U __isnanl
> > >                  U isnan
> > >                  U __isnanf
> > >                  U isnan
> > >                  U isnanf
> > > s_isnan.o:
> > > 0000000000000000 T __isnanf
> > > 0000000000000030 T __isnanl
> > > 0000000000000000 W isnanf
> > >                  U isnan
> > > 
> > > libm.a compiled with /usr/lib/gcc
> > > troutmask:fvwm:kargl[232] nm /usr/lib/libm.a | grep isnan
> > >                  U __isnanl
> > >                  U __isnanf
> > >                  U __isnanl
> > >                  U __isnanf
> > > s_isnan.o:
> > > 0000000000000000 T __isnanf
> > > 0000000000000030 T __isnanl
> > > 0000000000000000 W isnanf
> > > 
> > 
> > This appears to fix the problem.  Don't know if this is
> > th right way to handle it.
> > 
> > Index: src/s_isnan.c
> > ===================================================================
> > --- src/s_isnan.c	(revision 242701)
> > +++ src/s_isnan.c	(working copy)
> > _at__at_ -40,7 +40,6 _at__at_
> >  	u.d = d;
> >  	return (u.bits.exp == 2047 && (u.bits.manl != 0 || u.bits.manh != 0));
> >  }
> > -#endif
> >  
> >  int
> >  __isnanf(float f)
> > _at__at_ -51,6 +50,9 _at__at_
> >  	return (u.bits.exp == 255 && u.bits.man != 0);
> >  }
> >  
> > +__weak_reference(__isnanf, isnanf);
> > +#endif
> > +
> >  int
> >  __isnanl(long double e)
> >  {
> > _at__at_ -60,5 +62,3 _at__at_
> >  	mask_nbit_l(u);
> >  	return (u.bits.exp == 32767 && (u.bits.manl != 0 || u.bits.manh != 0));
> >  }
> > -
> > -__weak_reference(__isnanf, isnanf);
> Is this patch against src/msun ?
> 
> This is only a workaround, which break ABI and older binaries.
> The bug is apparently in clang, which inserts the undef reference
> into the resulting object file, when weak alias references undefined
> symbol. Gnu as does not have the bug.
> 
> There is some magic switch to reduce amount of clang bugs, like
> -fno-integrated-as. Please try to compile the problematic .o with the
> switch.

This is what I am seeing here:

pes msun$ touch src/s_isnan.c 
pes msun$ make
Warning: Object directory not changed from original /usr/home/rdivacky/freebsd-head/lib/msun
clang -O2 -pipe  -I/usr/home/rdivacky/freebsd-head/lib/msun/ld80 -I/usr/home/rdivacky/freebsd-head/lib/msun/src -I/usr/home/rdivacky/freebsd-head/lib/msun/../libc/include  -I/usr/home/rdivacky/freebsd-head/lib/msun/../libc/amd64  -std=gnu99 -Wsystem-headers -Wno-pointer-sign -c /usr/home/rdivacky/freebsd-head/lib/msun/src/s_isnan.c
building static m library
ranlib libm.a
clang -pg -O2 -pipe  -I/usr/home/rdivacky/freebsd-head/lib/msun/ld80 -I/usr/home/rdivacky/freebsd-head/lib/msun/src -I/usr/home/rdivacky/freebsd-head/lib/msun/../libc/include  -I/usr/home/rdivacky/freebsd-head/lib/msun/../libc/amd64  -std=gnu99 -Wsystem-headers -Wno-pointer-sign -c /usr/home/rdivacky/freebsd-head/lib/msun/src/s_isnan.c -o s_isnan.po
building profiled m library
ranlib libm_p.a
clang -fpic -DPIC -O2 -pipe  -I/usr/home/rdivacky/freebsd-head/lib/msun/ld80 -I/usr/home/rdivacky/freebsd-head/lib/msun/src -I/usr/home/rdivacky/freebsd-head/lib/msun/../libc/include  -I/usr/home/rdivacky/freebsd-head/lib/msun/../libc/amd64  -std=gnu99 -Wsystem-headers -Wno-pointer-sign -c /usr/home/rdivacky/freebsd-head/lib/msun/src/s_isnan.c -o s_isnan.So
building shared library libm.so.5
pes msun$ nm s_isnan.o
0000000000000000 T __isnanf
0000000000000030 T __isnanl
0000000000000000 W isnanf
pes msun$

ie. no U for isnan. This is with todays clang not the one in base. So either
this bug is already gone in clang trunk (and will get fixed when we import
new clang). Or something else is going on...


Roman
Received on Fri Nov 09 2012 - 12:09:24 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:32 UTC