Patch for gcc 2.95.2

Charles-Antoine Gauthier charles.gauthier at nrc.ca
Wed Mar 8 19:55:26 UTC 2000


Ian Lance Taylor wrote:
> 
>    Date: Wed, 08 Mar 2000 13:57:30 -0500
>    From: Charles-Antoine Gauthier <charles.gauthier at nrc.ca>
> 
>    >    Disabling of weak symbols is necessary when configuring gcc with
>    >    --enable-threads=posix, otherwise the pthred_xxx() calls are declared
>    >    weak. The result is that they typically are left undefined at link time,
>    >    but the link succeeds. The end results are explicit calls to address 0.
>    >
>    > C++ uses weak symbols when handling templates.  Weak symbols are
>    > generally useful in any case.  Don't disable them.  Fix this problem
>    > in a different way.
> 
>    OK. Suggestions or pointers to the ld manual? (Just trying to save
>    myself some time looking for an answer).
> 
> For example, force the functions to be linked in from RTEMS, by
> referencing them directly from your application, or from crt0.o.  For
> another example, don't mark them as weak in gthr-posix.h, or simply
> define GTHREAD_USE_WEAK as 0.

That last one sounds good. I will investigate. Thanks.

> 
>    in gcc/gthr-posix.h:
> 
>    static inline int
>    __gthread_once (__gthread_once_t *once, void (*func) (void))
>    {
>      if (__gthread_active_p ())
>        return pthread_once (once, func);
>      else
>        return -1;
>    }
> 
>    is called from eh_context_initialize() in gcc/libgcc2.c. This is one
>    that I tripped over many times, where pthred_once was not linked in.
> 
> __gthread_active_p will only return non-zero if pthread_create is
> defined--i.e., linked into the executable.
> 
> Is it the case that pthread_create is linked into the executable but
> pthread_once is not?  What would cause that to happen?  How can it be
> avoided?

I don't have the bad image anymore, so I can't check. But I certainly
have had situations where only pthread_once was missing; other pthread
functions were linked in. I suspect that the pthread functions that are
linked in are referenced by the application. The application object
files are specified first, ahead of the runtime library group. I just
assumed that any weak symbols referenced only from libgcc but defined in
librtemsall were silently ignored. pthread_create would certainly have
been pulled in from the application to create the initial Java thread.

> 
> Ian

-- 
Charles-Antoine Gauthier
Institute for Information Technology   Institut de technologie de
l'information
National Research Council of Canada    Conseil national de recherches du
Canada



More information about the users mailing list