This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Determining the memory used by a dynamically loaded shared object


Thanks Carlos, this is helpful.

Marcus.


Carlos O'Donell wrote:
On Mon, Aug 10, 2009 at 1:13 PM, Marcus Clyne<maccaday@gmail.com> wrote:
Is there any way to determine the actual memory used by a dynamically loaded
(i.e. by dlopen...) shared object.  AFAIK this is less than the size of the
.so file on disk, but I'm not sure how to calculate it.

Can anyone help?

The upper bound of the actual memory used is "all of the memory available to the process," since an initializer in the library could consume arbitrary amounts of memory.

A loose lower bound is the memory size of all of the loadable ELF
segments (see the ELF standard for more information).

e.g.
readealf -a libmylib.so
....
Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000000 0x00000000 0x00000000 0x0ed14 0x0ed14 R E 0x1000
  LOAD           0x00f000 0x0000f000 0x0000f000 0x00e40 0x00e48 RW  0x1000
  DYNAMIC        0x00f060 0x0000f060 0x0000f060 0x000d0 0x000d0 RW  0x4
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x4
...

The loose lower bound is 64,556 bytes.

You need to account for alignment, so probably ~65,304 bytes.

Then the C library is going to allocate a link map for this shared
object. I don't know how much space is used by the link map, or if it
varies by number of global symbols.

I hope that helps you get started on an answer.

Cheers,
Carlos.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]