bug-hurd
[Top][All Lists]
Advanced

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

Re: libpthread not loading indirectly?


From: Roland McGrath
Subject: Re: libpthread not loading indirectly?
Date: Mon, 2 May 2005 17:14:55 -0700 (PDT)

There are two definitions of _cthread_init_routine, one in libc and one in
libpthread.  You need libc's references to resolve to the libpthread
definition so it sees that initialized value.  This means that libpthread
has to precede libc in the symbol search order, as things are now.  Your
link with -lxml2 -lpthread -lc does this (breadth-first yields: xml2,
pthread, c, pthread; the second copy is ignored), but with -lxml2 -lc
does not (breadth-first yields: xml2, c, pthread).

I'm not having any luck at the moment thinking of a clever solution to this
given the status quo.  If libc's definition of _cthread_init_routine were
weak, and you always set the LD_DYNAMIC_WEAK environment variable, then it
would work.  But LD_DYNAMIC_WEAK behavior is not the default any more.

The _cthread_init_routine trick was done originally really without thought
to dynamic linking, which was not around at the time.  It doesn't mesh well
in the complicated cases, like the one you have hit.

I think the minimal change we can manage to get this going is the following
glibc change.  If we aren't concerned about compatibility of the new glibc
with the existing libthreads/libpthreads binaries, we could instead dump
the _cthread_init_routine variable entirely and make it a weak reference to
a function instead, which would be slightly cleaner.  Given the kludgey
nature of the whole area and the long-term intent to replace it completely
(with something not requiring the stack switching at all), I am inclined to
just go with this minimal kludge if it does in fact work.


Thanks,
Roland

Index: sysdeps/mach/hurd/i386/init-first.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/mach/hurd/i386/init-first.c,v
retrieving revision 1.43
diff -B -b -p -u -r1.43 init-first.c
--- sysdeps/mach/hurd/i386/init-first.c 13 Sep 2004 00:42:46 -0000
    1.43
+++ sysdeps/mach/hurd/i386/init-first.c 3 May 2005 00:11:14 -0000
@@ -54,7 +55,7 @@ extern int __libc_argc attribute_hidden;
 extern char **__libc_argv attribute_hidden;
 extern char **_dl_argv;
 
-void *(*_cthread_init_routine) (void); /* Returns new SP to use.  */
+extern void *(*_cthread_init_routine) (void) __attribute__ ((weak));
 void (*_cthread_exit_routine) (int status) __attribute__ ((__noreturn__));
 
 /* Things that want to be run before _hurd_init or much anything else.
@@ -203,7 +204,7 @@ init (int *data)
      code as the return address, and the argument data immediately above
      that on the stack.  */
 
-  if (_cthread_init_routine)
+  if (&_cthread_init_routine && _cthread_init_routine)
     {
       /* Initialize cthreads, which will allocate us a new stack to run on.  */
       int *newsp = (*_cthread_init_routine) ();





reply via email to

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