This is the mail archive of the
libc-ports@sources.redhat.com
mailing list for the libc-ports project.
Versioning a symbol in libpthread.
- From: "Carlos O'Donell" <carlos at systemhalted dot org>
- To: Roland McGrath <roland at redhat dot com>, libc-ports at sourceware dot org, aloiret at debian dot org
- Date: Fri, 27 Feb 2009 07:20:19 -0500
- Subject: Versioning a symbol in libpthread.
Roland,
I have some questions about versioning symbols in libpthread. From
the recipe given below, I did not expect to have to do step #5
(manually version pthread_mutex_init). Could you review the process
and comment on step #5 please? I would have expected the Versions file
to version pthread_mutex_init at GLIBC_2.9.
1. Create a Versions file
Versions
~~~
libc {
GLIBC_2.9 {
pthread_mutex_init;
}
}
libpthread {
GLIBC_2.9 {
pthread_mutex_init;
# protected?
__pthread_mutex_init;
}
}
~~~
Notes: Why is __pthread_mutex_init in the Versions list? I would have
expected this to be the local default used internally by libpthread.
This appears to be something historical.
2. Define old version of structures in machine dependent internaltypes.h
3. Create the old version of the library function e.g.
old_pthread_mutex_init.c
~~~
/* snip */
#include <errno.h>
#include "pthreadP.h"
#include <shlib-compat.h>
#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_9)
int
__pthread_mutex_init_hppa_2_0 (pthread_mutex_hppa_2_0_t *var,
const pthread_mutexattr_t *attr)
{
compat_init(var);
compat_malloc(var);
return __pthread_mutex_init(var->compat, attr);
}
compat_symbol (libpthread, __pthread_mutex_init_hppa_2_0, pthread_mutex_init,
GLIBC_2_0);
#endif
~~~
4. Make copies of foward.c, init.c and pthreadP.h, all required to
update the forwarding stubs in libc.
Notes: ports nptl/init.c will be used by csu/init.c, therefore rename
csu/init.c to csu/csu-init.c and fixup csu/Makefile.
forward.c:
~~~
/* snip */
#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_9)
FORWARD2 (__pthread_mutex_init_hppa_2_0, int attribute_compat_text_section,
(pthread_mutex_hppa_2_0_t *mutex, const pthread_mutexattr_t
*mutexattr),
(mutex, mutexattr), return 0)
compat_symbol (libc, __pthread_mutex_init_hppa_2_0, pthread_mutex_init,
GLIBC_2_0);
#endif
FORWARD (pthread_mutex_init,
(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr),
(mutex, mutexattr), 0)
versioned_symbol (libc, __pthread_mutex_init, pthread_mutex_init,
GLIBC_2_9);
/* snip */
~~~
init.c
~~~
/* snip */
.ptr_pthread_mutex_init = INTUSE(__pthread_mutex_init),
# if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_9)
.ptr___pthread_mutex_init_hppa_2_0 = __pthread_mutex_init_hppa_2_0,
# endif
/* snip */
~~~
pthreadP.h
~~~
/* snip */
extern int __pthread_mutex_init (pthread_mutex_t *__mutex,
__const pthread_mutexattr_t *__mutexattr);
extern int __pthread_mutex_init_hppa_2_0 (pthread_mutex_hppa_2_0_t *__mutex,
__const pthread_mutexattr_t *__mutexattr);
/* snip */
~~~
5. Version __pthread_mutex_init.
~~~
/* snip */
#ifndef INCLUDED_SELF
# define INCLUDED_SELF
# include <pthread_mutex_init.c>
#else
# include <shlib-compat.h>
# include <libc-symbols.h>
# include "pthreadP.h"
# undef strong_alias
# define strong_alias(name, aliasname)
# include_next <pthread_mutex_init.c>
# undef strong_alias
# define strong_alias(name, aliasname) _strong_alias(name, aliasname)
versioned_symbol (libpthread, __pthread_mutex_init,
pthread_mutex_init, GLIBC_2_9);
INTDEF(__pthread_mutex_init)
#endif
~~~
With step #5 libpthread contains:
~~~
eu-readelf -a nptl/libpthread.so.0 | grep pthread_mutex_init
0x0001cf08 PARISC_IPLT 0x00009ac8 +0 __pthread_mutex_init
115: 00009ac8 540 FUNC GLOBAL DEFAULT 11
__pthread_mutex_init@@GLIBC_2.2
232: 00009ac8 540 FUNC GLOBAL DEFAULT 11
pthread_mutex_init@@GLIBC_2.9
233: 00017560 260 FUNC GLOBAL DEFAULT 11
pthread_mutex_init@GLIBC_2.2
270: 00009ac8 540 FUNC LOCAL HIDDEN 11
__pthread_mutex_init_internal
355: 00017560 260 FUNC LOCAL DEFAULT 11
__pthread_mutex_init_hppa_2_0
451: 00009ac8 540 FUNC GLOBAL DEFAULT 11 __pthread_mutex_init
530: 00009ac8 540 FUNC GLOBAL DEFAULT 11
pthread_mutex_init@@GLIBC_2.9
603: 00017560 260 FUNC GLOBAL DEFAULT 11
pthread_mutex_init@GLIBC_2.2
~~~
Which correctly has pthread_mutex_init@@GLIBC_2.9. However I did not
expect __pthread_mutex_init@@GLIBC_2.2, but this is likely becuase the
underscored symbol isn't versioned and falls into the default minimum
symbol set.
*Without* step #5 libpthread contains:
~~~
eu-readelf -a libpthread.so.0 | grep pthread_mutex_init
0x0001cee4 PARISC_IPLT 0x00009aa8 +0 __pthread_mutex_init
115: 00009aa8 540 FUNC GLOBAL DEFAULT 11
__pthread_mutex_init@@GLIBC_2.2
232: 00017540 260 FUNC GLOBAL DEFAULT 11
pthread_mutex_init@GLIBC_2.2
181: 00009aa8 540 FUNC LOCAL DEFAULT 11 pthread_mutex_init
271: 00009aa8 540 FUNC LOCAL HIDDEN 11
__pthread_mutex_init_internal
356: 00017540 260 FUNC LOCAL DEFAULT 11
__pthread_mutex_init_hppa_2_0
452: 00009aa8 540 FUNC GLOBAL DEFAULT 11 __pthread_mutex_init
603: 00017540 260 FUNC GLOBAL DEFAULT 11
pthread_mutex_init@GLIBC_2.2
~~~
Which is missing a global default pthread_mutex_init@@GLIBC_2.9, or
even a pthread_mutex_init with global default visibility.
Cheers,
Carlos.