1

In my following scenario:

  • libA.so library links libCommon.so
  • libB.so library also links libCommon.so
  • even though both libraries link the same libCommon.so, they setup different configuration of libCommon.so

             --> libA.so --> libCommon.so
            /
    ProgramA
            \
             --> libB.so --> libCommon.so
    
    
    
             --> libA.so
            /           \
    ProgramA              --> libCommon.so
            \           /
             --> libB.so
    

Will my program share the same copy of libCommon.so or they have use different copy? As I mentioned earlier, libCommon.so are used with different setting. Ideally, I want to have it like the first diagram, that libCommon.so have different copies in the memory. I am trying to avoid call to one copy affect the behavior of other side.

user926958
  • 9,355
  • 7
  • 28
  • 33

1 Answers1

1

Short answer: You get the second diagram. And that's usually what most developers want, otherwise there would less benefit to dynamic linking. It's really up to the implementation of libCommon to allow multiple instantiation within the same process - usually achieved by avoiding global variables within libraries to maintain state between exported function calls.

Do you maintain the source to libCommon? If so, then explore ways to fix it to have it's usage be based on "sessions" instead of maintaining all state in globals.

If not, then do you maintain the source to libA or libB? You can essentially get the first diagram, by having one or both of libA and libB statically linking to libCommon.a instead of libCommon.so - that presumes that a statically compiled version of libCommon.a exists.

selbie
  • 100,020
  • 15
  • 103
  • 173