From d8f78dca3469076ffed75713a9709b798765d879 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Tue, 6 Aug 2019 01:03:20 +0000 Subject: [PATCH] binfmt_misc: add detection for 386 Detects x86 32-bit architectures Signed-off-by: Tibor Vass --- util/binfmt_misc/386_binary.go | 8 ++++++++ util/binfmt_misc/386_check.go | 7 +++++++ util/binfmt_misc/386_check_386.go | 7 +++++++ util/binfmt_misc/Dockerfile | 8 +++++++- util/binfmt_misc/detect.go | 8 ++++++++ util/binfmt_misc/fixtures/exit.386.s | 6 ++++++ 6 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 util/binfmt_misc/386_binary.go create mode 100644 util/binfmt_misc/386_check.go create mode 100644 util/binfmt_misc/386_check_386.go create mode 100644 util/binfmt_misc/fixtures/exit.386.s diff --git a/util/binfmt_misc/386_binary.go b/util/binfmt_misc/386_binary.go new file mode 100644 index 00000000..580f152f --- /dev/null +++ b/util/binfmt_misc/386_binary.go @@ -0,0 +1,8 @@ +// +build !386 + +package binfmt_misc + +// This file is generated by running make inside the binfmt_misc package. +// Do not edit manually. + +const Binary386 = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\xec\xd8\x31\x6e\xc2\x30\x14\x06\xe0\xdf\x8d\xdb\x26\x6a\x07\x1f\x20\xaa\x3a\x74\xe8\x64\xb5\x52\xae\x00\x2c\x88\x8d\x03\x80\x14\xc1\x94\x44\x89\x91\x60\x22\x47\x60\xe0\x20\x8c\x8c\x5c\x80\x13\x70\x19\xf4\xe2\x67\x91\x81\x25\xfb\xfb\xa4\x5f\x16\xcf\xe6\x29\xeb\x7b\xfb\xd1\x74\xac\x94\x42\xf0\x82\x08\xdd\xaf\x83\x8e\x33\x00\x7f\xc6\xd7\x33\x7c\x23\xc2\x2f\x74\xb8\x27\xad\x8e\x29\x27\x00\x14\x4d\x35\x03\x7f\x6f\x7c\x0f\x4a\x02\x80\xf2\xca\x75\x7a\x77\xa4\xb4\x3a\xa6\xa4\x00\x52\xfe\x7f\xc8\x27\xbf\x9f\xcc\xe6\xd4\xef\x42\xb5\xc7\x57\x0a\x21\x84\x10\x42\x08\x21\x84\x10\x62\x88\x33\x0d\xd5\xff\xb7\x6b\x0b\xdb\xac\x1b\x57\xbb\xc5\x12\xb6\x28\x5d\x6e\x57\xc5\xc6\x56\x75\x59\xe5\xb5\xdb\xc1\xba\x7c\xeb\x86\xf4\xfd\x00\xf0\xde\xed\x13\x78\xce\xe7\x19\x3f\xd0\x7c\x7e\xf1\x5c\xff\xc6\x3b\x07\x18\xbf\x2b\x08\x54\xef\x8c\x7a\xf5\xc4\x00\x3f\x4f\xde\xdd\x03\x00\x00\xff\xff\x8d\xf7\xd2\x72\xd0\x10\x00\x00" diff --git a/util/binfmt_misc/386_check.go b/util/binfmt_misc/386_check.go new file mode 100644 index 00000000..8137d350 --- /dev/null +++ b/util/binfmt_misc/386_check.go @@ -0,0 +1,7 @@ +// +build !386 + +package binfmt_misc + +func i386Supported() error { + return check(Binary386) +} diff --git a/util/binfmt_misc/386_check_386.go b/util/binfmt_misc/386_check_386.go new file mode 100644 index 00000000..2b2ab45b --- /dev/null +++ b/util/binfmt_misc/386_check_386.go @@ -0,0 +1,7 @@ +// +build 386 + +package binfmt_misc + +func i386Supported() error { + return nil +} diff --git a/util/binfmt_misc/Dockerfile b/util/binfmt_misc/Dockerfile index a27b8d44..6f19089b 100644 --- a/util/binfmt_misc/Dockerfile +++ b/util/binfmt_misc/Dockerfile @@ -3,6 +3,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ binutils-arm-linux-gnueabihf \ binutils-aarch64-linux-gnu \ binutils-x86-64-linux-gnu \ + binutils-i686-linux-gnu \ binutils-riscv64-linux-gnu \ binutils-s390x-linux-gnu \ binutils-powerpc64le-linux-gnu @@ -13,6 +14,10 @@ FROM base AS exit-amd64 COPY fixtures/exit.amd64.s . RUN x86_64-linux-gnu-as -o exit.o exit.amd64.s && x86_64-linux-gnu-ld -o exit -s exit.o +FROM base AS exit-386 +COPY fixtures/exit.386.s . +RUN i686-linux-gnu-as -o exit.o exit.386.s && i686-linux-gnu-ld -o exit -s exit.o + FROM base AS exit-arm64 COPY fixtures/exit.arm64.s . RUN aarch64-linux-gnu-as -o exit.o exit.arm64.s && aarch64-linux-gnu-ld -o exit -s exit.o @@ -36,6 +41,7 @@ RUN powerpc64le-linux-gnu-as -o exit.o exit.ppc64le.s && powerpc64le-linux-gnu-l FROM golang:1.12-alpine AS generate WORKDIR /src COPY --from=exit-amd64 /src/exit amd64 +COPY --from=exit-386 /src/exit 386 COPY --from=exit-arm64 /src/exit arm64 COPY --from=exit-arm /src/exit arm COPY --from=exit-riscv64 /src/exit riscv64 @@ -43,7 +49,7 @@ COPY --from=exit-s390x /src/exit s390x COPY --from=exit-ppc64le /src/exit ppc64le COPY generate.go . -RUN go run generate.go amd64 arm64 arm riscv64 s390x ppc64le && ls -l +RUN go run generate.go amd64 386 arm64 arm riscv64 s390x ppc64le && ls -l FROM scratch diff --git a/util/binfmt_misc/detect.go b/util/binfmt_misc/detect.go index 38c3e86e..1a250a5d 100644 --- a/util/binfmt_misc/detect.go +++ b/util/binfmt_misc/detect.go @@ -30,6 +30,9 @@ func SupportedPlatforms() []string { if p := "linux/s390x"; def != p && s390xSupported() == nil { arr = append(arr, p) } + if p := "linux/386"; def != p && i386Supported() == nil { + arr = append(arr, p) + } if !strings.HasPrefix(def, "linux/arm/") && armSupported() == nil { arr = append(arr, "linux/arm/v7", "linux/arm/v6") } else if def == "linux/arm/v7" { @@ -71,6 +74,11 @@ func WarnIfUnsupported(pfs []string) { printPlatfromWarning(p, err) } } + if p == "linux/386" { + if err := i386Supported(); err != nil { + printPlatfromWarning(p, err) + } + } if strings.HasPrefix(p, "linux/arm/v6") || strings.HasPrefix(p, "linux/arm/v7") { if err := armSupported(); err != nil { printPlatfromWarning(p, err) diff --git a/util/binfmt_misc/fixtures/exit.386.s b/util/binfmt_misc/fixtures/exit.386.s new file mode 100644 index 00000000..2a684eee --- /dev/null +++ b/util/binfmt_misc/fixtures/exit.386.s @@ -0,0 +1,6 @@ + .global _start + .text +_start: + mov $1, %eax + xor %ebx, %ebx + int $0x80