471,343 Members | 1,350 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,343 software developers and data experts.

pthread_create symbols in libpthread, libthread and libc

There are pthread_create symbols in libphread.so, libthread.so and libc.so.
The following symbols displayed with the nm command:

[Index] Value Size Type Bind Other Shndx Name

[5003] | 637360| 36|FUNC |WEAK |0 |9 |_pthread_create
[2867] | 637360| 36|FUNC |WEAK |0 |9 |pthread_create

[291] | 14964| 8|FUNC |GLOB |0 |7 |_pthread_create
[283] | 14964| 8|FUNC |WEAK |0 |7 |pthread_create

[658] | 48640| 712|FUNC |GLOB |0 |9 |_pthread_create
[259] | 48640| 712|FUNC |LOCL |0 |9 |_ti_pthread_create
[662] | 48640| 712|FUNC |WEAK |0 |9 |pthread_create

The pthread_create() returns -1 linking only libc.so, and work properly
linking both libc.so and libpthread.so in spite of link's ordering.
I understand it is realized using "#pragma weak", so I tried to make a program
to do the same in the following programs, but I can't.
The foo() returns 0 in main.c when linking libfoo.so before libdummy.so,
that is to say, "cc main.c -lfoo -ldummy", but foo() returns -1 when linking
libdummy.so before libfoo.so, that is to say, "cc main.c -ldummy -lfoo".
Could someone tell me about this mechanism?

in main.c
in libdummy.so
#pragma weak foo
int foo()
return -1;
in libfoo.so
#pragma weak foo = _foo
int _foo()
return 0;
Feb 8 '07 #1
1 1824
1,251 Expert 1GB
Wow, I didn't even know that gcc used pragmas. I've only used the __attribute__ for doing similar things.

Anyway, I don't know off hand so I will have to get back to you or you can google the words: gcc and pragma, or go to the gcc documentation at http://gcc.gnu.org/onlinedocs/ which is what I am going to do to answer this question.

Feb 9 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Hug | last post: by
20 posts views Thread by int main(void) | last post: by
9 posts views Thread by Gary Wessle | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.