LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-05-2010, 07:08 AM   #1
painulyarun
LQ Newbie
 
Registered: Apr 2010
Posts: 2

Rep: Reputation: 0
Post '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.
 
Old 04-05-2010, 07:55 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
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 ?
 
Old 04-05-2010, 11:12 AM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
http://tldp.org/HOWTO/Program-Librar...libraries.html
 
Old 04-06-2010, 03:46 AM   #4
painulyarun
LQ Newbie
 
Registered: Apr 2010
Posts: 2

Original Poster
Rep: Reputation: 0
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!
 
Old 04-06-2010, 04:04 AM   #5
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by painulyarun View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Debugger selectively not using symbols in library with symbols Millenniumman Programming 5 03-25-2007 09:44 AM
Debugger selectively not using symbols in library with symbols Millenniumman Programming 1 03-03-2007 07:46 PM
Hiding global symbols in a shared/static library jineshkj Programming 16 08-30-2006 12:45 AM
Hiding Symbols in Static Libraries JCipriani Programming 2 03-03-2006 05:15 PM


All times are GMT -5. The time now is 11:55 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration