diff options
author | Bryan C. Mills <bcmills@google.com> | 2019-11-21 16:26:09 -0500 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2019-11-22 19:03:50 +0000 |
commit | 941ac9ce706aabc970aa220504a4213fe3abc8a9 (patch) | |
tree | 916cbcb658399fa2581fbdb7cc55899219414dac /src/cmd/go/internal/load/pkg.go | |
parent | 28314cf12491181df3c06047826f419fd1716f89 (diff) | |
download | go-941ac9ce706aabc970aa220504a4213fe3abc8a9.tar.gz go-941ac9ce706aabc970aa220504a4213fe3abc8a9.zip |
cmd/go: do not panic when computing Shlib for a package with no Target
In module mode, a non-main package lacks an install target.
The location of the .shlib corresponding to a given target is stored
in a .shlibname file alongside its install target, so in module mode
a non-main package also lacks a .shlibname file.
This also implies that such a package cannot be installed with
'go install -buildmode=linkshared', but that is a problem
for another day.
Fixes #35759
Updates #34347
Change-Id: Id3e0e068266d5fb9b061a59e70f9a65985d4973b
Reviewed-on: https://go-review.googlesource.com/c/go/+/208233
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/cmd/go/internal/load/pkg.go')
-rw-r--r-- | src/cmd/go/internal/load/pkg.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go index 8fc33e35fa..0d63187e06 100644 --- a/src/cmd/go/internal/load/pkg.go +++ b/src/cmd/go/internal/load/pkg.go @@ -1584,7 +1584,10 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) { p.Target = "" } else { p.Target = p.Internal.Build.PkgObj - if cfg.BuildLinkshared { + if cfg.BuildLinkshared && p.Target != "" { + // TODO(bcmills): The reliance on p.Target implies that -linkshared does + // not work for any package that lacks a Target — such as a non-main + // package in module mode. We should probably fix that. shlibnamefile := p.Target[:len(p.Target)-2] + ".shlibname" shlib, err := ioutil.ReadFile(shlibnamefile) if err != nil && !os.IsNotExist(err) { |