This is the mail archive of the gcc-patches@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]

Re: RFC: "Generic" gthread model


OK, you basically sold me. ;-)  I think you need approval from someone
with global write privs.  I am just a mere user of the gthr.h API in
code I rewrote for libstdc++, not someone that can approve a change.

I have tested your assertion regarding library order, etc.

/* t.c */

#include <stdio.h>

#define STRING(x) STRINGX(x)
#define STRINGX(x) #x

void foo (void) { printf (__FUNCTION__ " " STRING(UNIQ) "\n"); }

void UNIQ (void) { foo (); printf (__FUNCTION__ " " STRING(UNIQ) "\n"); }


/* main.c */

#include <stdio.h>

void foo (void);
void t1 (void);
void t2 (void);
void t3 (void);
void t4 (void);

int main (void)
{
  foo ();
  t1 ();
  t2 ();
  t3 ();
  t4 ();
  return 0;
}

gcc -DUNIQ\=t1 -fpic -shared -o libt1.so t.c
gcc -DUNIQ\=t2 -fpic -shared -o libt2.so t.c
gcc -DUNIQ\=t3 -c -o t3.o t.c
gcc -DUNIQ\=t4 -c -o t4.o t.c
ar r libt4.a t4.o 
ar r libt3.a t3.o
gcc -lt1 -lt2  -L. -R. main.c -lt3 -lt4
./libt4.a(t4.o): In function `foo':
t4.o(.text+0x0): multiple definition of `foo'
./libt3.a(t3.o)(.text+0x0): first defined here
collect2: ld returned 1 exit status

Perhaps a contrived example...  But it actually shows a problem I
didn't expect: namely, collision between static libraries...

If I make foo weak, by adding:
#pragma weak foo
and then redoing all steps above:

a.out
foo t3
foo t3
t1 t1
foo t3
t2 t2
foo t3
t3 t3
foo t3
t4 t4

It appears on this platform, static libraries dominate the dynamic
libraries when the symbol was declared weak everywhere...

Make the symbol non-weak in the two dynamic libraries (keep it weak in
the static libraries) and recompile main.c:

a.out
foo t1
foo t1
t1 t1
foo t1
t2 t2
foo t1
t3 t3
foo t1
t4 t4

My analysis is that you had better make the symbol weak on platforms
that support it.  Thread model "unknown" may be unusable in the manner
you want on platforms without weak support.  This analysis is not
complete since I didn't cover all combinations of static and dynamic
nor all platforms of interest.

Sorry to be a pain but I think we need to know these answers before we
make "unknown" the default for all platforms.  I am not against any
other part of your patch since it would have to be enabled explicitly
for a platform by someone that knows the platform (or the user via a
non-standard configure-time switch)...

Regards,
Loren


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