public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: stsp <stsp2@yandex.ru>
To: Florian Weimer <fweimer@redhat.com>,
	Stas Sergeev via Libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [PATCH 2/2] dlfcn,elf: implement dlmem() function [BZ #11767]
Date: Tue, 14 Feb 2023 18:13:17 +0500	[thread overview]
Message-ID: <78f30396-af4d-bb5c-e4cc-1781f26353bc@yandex.ru> (raw)
In-Reply-To: <87mt5ga82l.fsf@oldenburg.str.redhat.com>


14.02.2023 14:51, Florian Weimer пишет:
> * Stas Sergeev via Libc-alpha:
> With the mandatory copy, I'm not sure if this is a substantial
> improvement over the pedestrian implementation using memfd_create,
> included below.

In its current form:
- portability perhaps. Not many glibc-supported
   systems have memfd_create(), though I am not
   sure if it is any better than shm_open() here.
- one more mem copy (write() in your case)
- the need to peek into /proc just to get the
   path for dlopen(). Again, with shm_open()
   its probably simpler as it has an explicit mount
   point at least.

But considering the planned extensions, dlmem()
offers the best potential than its alternatives.
I want add a possibility for LD_AUDIT to provide
an fd to dlmem(), from which it will mmap().
Currently it does anonymous mmap(), but this
is only the first step. I want to provide it with
the fd from shm_open() to have an ability to
duplicate the solib in an address space.
I have a 32bit VM, and the memory of the
32bit process is mapped to some window
in 64bit address space. In order for this VM
to work with solib, I need to relocate the
solib to some low address in the first 4Gb.
But the aforementioned memory window
is above 4Gb. So my plan is:
- in LD_AUDIT set the load address within low 4Gb
- in LD_AUDIT provide an fd from shm_open() for dlmem()
- mmap that fd into the VM memory window
   in an upper space.

I do not suppose such an extension is possible
for any API that already has an fd. But adding
an fd arg to dlmem() itself will likely be too
confusing. So I decided to first create a minimal
impl, and then extend it via LD_AUDIT multiple
times.

OTOH how do you propose to implement dlmem()
directly on a user's buffer? If this is possible then
maybe I can try that out. But the loader will
need to move the sections around, overwriting
the existing content. Or do you want the user
to pre-load the sections to their vaddr's? In that
case he will write the half of dlmem() himself.
So my current understanding is that memcpy()
is all or nothing. If we avoid memcpy(), then we
avoid dlmem(). The dlmem() that you demonstrated,
does even more memcopies than mine.

> What's the debugger story with your dlmem variant?  It looks like GDB
> gets confused even with the memfd_create mapping, which really isn't
> great.
One can do
add-symbol-file <solib_name> <some_addr>
Unfortunately I can't figure out the right
address... lm->l_addr from dlinfo() or dli_fbase
from dladdr() do not suit, but they are close.
Some offset is probably needed and I don't
know what is it. :( Can try to figure that out
if really needed.

  reply	other threads:[~2023-02-14 13:13 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-14  8:41 [PATCH v4 0/2] implement dlmem() function Stas Sergeev
2023-02-14  8:41 ` [PATCH 1/2] elf: strdup() l_name if no realname [BZ #30100] Stas Sergeev
2023-02-14  8:41 ` [PATCH 2/2] dlfcn,elf: implement dlmem() function [BZ #11767] Stas Sergeev
2023-02-14  9:51   ` Florian Weimer
2023-02-14 13:13     ` stsp [this message]
2023-02-15 11:30     ` stsp
2023-03-18 16:58     ` stsp
  -- strict thread matches above, loose matches on Subject: below --
2023-02-15 11:21 [PATCH v5 0/2] implement dlmem() with audit extension Stas Sergeev
2023-02-15 11:21 ` [PATCH 2/2] dlfcn,elf: implement dlmem() function [BZ #11767] Stas Sergeev
2023-02-13 13:23 [PATCH v3 0/2] implement dlmem() function Stas Sergeev
2023-02-13 13:23 ` [PATCH 2/2] dlfcn,elf: implement dlmem() function [BZ #11767] Stas Sergeev
2023-02-13 13:45   ` Florian Weimer
2023-02-13 16:36     ` stsp
2023-02-14  8:43     ` stsp
2023-03-18 17:28     ` stsp
2023-02-10 14:07 [PATCH 1/2] elf: strdup() l_name if no realname [BZ #30100] Stas Sergeev
2023-02-10 14:07 ` [PATCH 2/2] dlfcn,elf: implement dlmem() function [BZ #11767] Stas Sergeev
2023-02-10 21:51   ` Joseph Myers
2023-02-11 20:10     ` stsp
2023-02-13 21:46       ` Joseph Myers
2023-02-14  8:42         ` stsp

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=78f30396-af4d-bb5c-e4cc-1781f26353bc@yandex.ru \
    --to=stsp2@yandex.ru \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.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).