This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC 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: reload .so without restarting process


Hatt Tom writes:

Here is one  example :

First, I linked  liba.so into executable target by the compiler
command  "g++ -la " at linking stage .

then ,I use dlopen to load liba.so in the executable's process .

At this time ,the reference count of liba.so is 2 ,  am I right ?

Right.

And if you think you can just dlclose() it an extra time, think again. It won't work. For at least two reasons.

1) dlopen() returns an opaque handle for each open. Opening the same .so is going to give you a technically different handle, and because you can only dlclose() a handle that you've opened, and you do not have a handle that was used to, essentially, dlopen the directly-linked library, you can't do it.

2) Your existing executable has resolved the external symbols to your .so already (via a process that's equivalent to dlsym(), even before your executable ran). Even if you somehow manage to close it, and dlopen it back, the existing linkage remains what it is. Hillarity ensues.

So, you have no choice but to dlopen() your library, right from the start. You have no other options.




2013/12/3 Sam Varshavchik <mrsam@courier-mta.com>:
> Hatt Tom writes:
>
>> Thanks ! The problem has been resolved .
>>
>> And hereis one question I should get to be clear of . if I link one
>> .so into one executeable file , would this increase the reference
>> count by one already ? so dlclose would not unload that .so until the
>> reference count decrease to zero .
>
>
> Correct.
>
>
>>
>> 2013/12/2 Sam Varshavchik <mrsam@courier-mta.com>:
>> > Hatt Tom writes:
>> >
>> >> If I use dlsym() to load the address manually ,will  GOT  be  needed
>> >> any
>> >> more ?
>> >
>> >
>> > If you always use dlopen(), and the dlsym() to call methods from a .so,
>> > you
>> > don't really need to link to it directly, any more, so this is a moot
>> > point.
>> >
>> >
>> >
>> >> 2013/12/2 Nicholas Mc Guire <der.herr@hofr.at>:
>> >> > On Mon, 02 Dec 2013, Hatt Tom wrote:
>> >> >
>> >> >> And also : why cannot I dlclose a .so that I've linked my executable
>> >> >> to, in the usual fashion.
>> >> >>
>> >> >> is it because the reference count of that .so  would not alwayes to
>> >> >> be
>> >> >> zero ?
>> >> >>
>> >> >> It seems puzzling to me ?
>> >> >>
>> >> > how would you ensure consistency of the GOT ?
>> >> > I think the problem is that you would end up with invalid addresses
>> >> > in
>> >> > the GOT
>> >> > as they were setup by ld based on link-time information.
>> >> >
>> >> > thx!
>> >> > hofrat
>> >>
>> >>
>> >>
>> >> --
>> >> Best Regards!
>>
>>
>>
>> --
>> Best Regards!



--
Best Regards!

Attachment: pgpV0bYsws6ao.pgp
Description: PGP signature


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