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

login
register
mail settings
Submitter Natanael Copa
Date Aug. 20, 2012, 2:33 p.m.
Message ID <CAJT+8ezf2ODXuBcCx498DckgtV8SwrEezhWBsbuhqgvMw1Lxbg@mail.gmail.com>
Download mbox | patch
Permalink /patch/178850/
State New
Headers show

Comments

Natanael Copa - Aug. 20, 2012, 2:33 p.m.
On Mon, Aug 20, 2012 at 3:27 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.
>
> 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.

smells missing -lpthread.

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

Agree.

Will configure pass if you:



Thanks for feedback!
Peter Maydell - Aug. 20, 2012, 2:41 p.m.
On 20 August 2012 15:33, Natanael Copa <natanael.copa@gmail.com> wrote:
> On Mon, Aug 20, 2012 at 3:27 PM, Peter Maydell <peter.maydell@linaro.org> wrote:
>> 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.
>
> smells missing -lpthread.
>
>> (This seems to me like a glibc bug but since it's out there we rather
>> have to deal with it I think.)
>
> Agree.
>
> Will configure pass if you:
> --- a/configure
> +++ b/configure
> @@ -2661,6 +2661,10 @@ if compile_prog "" "" ; then
>  elif compile_prog "" "-lrt" ; then
>    LIBS="-lrt $LIBS"
>    libs_qga="-lrt $libs_qga"
> +# we might need -lpthread in case static linking on glibc
> +elif compile_prog "" "-lrt -lpthread" ; then
> +  LIBS="-lrt -lpthread $LIBS"
> +  libs_qga="-lrt -lpthread $libs_qga"
>  else
>    echo
>    echo "Error: librt check failed"

Yes, that will work.

-- PMM

Patch

--- a/configure
+++ b/configure
@@ -2661,6 +2661,10 @@  if compile_prog "" "" ; then
 elif compile_prog "" "-lrt" ; then
   LIBS="-lrt $LIBS"
   libs_qga="-lrt $libs_qga"
+# we might need -lpthread in case static linking on glibc
+elif compile_prog "" "-lrt -lpthread" ; then
+  LIBS="-lrt -lpthread $LIBS"
+  libs_qga="-lrt -lpthread $libs_qga"
 else
   echo
   echo "Error: librt check failed"