Description
What version of Go are you using (go version
)?
$ go version go version go1.16beta1 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
Compiled using darwin, amd64. Executed on darwin, arm64
Build env:
go env
Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/Users/user-js/Library/Caches/go-build" GOENV="/Users/user-js/Library/Application Support/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/user-js/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/user-js/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/Users/user-js/go/go1.16beta1" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/Users/user-js/go/go1.16beta1/pkg/tool/darwin_amd64" GOVCS="" GOVERSION="go1.16beta1" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/dev/null" 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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/s6/fv1xpj4n7j9c9l1flw1j4lxr0000gn/T/go-build580121957=/tmp/go-build -gno-record-gcc-switches -fno-common" GOROOT/bin/go version: go version go1.16beta1 darwin/amd64 GOROOT/bin/go tool compile -V: compile version go1.16beta1 uname -v: Darwin Kernel Version 19.6.0: Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64 ProductName: Mac OS X ProductVersion: 10.15.7 BuildVersion: 19H15 lldb --version: lldb-1200.0.41 Apple Swift version 5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8) gdb --version: GNU gdb (GDB) 8.3
Execution env:
go env
Output
$ go env GO111MODULE="" GOARCH="arm64" GOBIN="" GOCACHE="/Users/user-es/Library/Caches/go-build" GOENV="/Users/user-es/Library/Application Support/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/user-es/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/user-es/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/opt/homebrew/Cellar/go/1.15.6/libexec" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/opt/homebrew/Cellar/go/1.15.6/libexec/pkg/tool/darwin_arm64" GOVCS="" GOVERSION="go1.16beta1" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/dev/null" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/v1/1y48b2yx6tndh56_yn2fqx4c0000gn/T/go-build161273293=/tmp/go-build -gno-record-gcc-switches -fno-common" GOROOT/bin/go version: go version go1.16beta1 darwin/arm64 GOROOT/bin/go tool compile -V: compile version go1.16beta1 uname -v: Darwin Kernel Version 20.1.0: Sat Oct 31 00:07:10 PDT 2020; root:xnu-7195.50.7~2/RELEASE_ARM64_T8101 ProductName: macOS ProductVersion: 11.0.1 BuildVersion: 20B29 lldb --version: lldb-1200.0.44.2 Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)
cross compile code on darwin amd64 then execute on darwin arm64.
% cat main.go
package main
import (
"log"
"os"
"os/user"
"runtime"
)
func main() {
log.Printf("GOOS: %s, GOARCH: %s", runtime.GOOS, runtime.GOARCH)
lookup, err := user.Lookup(os.Args[1])
if err != nil {
log.Panic(err)
}
log.Printf("User: %v\n", lookup)
}
Compile on darwin amd64 for arm64
GOOS=darwin GOARCH=arm64 go build main.go
Download to darwin arm64 computer then execute without and with sudo
.
% whoami
user-es
% ./main $(whoami)
2021/01/06 09:08:50 GOOS: darwin, GOARCH: arm64
2021/01/06 09:08:50 User: &{501 20 user-es /Users/user-es}
% sudo ./main $(whoami)
2021/01/06 09:08:50 GOOS: darwin, GOARCH: arm64
2021/01/06 09:08:50 user: unknown user user-es
panic: user: unknown user user-es
goroutine 1 [running]:
log.Panic(0x1400010ff38, 0x1, 0x1)
/Users/user-js/go/go1.16beta1/src/log/log.go:354 +0x98
main.main()
/Users/user-js/dev/go1.16beta1-maybebug/main.go:14 +0xe8
What did you expect to see?
I expected the user user-es
found by the function user.Lookup(string)
when running as root, same as it does without root.
I also expected the same error when the code is compiled on darwin-arm64 and executed on darwin-arm64. However if compiled on the target machine the function user.Lookup(string)
works as expected when ran as both user and root.
What did you see instead?
The function user.Lookup(string)
fails to find the user user-es
when running as root, when cross compiled from darwin-amd64.