Hi,
I found a very strange thing when I linked my executable with a shared library. That is the executable only references a small function of the shared library, and the size of this function is only hundred bytes, but when I check the /proc/pid/smaps, I found that the 'Rss' of this shared library is 76 KB that is much larger than the actual size of the referenced function. I just wonder why it is. What's the extra data in this 76 KB of memory? Thanks in advance.
---------- Post updated at 08:34 AM ---------- Previous update was at 06:37 AM ----------
Can anybody tell me the reason???
---------- Post updated 05-25-10 at 07:15 AM ---------- Previous update was 05-24-10 at 08:34 AM ----------
Cheers!!!
Last edited by Scott; 05-24-2010 at 08:55 AM..
Reason: Code tags
Shared libraries have a hashtable (an index) and a symbol table, both of which have to be present/locatable in memory before dl_open can access one of the members. RSS is a process resident header for that rtl library's shared memory segment. Each shared memory segment has one.
In Linux, rss is part of the task struct in the kernel, an unsigned long.
If your system has pmap try
And you will see that all of the shared memory segments have an rss, it is part of using shared libraries. And shared memory.
Are you running in an ARM or similar environment? If so, consider linking your tiny function into your code statically.
Last edited by jim mcnamara; 05-25-2010 at 12:45 PM..
Thanks so much for your reply!!!
You said that a shared library has a hash table and a symbol table. Do you mean the .hash and .dynsym sections of a shared library? And these two sections must be loaded in the memory before actual codes are referenced. Are there any other sections of a shared library must be loaded before actual reference? such as .dynstr, .plt, .got, etc..
Another question is that all these sections must be loaded entirely or just a portion of them.
Actually I got the above smaps from my test programs. I wrote a test shared library contains 20000 functions and a executable only references one function of the shared library (I do not know if these test programs are appropriate) The following is the output of section information of the test library:
You can see that the .hash and .dynsym sections are quite large. Then I ran the executable and read the smaps (as shown previously) of the process, the Rss of the test shared library was much smaller than the size of hash table or symbol table. Does it mean that only a portion of these sections are loaded in the memory?
Those RSS entries are unsigned long words that point to memory that is resident in the process - resident set size. That ememory is local to the process. Those entries are used in part to access (map to) non-resident shared memory segments. They may also be process-resident data.
I did not mean to imply the symbol table/hashtable was actually in the process resident shared memory segment. If that were true then all processes running libc would have a huge rss segment just for the symbol/hash tables.
Sample pmap -x -a output
Note the relatively small size of the segments.
well, if the resident shared memory does not contain hash table or symbol table, what else does it contain except the pure code referenced by the executable? As I mentioned before, the size of the referenced function is only hundred bytes, but the size of resident shared memory is 76 KB. So there must be other sections loaded in the physical memory when use a share library, right?
Before we can fully answer that question you would have to disclose how you build your shared library, the source code of the function you are calling, whether you used lazy loading, etc. what OS and platform you are on, what compiler you are using, what linker you are using, what loader you are using, and lots more.
I'm trying to install libiconv to AIX 7.1 from an rpm off of the perzl site. The rpm appears to install but I get this error message.
add shr4.o shared members from /usr/lib/libiconv.a to /opt/freeware/lib/libiconv.a
add shr.o shared members from /usr/lib/libiconv.a to ... (5 Replies)
Hello.
I am new to this forum and I would like to ask for advice about low level POSIX programming.
I have to implement a POSIX compliant C shared library.
A file will have some variables and the shared library will have some functions which need those variables.
There is one special... (5 Replies)
Hi All
I have been given by someone else header file and a shared library to be used by my C++ application. Compilation is fine but when I try to executes the application I receive the following error.
./first: error while loading shared libraries: libMyLib.so.9: cannot open shared object file:... (2 Replies)
Hi:
I have a library that it only offers Makefile for building static library. It built libxxx.a file. How do I in any way build a shared library? (either changin the Makefile or direct script or command to build shared library)
Thanks. (1 Reply)
I have never seen this issue before, but here is what is happening. I link an executable against two dynamic mlib libraries veclib and lapack. We place a newer version of these libraries in a write only directory and point the shlib_path at that directory. When the executable runs, it gets a... (3 Replies)
I am writing a shared library in Linux (but compatible with other UNIXes) and I want to allow multiple instances to share a piece of memory -- 1 byte is enough. What's the "best" way to do this? I want to optimize for speed and portability.
Obviously, I'll have to worry about mutual exclusion. (0 Replies)
I need to create a shared library to access an in memory DB. The DB is not huge, but big enough to make it cumbersome to carry around in every single process using the shared library. Luckily, it is pretty static information, so I don't need to worry much about synchronizing the data between... (12 Replies)
I have this error when I try to do check on the oracle database...
Can you help me figure out whats the problem? Thanks for all the help!
/usr/lib/pa20_64/dld.sl: Unable to find library 'libjox8.sl'.
/usr/lib/pa20_64/dld.sl: Unable to find library 'libjox8.sl'. ... (1 Reply)