AnsweredAssumed Answered

Strace and ld.so problem : load again shared libraries already in use

Question asked by Jbruneaux on Dec 28, 2012
Latest reply on Jan 8, 2013 by sonic

Hi,

 

We are currently trying to find why we have some random memory problems while loading our application. to achieve this, I need to be able to track the memory allocations made at application startup because it's there that the problem appears.

I want to use strace to do those traces but I'm facing a problem :

I run a small program which loads Qt libraries (it could also load any library), using dlopen() calls. This program is named loadQT (for future reference)

I can load several instances of this program and only the 'data' part of the library is loaded per instance.

If I use strace to trace this program (or an other program wich uses the same libraries), then the whole library is loaded again in RAM at different addresse (using strace make ld-uClibc.so act like it never had loaded that library. this lead to a crash because our memory isn't large enought to hold the library if I try to strace 2 programs.

1/ Running the program loadQT using this command line produce the output in the attached file LD_DEBUG=files_loadQT.log (part 1) :

LD_DEBUG=files /usr/local/bin/loadQT &

2/ Then, runnong the program loadQT with strace using this command line produce the attached file LD_DEBUG=files_strace_loadQT.log :

LD_DEBUG=files strace -o /tmp/strace /usr/local/bin/loadQT &

After that, typing the command 'cat /proc/maps' outputs :

00400000-007bd000 r-xs 00000000 00:01 736        /usr/lib/libQtGui.so
  00c00000-00e04000 r-xs 00000000 00:01 712        /usr/lib/libQtCore.so
  011c0000-011e8000 r-xs 00000000 00:01 740        /usr/lib/libQtXml.so
  01400000-0144c000 r-xs 00000000 00:01 739        /usr/lib/libQtNetwork.so
  01480000-014c4000 r-xs 00000000 00:01 744        /usr/lib/libQtDBus.so
  01640000-01668000 r-xp 00000000 00:01 740        /usr/lib/libQtXml.so
  01780000-017cc000 r-xp 00000000 00:01 739        /usr/lib/libQtNetwork.so
  01800000-01a04000 r-xp 00000000 00:01 712        /usr/lib/libQtCore.so
  01c00000-01fbd000 r-xp 00000000 00:01 736        /usr/lib/libQtGui.so
  03800000-03844000 r-xp 00000000 00:01 744        /usr/lib/libQtDBus.so

This output shows that somehow the flags 'MAP_SHARED' has been changed to 'MAP_PRIVATE' when strace was used...

 

3/ Finally, running again the loadQT program using this command line produce the second part of the LD_DEBUG=files_loadQT.log file

LD_DEBUG=files /usr/local/bin/loadQT &

 

I've had a quick look into the ld-uClibc.so sources and on library loading, in dl-elf.c, the _dl_load_elf_shared_library function looks in a global table if the library is already loaded or not. It seems that when using strace, this doesn't work.

Do you have any clue of what happens ?

Regards, Jerome

Outcomes