[lxc-devel] [PATCH] Link against pthread when not on bionic.

Stéphane Graber stgraber at ubuntu.com
Mon Feb 18 21:29:00 UTC 2013


On 02/18/2013 04:10 PM, Daniel Lezcano wrote:
> On 02/18/2013 09:46 PM, Stéphane Graber wrote:
>> On 02/18/2013 03:40 PM, Daniel Lezcano wrote:
>>> On 02/18/2013 06:23 PM, Stéphane Graber wrote:
>>>> dpkg spotted that we're not explicitly linking against pthread even though
>>>> we use some of its symbols (sem_*).
>>> uh ? wait.
>>>
>>> We shouldn't link against the lib pthread.
>>>
>>> I don't think sem_* is a symbol coming from the pthread library.
>>>
>>> Could you give the output of dpkg ?
>> From "man sem_open":
>>        Link with -pthread.
> 
> -pthread, not -lpthread

Oops, misread ...

> or -librt
> 
> As lxc is not thread safe, you should prevent to link against the
> libpthread because the user will think it is thread safe and that could
> lead to some unexpected behavior.

Right, please ignore the patch as it's definitely not something we want
to do. Would be nice to find a way to make dpkg happy though as this may
result into wrongly autogenerated package dependencies (though as in
this case it's against libc, it's not really a problem).

> Linking against librt should be ok. I don't understand the warning of dpkg.
> 
> Could you check by commenting the lines below if the warning still appear ?
> 
> #if !IS_BIONIC
> liblxc_so_LDADD += -lutil -lrt
> #endif

Building without those fails with:
liblxc.so: undefined reference to `sem_post'
liblxc.so: undefined reference to `sem_open'
liblxc.so: undefined reference to `sem_timedwait'
liblxc.so: undefined reference to `sem_wait'
liblxc.so: undefined reference to `sem_init'
liblxc.so: undefined reference to `sem_destroy'
liblxc.so: undefined reference to `sem_close'


So maybe it's just the tools being confused...
Building with -lutil -lrt does work fine, it's just that dpkg-shlibdeps
thinks something's wrong and there doesn't appear to be an easy way to
shut it...


>> dpkg-shlibdeps output:
>> dpkg-shlibdeps: warning: symbol sem_post used by
>> debian/liblxc0/usr/lib/x86_64-linux-gnu/liblxc.so.0.9.0.alpha3 found in
>> none of the libraries
>> dpkg-shlibdeps: warning: symbol sem_open used by
>> debian/liblxc0/usr/lib/x86_64-linux-gnu/liblxc.so.0.9.0.alpha3 found in
>> none of the libraries
>> dpkg-shlibdeps: warning: symbol sem_close used by
>> debian/liblxc0/usr/lib/x86_64-linux-gnu/liblxc.so.0.9.0.alpha3 found in
>> none of the libraries
>> dpkg-shlibdeps: warning: symbol sem_init used by
>> debian/liblxc0/usr/lib/x86_64-linux-gnu/liblxc.so.0.9.0.alpha3 found in
>> none of the libraries
>> dpkg-shlibdeps: warning: symbol sem_timedwait used by
>> debian/liblxc0/usr/lib/x86_64-linux-gnu/liblxc.so.0.9.0.alpha3 found in
>> none of the libraries
>> dpkg-shlibdeps: warning: symbol sem_destroy used by
>> debian/liblxc0/usr/lib/x86_64-linux-gnu/liblxc.so.0.9.0.alpha3 found in
>> none of the libraries
>> dpkg-shlibdeps: warning: symbol sem_wait used by
>> debian/liblxc0/usr/lib/x86_64-linux-gnu/liblxc.so.0.9.0.alpha3 found in
>> none of the libraries
>>
>>
>> Looking at pthread.so it appears to provide:
>> sem_init
>> sem_destroy
>> sem_open
>> sem_close
>> sem_unlink
>> sem_getvalue
>> sem_wait
>> sem_trywait
>> sem_timedwait
>> sem_post
>>
>>>> Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
>>>> ---
>>>>  src/lxc/Makefile.am | 2 +-
>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
>>>> index 8974ca9..a0077aa 100644
>>>> --- a/src/lxc/Makefile.am
>>>> +++ b/src/lxc/Makefile.am
>>>> @@ -115,7 +115,7 @@ liblxc_so_LDFLAGS = \
>>>>  liblxc_so_LDADD = $(CAP_LIBS) $(APPARMOR_LIBS) $(SECCOMP_LIBS)
>>>>  
>>>>  if !IS_BIONIC
>>>> -liblxc_so_LDADD += -lutil -lrt
>>>> +liblxc_so_LDADD += -lutil -lrt -lpthread
>>>>  endif
>>>>  
>>>>  bin_SCRIPTS = \
>>
> 


-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 901 bytes
Desc: OpenPGP digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20130218/a7bc7995/attachment.pgp>


More information about the lxc-devel mailing list