[PATCH] fix errno location for non-TLS case

Peter Mazinger ps.m at gmx.net
Thu Dec 1 19:09:15 UTC 2011


Hi

On 12/01/2011 06:35 PM, Peter Mazinger wrote:

> > hi
> >
> >> __errno_location() function should not be library-wide hidden in
> >> non-TLS (thread local storage) case since it should be overriden
> >> by thread-aware function from linuxthreads.old/linuxthreads.
> >> If the function is hidden, calls from libc itself always use it
> >> regardless libpthread linked or not. As the result errno set
> >> in, for example, recv() function is stored in global errno variable
> >> instead of thread-specific location.
> >>
> >> Signed-off-by: Andrew Rybchenko<Andrew.Rybchenko at oktetlabs.ru>
> >> ---
> >>    libc/misc/internals/__errno_location.c |    3 +++
> >>    libc/sysdeps/linux/common/bits/errno.h |    2 ++
> >>    2 files changed, 5 insertions(+), 0 deletions(-)
> >>
> >> diff --git a/libc/misc/internals/__errno_location.c
> >> b/libc/misc/internals/__errno_location.c
> >> index aec7641..371bd26 100644
> >> --- a/libc/misc/internals/__errno_location.c
> >> +++ b/libc/misc/internals/__errno_location.c
> >> @@ -7,6 +7,9 @@
> >>    #include "internal_errno.h"
> >>     /* psm: moved to bits/errno.h: */
> >> +#ifndef __UCLIBC_HAS_TLS__
> >> +libc_hidden_proto(__errno_location)
> >> +#endif
> > libc_hidden_proto does not hide __errno_location, it hides in reality 
> __GI___errno_location
> Yes, exactly. I'm afraid "hidden" term is brought here from GCC and a 
> bit confusing/misleading.
> 
> As I understand (please, correct me if I'm wrong) 
> ./include/libc-symbols.h line 368 clear states
> that libc_hidden_proto() should be used for PLT bypassing withing 
> libc.so. It is exactly what
> happens with __errno_location() if libc_hidden_proto() is used in header 
> - all calls to __errno_location()
> inside libc go directly to libc implementation of __errno_location() 
> regardless libpthread() linked.
> 
libc_hidden_proto creates a hidden __GI_X function and redirects all calls 
from X (in our case __errno_location) to __GI_X (done by definitions in 
header)
In a *.c file the libc_hidden_def (or *_weak) creates an alias from __GI_X 
to X and makes X visible. All internal calls within libc are using __GI_X, 
external apps will use the visible variant X.

> 
> linuxthreads.old implementation just wraps libc socket calls like recv() 
> which set errno.
> Since errno is set from libc call and libc_hidden_proto() is used for 
> __errno_location(),
> libc version of the function is called and provides pointer to global 
> errno variable (not
> thread-specific location).
the error handling within LT_OLD needs some tweaks to cope with internally 
hidden __(GI)___errno_location. I have patches locally for this, waiting 
for commits of future branch to head

> 
> 
> Also it is important here that linuxthreads.old does not use TLS. That's 
> why I use
> __UCLIBC_HAS_TLS__ conditional.
> 
> There is no such bug in 0.9.30.x.
> 
__errno_location has to be defnitely visible for LT_OLD in current shape 
(see also future branch, where IIRC I fixed this)

Regards, Peter

> 
> Andrew.
> > Peter
> >>    int *
> >>    #ifndef __UCLIBC_HAS_THREADS__
> >>    weak_const_function
> >> diff --git a/libc/sysdeps/linux/common/bits/errno.h
> >> b/libc/sysdeps/linux/common/bits/errno.h
> >> index 0bf6354..5f96c31 100644
> >> --- a/libc/sysdeps/linux/common/bits/errno.h
> >> +++ b/libc/sysdeps/linux/common/bits/errno.h
> >> @@ -43,7 +43,9 @@
> >>    # ifndef __ASSEMBLER__
> >>    /* Function to get address of global `errno' variable.  */
> >>    extern int *__errno_location (void) __THROW __attribute__ 
> ((__const__));
> >> +#ifdef __UCLIBC_HAS_TLS__
> >>    libc_hidden_proto(__errno_location)
> >> +#endif
> >>     #  ifdef __UCLIBC_HAS_THREADS__
> >>    /* When using threads, errno is a per-thread value.  */
> >> -- 
> >> 1.7.2.5
> >> _______________________________________________
> >> uClibc mailing list
> >> uClibc at uclibc.org
> >> http://lists.busybox.net/mailman/listinfo/uclibc
> 
> 
> -- 
> Andrew Rybchenko
> OKTET Labs, St.-Petersburg, Russia    Web: www.oktetlabs.ru
> Office: +7 812 7832191  Fax: +7 812 7846591  Mobile: +7 921 7479683
> 
> 
        
-- 
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!		
Jetzt informieren: http://www.gmx.net/de/go/freephone


More information about the uClibc mailing list