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

Cannot build code containing debug.SetGCPercent() for Android ARM #48246

Closed
evanw opened this issue Sep 8, 2021 · 1 comment
Closed

Cannot build code containing debug.SetGCPercent() for Android ARM #48246

evanw opened this issue Sep 8, 2021 · 1 comment

Comments

@evanw
Copy link

evanw commented Sep 8, 2021

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

$ go version
go version go1.17 darwin/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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/evan/Library/Caches/go-build"
GOENV="/Users/evan/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/evan/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/evan/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/evan/dev/esbuild/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 -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/j6/np400cw17sz0n5ljd67byrzw0000gn/T/go-build3774117208=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I tried to build the following program for Android ARM:

package main

import "runtime/debug"

func main() {
	debug.SetGCPercent(-1)
}

This is a reduced test case from a real program: https://github.com/evanw/esbuild. I am able to cross-compile this program for all platforms except for Android ARM. More context is here: evanw/esbuild#1578.

What did you expect to see?

I expected the build to succeed.

What did you see instead?

The build fails with a cgo-related error. The build also fails if cgo is enabled:

$ GOOS="android" GOARCH="arm" go build main.go
# command-line-arguments
loadinternal: cannot find runtime/cgo
/usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: unknown option: -z
clang: error: linker command failed with exit code 1 (use -v to see invocation)

$ CGO_ENABLED=1 GOOS="android" GOARCH="arm" go build main.go
# runtime/cgo
clang: error: argument unused during compilation: '-marm' [-Werror,-Wunused-command-line-argument]

Building the same program for Android ARM64 works fine:

$ GOOS="android" GOARCH="arm64" go build main.go && file main
main: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /system/bin/linker64, Go BuildID=alvXLw57shg5zRLjPYoO/GyVC8TDUJ07MNhoXCsu-/nzi6B7uKoZ53M53L4eR-/0JYttdF-za9eeF0oEvPR, not stripped
@cherrymui
Copy link
Member

To cross compile, you need to set CC to a C cross compiler targeting Android ARM.

Currently we support internal linking for Android ARM64, but not for Android ARM(32). So you'll need a C toolchain to build. Thanks.

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

3 participants