Closed
Description
What version of Go are you using (go version
)?
root@71fe8ef0fc55:/go_src# go version go version go1.14.2 linux/amd64
Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="on" GOARCH="amd64" GOBIN="" GOCACHE="/root/.cache/go-build" GOENV="/root/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" 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="/go_src/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-build091221661=/tmp/go-build -gno-record-gcc-switches"
What did you do?
Refer to: https://github.com/ramanvis/buildsharedwithmod
I did the following:
- Generated a shared library of my package using
buildmode=shared
for library "github.com/ramanvis/buildsharedwithmod/lib/advmath".
root@71fe8ef0fc55:/go_src# go install -buildmode=shared std
root@71fe8ef0fc55:/go_src# go install -buildmode=shared -linkshared github.com/ramanvis/buildsharedwithmod/lib/advmath
root@71fe8ef0fc55:/go_src# ls
Dockerfile README.md cmd go.mod go.sum lib libgithub.com-ramanvis-buildsharedwithmod-lib-advmath.so
- When I create my executable using linkshared option, then I do see executable created successfully.
root@71fe8ef0fc55:/go_src# go build -o /bin/advmath -linkshared github.com/ramanvis/buildsharedwithmod/cmd/advmath
- ldd of the the executable does not link to the shared library.
How to reproduce:
- Use this docker image to reproduce the problem:
docker pull ramanvis/buildsharedwithmod:latest
docker run --rm -it ramanvis/buildsharedwithmod:latest /bin/bash
- Execute the following commands:
go install -buildmode=shared std
go install -buildmode=shared -linkshared github.com/ramanvis/buildsharedwithmod/lib/advmath
go build -o /bin/advmath -linkshared github.com/ramanvis/buildsharedwithmod/cmd/advmath
- Verify with ldd
ldd /bin/advmath
What did you expect to see?
I was expecting to see the binary being dynamically linked to libgithub.com-ramanvis-buildsharedwithmod-lib-advmath.so
root@71fe8ef0fc55:/go_src# ldd /bin/advmath
linux-vdso.so.1 (0x00007fff1b9fc000)
libstd.so => /usr/local/go/pkg/linux_amd64_dynlink/libstd.so (0x00007f267554e000)
libgithub.com-ramanvis-buildsharedwithmod-lib-advmath.so => (/go_src/libgithub.com-ramanvis-buildsharedwithmod-lib-advmath.so)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2675389000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f2675384000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f2675363000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2677c7b000)
What did you see instead?
root@71fe8ef0fc55:/go_src# ldd /bin/advmath
linux-vdso.so.1 (0x00007fff1b9fc000)
libstd.so => /usr/local/go/pkg/linux_amd64_dynlink/libstd.so (0x00007f267554e000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2675389000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f2675384000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f2675363000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2677c7b000)