From: Richard Henderson <richard.henderson@linaro.org>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org, "Alex Bennée" <alex.bennee@linaro.org>,
"Laurent Vivier" <laurent@vivier.eu>,
ncopa@alpinelinux.org, "Kyle Evans" <kevans@freebsd.org>,
"Warner Losh" <imp@bsdimp.com>,
"Peter Maydell" <peter.maydell@linaro.org>
Subject: Re: [PATCH] linux-user,bsd-user: re-exec with G_SLICE=always-malloc
Date: Thu, 6 Oct 2022 11:29:05 -0700 [thread overview]
Message-ID: <0d3f27ab-de02-c5b5-488f-08fb7e329bd8@linaro.org> (raw)
In-Reply-To: <Yz8aqBq7m0wn0jvS@redhat.com>
On 10/6/22 11:12, Daniel P. Berrangé wrote:
> On Tue, Oct 04, 2022 at 07:59:18AM -0700, Richard Henderson wrote:
>> On 10/4/22 05:00, Daniel P. Berrangé wrote:
>>> g_slice uses a one-time initializer to check the G_SLICE env variable
>>> making it hard for QEMU to set the env before any GLib API call has
>>> triggered the initializer. Even attribute((constructor)) is not
>>> sufficient as QEMU has many constructors and there is no ordering
>>> guarantee between them.
>>
>> There are orderings for constructors, see __attribute__((constructor(priority))).
>
> Oh, thanks for pointing that out. I tried it, but glib threw
> a bag of rocks at me ;-P
>
> The priority works for ordering within the scope of the binary
> containing the constructor.
Yes.
>
> libglib.so itself has a constructor function registered, and that
> calls APIs that trigger GSlice initialization:
Ah. I had been hoping that gslice would be initialized on first use, so as long as we
could get the setenv done before any other qemu code ran, we'd be fine.
> This all takes place when libglib.so is loaded, which happens prior
> to any code in QEMU being loaded / executed. So no constructor in
> QEMU code can ever pre-empt this in dynamic builds.
Shared libraries have a defined initialization order too, but we'd have to play real
irritating games to make this happen, installing a shared library of our own (linked later
in the sequence to qemu, and itself *not* linked to libglib.so). Not worth it.
> The only possible silver linining is that in static linked builds,
> it appears that a QEMU constructor with priority 101, will pre-empt
> the constructor from any library. This is kind of crazy, as it means
> if any library or app code uses priorities, it'll get totally different
> execution ordering depending on whether it is dynamic or statically
> built.
Plausible...
> I guess we could rely on this hack if we declare that everyone using
> binfmt is probably relying on static linked QEMU, and in non-binfmt
> cases people can set the env var themselves. It still feels pretty
> dirty.
... but as you say, dirty.
Alternately, report it as a bug to glib, because we can't be the only project impacted by
this.
r~
next prev parent reply other threads:[~2022-10-06 18:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-04 12:00 [PATCH] linux-user,bsd-user: re-exec with G_SLICE=always-malloc Daniel P. Berrangé
2022-10-04 12:05 ` Peter Maydell
2022-10-04 14:59 ` Richard Henderson
2022-10-06 18:12 ` Daniel P. Berrangé
2022-10-06 18:29 ` Richard Henderson [this message]
2022-10-06 18:49 ` Kyle Evans
2022-12-01 6:55 ` Emilio Cota
2022-12-01 10:49 ` Alex Bennée
2023-01-11 4:01 ` Emilio Cota
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=0d3f27ab-de02-c5b5-488f-08fb7e329bd8@linaro.org \
--to=richard.henderson@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=berrange@redhat.com \
--cc=imp@bsdimp.com \
--cc=kevans@freebsd.org \
--cc=laurent@vivier.eu \
--cc=ncopa@alpinelinux.org \
--cc=peter.maydell@linaro.org \
--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).