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

Using // +build directives does not show unknown syscall.Stat_t build error #24005

Closed
henesy opened this issue Feb 21, 2018 · 6 comments
Closed

Comments

@henesy
Copy link

henesy commented Feb 21, 2018

Please answer these questions before submitting your issue. Thanks!

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

go1.10 plan9/amd64

Does this issue reproduce with the latest release?

Yes.

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

GOARCH='amd64'
GOBIN='/usr/henesy/go/bin'
GOCACHE='/usr/henesy/lib/cache/go-build'
GOEXE=''
GOHOSTARCH='amd64'
GOHOSTOS='plan9'
GOOS='plan9'
GOPATH='/usr/henesy/git'
GORACE=''
GOROOT='/sys/go/go'
GOTMPDIR=''
GOTOOLDIR='/sys/go/go/pkg/tool/plan9_amd64'
GCCGO='gccgo'
CC='6c'
CXX='g++'
CGO_ENABLED='0'
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build797076891=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I ran/built https://github.com/src-d/go-git with a patch on the https://github.com/src-d/go-billy dependency as per src-d/go-billy#52.

If you go install go-git without any changes, the library builds and you can then build the demo programs in go-git/_examples clone.go and commit.go successfully. Clone will run successfully, but if you build and run commit you get the following crash error:

panic: runtime error: invalid memory address or nil pointer dereference
[signal sys: trap: fault read code=0x0 addr=0x0 pc=0x509499]

goroutine 1 [running]:
gopkg.in/src-d/go-git%2ev4.(*Worktree).doUpdateFileToIndex(0x4209a3aa0, 0x420954200, 0x5c3607, 0x9, 0x3f34afae9c41494b, 0xbc744bc185055bf0, 0x6121711061217110, 0x0, 0x20f94d)
	/usr/henesy/git/src/gopkg.in/src-d/go-git.v4/worktree_status.go:375 +0x149
gopkg.in/src-d/go-git%2ev4.(*Worktree).addOrUpdateFileToIndex(0x4209a3aa0, 0x5c3607, 0x9, 0x3f34afae9c41494b, 0xbc744bc185055bf0, 0x61217110, 0x0, 0x0)
	/usr/henesy/git/src/gopkg.in/src-d/go-git.v4/worktree_status.go:343 +0x15e
gopkg.in/src-d/go-git%2ev4.(*Worktree).Add(0x4209a3aa0, 0x5c3607, 0x9, 0x0, 0x0, 0x0, 0x10, 0x4209a8490)
	/usr/henesy/git/src/gopkg.in/src-d/go-git.v4/worktree_status.go:265 +0x2d1
main.main()
	/usr/henesy/prg/go/git/commit.go:35 +0x12c

If you copy the linux worktree file as follows in go-git and change the header to // +build plan9, the compiler catches the error:
cp worktree_linux.go worktree_plan9.go

sav-cpu% go install
# gopkg.in/src-d/go-git.v4
./worktree_plan9.go:14:22: undefined: syscall.Stat_t

What did you expect to see?

A compiler error pointing out that syscall.Stat_t is not present on Plan 9.

What did you see instead?

No errors at build time. Running the program results in a crash with an error.

@bradfitz
Copy link
Contributor

Sorry, this looks like a bug in go-git (or simply lack of plan9 support in go-git). But there's nothing owned by the Go project here, so closing this bug.

I suggest you file this bug at .... oh, you already did: src-d/go-git#756

That's the right place.

@henesy
Copy link
Author

henesy commented Feb 21, 2018

Is the issue not with the //+build not finding the syscall.Stat_t? The lack of support in go-git is not the issue I'm pointing out here. Should //+build if not given a target for a platform (in this case plan9) build the usage of syscall.Stat_t in without throwing an error?

@bradfitz
Copy link
Contributor

Should //+build if not given a target for a platform (in this case plan9) build the usage of syscall.Stat_t in without throwing an error?

I don't know what this question means. But I imagine if you read https://golang.org/pkg/go/build/#hdr-Build_Constraints you'll see how it works.

For questions about Go, see https://golang.org/wiki/Questions.

@henesy
Copy link
Author

henesy commented Feb 21, 2018

My apologies for the lack of clarity. I have made a simpler proof of concept: https://github.com/henesy/buildpoc

In the state that the linked demo is in, if built, it yields:

henesy@FatboySlim:~/go/src/github.com/henesy/buildpoc/x/mypkg$ GOOS=plan9 GOARCH=amd64 go install
# github.com/henesy/buildpoc/x/mypkg
./test_plan9.go:12: undefined: syscall.Stat_t

If we delete test_plan9.go (leaving the only built file as test_linux.go) then the build completes as follows:

henesy@FatboySlim:~/go/src/github.com/henesy/buildpoc/x/mypkg$ rm test_plan9.go
henesy@FatboySlim:~/go/src/github.com/henesy/buildpoc/x/mypkg$ GOOS=plan9 GOARCH=amd64 go install
henesy@FatboySlim:~/go/src/github.com/henesy/buildpoc/x/mypkg$ ls
lib.go  test_linux.go  test_plan9_correct.go

If we then go up to the base folder we get a successful build, but running will fail:

sav-cpu% lc
README.md	test.go		x/
sav-cpu% go build
sav-cpu% ./buildpoc
test follows
panic: runtime error: invalid memory address or nil pointer dereference
[signal sys: trap: fault read code=0x0 addr=0x0 pc=0x283abb]

goroutine 1 [running]:
main.main()
	/usr/henesy/go/src/github.com/henesy/buildpoc/test.go:12 +0xcb

@bradfitz
Copy link
Contributor

leaving the only built file as test_linux.go

That's not true and that's why you're confused.

Look at GOOS=plan9 GOARCH=amd64 go list -json github.com/henesy/buildpoc/x/mypkg before & after deleting that file.

And read the URL I sent you before. (https://golang.org/pkg/go/build/#hdr-Build_Constraints)

For questions about Go, see https://golang.org/wiki/Questions.

@henesy
Copy link
Author

henesy commented Feb 21, 2018

The list output clarified the situation for me, I had not read the build doc closely enough, thank you. My apologies for the noise.

@golang golang locked and limited conversation to collaborators Feb 21, 2019
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