On Wed, Nov 4, 2020 at 11:33 AM zero <daohu...@gmail.com> wrote:

> Hi all,
>
> The issue is on github link
> <https://github.com/cloudius-systems/osv/issues/47>
>
> Then we continue the discuss.
>
> But I don't understand the "implicit" dependence you mention... It seems
>> you mean that for some reason your application wants to know when or
>> whether B is loaded
>
>
> Actually, I'm talking about the reference count of A, and B depends on A.
> When load B, it will recursive dlopen A.
> So, there is a question, when load B how could *OSv *add A's reference
> count too?
>
> If we don't know the count, when unload A and load A again, because A is
> still in memory, dlopen A will return a handle. the static variables in A
> will not be reinitialized.
>

I think maybe I finally understand what you mean.

The dlclose() documentation suggests that it and dlopen() do their own
reference counting - and if you dlclose() a library that has been
dlopen()ed just once - the library will be unloaded. *Even if *some other
library also used it as DT_NEEDED and even if one of the functions in the
to-be-unloaded library is being used (because some other library resolved
it).

But is this really what should happen, or happens, in Linux? If you
dlopen() A and *also* dlopen() B which needs A, I think the reference count
of A increases twice. How could things work otherwise?



> If we use static variables's default constructors dynamic create some
> thing in dlopen(we know that dlopen will do init first and then transfer
> control to main), if A is in already in memory the init will not work!
>
> The following is the whole process:
> 1. load A
> 2. load B(B depends on A )
> 3. unload A
> 4. load A   ----->  *static variables* in A will not be reinitialized
>

Did you try this on Linux? Does it behave differently from what it does in
OSv?
If step 3 were to *really* unload A, how would B's code, which is still
loaded and may be using symbols from A, continue to work?
If between points 3 and 4 you run some function from B, what is supposed to
happen?

>
>
> If we have reference count of A is still 1(because we implement reference
> count ourselves, I think when we unload A the reference count is 0, but
> dlopen in system will be 1), then we know A is still in memory, and do some
> work do deal with it.
>
> Of course, we can also judge whether A is already in memory use dlopen
> with *RTLD_NOLOAD* , if A is in memory we will deal with it.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "OSv Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to osv-dev+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/osv-dev/CADNiy7oBE1Ldc9hcd0dZf35H885Q8icjNAeiXXbZaPK14C16Rg%40mail.gmail.com
> <https://groups.google.com/d/msgid/osv-dev/CADNiy7oBE1Ldc9hcd0dZf35H885Q8icjNAeiXXbZaPK14C16Rg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/CANEVyjspimy%3DA4WBMhkY7285qg6y%3Dyn6p%3D8vcRgxF%3DSfTVz-Zw%40mail.gmail.com.

Reply via email to