tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Moving pthread_(cond|mutex) to libc



Starting with NetBSD 6.0, libpthread is cursed with the NOLOAD flag,
which means it cannot be loaded by dlopen(). The problem is that we can
easily get to dlopen'able modules that do not use pthreads, but are
linked to libraries that are linked with -lpthread. Such module cannot
be loaded anymore in NetBSD 6.0.

It seems there is a conensus that pthread_(cond|mutex) should move to
libc so that libpthread could be freed from NOLOAD [1]. I started
looking at it and of course it raises a few problems.

1) src/lib/libpthread/pthread_(cond|mutex).c include "pthread_md.h"
which should be taken from src/lib/libpthread/arch/$arch/pthread_md.h.
Once moved to src/lib/libc they do not find it anymore. I worked around
this problem by adding in src/lib/libc/gen/Makefile.inc this, which
calls for comments:

PTHREAD_ARCHDIR=        ${NETBSDSRCDIR}/lib/libpthread/arch
.if defined(PTHREAD_MACHINE_ARCH) && !empty(PTHREAD_MACHINE_ARCH) && \
    exists(${PTHREAD_ARCHDIR}/${PTHREAD_MACHINE_ARCH})
PTHREAD_ARCHSUBDIR=     ${PTHREAD_ARCHDIR}/${PTHREAD_MACHINE_ARCH}
.elif exists(${PTHREAD_ARCHDIR}/${MACHINE_ARCH})
PTHREAD_ARCHSUBDIR=     ${PTHREAD_ARCHDIR}/${MACHINE_ARCH}
.elif exists(${PTHREAD_ARCHDIR}/${MACHINE_CPU})
PTHREAD_ARCHSUBDIR=     ${PTHREAD_ARCHDIR}/${MACHINE_CPU}
.endif  
        
CPPFLAGS.pthread_cond.c+=       -I${PTHREAD_ARCHSUBDIR}
CPPFLAGS.pthread_mutex.c+=      -I${PTHREAD_ARCHSUBDIR} 

2) libc then fails to link,which suggest more stuff should move from
libpthread to libc. Shall I carry on that way?

libc_pic.a(pthread_cond.pico):(.text+0x13d): undefined reference to
`pthread__errorfunc'
libc_pic.a(pthread_cond.pico):(.text+0x2a7): undefined reference to
`pthread__errorfunc'
libc_pic.a(pthread_cond.pico): In function `__libc_cond_init':
pthread_cond.c:(.text+0x337): undefined reference to
`pthread__errorfunc'p
thread_cond.c:(.text+0x355): undefined reference to `pthread_lockinit'
pthread_cond.c:(.text+0x3a2): undefined reference to `pthread_lockinit'
libc_pic.a(pthread_cond.pico): In function `__libc_cond_destroy':
pthread_cond.c:(.text+0x43b): undefined reference to
`pthread__errorfunc'
pthread_cond.c:(.text+0x46c): undefined reference to
`pthread__errorfunc'
libc_pic.a(pthread_cond.pico): In function `__libc_cond_timedwait':
pthread_cond.c:(.text+0x514): undefined reference to
`pthread__errorfunc'
pthread_cond.c:(.text+0x67a): undefined reference to
`pthread__cancelled'
pthread_cond.c:(.text+0x6a8): undefined reference to
`pthread__errorfunc'
pthread_cond.c:(.text+0x6e4): undefined reference to
`pthread__errorfunc'
pthread_cond.c:(.text+0x791): undefined reference to
`pthread__testcancel'


[1] See that thread for background
http://mail-index.netbsd.org/tech-pkg/2013/01/19/msg010635.html

-- 
Emmanuel Dreyfus
http://hcpnet.free.fr/pubz
manu%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index