Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: make go install -buildmode=pie cmd/compile reproducible #31320

Closed
eliasnaur opened this issue Apr 7, 2019 · 2 comments
Closed

cmd/go: make go install -buildmode=pie cmd/compile reproducible #31320

eliasnaur opened this issue Apr 7, 2019 · 2 comments

Comments

@eliasnaur
Copy link
Contributor

eliasnaur commented Apr 7, 2019

I'm trying to run Android builders directly from the device without a host. To do that, make.bash must successfully complete. However, the Android kernel will only execute PIE executables, which means that the toolchain must be built with the equivalent of -buildmode=pie enabled all the time.

After hacking buildmode=pie, ./make.bash will complain that the bootstrap process does not converge. The root cause is that the build ids of the toolchain never converge.

To demonstrate the problem, I'm building cmd/compile with buildmode=pie on my host linux machine and comparing the build ids.

What version of Go are you using (go version)?

$ go version
go version devel +cb6646234c Fri Apr 5 20:54:50 2019 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/elias/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/elias/go"
GOPROXY=""
GORACE=""
GOROOT="/home/elias/dev/go-tip"
GOTMPDIR=""
GOTOOLDIR="/home/elias/dev/go-tip/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/elias/dev/go-tip/src/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build246738344=/tmp/go-build -gno-record-gcc-switches"

What did you do?

$ go install -buildmode=pie cmd/compile && file ../pkg/tool/linux_amd64/compile
../pkg/tool/linux_amd64/compile: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, Go BuildID=p1yMqYIYR70YO68fXa_U/2AOqrHjBazbV9Pmqp2sx/mXSClqAD4HkdJo6pdJuD/f1DbS9Mtz2lCJo8Le99p, BuildID[sha1]=4bf0f9af8307f82987827bc36d9df21b954621dc, not stripped
$ go install -buildmode=pie cmd/compile && file ../pkg/tool/linux_amd64/compile
../pkg/tool/linux_amd64/compile: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, Go BuildID=3JjeFa844Dxo9khAB0VA/4Cl1BAWmnJOrPX_KfkEv/mXSClqAD4HkdJo6pdJuD/TdYbWSqMM26Lmo_Gf6WL, BuildID[sha1]=68be3330ad82371c8c3823114e337ef9a3a26e03, not stripped

What did you expect to see?

The same build ids in two consecutive builds of cmd/compile.

What did you see instead?

The build ids never converge.

buildmode=pie enables external linking (#18968), but the test for reproducible Cgo builds does pass for me with PIE enabled:

$ go test -buildmode=pie -run TestCgoConsistentResults cmd/go
ok  	cmd/go	2.318s
@eliasnaur
Copy link
Contributor Author

eliasnaur commented Apr 7, 2019

It seems the culprit the ELF build ids. Using --build-id=none makes the build ids match:

$ CGO_LDFLAGS="-Wl,--build-id=none" go install -buildmode=pie -a cmd/compile && file ../pkg/tool/linux_amd64/compile
../pkg/tool/linux_amd64/compile: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, Go BuildID=VzdcHcFht3eH3P1KPRnn/ZK6he554u3xbpIEMBilo/mXSClqAD4HkdJo6pdJuD/aM9_XXpJYAYVBAex8sXW, not stripped
$ CGO_LDFLAGS="-Wl,--build-id=none" go install -buildmode=pie -a cmd/compile && file ../pkg/tool/linux_amd64/compile
../pkg/tool/linux_amd64/compile: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, Go BuildID=VzdcHcFht3eH3P1KPRnn/ZK6he554u3xbpIEMBilo/mXSClqAD4HkdJo6pdJuD/aM9_XXpJYAYVBAex8sXW, not stripped

@gopherbot
Copy link

Change https://golang.org/cl/170942 mentions this issue: cmd/go/internal/work: make toolchain builds reproducible when buildmode=pie

@golang golang locked and limited conversation to collaborators Apr 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants