468,735 Members | 2,237 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,735 developers. It's quick & easy.

pthread_create symbols in libpthread, libthread and libc

2
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

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

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

libthread.so
[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
main()
{
foo();
}
---------------------
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 1765
AdrianH
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.

Adrian
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.