LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   'nm' lists all symbols - including static library symbols (https://www.linuxquestions.org/questions/programming-9/nm-lists-all-symbols-including-static-library-symbols-800108/)

painulyarun 04-05-2010 07:08 AM

'nm' lists all symbols - including static library symbols
 
Hi All,

By issuing the 'nm' command on shared library (internally using one static library), the functions exposed by static library is also being listed, Which allows to use internal functions which is of course not intended.

I have one static library having A(), B() and C() functions. Creating one shared library which has function XYS() that is using A() and B() functions from Static library. While doing 'nm' on shared library, alll the static library function are being listed.

Static Lib:

#include<stdio.h>
void A(char *msg)
{
printf("\nMessage: %s\n", msg);
}
int B(int a,int b)
{
return (a+b);
}

void C()
{
}



Shared Lib:

#include<stdio.h>
extern int sumNos(int,int);
int XYZ(void)
{
printf("\nSharedLibFun\n");
A();
}


Makefile:

all:

gcc -c -fPIC statLib.c
ar clq libStat.a statLib.o
gcc -c -fPIC sharedLib.c
gcc -shared -o libShared.so sharedLib.o /path/to/static/lib/libStat.a

Output geneerated after building shared object "libShared.so"

$ nm libShared.so
0000000000000798 T A
00000000000007bb T B
0000000000100b18 A __bss_start
00000000000007cd T C
00000000000006d0 t call_gmon_start
0000000000100b18 b completed.1
0000000000100918 d __CTOR_END__
0000000000100910 d __CTOR_LIST__
w __cxa_finalize@@GLIBC_2.2.5
00000000000007e0 t __do_global_ctors_aux
00000000000006f0 t __do_global_dtors_aux
0000000000100b08 d __dso_handle
0000000000100928 d __DTOR_END__
0000000000100920 d __DTOR_LIST__
0000000000100938 A _DYNAMIC
0000000000100b18 A _edata
0000000000100b20 A _end
0000000000000818 T _fini
0000000000000740 t frame_dummy
0000000000000908 r __FRAME_END__
0000000000100ad0 A _GLOBAL_OFFSET_TABLE_
w __gmon_start__
0000000000000668 T _init
0000000000100930 d __JCR_END__
0000000000100930 d __JCR_LIST__
w _Jv_RegisterClasses
0000000000100b10 d p.0
U printf@@GLIBC_2.2.5
000000000000076c T XYZ
$


Any help will be highly appreciated.

Sergei Steshenko 04-05-2010 07:55 AM

By

Code:

gcc -shared -o libShared.so sharedLib.o /path/to/static/lib/libStat.a
you are telling the linker to link everything together, don't you ?

Sergei Steshenko 04-05-2010 11:12 AM

http://tldp.org/HOWTO/Program-Librar...libraries.html

painulyarun 04-06-2010 03:46 AM

Hi Sergei,

Thanks for your response.

>>> you are telling the linker to link everything together, don't you ?
Yes, i think we need to provide the static library while creating shared object here. Please let me know your suggestions.

I went throgh the link you provided, tried with "-Wl,-export-dynamic" options but that didn't help :(

Thanks!

Sergei Steshenko 04-06-2010 04:04 AM

Quote:

Originally Posted by painulyarun (Post 3925898)
Hi Sergei,

Thanks for your response.

>>> you are telling the linker to link everything together, don't you ?
Yes, i think we need to provide the static library while creating shared object here. Please let me know your suggestions.

I went throgh the link you provided, tried with "-Wl,-export-dynamic" options but that didn't help :(

Thanks!

You have to understand how/when libraries are used. If you want only certain symbols to be taken from something, that something needs to be specified to linker as a library, not just as an item on command line.

The URL I gave you contains examples in which some items are specified as a library.


All times are GMT -5. The time now is 02:17 PM.