public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Sam Varshavchik <mrsam@courier-mta.com>
To: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: reload .so without restarting process
Date: Tue, 03 Dec 2013 03:17:00 -0000	[thread overview]
Message-ID: <cone.1386040640.73101.20574.1000@monster.email-scan.com> (raw)
In-Reply-To: <CAHvbk5MQRB8cYhHbuk_t_-yFdtcgFFWk5OWfnLuNktaAwnzZZA@mail.gmail.com>

[-- 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 --]

  reply	other threads:[~2013-12-03  3:17 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-01 14:15 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cone.1386040640.73101.20574.1000@monster.email-scan.com \
    --to=mrsam@courier-mta.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).