Skip to contentSkip to conversation

shared objects, ELFs and memory usage

DISCUSSION Nir Livni 2 participants 2 messages May 6, 2003

lore
Share & tools
lore

Nir Livni

author
#0 lore raw

Hi all,
If this is not the mailing list to ask this question - please let me know where should I ask it.

I have an executable whose size is almost 2MB, and it uses a shared object that is almost 2MB.
when I run the process, I see (using "top") that the amount of "used memory" raises with 4MB. (make sence...). the process seem to share 2MB ("shared" column).

When the process forks, it seems that the amount of "used memory" raises with 4MB again.

Does it mean the shared object is not really shared ? That doesn't make sence...

Help is appreciated.
Please CC me because I am not subscribed.

Thanks,
Nir

#1 lore raw
Quoted 13 lines · Nir Livni

Hi all,
If this is not the mailing list to ask this question - please let me know where should I ask it.

I have an executable whose size is almost 2MB, and it uses a shared object that is almost 2MB.
when I run the process, I see (using "top") that the amount of "used memory" raises with 4MB. (make sence...). the process seem to share 2MB ("shared" column).

When the process forks, it seems that the amount of "used memory" raises with 4MB again.

Quoted 8 lines

Does it mean the shared object is not really shared ? That doesn't make sence...

Help is appreciated.
Please CC me because I am not subscribed.

Thanks,
Nir

If your shared object is truly a shared object, then it is shared. Use strace to trace the startup of your program. You should see it mmap() some portion of your shared object. You can also put a pause() in you program, then look at /proc/<PID>/maps and see what your program has memapped.

Note that merely linking some object files together does not create a shared object! You need to compile any 'C' code with the '-shared' parameter, and any assembly code needs to not use COMM variables. Then you need to link them as

	ld -warn-common -O2 -shared -Map Shared.Map $(OBJS) -o $(SLIB)

...where OBJS is you list of object files, and SLIB is your new shared library.

You can inspect Shared.Map to see what is in the library. When you link against the shared library, you need to tell the linker where to find the runtime file, i.e., you need to use -rpath.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.20 on an i686 machine (797.90 BogoMips). Why is the government concerned about the lunatic fringe? Think about it.