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: Building a shared library in modules mode produces empty library #37675

Open
misha-ridge opened this issue Mar 4, 2020 · 2 comments
Open

Comments

@misha-ridge
Copy link

@misha-ridge misha-ridge commented Mar 4, 2020

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

go version go1.14 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

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

go env Output
GO111MODULE=""
GOARCH="amd64"
GOBIN="/Users/dottedmag/go/bin"
GOCACHE="/Users/dottedmag/Library/Caches/go-build"
GOENV="/Users/dottedmag/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY="github.com/ridge"
GONOSUMDB="github.com/ridge"
GOOS="darwin"
GOPATH="/Users/dottedmag/go"
GOPRIVATE="github.com/ridge"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/dottedmag/tectonic/_deps.darwin-amd64/go-1.14"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/dottedmag/tectonic/_deps.darwin-amd64/go-1.14/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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/bw/6hyp_vyj68v973qbhlbcvlcr0000gn/T/go-build983884458=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Tried to build a shared library and a binary that links to that shared library in modules mode. A repository with reproducer: https://github.com/misha-ridge/splitlib

Packages:

  • github.com/misha-ridge/splitlib/a (imports ./c)
  • github.com/misha-ridge/splitlib/b (imports ./c)
  • github.com/misha-ridge/splitlib/c
  • github.com/misha-ridge/splitlib (imports ./a, ./b, ./c)

./a and ./c ought to end up in a shared library, ./b and splitlib in binary.

Build:

$ go install -buildmode=shared std
$ go install -buildmode=shared -linkshared  -gcflags='-N -l' ./a
$ go build -o main -linkshared  -gcflags='-N -l' .

What did you expect to see?

  1. libgithub.com-misha-ridge-splitlib-a.so with code from ./a and ./c packages, dynamically linking to std.
  2. splitlib binary with code from ./b and splitlib, dynamically linking to std and libgithub.com-misha-ridge-splitlib-a.so.

What did you see instead?

  1. libgithub.com-misha-ridge-splitlib-a.so is empty:
$ go tool nm libgithub.com-misha-ridge-splitlib-a.so  | grep splitlib
  104cd0 D go.link.abihash.libgithub.com-misha-ridge-splitlib-a.so
  1. splitlib contains code from ./a, ./b, ./c and splitlib and dynamically links only to std:
$ go tool nm main  | grep splitlib
    2180 T github.com/misha-ridge/splitlib/a.SetC
    2190 T github.com/misha-ridge/splitlib/b.SetC
    2170 T github.com/misha-ridge/splitlib/c.Get
    5210 D github.com/misha-ridge/splitlib/c.i
    2180 t local.github.com/misha-ridge/splitlib/a.SetC
    2190 t local.github.com/misha-ridge/splitlib/b.SetC
    2170 t local.github.com/misha-ridge/splitlib/c.Get

Additional info

Trying to build the same using Go 1.13 triggers #35759.

@misha-ridge misha-ridge changed the title Building shared library in module mode produces empty library Building shared library in modules mode produces empty library Mar 4, 2020
@misha-ridge misha-ridge changed the title Building shared library in modules mode produces empty library Building a shared library in modules mode produces empty library Mar 4, 2020
@toothrot toothrot changed the title Building a shared library in modules mode produces empty library cmd/go: Building a shared library in modules mode produces empty library Mar 9, 2020
@toothrot toothrot added this to the Backlog milestone Mar 9, 2020
@toothrot

This comment has been minimized.

Copy link
Contributor

@toothrot toothrot commented Mar 9, 2020

@bcmills bcmills added the modules label Mar 9, 2020
@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Mar 9, 2020

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
3 participants
You can’t perform that action at this time.