This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Exception handling, dynamic linking and weak symbol tricks


Lately, I've been wondering about doing a port of the gthr.h definitions
to support the Mach/cthreads thread library, and so happened to be gazing
at gthr-posix.h.  Looking at the code, it appears that it does a clever
trick to using weak symbols (if they are available) avoid the work of
making exceptions thread safe if there is only one thread.

The trick in gthr-posix.h looks like this:

    #pragma weak pthread_key_create
	:
	: ... and other pthread functions too...
	:
    static void *__gthread_active_ptr = &pthread_create;

    static inline int
    __gthread_active_p ()
    {
      return __gthread_active_ptr != 0;
    }

Looking at this, I wondered about the case of a program whose main code
doesn't use threads, but dynamically loads a library routine that does.
It looks to me like __gthread_active_p will have already returned 0 and
so exception handling will have committed itself to not being thread-safe.

Then I realized that matters may be even worse -- the new ``__throw''
method for exception handling does not appear to be compatible with
dynamic linking at all (at least in its current incarnation), since
seems to assume that frame information will be statically determined.

Thoughts anyone?

    Melissa.

P.S. If anyone else is thinking about doing a a gthr-mach.h, do let me
know so I don't go duplicating work.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]