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

os/user: "GroupIds requires cgo" when building for linux/arm with tag osusergo #35770

Open
mullerch opened this issue Nov 22, 2019 · 3 comments
Open

Comments

@mullerch
Copy link

@mullerch mullerch commented Nov 22, 2019

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

$ go version go1.13.4 windows/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
λ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\chris\AppData\Local\go-build
set GOENV=C:\Users\chris\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\chris\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\chris\AppData\Local\Temp\go-build206665018=/tmp/go-build -gno-record-gcc-switches

What did you do?

Cross-compile a go application for linux/arm using windows/amd64 using -tags="osusergo"
Cross-compile a go application for linux/arm using linux/amd64 using -tags="osusergo"

What did you expect to see?

The application builds fine and uses go implementation of os/user.
os/user.GroupIds should work fine on an application not using CGO.

What did you see instead?

The application builds fine but uses CGO implementation of os/user.
os/user.GroupIds call returns "user: GroupIds requires cgo"

The same application is correctly compiled/linked with go 1.12 on linux/amd64 for linux/arm.

@mullerch mullerch changed the title Tag osusergo does not work when cross-compiling a go application for linux/arm using windows/amd64 Tag osusergo does not work with go 1.13 Nov 22, 2019
@mullerch mullerch changed the title Tag osusergo does not work with go 1.13 Tag osusergo does not work with go 1.13 in linux/arm Nov 22, 2019
@bcmills bcmills changed the title Tag osusergo does not work with go 1.13 in linux/arm os/user: "GroupIds requires cgo" when building for linux/arm with tag osusergo Nov 22, 2019
@bcmills
Copy link
Member

@bcmills bcmills commented Nov 22, 2019

The error message user: GroupIds requires cgo implies that the build is not using the cgo implementation. It comes from here:

return nil, errors.New("user: GroupIds requires cgo")

So the question is, why were you not getting that error on 1.12?

(What are the exact commands that you ran, and the results using go1.12.13 and go1.13.4 binaries from golang.org/dl?)

@mullerch
Copy link
Author

@mullerch mullerch commented Nov 25, 2019

I am not able to reproduce the working example with go 1.12.
Sadly I did not kept the config nor the binaries.

Regarding the docs, shouldn't the build without CGO or with -tags="osusergo" be linked against:

func lookupGroupId(id string) (*Group, error) {

https://golang.org/pkg/os/user/

For most Unix systems, this package has two internal implementations of resolving user and group ids to names. One is written in pure Go and parses /etc/passwd and /etc/group. The other is cgo-based and relies on the standard C library (libc) routines such as getpwuid_r and getgrnam_r.
When cgo is available, cgo-based (libc-backed) code is used by default. This can be overridden by using osusergo build tag, which enforces the pure Go implementation.

@bcmills
Copy link
Member

@bcmills bcmills commented Nov 25, 2019

lookupGroupId is the implementation for the user.LookupGroupId function, not the (*user.User).GroupIds method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.