public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* reload .so without restarting process
@ 2013-12-01 14:15 Hatt Tom
  2013-12-01 14:28 ` Sam Varshavchik
  0 siblings, 1 reply; 20+ messages in thread
From: Hatt Tom @ 2013-12-01 14:15 UTC (permalink / raw)
  To: gcc-help

hi:

Is it possible to reload .so file withour restarting thr process ?

As I need to update some functions in my .so  ,  and it is not
pleasure to interrupt the main process . is there way to achive this?

-- 
Best Regards!

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: reload .so without restarting process
  2013-12-01 14:15 reload .so without restarting process Hatt Tom
@ 2013-12-01 14:28 ` Sam Varshavchik
  2013-12-02  3:01   ` Hatt Tom
  0 siblings, 1 reply; 20+ messages in thread
From: Sam Varshavchik @ 2013-12-01 14:28 UTC (permalink / raw)
  To: Hatt Tom; +Cc: gcc-help

Hatt Tom writes:

> hi:
>
> Is it possible to reload .so file withour restarting thr process ?
>
> As I need to update some functions in my .so  ,  and it is not
> pleasure to interrupt the main process . is there way to achive this?

Only if you, yourself has manually loaded the .so with dlopen(). Then, you  
just dlclose() and dlopen() it again.

man dlopen


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: reload .so without restarting process
  2013-12-01 14:28 ` Sam Varshavchik
@ 2013-12-02  3:01   ` Hatt Tom
  2013-12-02  3:36     ` Sam Varshavchik
  0 siblings, 1 reply; 20+ messages in thread
From: Hatt Tom @ 2013-12-02  3:01 UTC (permalink / raw)
  To: Sam Varshavchik, gcc-help

Thanks !
 I have tried this method ,but the problem is the main process still
use old functions , though I have dlclose that .so and then load the
newer one .


what is the reason ?How could I fix this ?


2013/12/1 Sam Varshavchik <mrsam@courier-mta.com>:
> Hatt Tom writes:
>
>> hi:
>>
>> Is it possible to reload .so file withour restarting thr process ?
>>
>> As I need to update some functions in my .so  ,  and it is not
>> pleasure to interrupt the main process . is there way to achive this?
>
>
> Only if you, yourself has manually loaded the .so with dlopen(). Then, you
> just dlclose() and dlopen() it again.
>
> man dlopen
>
>



-- 
Best Regards!

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: reload .so without restarting process
  2013-12-02  3:01   ` Hatt Tom
@ 2013-12-02  3:36     ` Sam Varshavchik
  2013-12-02  4:59       ` Hatt Tom
  2013-12-02  5:27       ` Hatt Tom
  0 siblings, 2 replies; 20+ messages in thread
From: Sam Varshavchik @ 2013-12-02  3:36 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1392 bytes --]

Hatt Tom writes:

> Thanks !
>  I have tried this method ,but the problem is the main process still
> use old functions , though I have dlclose that .so and then load the
> newer one .
>
>
> what is the reason ?How could I fix this ?

In order for you to be able to dlclose a .so, it must've been initially  
opened with dlopen.

You cannot dlclose a .so that you've linked your executable to, in the usual  
fashion.

If you want to be able to reload a .so, you must manually open it with  
dlopen(), and then use dlsym() to look up the functions' addresses in  
the .so.

After you dlclose() the .so, and dlopen() it back again you must then use  
dlsym() again to look up all the functions' addresses. Even functions that  
have not been changed, in the new version of your .so, might now be loaded  
at a completely different address.


>
>
> 2013/12/1 Sam Varshavchik <mrsam@courier-mta.com>:
> > Hatt Tom writes:
> >
> >> hi:
> >>
> >> Is it possible to reload .so file withour restarting thr process ?
> >>
> >> As I need to update some functions in my .so  ,  and it is not
> >> pleasure to interrupt the main process . is there way to achive this?
> >
> >
> > Only if you, yourself has manually loaded the .so with dlopen(). Then, you
> > just dlclose() and dlopen() it again.
> >
> > man dlopen
> >
> >
>
>
>
> --
> Best Regards!

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: reload .so without restarting process
  2013-12-02  3:36     ` Sam Varshavchik
@ 2013-12-02  4:59       ` Hatt Tom
  2013-12-02 11:52         ` Sam Varshavchik
  2013-12-02  5:27       ` Hatt Tom
  1 sibling, 1 reply; 20+ messages in thread
From: Hatt Tom @ 2013-12-02  4:59 UTC (permalink / raw)
  To: Sam Varshavchik, gcc-help

thanks for reply!

 I have used dlsym() to reload function A address ,  function B is
called from A , if I have modified function B ,do I need to use
dlsym() to reload B's address ?

I think it does not need ,as the dynamic linker will do this when
linking function A . Am I right ?




2013/12/2 Sam Varshavchik <mrsam@courier-mta.com>:
> Hatt Tom writes:
>
>> Thanks !
>>  I have tried this method ,but the problem is the main process still
>> use old functions , though I have dlclose that .so and then load the
>> newer one .
>>
>>
>> what is the reason ?How could I fix this ?
>
>
> In order for you to be able to dlclose a .so, it must've been initially
> opened with dlopen.
>
> You cannot dlclose a .so that you've linked your executable to, in the usual
> fashion.
>
> If you want to be able to reload a .so, you must manually open it with
> dlopen(), and then use dlsym() to look up the functions' addresses in the
> .so.
>
> After you dlclose() the .so, and dlopen() it back again you must then use
> dlsym() again to look up all the functions' addresses. Even functions that
> have not been changed, in the new version of your .so, might now be loaded
> at a completely different address.
>
>
>
>>
>>
>> 2013/12/1 Sam Varshavchik <mrsam@courier-mta.com>:
>> > Hatt Tom writes:
>> >
>> >> hi:
>> >>
>> >> Is it possible to reload .so file withour restarting thr process ?
>> >>
>> >> As I need to update some functions in my .so  ,  and it is not
>> >> pleasure to interrupt the main process . is there way to achive this?
>> >
>> >
>> > Only if you, yourself has manually loaded the .so with dlopen(). Then,
>> > you
>> > just dlclose() and dlopen() it again.
>> >
>> > man dlopen
>> >
>> >
>>
>>
>>
>> --
>> Best Regards!



-- 
Best Regards!

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: reload .so without restarting process
  2013-12-02  3:36     ` Sam Varshavchik
  2013-12-02  4:59       ` Hatt Tom
@ 2013-12-02  5:27       ` Hatt Tom
  2013-12-02  6:24         ` Nicholas Mc Guire
  1 sibling, 1 reply; 20+ messages in thread
From: Hatt Tom @ 2013-12-02  5:27 UTC (permalink / raw)
  To: Sam Varshavchik, gcc-help

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 ?

2013/12/2 Sam Varshavchik <mrsam@courier-mta.com>:
> Hatt Tom writes:
>
>> Thanks !
>>  I have tried this method ,but the problem is the main process still
>> use old functions , though I have dlclose that .so and then load the
>> newer one .
>>
>>
>> what is the reason ?How could I fix this ?
>
>
> In order for you to be able to dlclose a .so, it must've been initially
> opened with dlopen.
>
> You cannot dlclose a .so that you've linked your executable to, in the usual
> fashion.
>
> If you want to be able to reload a .so, you must manually open it with
> dlopen(), and then use dlsym() to look up the functions' addresses in the
> .so.
>
> After you dlclose() the .so, and dlopen() it back again you must then use
> dlsym() again to look up all the functions' addresses. Even functions that
> have not been changed, in the new version of your .so, might now be loaded
> at a completely different address.
>
>
>
>>
>>
>> 2013/12/1 Sam Varshavchik <mrsam@courier-mta.com>:
>> > Hatt Tom writes:
>> >
>> >> hi:
>> >>
>> >> Is it possible to reload .so file withour restarting thr process ?
>> >>
>> >> As I need to update some functions in my .so  ,  and it is not
>> >> pleasure to interrupt the main process . is there way to achive this?
>> >
>> >
>> > Only if you, yourself has manually loaded the .so with dlopen(). Then,
>> > you
>> > just dlclose() and dlopen() it again.
>> >
>> > man dlopen
>> >
>> >
>>
>>
>>
>> --
>> Best Regards!



-- 
Best Regards!

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: reload .so without restarting process
  2013-12-02  5:27       ` Hatt Tom
@ 2013-12-02  6:24         ` Nicholas Mc Guire
  2013-12-02  6:49           ` Hatt Tom
  0 siblings, 1 reply; 20+ messages in thread
From: Nicholas Mc Guire @ 2013-12-02  6:24 UTC (permalink / raw)
  To: Hatt Tom; +Cc: Sam Varshavchik, gcc-help

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

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: reload .so without restarting process
  2013-12-02  6:24         ` Nicholas Mc Guire
@ 2013-12-02  6:49           ` Hatt Tom
  2013-12-02 11:55             ` Sam Varshavchik
  0 siblings, 1 reply; 20+ messages in thread
From: Hatt Tom @ 2013-12-02  6:49 UTC (permalink / raw)
  To: Nicholas Mc Guire, gcc-help

If I use dlsym() to load the address manually ,will  GOT  be  needed any more ?







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!

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: reload .so without restarting process
  2013-12-02  4:59       ` Hatt Tom
@ 2013-12-02 11:52         ` Sam Varshavchik
  0 siblings, 0 replies; 20+ messages in thread
From: Sam Varshavchik @ 2013-12-02 11:52 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 500 bytes --]

Hatt Tom writes:

> thanks for reply!
>
>  I have used dlsym() to reload function A address ,  function B is
> called from A , if I have modified function B ,do I need to use
> dlsym() to reload B's address ?
>
> I think it does not need ,as the dynamic linker will do this when
> linking function A . Am I right ?

If you're not calling function B, you do not need to reload its symbol. You  
only need to call dlsym() for every function in the .so you are directly  
calling from your executable.


[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: reload .so without restarting process
  2013-12-02  6:49           ` Hatt Tom
@ 2013-12-02 11:55             ` Sam Varshavchik
  2013-12-03  1:23               ` Hatt Tom
  0 siblings, 1 reply; 20+ messages in thread
From: Sam Varshavchik @ 2013-12-02 11:55 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 844 bytes --]

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!

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: reload .so without restarting process
  2013-12-02 11:55             ` Sam Varshavchik
@ 2013-12-03  1:23               ` Hatt Tom
  2013-12-03  2:05                 ` Sam Varshavchik
  0 siblings, 1 reply; 20+ messages in thread
From: Hatt Tom @ 2013-12-03  1:23 UTC (permalink / raw)
  To: Sam Varshavchik, gcc-help

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 .

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!

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: reload .so without restarting process
  2013-12-03  1:23               ` Hatt Tom
@ 2013-12-03  2:05                 ` Sam Varshavchik
  2013-12-03  2:28                   ` Hatt Tom
  0 siblings, 1 reply; 20+ messages in thread
From: Sam Varshavchik @ 2013-12-03  2:05 UTC (permalink / raw)
  To: Hatt Tom; +Cc: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1355 bytes --]

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!

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: reload .so without restarting process
  2013-12-03  2:05                 ` Sam Varshavchik
@ 2013-12-03  2:28                   ` Hatt Tom
  2013-12-03  3:17                     ` Sam Varshavchik
  0 siblings, 1 reply; 20+ messages in thread
From: Hatt Tom @ 2013-12-03  2:28 UTC (permalink / raw)
  To: Sam Varshavchik, gcc-help

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 ?



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!

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: reload .so without restarting process
  2013-12-03  2:28                   ` Hatt Tom
@ 2013-12-03  3:17                     ` Sam Varshavchik
  2013-12-05  2:02                       ` Hatt Tom
  0 siblings, 1 reply; 20+ messages in thread
From: Sam Varshavchik @ 2013-12-03  3:17 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 2763 bytes --]

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 #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: reload .so without restarting process
  2013-12-03  3:17                     ` Sam Varshavchik
@ 2013-12-05  2:02                       ` Hatt Tom
  2013-12-05  2:14                         ` Jonathan Wakely
  2013-12-05 11:55                         ` Sam Varshavchik
  0 siblings, 2 replies; 20+ messages in thread
From: Hatt Tom @ 2013-12-05  2:02 UTC (permalink / raw)
  To: Sam Varshavchik, gcc-help

2013/12/3 Sam Varshavchik <mrsam@courier-mta.com>:
> 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 if I link that .so against my executable by "g++ -l " command
,then I can not dlclose it fully in process at all  ?

Tp dlclose it  fully , I must not link it by compiler ,but manually
use dlopen and dlsym to resolve the external symbols  .

But if so ,how to make  the compiler not to compalain "not reference
to symbol xxx" at compiling stage ?


Thanks!

>
> 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!



-- 
Best Regards!

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: reload .so without restarting process
  2013-12-05  2:02                       ` Hatt Tom
@ 2013-12-05  2:14                         ` Jonathan Wakely
  2013-12-05  5:24                           ` Hatt Tom
  2013-12-05 11:55                         ` Sam Varshavchik
  1 sibling, 1 reply; 20+ messages in thread
From: Jonathan Wakely @ 2013-12-05  2:14 UTC (permalink / raw)
  To: Hatt Tom; +Cc: Sam Varshavchik, gcc-help

On 5 December 2013 02:02, Hatt Tom wrote:
>
> So if I link that .so against my executable by "g++ -l " command
> ,then I can not dlclose it fully in process at all  ?

Right. Why is that a problem?  Why do you think you need to dlclose it?

> Tp dlclose it  fully , I must not link it by compiler ,but manually
> use dlopen and dlsym to resolve the external symbols  .
>
> But if so ,how to make  the compiler not to compalain "not reference
> to symbol xxx" at compiling stage ?

That means your program depends on symbols in the library directly, so
you should link to it directly, and then you can't dlclose it.  But
that should not be a problem.

What are you trying to do?  Why can't you just let the linker do its
job normally?

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: reload .so without restarting process
  2013-12-05  2:14                         ` Jonathan Wakely
@ 2013-12-05  5:24                           ` Hatt Tom
  0 siblings, 0 replies; 20+ messages in thread
From: Hatt Tom @ 2013-12-05  5:24 UTC (permalink / raw)
  To: Jonathan Wakely, gcc-help; +Cc: Sam Varshavchik

Thanks for reply!

In my project ,  there need one script.so lib to be dynamiclly
modified and reloaded without reboot the process .the main process
uses its export functions ,I think dlopen and dlsym can do this .

At prevoius  ,I failed to achive this due to linking script.so lib
against executable   at compling time with "g++ -l "command ,it result
into dlclose can not remove script.so fully ,it would be because  the
reference count of script.so library  . So  the modification does not
work after reloading script.so .

After that failure , I tried to link script.so to middle.so ,than link
middle.so directly to executable .
It works ! script.so can be reloaded successfully , dlclose can remove
script.so fully .

During this work ,I find there are details of linking I should get to
be clear of .

Thanks!



 .

2013/12/5 Jonathan Wakely <jwakely.gcc@gmail.com>:
> On 5 December 2013 02:02, Hatt Tom wrote:
>>
>> So if I link that .so against my executable by "g++ -l " command
>> ,then I can not dlclose it fully in process at all  ?
>
> Right. Why is that a problem?  Why do you think you need to dlclose it?
>
>> Tp dlclose it  fully , I must not link it by compiler ,but manually
>> use dlopen and dlsym to resolve the external symbols  .
>>
>> But if so ,how to make  the compiler not to compalain "not reference
>> to symbol xxx" at compiling stage ?
>
> That means your program depends on symbols in the library directly, so
> you should link to it directly, and then you can't dlclose it.  But
> that should not be a problem.
>
> What are you trying to do?  Why can't you just let the linker do its
> job normally?



-- 
Best Regards!

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: reload .so without restarting process
  2013-12-05  2:02                       ` Hatt Tom
  2013-12-05  2:14                         ` Jonathan Wakely
@ 2013-12-05 11:55                         ` Sam Varshavchik
  2013-12-05 14:02                           ` net.study.sea
  1 sibling, 1 reply; 20+ messages in thread
From: Sam Varshavchik @ 2013-12-05 11:55 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1620 bytes --]

Hatt Tom writes:

> 2013/12/3 Sam Varshavchik <mrsam@courier-mta.com>:
> > 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 if I link that .so against my executable by "g++ -l " command
> ,then I can not dlclose it fully in process at all  ?

Correct.

>
> Tp dlclose it  fully , I must not link it by compiler ,but manually
> use dlopen and dlsym to resolve the external symbols  .

Correct.

>
> But if so ,how to make  the compiler not to compalain "not reference
> to symbol xxx" at compiling stage ?

Because you did not use dlsym to resolve the external symbols.


[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: reload .so without restarting process
  2013-12-05 11:55                         ` Sam Varshavchik
@ 2013-12-05 14:02                           ` net.study.sea
  2013-12-13  1:13                             ` Ángel González
  0 siblings, 1 reply; 20+ messages in thread
From: net.study.sea @ 2013-12-05 14:02 UTC (permalink / raw)
  To: Sam Varshavchik; +Cc: gcc-help

So what is the difference between linking a .so into a library and into a executable?

发自我的 iPhone

在 2013-12-5,19:55,Sam Varshavchik <mrsam@courier-mta.com> 写道:

> Hatt Tom writes:
> 
>> 2013/12/3 Sam Varshavchik <mrsam@courier-mta.com>:
>> > 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 if I link that .so against my executable by "g++ -l " command
>> ,then I can not dlclose it fully in process at all  ?
> 
> Correct.
> 
>> 
>> Tp dlclose it  fully , I must not link it by compiler ,but manually
>> use dlopen and dlsym to resolve the external symbols  .
> 
> Correct.
> 
>> 
>> But if so ,how to make  the compiler not to compalain "not reference
>> to symbol xxx" at compiling stage ?
> 
> Because you did not use dlsym to resolve the external symbols.
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: reload .so without restarting process
  2013-12-05 14:02                           ` net.study.sea
@ 2013-12-13  1:13                             ` Ángel González
  0 siblings, 0 replies; 20+ messages in thread
From: Ángel González @ 2013-12-13  1:13 UTC (permalink / raw)
  To: net.study.sea; +Cc: Sam Varshavchik, gcc-help

On 05/12/13 15:01, net.study.sea@gmail.com wrote:
> So what is the difference between linking a .so into a library and into a executable?
>
> 发自我的 iPhone
When you link into an executable, it ensures all the symbols are 
provided. But when you
make a library, it doesn't (the missing symbols might be provided by the 
executable, although
it's not common).

I suspect you're doing something wrong with your "solution", I'm afraid.

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2013-12-13  1:13 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-01 14:15 reload .so without restarting process Hatt Tom
2013-12-01 14:28 ` Sam Varshavchik
2013-12-02  3:01   ` Hatt Tom
2013-12-02  3:36     ` Sam Varshavchik
2013-12-02  4:59       ` Hatt Tom
2013-12-02 11:52         ` Sam Varshavchik
2013-12-02  5:27       ` Hatt Tom
2013-12-02  6:24         ` Nicholas Mc Guire
2013-12-02  6:49           ` Hatt Tom
2013-12-02 11:55             ` Sam Varshavchik
2013-12-03  1:23               ` Hatt Tom
2013-12-03  2:05                 ` Sam Varshavchik
2013-12-03  2:28                   ` Hatt Tom
2013-12-03  3:17                     ` Sam Varshavchik
2013-12-05  2:02                       ` Hatt Tom
2013-12-05  2:14                         ` Jonathan Wakely
2013-12-05  5:24                           ` Hatt Tom
2013-12-05 11:55                         ` Sam Varshavchik
2013-12-05 14:02                           ` net.study.sea
2013-12-13  1:13                             ` Ángel González

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).