Allow arm64 to fallback to arm (v8, v7, v6, v5)

This isn't supported by *all* arm64 chips, but it is common enough that I think it's worth an explicit fallback.  I think it will be more common for images to have arm64 support without arm support, but even if a user has an arm64 chip that does not support arm32, having it fail to run the arm32 image is an acceptable compromise (because it's non-trivial to detect arm32 support without running a binary, AFAIK).

Also, before this change the failure would've simply been "no such image" instead of "failed to run" so I think it's pretty reasonable to allow it to try the additional 32bit set of images just in case one of them actually does work (like it will on many popular chips like 64bit Raspberry Pis and AWS Graviton).

Signed-off-by: Tianon Gravi <admwiggin@gmail.com>
This commit is contained in:
Tianon Gravi 2020-09-04 11:16:47 -07:00
parent 124fc14a46
commit 4073aaa7a9
3 changed files with 18 additions and 11 deletions

View File

@ -57,6 +57,18 @@ func platformVector(platform specs.Platform) []specs.Platform {
}) })
} }
} }
case "arm64":
variant := platform.Variant
if variant == "" {
variant = "v8"
}
vector = append(vector, platformVector(specs.Platform{
Architecture: "arm",
OS: platform.OS,
OSVersion: platform.OSVersion,
OSFeatures: platform.OSFeatures,
Variant: variant,
})...)
} }
return vector return vector

View File

@ -166,17 +166,17 @@ func TestOnly(t *testing.T) {
platform: "linux/arm64", platform: "linux/arm64",
matches: map[bool][]string{ matches: map[bool][]string{
true: { true: {
"linux/arm",
"linux/arm/v5",
"linux/arm/v6",
"linux/arm/v7",
"linux/arm/v8",
"linux/arm64", "linux/arm64",
"linux/arm64/v8", "linux/arm64/v8",
}, },
false: { false: {
"linux/amd64", "linux/amd64",
"linux/arm",
"linux/arm/v4", "linux/arm/v4",
"linux/arm/v5",
"linux/arm/v6",
"linux/arm/v7",
"linux/arm/v8",
"linux/arm/v9", "linux/arm/v9",
"linux/arm64/v9", "linux/arm64/v9",
"windows/amd64", "windows/amd64",

View File

@ -107,12 +107,7 @@ func getCPUVariant() string {
switch strings.ToLower(variant) { switch strings.ToLower(variant) {
case "8", "aarch64": case "8", "aarch64":
// special case: if running a 32-bit userspace on aarch64, the variant should be "v7" variant = "v8"
if runtime.GOARCH == "arm" {
variant = "v7"
} else {
variant = "v8"
}
case "7", "7m", "?(12)", "?(13)", "?(14)", "?(15)", "?(16)", "?(17)": case "7", "7m", "?(12)", "?(13)", "?(14)", "?(15)", "?(16)", "?(17)":
variant = "v7" variant = "v7"
case "6", "6tej": case "6", "6tej":