all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: <tomas@tuxteam.de>
To: help-gnu-emacs@gnu.org
Subject: Re: dynamic reload of dynamic module not dynamic?
Date: Tue, 19 Apr 2022 07:13:52 +0200	[thread overview]
Message-ID: <Yl5FEGUBdw4zhDlO@tuxteam.de> (raw)
In-Reply-To: <87lew3lb94.fsf@zoho.eu>

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

On Sun, Apr 17, 2022 at 10:12:55PM +0200, Emanuel Berg via Users list for the GNU Emacs text editor wrote:
> Philipp Stephani wrote:
> 
> >> It seems recompiling the C for an Emacs dynamic module and
> >> then loading the new SO file from the same Emacs instance
> >> that loaded the old doesn't get you the new stuff?
> >
> > Yeah, we never call dlclose on the returned shared object
> > handle, so reloading a module will only increment the
> > handle's reference count. It might make sense to support
> > reloading in some way (by having unload-feature eventually
> > call dlclose), but it's not trivial: we need to be careful
> > to invalidate all references to affected module functions
> > before calling dlclose.
> 
> Okay, where are they stored then so one can apply invalidate
> to all members and then call dlclose and `load' again?

This is not completely trivial. Parts of the application may
have become dependent on the loaded library. That's why dlclose()
is described as "advisory" [1]. It may do, but then, it might
not.

Just imagine your application storing a pointer to some function
in that DL. You remove it, the address space becomes free and
is replaced by something totally different. The above code calls
into this pointer and... kaboom. You literally pulled the rug
from under your poor application :-)

Now you would say you wouldn't ever hoard pointers to random
library functions, but that's exactly what the dynamic loader
is doing for you.

Not saying it's impossible, but that it's trickier than it seems.
Most of the time you'll have to live with several incarnations
of "some functions" because your "old function" refuses to die.
Most applications choose to restart.

Just search for "dlclose problem" in the GNU libc mailing list
to see what I mean. Here's [2] one.

Cheers

[1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/dlclose.html
[2] https://sourceware.org/pipermail/libc-help/2010-November/thread.html#1644

-- 
t


> 
> -- 
> underground experts united
> https://dataswamp.org/~incal
> 
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

  reply	other threads:[~2022-04-19  5:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-17  4:42 dynamic reload of dynamic module not dynamic? Emanuel Berg via Users list for the GNU Emacs text editor
2022-04-17 18:31 ` Eduardo Ochs
2022-04-17 20:18   ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-04-17 18:44 ` Philipp Stephani
2022-04-17 20:12   ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-04-19  5:13     ` tomas [this message]
2022-04-19 11:08       ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-04-20 17:06         ` Eli Zaretskii
2022-04-19 12:46     ` Philipp Stephani
2022-04-19 14:01       ` Emanuel Berg via Users list for the GNU Emacs text editor
  -- strict thread matches above, loose matches on Subject: below --
2024-07-04  7:00 Psionic K

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=Yl5FEGUBdw4zhDlO@tuxteam.de \
    --to=tomas@tuxteam.de \
    --cc=help-gnu-emacs@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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.