bug-hurd
[Top][All Lists]
Advanced

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

Re: dlerror sets errno to ENOSYS


From: Samuel Thibault
Subject: Re: dlerror sets errno to ENOSYS
Date: Sun, 28 Feb 2016 19:57:43 +0100
User-agent: Mutt/1.5.21+34 (58baf7c9f32f) (2010-12-30)

Hello,

Diego Nieto Cid, on Sun 28 Feb 2016 01:10:27 -0300, wrote:
> Any ideas?

Using watch in gdb :)

I've added fprintf(stderr,"%p\n", &errno); to get the address of errno: 

(gdb) r
Starting program: /home/samy/main 
[New Thread 28384.6]

Breakpoint 1, main (argc=1, argv=0x102bda4) at main.c:11
11        fprintf(stderr,"%p\n", &errno);
(gdb) n
0x1285688
13        void* shobj = dlopen ("./non-existent.so", RTLD_LAZY);
(gdb) watch * (unsigned long*)0x1285688
Hardware watchpoint 2: * (unsigned long*)0x1285688
(gdb) c
Continuing.
Hardware watchpoint 2: * (unsigned long*)0x1285688

Old value = 0
New value = 1073741902
cthread_keycreate (key=0x104a070 <key>) at ../sysdeps/mach/hurd/cthreads.c:31
31      ../sysdeps/mach/hurd/cthreads.c: Aucun fichier ou dossier de ce type.
(gdb) p 1073741902-0x40000000
$3 = 78
(gdb) bt
#0  cthread_keycreate (key=0x104a070 <key>) at 
../sysdeps/mach/hurd/cthreads.c:31
#1  0x01047459 in init () at dlerror.c:177
#2  _dlerror_run (operate=operate@entry=0x1046bd0 <dlopen_doit>, 
    args=args@entry=0x102bce0) at dlerror.c:129
#3  0x01046cef in __dlopen (file=0x80487b4 "./non-existent.so", mode=1) at 
dlopen.c:87
#4  0x08048689 in main (argc=1, argv=0x102bda4) at main.c:13

Mmm... All of this is bogus in various ways.

To summarize: init calls __libc_key_create to create per-thread
storage.  This is #defined to cthreads_keycreate on hurd, and #defined
to something calling pthread_key_create on linux only when libpthread is
available.

cthread_keycreate is right in putting ENOSYS in errno.  In Linux errno
is not set because when libpthread is not loaded no call is made, and
"1" is simply returned.

We could do something similar in sysdeps/mach/libc-lock.h and
sysdeps/mach/hurd/libc-lock.h, something like this to replace the
existing two __libc_key_create definitions:

extern void *(*_cthread_init_routine) (void) __attribute__ ((weak));
#define __libc_key_create(KEY,DEST) 
(_cthread_init_routine?cthread_keycreate(KEY):1)

No need to fix getspecific and setspecific: since key_create will have
returned an error, libdl will not try to call them, and use a static
buffer instead, which is what is expected.

Could you give that a try?

Samuel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]