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: unable to install sub-module with buildmode=shared with go modules but $GOPATH works #37034

Closed
affanshahid opened this issue Feb 5, 2020 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@affanshahid
Copy link

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

$ go version
go version go1.13.7 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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/project/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-build808455707=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I am trying to compile a project with -buildmode=shared. My project has the following file structure:

go.mod
main.go
util
   /util.go

My go.mod file:

module example.com/affan/project

go 1.13

and my main.go simply imports example.com/affan/project/util and runs some code. Now following this stackoverflow link I am trying to compile my project in a way such that my main binary links to an .so of example.com/affan/project/util.

What did you expect to see?

I expected it to compile a binary and link to an so file of my sub-package

What did you see instead?

When I run go install -buildmode=shared -linkshared example.com/affan/project/util, I get the following:

panic: runtime error: slice bounds out of range [:-2]

goroutine 1 [running]:
cmd/go/internal/load.(*Package).load(0xc000096900, 0xc0001359f0, 0xc000045180, 0x0, 0x0)
        /usr/local/go/src/cmd/go/internal/load/pkg.go:1491 +0x36db
cmd/go/internal/load.loadImport(0xc000280200, 0x7fff3c03febc, 0x1e, 0xc000024024, 0xd, 0x0, 0xc0001359f0, 0x0, 0x0, 0x0, ...)
        /usr/local/go/src/cmd/go/internal/load/pkg.go:511 +0xdf2
cmd/go/internal/load.PackagesAndErrors(0xc000020090, 0x1, 0x1, 0x0, 0x0, 0x0)
        /usr/local/go/src/cmd/go/internal/load/pkg.go:1982 +0x398
cmd/go/internal/load.PackagesForBuild(0xc000020090, 0x1, 0x1, 0x9b9a00, 0x0, 0x0)
        /usr/local/go/src/cmd/go/internal/load/pkg.go:2028 +0x5d
cmd/go/internal/work.runInstall(0xea4340, 0xc000020090, 0x1, 0x1)
        /usr/local/go/src/cmd/go/internal/work/build.go:483 +0x44
main.main()
        /usr/local/go/src/cmd/go/main.go:189 +0x57f

I thought maybe I'm not specifying the path correctly so I tried. ./util as the final argument as well, but it had the same result.

It works with $GOPATH

I removed go.mod and copied everything to under $GOPATH/src with the correct paths. After that running the commands from the above link works perfectly, I get a binary linked to an .so of my util package just as I expect. So this is definitely something to do with go-modules (or maybe me doing something wrong?)

@affanshahid affanshahid changed the title Unable to install module with buildmode=shared Unable to install sub-module with buildmode=shared Feb 5, 2020
@odeke-em odeke-em changed the title Unable to install sub-module with buildmode=shared cmd/go: unable to install sub-module with buildmode=shared with go modules but $GOPATH works Feb 5, 2020
@odeke-em
Copy link
Member

odeke-em commented Feb 5, 2020

Thank you for this report @affanshahid and welcome to the Go project!

Interesting bug report and crash! Kindly paging @jayconrod @bcmills
In the meantime @affanshahid, could you please try with Go1.14 beta as per https://golang.org/dl/#unstable and see if the problem persists?

@odeke-em odeke-em added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 5, 2020
@bcmills
Copy link
Contributor

bcmills commented Feb 5, 2020

Duplicate of #35759

@bcmills bcmills marked this as a duplicate of #35759 Feb 5, 2020
@bcmills bcmills closed this as completed Feb 5, 2020
@odeke-em
Copy link
Member

odeke-em commented Feb 5, 2020

@bcmills thanks for the follow-up! Shall we then recommend that the user expect it the fix in Go1.14?

@golang golang locked and limited conversation to collaborators Feb 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants