mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: info@mobile-stream.com
Cc: musl@lists.openwall.com
Subject: Re: [PATCH] mips: add single-instruction math functions
Date: Thu, 19 Sep 2019 09:14:37 -0400	[thread overview]
Message-ID: <20190919131437.GF9017@brightrain.aerifal.cx> (raw)
In-Reply-To: <1641023798.20190919155431@mobile-stream.com>

On Thu, Sep 19, 2019 at 03:54:31PM +0300, info@mobile-stream.com wrote:
> R> It's not. The presence of a new instruction for non-arithmetic abs
> R> would be a fine-grained ISA feature. An incompatible change in an
> R> existing instruction is a *different ISA*, which needs a different
> R> ldsoname per musl policy of always allowing different ISAs to coexist
> R> in the same filesystem and have their own library ecosystems.
> 
> 1) -mabs=legacy ("baseline") musl is safe on -mabs=2008
> ("non-baseline") system cause it uses no explicit ABS.fmt in
> fabs[f]().
> And since compiler does not generate trapping ABS.fmt/NEG.fmt unless
> specifically instructed there will be no implicit insns too.
> Even whatever explicit __mips_abs2008-protected code would not
> change (for good or for bad) anything here.

OK, this is really good to know. I tried to follow these discussions
when they first happened for the tooling and glibc, but got lost in it
all and was unclear on what the compatibility properties are and
whether they're different for nan2008 vs abs2008 (AIUI now they are).

> 2) -mabs=2008 application will work correctly with -mabs=legacy musl
> on a -mabs=2008 system.

Are you sure? This seems to disagree with what you're saying below
about the same ABI tagging being used for abs2008 and nan2008 and
kernel refusing to load mismatching binaries.

> 3) It is not musl's business if some -mabs=legacy application
> behaves unexpectedly on a -mabs=2008 system due to non-trapping
> ABS.fmt/NEG.fmt.

Absolutely.

> 4) -mnan=legacy musl is probably not safe on a -mnan=2008 system but
> this is externally prevented by the kernel and there is *no* need
> for two ecosystems as CPU is *either* 2008 or legacy.

musl supports multiple ecosystems in the same filesystem regardless of
whether a cpu does; that's the whole point of supporting even multiple
unrelated archs like mips and arm or x86 and riscv and why they all
have differing ldso names. For example you can be running the foreign
ISA via qemu-user with binfmt_misc or explicitly.

Now, musl doesn't really do anything special with signaling nans and
doesn't particularly consider them a supported feature, so in some
sense it probably does work anyway for them to mismatch. But if the
kernel refuses to load -mnan=legacy binaries on nan2008 hardware, that
undermines the above.

> That is, this is *not* like o32 or n32 ABI on 64-bit MIPS (which can
> run these directly at the same time for different goals), not a
> soft-float set of libraries on a hard-float system (which is usually
> just a subset with different argument passing convention), not a
> hard-float binary on a soft-float system with kernel FPU emulation.
> 
> It is not even like r2 set of libraries on r6 (where kernel may want
> to emulate missing/redefined r2 instructions) -- *efficient*
> emulation of trapping ABS.fmt/NEG.fmt or 1985-style NaNs generation
> seems impossible on a 2008 system.
> 
> 5) From the kernel pov (IIUC), nan2008 flag in the ELF header
> defines the abs2008 behaviour too (though these are distinct
> bits/flags per arch spec and in compilers).

In that case, it seems like the kernel would refuse to load
-mabs=legacy binaries on nan2008 hardware, gratuitously due to
conflating the two properties. :( Is that the case, and if so, is
there any way to avoid it?

> I know glibc and uclibc have different ldso names for nan2008. I
> think it is because they have implemented it years ago when
> 1) the kernel had no nan2008 enforcement;
> 2) the mips r3 spec defined nan2008/abs2008 FCSR bits as possibly
> writable on a given CPU.
> 
> mips r5 spec has changed these bits to be strictly read-only and no
> r3 cores from IMG with writable nan2008/abs2008 bits exist (per spec
> at least).
> 
> So the feature bits are hard-wired, cross-binary and cross-system
> consistency is externally enforced, efficient emulation is barely
> possible.
> 
> Why bother with different ldsoname for nan2008 then?

If the tooling is capable of treating them as the same ABI (which
implies considering signaling nan an unsupported feature and treating
all nans as the same), then it's not needed. But if it's enforced that
they're separate ABIs, they need separate ldsonames.

> (though all this nan2008 stuff is independent from the
> __mips_abs2008 fabs[f]() oneliners).

I think that sounds correct.

> R> I'm guessing we've hit a situation where people have been building
> R> binaries for an incompatible MIPS-family ISA reusing the same
> R> ldsoname, which is a huge mess we probably need to figure out how to
> R> deal with...
> 
> R> actually it probably doesn't matter even if it does since I can't
> R> imagine the compiler generates dsp insns for anything in libc) you can
> 
> Sure it does, and for good. Indexed load/stores (gcc/clang), 64-bit
> additions with ADDWC/ADDSC (clang).

OK.

> But do you essentially deny non-baseline musl without new ldsoname
> just because someone could misuse it on a baseline system?

No. It's the same ldsoname because binaries with or without dsp
features can use the same baseline (without dsp) libc.so/ldso.

> If not, the -mabs=2008 ("non-baseline") musl on a -mabs=legacy
> ("baseline") system is irrelevant (though wrong of course).
> 
> If yes, do you consider x86 with LZCNT a different ISA?

No. Both binaries using lzcnt and binaries not using lzcnt can share
the same ldso with the baseline ISA.

> It is perfectly possible to build musl with -mlzcnt ("non-baseline")
> and let it fail silently on non-ABM/BMIx system ("baseline").
> Neither musl nor kernel prevents this yet nobody invents new
> ldsoname for this case.

Because the ABI is the same.

> It is probably possible to build soft-float ARMv6 musl with LDRD and
> let it crash on XScale v5TE system due to stricter alignment
> requirements. Does musl prevent this with whatever ldsonames? I
> think not.

No, because the ABI is the same and you can run armv6 and armv5
binaries using the same libc.so/ldso.

> And if the kernel would reject such binary (dunno), why are you
> against external nan2008 enforcement then?
> 
> Finally, I believe it is possible to build mips32r2 binary with
> rotate instructions and let it fail silently and strangely on r1
> system (rotate opcode reuses one of the shift opcodes) as kernel
> apparently ignores the corresponding flag in the ELF header. This
> seems to be the only case of three you want to fix.

This isn't about noisy or silent failure of binaries using new ISA
features on old cpus. It's about the inability to use a
baseline-supporting libc.so/ldso on a newer cpu with the changed ISA,
for binaries built with the changed ISA.

Rich


  reply	other threads:[~2019-09-19 13:14 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-11 10:05 info
2019-09-11 11:46 ` Rich Felker
2019-09-12 17:57 ` Rich Felker
2019-09-13 11:46   ` info
2019-09-13 18:31 ` Rich Felker
2019-09-13 18:56   ` Rich Felker
2019-09-13 19:12     ` James Y Knight
2019-09-13 20:01       ` Rich Felker
2019-09-13 20:23         ` Rich Felker
2019-09-18 13:07   ` info
2019-09-18 13:49     ` Rich Felker
2019-09-18 17:18   ` info
2019-09-18 20:04     ` Rich Felker
2019-09-19 12:54       ` info
2019-09-19 13:14         ` Rich Felker [this message]
2019-09-19 13:25           ` Rich Felker
2019-09-19 18:26           ` info
2019-09-19 19:10             ` Rich Felker
2019-10-14 14:18 ` Rich Felker

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=20190919131437.GF9017@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=info@mobile-stream.com \
    --cc=musl@lists.openwall.com \
    /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 public inbox

	https://git.vuxu.org/mirror/musl/

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).