Patchwork [v2] configure: properly check if -lrt and -lm is needed

login
register
mail settings
Submitter Natanael Copa
Date Aug. 16, 2012, 1:22 p.m.
Message ID <1345123356-6673-1-git-send-email-ncopa@alpinelinux.org>
Download mbox | patch
Permalink /patch/177989/
State New
Headers show

Comments

Natanael Copa - Aug. 16, 2012, 1:22 p.m.
Fixes build against uClibc.

uClibc provides 2 versions of clock_gettime(), one with realtime
support and one without (this is so you can avoid linking in -lrt
unless actually needed). This means that the clock_gettime() don't
need -lrt. We still need it for timer_create() so we check for this
function in addition.

We also need check if -lm is needed for isnan().

Both -lm and -lrt are needed for libs_qga.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
---
The Xen people have nagged me to get this patch upstream so I have come
up with a rebased v2 patch after consulting with pm215 on IRC.

Please consider include this.

Changes v1->v2:
 - Check for sin() in addition to isnan()
 - Add comment on why we also check for timer_create
 - Use $LIBS and $libs_qga instead of $libm and $librt, based on
   feedback from pm215 on IRC
 - Do not remove the explicit add of -lm unless Haiku. This was due
   to http://www.mail-archive.com/qemu-devel@nongnu.org/msg102965.html
   I am not sure if this is valid, though.

 configure | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)
Juan Quintela - Aug. 20, 2012, 12:19 p.m.
Natanael Copa <natanael.copa@gmail.com> wrote:
> Fixes build against uClibc.
>
> uClibc provides 2 versions of clock_gettime(), one with realtime
> support and one without (this is so you can avoid linking in -lrt
> unless actually needed). This means that the clock_gettime() don't
> need -lrt. We still need it for timer_create() so we check for this
> function in addition.
>
> We also need check if -lm is needed for isnan().
>
> Both -lm and -lrt are needed for libs_qga.
>
> Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>

Reviewed-by: Juan Quintela <quintela@redhat.com>
Peter Maydell - Aug. 20, 2012, 12:43 p.m.
On 16 August 2012 14:22, Natanael Copa <natanael.copa@gmail.com> wrote:
> Fixes build against uClibc.
>
> uClibc provides 2 versions of clock_gettime(), one with realtime
> support and one without (this is so you can avoid linking in -lrt
> unless actually needed). This means that the clock_gettime() don't
> need -lrt. We still need it for timer_create() so we check for this
> function in addition.
>
> We also need check if -lm is needed for isnan().
>
> Both -lm and -lrt are needed for libs_qga.
>
> Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
> ---
> The Xen people have nagged me to get this patch upstream so I have come
> up with a rebased v2 patch after consulting with pm215 on IRC.
>
> Please consider include this.
>
> Changes v1->v2:
>  - Check for sin() in addition to isnan()
>  - Add comment on why we also check for timer_create
>  - Use $LIBS and $libs_qga instead of $libm and $librt, based on
>    feedback from pm215 on IRC
>  - Do not remove the explicit add of -lm unless Haiku. This was due
>    to http://www.mail-archive.com/qemu-devel@nongnu.org/msg102965.html
>    I am not sure if this is valid, though.

Certainly building a linux-user target works for me even without
that explicit 'LIBS+=-lm' in Makefile.target. Blue, can you remember
what you had in mind when you wrote that email?

thanks
-- PMM
Peter Maydell - Aug. 20, 2012, 1:27 p.m.
On 16 August 2012 14:22, Natanael Copa <natanael.copa@gmail.com> wrote:
> Fixes build against uClibc.
>
> uClibc provides 2 versions of clock_gettime(), one with realtime
> support and one without (this is so you can avoid linking in -lrt
> unless actually needed). This means that the clock_gettime() don't
> need -lrt. We still need it for timer_create() so we check for this
> function in addition.
>
> We also need check if -lm is needed for isnan().
>
> Both -lm and -lrt are needed for libs_qga.

This patch breaks building the linux-user targets with --static:

cam-vm-266:precise:qemu$ ./configure --target-list=arm-linux-user --static

Error: librt check failed


The test program is failing to link with this
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/librt.a(timer_create.o):
In function `timer_create':
(.text+0x121): undefined reference to `pthread_once'

and a lot of similar errors.

(This seems to me like a glibc bug but since it's out there we rather
have to deal with it I think.)

-- PMM
Blue Swirl - Aug. 20, 2012, 7:53 p.m.
On Mon, Aug 20, 2012 at 12:43 PM, Peter Maydell
<peter.maydell@linaro.org> wrote:
> On 16 August 2012 14:22, Natanael Copa <natanael.copa@gmail.com> wrote:
>> Fixes build against uClibc.
>>
>> uClibc provides 2 versions of clock_gettime(), one with realtime
>> support and one without (this is so you can avoid linking in -lrt
>> unless actually needed). This means that the clock_gettime() don't
>> need -lrt. We still need it for timer_create() so we check for this
>> function in addition.
>>
>> We also need check if -lm is needed for isnan().
>>
>> Both -lm and -lrt are needed for libs_qga.
>>
>> Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
>> ---
>> The Xen people have nagged me to get this patch upstream so I have come
>> up with a rebased v2 patch after consulting with pm215 on IRC.
>>
>> Please consider include this.
>>
>> Changes v1->v2:
>>  - Check for sin() in addition to isnan()
>>  - Add comment on why we also check for timer_create
>>  - Use $LIBS and $libs_qga instead of $libm and $librt, based on
>>    feedback from pm215 on IRC
>>  - Do not remove the explicit add of -lm unless Haiku. This was due
>>    to http://www.mail-archive.com/qemu-devel@nongnu.org/msg102965.html
>>    I am not sure if this is valid, though.
>
> Certainly building a linux-user target works for me even without
> that explicit 'LIBS+=-lm' in Makefile.target. Blue, can you remember
> what you had in mind when you wrote that email?

Build failed since math library functions (sin() etc.) were not found.

>
> thanks
> -- PMM
Natanael Copa - Aug. 21, 2012, 6:10 a.m.
On Mon, 20 Aug 2012 19:53:22 +0000
Blue Swirl <blauwirbel@gmail.com> wrote:

> >>  - Do not remove the explicit add of -lm unless Haiku. This was due
> >>    to
> >> http://www.mail-archive.com/qemu-devel@nongnu.org/msg102965.html I
> >> am not sure if this is valid, though.
> >
> > Certainly building a linux-user target works for me even without
> > that explicit 'LIBS+=-lm' in Makefile.target. Blue, can you remember
> > what you had in mind when you wrote that email?
> 
> Build failed since math library functions (sin() etc.) were not found.

The v2 and v3 patches I sent tests for sin() in addition to isnan (which
normally is a macro). It might explain why it works now.

Adding a second -lm does not hurt, but omitting it when needed breaks
build on uclibc for sure, so it would be nice if the v3 patch could be
applied.

Thanks!

-nc
Blue Swirl - Aug. 21, 2012, 6:12 p.m.
On Tue, Aug 21, 2012 at 6:10 AM, Natanael Copa <ncopa@alpinelinux.org> wrote:
> On Mon, 20 Aug 2012 19:53:22 +0000
> Blue Swirl <blauwirbel@gmail.com> wrote:
>
>> >>  - Do not remove the explicit add of -lm unless Haiku. This was due
>> >>    to
>> >> http://www.mail-archive.com/qemu-devel@nongnu.org/msg102965.html I
>> >> am not sure if this is valid, though.
>> >
>> > Certainly building a linux-user target works for me even without
>> > that explicit 'LIBS+=-lm' in Makefile.target. Blue, can you remember
>> > what you had in mind when you wrote that email?
>>
>> Build failed since math library functions (sin() etc.) were not found.
>
> The v2 and v3 patches I sent tests for sin() in addition to isnan (which
> normally is a macro). It might explain why it works now.
>
> Adding a second -lm does not hurt, but omitting it when needed breaks
> build on uclibc for sure, so it would be nice if the v3 patch could be
> applied.

Now I get this on mingw32:
config-host.mak is out-of-date, running configure

Error: librt check failed

>
> Thanks!
>
> -nc

Patch

diff --git a/configure b/configure
index edf9da4..a351f9b 100755
--- a/configure
+++ b/configure
@@ -2624,17 +2624,48 @@  fi
 
 
 ##########################################
+# Do we need libm
+cat > $TMPC << EOF
+#include <math.h>
+int main(void) { return isnan(sin(0.0)); }
+EOF
+if compile_prog "" "" ; then
+  :
+elif compile_prog "" "-lm" ; then
+  LIBS="-lm $LIBS"
+  libs_qga="-lm $libs_qga"
+else
+  echo
+  echo "Error: libm check failed"
+  echo
+  exit 1
+fi
+
+##########################################
 # Do we need librt
+# uClibc provides 2 versions of clock_gettime(), one with realtime
+# support and one without. This means that the clock_gettime() don't
+# need -lrt. We still need it for timer_create() so we check for this
+# function in addition.
 cat > $TMPC <<EOF
 #include <signal.h>
 #include <time.h>
-int main(void) { return clock_gettime(CLOCK_REALTIME, NULL); }
+int main(void) {
+  timer_create(CLOCK_REALTIME, NULL, NULL);
+  return clock_gettime(CLOCK_REALTIME, NULL);
+}
 EOF
 
 if compile_prog "" "" ; then
   :
 elif compile_prog "" "-lrt" ; then
   LIBS="-lrt $LIBS"
+  libs_qga="-lrt $libs_qga"
+else
+  echo
+  echo "Error: librt check failed"
+  echo
+  exit 1
 fi
 
 if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \