GithubHelp home page GithubHelp logo

Comments (8)

kawasin73 avatar kawasin73 commented on July 23, 2024

Travis で、QEMU を利用して ARM のアーキテクチャの上でテストをしている模様

Linux カーネルには、binfmt_misc という仕組みがあり、実行バイナリの先頭のバイト列に一致するパターンがあった場合、指定のインタープリタを実行することができる。
Linuxのbinfmt_miscを使ってGoスクリプトを直接実行できるようにする

Docker の multiarch/qemu-user-static:register イメージを実行することで、ホストマシンの binfmt_misc に複数のアーキテクチャのバイナリを QEMU で実行するように修正する。

docker run --rm --privileged multiarch/qemu-user-static:register --reset

これを Travis 上で実行し、ARM の Docker イメージを実行することで ARM アーキテクチャで実行することが可能になる。

Go 言語の ARM 版 Docker イメージは https://hub.docker.com/r/arm64v8/golang/ である。

参考:amd64 以外のDocker イメージ

from bitset.

kawasin73 avatar kawasin73 commented on July 23, 2024

以下のエラーが発生して Arm 版の Dockerイメージ arm64v8/golang が実行できない。

docker: no matching manifest for linux/amd64 in the manifest list entries.

docker-library/official-images#3835

この問題に該当する

manifest が適合せずにイメージのプルに失敗している。

from bitset.

kawasin73 avatar kawasin73 commented on July 23, 2024

Go 言語は qemu の arm に対応していない。

https://www.reddit.com/r/golang/comments/6j08ux/what_the_best_arm_emulator_for_testing_go_binary/
golang/go#13024 (comment)

Yeah, I think we lost the ability to run Go binaries with
qemu-arm long time ago. tcg fatal error also seems to
suggest that it's a qemu bug. (the arm port used to be
developed with qemu-arm, but then as the port is able
to run on real hardwares, we no longer test on qemu-arm.)

from bitset.

kawasin73 avatar kawasin73 commented on July 23, 2024

以下の手順で arm64 上で Go のテストを実行したが、Little Endian であった。

sudo docker run --rm -it multiarch/debian-debootstrap:arm64-jessie bash
wget --no-check-certificate https://dl.google.com/go/go1.11.2.linux-arm64.tar.gz
tar -xvf go1.11.2.linux-arm64.tar.gz
mv go /usr/local
export GOROOT=/usr/local/go
export GOPATH=/root/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
cd /root
apt-get install -y git
git clone https://github.com/kawasin73/bitset.git

from bitset.

kawasin73 avatar kawasin73 commented on July 23, 2024

Travis で s390x を動かすことができている。 travis-ci/travis-ci#8869 (comment)
この上で Golang を動かすことを考える。

公式の Golang の s390x 向けのアーカイブ をダウンロード・解凍して go version を実行するも以下のエラーが発生

$ sudo docker run --rm -it multiarch/debian-debootstrap:s390x-jessie bash
root@3e8ef6ffcd82:~# go test
Illegal instruction (core dumped)

macOS 上でテストコードをコンパイルして、テストバイナリを Docker 上で実行するも同じくエラーが発生した。

# on macOS
GOOS=linux GOARCH=s390x go test -c
sudo docker run --rm -v $(pwd):/root -it multiarch/debian-debootstrap:s390x-jessie bash
# on Docker container
$ ./bitset.test -test.v
Illegal instruction (core dumped)

from bitset.

kawasin73 avatar kawasin73 commented on July 23, 2024

Go 言語が対応するアーキテクチャのうち Big Endian は以下の通り。

https://github.com/golang/go/wiki/MinimumRequirements#architectures

from bitset.

kawasin73 avatar kawasin73 commented on July 23, 2024

できた

GOOS=linux GOARCH=ppc64 go test -c -o bitset.test
docker run --rm -v $(pwd):/root multiarch/fedora:25-ppc64 /root/bitset.test -test.v

macOS + vagrant + Ubuntu 環境の Docker では動いた。

しかし、travis では動かなかった。以下のエラーが発生する。
https://travis-ci.com/kawasin73/bitset/jobs/157899588

0.42s$ docker run --rm -v $(pwd):/root  multiarch/fedora:25-ppc64 /root/bitset.test -test.v
standard_init_linux.go:185: exec user process caused "no such file or directory"
The command "docker run --rm -v $(pwd):/root  multiarch/fedora:25-ppc64 /root/bitset.test -test.v" exited with 1.

from bitset.

kawasin73 avatar kawasin73 commented on July 23, 2024

multiarch/qemu-user-static リポジトリで公開されている qemu-ppc64-static をダウンロードして ppc64 のアーキテクチャをエミュレートしてテストを行うことにした。

テストコードのバイナリ(go test -c で出力できる)を linux/ppc64 のバイナリにクロスコンパイルして実行している。

wget https://github.com/multiarch/qemu-user-static/releases/download/v3.0.0/qemu-ppc64-static
chmod 755 qemu-ppc64-static
GOOS=linux GOARCH=ppc64 go test -c -o bitset.test
./qemu-ppc64-static ./bitset.test -test.v

from bitset.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.