[PATCH] fix errno location for non-TLS case

Andrew Rybchenko Andrew.Rybchenko at oktetlabs.ru
Fri Dec 2 07:04:50 UTC 2011

Hi Peter,

On 12/01/2011 11:09 PM, Peter Mazinger wrote:
> On 12/01/2011 06:35 PM, Peter Mazinger wrote:
>> > 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.
Thanks a lot for detailed description of the technique. If I understand 
your description correct,
it does not change the result. If libc_hidden_proto() is used for 
__errno_location() in header,
all libc calls to __errno_location() will use internal function (not 
__errno_location() provided
by linuxthreads.old).

>> 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
That's great. I hope the issue will be fixed in 0.9.31 and 0.9.32 
branches as well.

>> 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)
Am I right that you talk about e934c55580d707710df6efc52718a8ed26775df4 and
If so, I'll try to check it (since I don't understand how it fixes the 
issue and I'd like to).

Thanks a lot,

Andrew Rybchenko
OKTET Labs, St.-Petersburg, Russia    Web: www.oktetlabs.ru
Office: +7 812 7832191  Fax: +7 812 7846591  Mobile: +7 921 7479683

More information about the uClibc mailing list