The go and Debian/Ubuntu architecture names are extremly close and
there was a typo in one of them (i386->386). In addition to fixing
the typo this commit also includes a list of known architectures
from the go source directly to ensure this change is correct.
There is no exported list of available architectures so it had to
be copied. There is `go tool dist list` which will list all
supported combinations of os/arch but the downside of using this
is that when architecture support gets dropped in the future the
test would start failing for no good reason.
* arch: add new `arch.Endian()` helper and use it in seccomp
Go has no good way to get the native endianness of a system.
However for certain use-cases (like seccomp) this is quite
important. We already have a (hackish) `isBigEndian()` helper
in our code. However this will also be needed in snap-seccomp
for PR#13014 this will also be needed so moving the helper
to the `arch` package seems to be prudent.
* arch: fix usage of runtimeGOARCH
Co-authored-by: Miguel Pires <miguelpires94@gmail.com>
---------
Co-authored-by: Miguel Pires <miguelpires94@gmail.com>
Before this there was an Uname implementation in arch and one in
release (the implementation is slightly tricky because
syscall.Utsname's internals are arch-dependent). This drops both in
favour of a new one in osutil, in order to keep syscalls limited to
this package as much as possible.
We have a build failure currently in the armhf build. It is caused
by the unknown kernel utsname value "armv8l". By adding this to
the arch table things work again.
We used GOARCH so far to map out a device we're running on as an ARM
device but that ignores the revision and doesn't detect armv6 devices
properly which we don't have a core snap for at the moment. This lead
to the armhf core snap being pulled on an armv6 device which doesn't
make any sense. This change now uses utsname to get the correct
machine type from the kernel and adjusts the detect architecture if
we're running on an armv6 based device.
The old C code supported the following cases for compat syscalls:
1. kernel and userspace are both 32 bit (no compat)
2. kernel and userspace are both 64 bit (need to load 32 bit arch for
32 bit compat)
3. kernel is 64 bit and userspace is 32 bit (need to load 64 bit arch
for native syscalls)
This commit ensures case (3) is now also supported with the new
go based seccomp code.
Note that (3) in the context of snaps is very strange. When snapd
runs as a 32bit app it will only request 32bit snaps from the
store. So there has to be 32bit snaps that contain 64bit code and
logic that can auto-detect if 64 bit code can be run and that then
makes use of this 64bit code.
The architecture handling used to be partly in the helpers and
partly in the snappy package. By moving it into a common package
subsequent branches (feature/snapfs-mount2) will become simpler.