diff mbox series

[v2,01/13] build-sys: fix qemu-ga -pthread linking

Message ID 20171215150659.1811-2-marcandre.lureau@redhat.com
State New
Headers show
Series Various build-sys and ASAN related fixes | expand

Commit Message

Marc-André Lureau Dec. 15, 2017, 3:06 p.m. UTC
When linking qemu-ga under some configuration (when gthread-2.0.pc
doesn't have -pthread, as happening atm with meson build), you may
have this linking issue:

/usr/bin/ld: libqemuutil.a(qemu-thread-posix.o): undefined reference to symbol 'pthread_setname_np@@GLIBC_2.12'
/usr/lib64/libpthread.so.0: error adding symbols: DSO missing from command line

Make sure qemu-ga links with the pthread library, by adding correct
flags to libs_qga.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 configure | 1 +
 1 file changed, 1 insertion(+)

Comments

Philippe Mathieu-Daudé Dec. 15, 2017, 6:21 p.m. UTC | #1
Hi Marc-André,

On 12/15/2017 12:06 PM, Marc-André Lureau wrote:
> When linking qemu-ga under some configuration (when gthread-2.0.pc
> doesn't have -pthread, as happening atm with meson build), you may
> have this linking issue:
> 
> /usr/bin/ld: libqemuutil.a(qemu-thread-posix.o): undefined reference to symbol 'pthread_setname_np@@GLIBC_2.12'
> /usr/lib64/libpthread.so.0: error adding symbols: DSO missing from command line
> 
> Make sure qemu-ga links with the pthread library, by adding correct
> flags to libs_qga.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  configure | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/configure b/configure
> index 0c6e7572db..2b8c71f522 100755
> --- a/configure
> +++ b/configure
> @@ -3436,6 +3436,7 @@ else
>        done
>        if test "$found" = "no"; then
>          LIBS="$pthread_lib $LIBS"
> +        libs_qga="$pthread_lib $libs_qga"
>        fi
>        PTHREAD_LIB="$pthread_lib"
>        break

Hmm why not add it later, around line 4270:

if compile_prog "" "" ; then
  :
# we need pthread for static linking. use previous pthread test result
elif compile_prog "" "$pthread_lib -lrt" ; then
  LIBS="$LIBS -lrt"
  libs_qga="$libs_qga -lrt" #  <-- here
fi
Peter Maydell Dec. 15, 2017, 6:31 p.m. UTC | #2
On 15 December 2017 at 18:21, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> Hi Marc-André,
>
> On 12/15/2017 12:06 PM, Marc-André Lureau wrote:
>> When linking qemu-ga under some configuration (when gthread-2.0.pc
>> doesn't have -pthread, as happening atm with meson build), you may
>> have this linking issue:
>>
>> /usr/bin/ld: libqemuutil.a(qemu-thread-posix.o): undefined reference to symbol 'pthread_setname_np@@GLIBC_2.12'
>> /usr/lib64/libpthread.so.0: error adding symbols: DSO missing from command line
>>
>> Make sure qemu-ga links with the pthread library, by adding correct
>> flags to libs_qga.

This commit message misled me temporarily, because it suggests
that the problem is with the gthread-2.0.pc pkg-config file.
But this is really a QEMU bug, because it's QEMU code that's
using pthread functions, and so we must explicitly link against
pthreads. The bug was just masked by the fact that often some
pkg-config or another for one of our dependencies will add
-pthread to the link line anyway.

>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> ---
>>  configure | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/configure b/configure
>> index 0c6e7572db..2b8c71f522 100755
>> --- a/configure
>> +++ b/configure
>> @@ -3436,6 +3436,7 @@ else
>>        done
>>        if test "$found" = "no"; then
>>          LIBS="$pthread_lib $LIBS"
>> +        libs_qga="$pthread_lib $libs_qga"
>>        fi
>>        PTHREAD_LIB="$pthread_lib"
>>        break

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>


> Hmm why not add it later, around line 4270:
>
> if compile_prog "" "" ; then
>   :
> # we need pthread for static linking. use previous pthread test result
> elif compile_prog "" "$pthread_lib -lrt" ; then
>   LIBS="$LIBS -lrt"
>   libs_qga="$libs_qga -lrt" #  <-- here
> fi

Because that's a different test, which is checking whether we
need to link against librt. We might need to link against pthread
even if we don't need to link against librt.

thanks
-- PMM
Marc-André Lureau Dec. 19, 2017, 3:43 p.m. UTC | #3
Hi

On Fri, Dec 15, 2017 at 7:21 PM, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> Hi Marc-André,
>
> On 12/15/2017 12:06 PM, Marc-André Lureau wrote:
>> When linking qemu-ga under some configuration (when gthread-2.0.pc
>> doesn't have -pthread, as happening atm with meson build), you may
>> have this linking issue:
>>
>> /usr/bin/ld: libqemuutil.a(qemu-thread-posix.o): undefined reference to symbol 'pthread_setname_np@@GLIBC_2.12'
>> /usr/lib64/libpthread.so.0: error adding symbols: DSO missing from command line
>>
>> Make sure qemu-ga links with the pthread library, by adding correct
>> flags to libs_qga.
>>
>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> ---
>>  configure | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/configure b/configure
>> index 0c6e7572db..2b8c71f522 100755
>> --- a/configure
>> +++ b/configure
>> @@ -3436,6 +3436,7 @@ else
>>        done
>>        if test "$found" = "no"; then
>>          LIBS="$pthread_lib $LIBS"
>> +        libs_qga="$pthread_lib $libs_qga"
>>        fi
>>        PTHREAD_LIB="$pthread_lib"
>>        break
>
> Hmm why not add it later, around line 4270:

This is check place for librt usage, better to keep it around pthread checks.

>
> if compile_prog "" "" ; then
>   :
> # we need pthread for static linking. use previous pthread test result
> elif compile_prog "" "$pthread_lib -lrt" ; then
>   LIBS="$LIBS -lrt"
>   libs_qga="$libs_qga -lrt" #  <-- here
> fi
>
diff mbox series

Patch

diff --git a/configure b/configure
index 0c6e7572db..2b8c71f522 100755
--- a/configure
+++ b/configure
@@ -3436,6 +3436,7 @@  else
       done
       if test "$found" = "no"; then
         LIBS="$pthread_lib $LIBS"
+        libs_qga="$pthread_lib $libs_qga"
       fi
       PTHREAD_LIB="$pthread_lib"
       break