Recent Linux on Aarch32 (without hw atomics) supports cmpxchg in the
VDSO, which does _not_ trap to the kernel, instead the kernel trap
exit has a PC adjust check which causes cmpxchg to fail if it was
interrupted. Linux on RISC-V has nothing similar right now but it
could be added.
> really wants to use the A extension.
>
> IMHO the linker path should - besides the ABI specifier - also
> include the ISA specifier of the minimum base ISA on which the
> code can run, so that we would end up with something like
> /lib32/ilp32/ld-linux-rv32i.so.1 or
> /lib32/ilp32/ld-linux-rv32ima.so.1.
> This would allow proper multiarch installations for different base
> ISAs.
>
> A related issue comes up with defining the "machine name"
> (UTS_MACHINE, which is returned by "uname -m") in the kernel.
> Currently we only return "riscv32" or "riscv64" depending on
> XLEN, but we don't provide proper ISA information. As the
> output of "uname -m" is used by configure scripts to determine on
> which platform they are running, to call the compiler with the
> proper prefix and set the proper options, wouldn't it make sense
> to return a full ISA specifier (e.g. riscv32ima or
> riscv64imafd)?
>
> Opinions and ideas welcome :-).
This area is rather confused. It's not very clear what problem we're
trying to solve. Here are my thoughts on the matter, but few answers:
The first question is what kind of multiarch are we trying to support.
I see three possibilities here:
1. ABI-compatible libraries, such as RV32IMA and RV32IA.
2. ABI-incompatible but related architectures, such as having RV32G
and RV64G simultaneously present on a machine that supports both
modes.
3. Arbitrary unrelated architectures, for instance a single rootfs
with both x86_64 and riscv64 binaries. Such a design could be used
for a network environment a la Plan 9, or as a transitional stage in
bootstrapping with qemu-user.
It seems to me that embedding the architecture/ABI in the basename of
ld.so is not useful, because _every_ system library needs to be scoped
to an ABI, and the sensible place to do that is the dirname. I'm not
sure about the "ld-linux" case; are there reasonable cases where two
kernels could share a /lib64 but need separate dynamic linkers?
Next question is: who is the target audience of gcc's builtin multiarch?
Fedora has a hard policy of /lib/
libc-2.24.so and /lib64/
libc-2.24.so
and is already patching gcc to use those paths (I _think_ Fedora is
less picky about the name of ld.so).
Debian appears to want full type-3 multiarch and scopes every library
to a triple.
People who get gcc's multiarch rules are people who are either
building gcc from source to use as a cross-compiler or distributions
that don't override it. How many of the latter exist? If people are
doing cross-compilation, that could well be from riscvSOMETHING to
riscvSOMETHINGELSE?
Triples seem in general to be poorly specified. We've been using
riscv32 and riscv64 to keep them separate, but nothing for POSIX has
really been done outside of RV64G. RISC-V is not the only modern
architecture that is specified piecemeal with optionally installed
facilities; "llc -mattr=help" gives me several pages of x86 variants,
and x86 has only been extended by two parties in recent years. RISC-V
will be far worse due to the larger number of parties, and I don't
know whether encoding all variations into the triple is possible or
desirable.
Fedora intends to compile all libraries for RV64G (possibly RV64GC
after support is added to qemu?) and rely on runtime discovery for
additional extensions. Of course this requires a way to do the
runtime discovery (the obvious way is to pass a config-string fragment
in the ELF auxiliary vector; I have been made aware that some people
want a very small number of course-grained extensions that could be
handled as a bitfield, but that seems unlikely given current trends).
The upstream version of config.sub can only handle the exact strings
"riscv32" and "riscv64". Changing that will be annoying.
Android does on-device compilation; iOS requires app submission as
bitcode which is compiled for each phone model on Apple's
infrastructure; I think it's clear that the future of medium- and
large-systems software is personalized binaries, although neither
Fedora nor Debian is in a position to do that *right now*. How does
this interact with the triples system? When a future large-systems
RISC-V chip requires 75 bits of information to describe the
architecture and tuning parameters, will we encode that in a triple,
or what will we use as a post-triple?
-s