From: Akihiko Odaki <akihiko.odaki@gmail.com>
To: Michael Tokarev <mjt@tls.msk.ru>,
QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: get_relocated_path: the configured paths are not looked for?
Date: Thu, 20 Apr 2023 14:29:29 +0900 [thread overview]
Message-ID: <20e76562-b1c7-3574-a277-7df6260226cc@gmail.com> (raw)
In-Reply-To: <7f96ff38-2268-07d3-23a3-d46bf036b711@msgid.tls.msk.ru>
On 2023/04/19 16:32, Michael Tokarev wrote:
> Hello!
>
> Today I discovered an interesting issue here: I copied a system-installed
> binary into another directory, in order to debug an unrelated issue. Just
> to discover it does not work, being unable to find any modules or data
> files.
>
> Here's how the strace of typical qemu-system-i386 run looks like (the
> relevant parts only):
>
> access("/tmp/qemu-bundle", R_OK) = -1 ENOENT (No such file or directory)
> access("/tmp/b/../lib/x86_64-linux-gnu/qemu/accel-tcg-i386.so", F_OK) =
> -1 ENOENT (No such file or directory)
> access("/var/run/qemu/Debian_1_8.0~rc4+dfsg-3/accel-tcg-i386.so", F_OK)
> = -1 ENOENT (No such file or directory)
>
> (the executable in this case is in /tmp, obviously). And it fails with
> error "fatal: could not load module for type 'tcg-accel-ops'".
>
> This is despite the fact that qemu has been configured with proper --libdir
> and other --foodir to point to actual dirs such as /usr/lib /usr/share etc.
Some files in QEMU installation is closely coupled with the binary so it
does not make much sense to copy only the executable to another
directory. You need to copy all of the files QEMU owns to relocate a
QEMU installation. QEMU uses relative paths to find such relocated files.
That said, it is indeed confusing that QEMU uses relative paths even if
you specify an absolute path for --libdir. I prefer to require to
specify relative paths for --libdir and other options to make a QEMU
installation relocatable, but I didn't dare making such a breaking change.
Regards,
Akihiko Odaki
>
> Looking at the code I see this, in cutil.c:get_relocated_path()
> (simplified):
>
> char *get_relocated_path(const char *dir)
> {
> const char *bindir = CONFIG_BINDIR;
> const char *exec_dir = qemu_get_exec_dir();
>
> result = concat(exec_dir, "/qemu-bundle");
> if (access(result, R_OK) == 0) { <== should be X_OK and should be
> dir, too!
> g_string_append(result, dir);
> } else if (!starts_with_prefix(dir) || !starts_with_prefix(bindir)) {
> g_string_assign(result, dir);
> } else {
> g_string_assign(result, exec_dir);
> .. search in execdir and its parents ..
> }
>
> This seems to be questionable. And btw, even when running qemu from
> the installed /usr/bin/ location, it does something weird:
>
> access("/usr/bin/qemu-bundle", R_OK) = -1 ENOENT (No such file or
> directory)
> access("/usr/bin/../lib/x86_64-linux-gnu/qemu/accel-tcg-x86_64.so",
> F_OK) = 0
> openat(AT_FDCWD,
> "/usr/bin/../lib/x86_64-linux-gnu/qemu/accel-tcg-x86_64.so",
> O_RDONLY|O_CLOEXEC) = 14
>
> so it is not obvious why it skips the full path in this case (the 2nd
> choice) and falls into the 3rd variant (search in execdir and parents).
>
> Why it *ever* wants to search in parent dirs relative to executable
> path? And why these !starts_with_prefix()?
>
> BTW, the second starts_with_prefix(bindir) condition is just stupid, -
> bindir is CONFIG_BINDIR (static), and start_with_prefix() checks for
> CONFIG_PREFIX which is also static.
>
> The whole this logic smells.. strange at best :)
>
> How about this: if qemu-bundle exists, use qemu-bundle/dir, instead
> use dir directly? Why do we need all other conditions? Why do we
> do different things depending on the place the executable is located?
>
> In the past, qemu tried to look in pc-bios/ and other similar places, -
> when run from the build dir. But since it does not do this anymore,
> we can just skip whole thing, no?
>
> /mjt
next prev parent reply other threads:[~2023-04-20 5:30 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-19 7:32 get_relocated_path: the configured paths are not looked for? Michael Tokarev
2023-04-20 5:29 ` Akihiko Odaki [this message]
2023-04-23 10:28 ` Michael Tokarev
2023-04-23 11:22 ` Akihiko Odaki
2023-04-23 11:31 ` Michael Tokarev
2023-04-23 11:47 ` Akihiko Odaki
2023-04-23 13:22 ` Michael Tokarev
2023-04-23 17:39 ` Akihiko Odaki
2023-04-23 18:10 ` Michael Tokarev
2023-04-23 18:24 ` Akihiko Odaki
2023-04-23 18:33 ` Michael Tokarev
2023-04-23 18:37 ` Michael Tokarev
2023-04-23 18:39 ` Akihiko Odaki
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=20e76562-b1c7-3574-a277-7df6260226cc@gmail.com \
--to=akihiko.odaki@gmail.com \
--cc=mjt@tls.msk.ru \
--cc=qemu-devel@nongnu.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 NNTP newsgroup(s).