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/link/internal/ld: linker problem with shared libraries #44031

Closed
kiap opened this issue Jan 31, 2021 · 3 comments
Closed

cmd/link/internal/ld: linker problem with shared libraries #44031

kiap opened this issue Jan 31, 2021 · 3 comments

Comments

@kiap
Copy link

@kiap kiap commented Jan 31, 2021

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

1.16rc1

Does this issue reproduce with the latest release?

Yes

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

go env Output
tested on CentOS 7 and RHEL8

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/usr/src/.cache"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/usr/src/it.dev/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/usr/src/it.dev"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/src/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/src/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel +4436114 Fri Jan 29 19:48:48 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/usr/src/it.dev/src/hello/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-build561658131=/tmp/go-build -gno-record-gcc-switches"

What did you do?

We have problem with shared library linking of new ld in 1.16rc1, I recreated the problem using standard library, we originally had the issue with our own developed libraries

I have chosen the following based on their dependencies hierarchy

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib runtime sync

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib runtime/race

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib unicode

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib unicode/utf8

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib unicode/utf16

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib math/bits

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib math

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib internal/unsafeheader

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib internal/reflectlite

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib internal/testlog

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib container/list

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib container/ring

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib crypto/internal/subtle

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib crypto/subtle

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib vendor/golang.org/x/crypto/cryptobyte/asn1

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib internal/nettrace

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib vendor/golang.org/x/crypto/internal/subtle

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib encoding

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib internal/goversion

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib hash/maphash

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib image/color

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib internal/cfg

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib image/color/palette

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib math/cmplx

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib runtime/metrics

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib internal/singleflight

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib internal/sysinfo

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib math/rand

go install -v -ldflags '-s -w' -gcflags '-trimpath /usr/src/go' -buildmode=shared -linkshared -pkgdir /usr/src/lib errors

What did you expect to see?

shared libraries built and placed into /usr/src/lib

/usr/src/lib/libcontainer-list.so
/usr/src/lib/libcontainer-ring.so
/usr/src/lib/libcrypto-internal-subtle.so
/usr/src/lib/libcrypto-subtle.so
/usr/src/lib/libencoding.so
/usr/src/lib/libhash-maphash.so
/usr/src/lib/libimage-color-palette.so
/usr/src/lib/libimage-color.so
/usr/src/lib/libinternal-cfg.so
/usr/src/lib/libinternal-goversion.so
/usr/src/lib/libinternal-nettrace.so
/usr/src/lib/libinternal-reflectlite.so
/usr/src/lib/libinternal-singleflight.so
/usr/src/lib/libinternal-sysinfo.so
/usr/src/lib/libinternal-testlog.so
/usr/src/lib/libinternal-unsafeheader.so
/usr/src/lib/libmath-bits.so
/usr/src/lib/libmath-cmplx.so
/usr/src/lib/libmath-rand.so
/usr/src/lib/libmath.so
/usr/src/lib/libruntime-metrics.so
/usr/src/lib/libruntime-race.so
/usr/src/lib/libruntime,sync.so
/usr/src/lib/libunicode.so
/usr/src/lib/libunicode-utf16.so
/usr/src/lib/libunicode-utf8.so
/usr/src/lib/libvendor-golang.org-x-crypto-cryptobyte-asn1.so
/usr/src/lib/libvendor-golang.org-x-crypto-internal-subtle.so
/usr/src/lib/liberrors.so

What did you see instead?

All shared libraries created except for liberrors.so

Attention it is possible to replicate this with strings, bufio, and so many other libraries, as well as our properietary libraries, older versions worked just fine)

/tmp/go-build3363267740/b011/liberrors.so

panic: runtime error: index out of range [23] with length 0

goroutine 1 [running]:
cmd/link/internal/ld.decodetypeKind(...)
/usr/src/go/src/cmd/link/internal/ld/decodesym.go:52
cmd/link/internal/ld.(*deadcodePass).decodeIfaceMethod(0xc000112c50, 0xc00009c000, 0x87f340, 0xc8, 0x68, 0x8b, 0xc0000be000, 0xc00009c000)
/usr/src/go/src/cmd/link/internal/ld/deadcode.go:391 +0x247
cmd/link/internal/ld.(*deadcodePass).flood(0xc000112c50)
/usr/src/go/src/cmd/link/internal/ld/deadcode.go:169 +0x5bb
cmd/link/internal/ld.deadcode(0xc000152000)
/usr/src/go/src/cmd/link/internal/ld/deadcode.go:308 +0xa9
cmd/link/internal/ld.Main(0x87f340, 0x20, 0x20, 0x1, 0x7, 0x10, 0x0, 0x0, 0x6e8658, 0x1b, ...)
/usr/src/go/src/cmd/link/internal/ld/main.go:247 +0xdf6
main.main()
/usr/src/go/src/cmd/link/main.go:68 +0x258

@kiap kiap changed the title cmd/link: ld linker problem with shared libraries cmd/link/internal/ld: ld linker problem with shared libraries Feb 1, 2021
@kiap kiap changed the title cmd/link/internal/ld: ld linker problem with shared libraries cmd/link/internal/ld: linker problem with shared libraries Feb 1, 2021
@thanm
Copy link
Contributor

@thanm thanm commented Feb 1, 2021

I'll take a look at this.

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 1, 2021

Change https://golang.org/cl/288496 mentions this issue: cmd/link: don't decode type symbol in deadcode when linkShared

Loading

@thanm
Copy link
Contributor

@thanm thanm commented Feb 1, 2021

Whoops, looks like Cherry is already working on it.

Loading

@gopherbot gopherbot closed this in 98f8454 Feb 2, 2021
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
4 participants
@gopherbot @thanm @kiap and others