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: slice bounds out of range #62098

Closed
swtch1 opened this issue Aug 17, 2023 · 11 comments
Closed

cmd/link: slice bounds out of range #62098

swtch1 opened this issue Aug 17, 2023 · 11 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@swtch1
Copy link

swtch1 commented Aug 17, 2023

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

$ go version
go version go1.21.0 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
$ go env
GO111MODULE='auto'
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users//Library/Caches/go-build'
GOENV='/Users//Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users//go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users//go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/Cellar/go/1.21.0/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/Cellar/go/1.21.0/libexec/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users//code///go.mod'
GOWORK='/Users//code//go.work'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/hy/sxcwypzn0h9bg08bpjz789y00000gn/T/go-build2316893392=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

cd project
go run .

The same thing happens with go build ..

What did you expect to see?

My program running the same way it did on 1.20

What did you see instead?

# gitlab.com/<org>/<repo>/<project>
panic: runtime error: slice bounds out of range [74:69]

goroutine 1 [running]:
cmd/link/internal/ld.typeSymbolMangle({0x49ac657b, 0x4f})
        /usr/local/Cellar/go/1.21.0/libexec/src/cmd/link/internal/ld/lib.go:1012 +0x379
cmd/link/internal/ld.(*Link).mangleTypeSym(0xc000110000)
        /usr/local/Cellar/go/1.21.0/libexec/src/cmd/link/internal/ld/lib.go:959 +0xb9
cmd/link/internal/ld.Main(_, {0x20, 0x20, 0x1, 0x7, 0x10, 0x0, {0xc0000ae2e9, 0x1, 0x1}, ...})
        /usr/local/Cellar/go/1.21.0/libexec/src/cmd/link/internal/ld/main.go:308 +0x124b
main.main()
        /usr/local/Cellar/go/1.21.0/libexec/src/cmd/link/main.go:72 +0xdfb

I have confirmed that a simple hello world program does work so there must be something specific to the code or project environment.

I searched for the same issue and found #61060 but this seemed too different to lump in with that, and it's happening on the latest release.

@dmitshur dmitshur changed the title link: slice bounds out of range cmd/link: slice bounds out of range Aug 17, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Aug 17, 2023
@dmitshur dmitshur added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 17, 2023
@dmitshur dmitshur added this to the Backlog milestone Aug 17, 2023
@dmitshur
Copy link
Contributor

Are you able to provide more information on how this panic can be reproduced? cd project; go run . doesn't have enough context to investigate this issue.

@swtch1
Copy link
Author

swtch1 commented Aug 17, 2023

I agree, but it's a large project with too much code to share. Here are some extra details. Let me know what other information I can provide.

This is the build commands (not all of them) from right before the panic.

go build -x .
...
EOF
mkdir -p $WORK/b001/exe/
cd .
/usr/local/Cellar/go/1.21.0/libexec/pkg/tool/darwin_amd64/link -o $WORK/b001/exe/a.out -importcfg $WORK/b001/importcfg.link -X=runtime.godebugDefault=panicnil=1 -buildmode=exe -buildid=SD7wguQIlnr-RgQWclwr/Ppl_IAU-mt3aUHyZlWNE/lWXWOjpK5ruyWZBONLpe/SD7wguQIlnr-RgQWclwr -extld=cc /Users/<me>/Library/Caches/go-build/92/920429ab911f6e21f24f38184d90a4003b59918063e47f930367455dd8730926-d
# gitlab.com/<org>/<repo>/<project>
panic: runtime error: slice bounds out of range [74:69]

goroutine 1 [running]:
cmd/link/internal/ld.typeSymbolMangle({0x49b4589c, 0x4f})
        /usr/local/Cellar/go/1.21.0/libexec/src/cmd/link/internal/ld/lib.go:1012 +0x379
cmd/link/internal/ld.(*Link).mangleTypeSym(0xc000158000)
        /usr/local/Cellar/go/1.21.0/libexec/src/cmd/link/internal/ld/lib.go:959 +0xb9
cmd/link/internal/ld.Main(_, {0x20, 0x20, 0x1, 0x7, 0x10, 0x0, {0xc0000124a9, 0x1, 0x1}, ...})
        /usr/local/Cellar/go/1.21.0/libexec/src/cmd/link/internal/ld/main.go:308 +0x124b
main.main()
        /usr/local/Cellar/go/1.21.0/libexec/src/cmd/link/main.go:72 +0xdfb

This is the call graph dumped (not the whole thing) from right before the panic.

go build -ldflags="-c" .
...
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).TryAcquire.func1 calls runtime.panicIndex
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).TryAcquire.func1 calls runtime.panicIndex
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).TryAcquire.func1 calls runtime.gopanic
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).TryAcquire.func1 calls runtime.deferreturn
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).TryAcquire.func1 calls runtime.morestack
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).TryAcquire.func1.2 calls golang.org/x/sync/semaphore.(*Weighted).Release
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).TryAcquire.func1.2 calls runtime.morestack
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).TryAcquire.func1.1 calls sync.(*Mutex).Unlock
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).TryAcquire.func1.1 calls runtime.morestack
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).TryAcquire.func2 calls sync.(*Mutex).Unlock
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).TryAcquire.func2 calls runtime.morestack
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls runtime.newobject
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls runtime.gcWriteBarrier1
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls runtime.gcWriteBarrier1
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls sync.(*Mutex).lockSlow
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls sync.(*Mutex).lockSlow
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls runtime.gcWriteBarrier2
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls sync.(*Mutex).unlockSlow
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls runtime.selectgo
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).releaseAcquiredResource
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls runtime.gcWriteBarrier2
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls runtime.gcWriteBarrier1
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls sync.(*WaitGroup).Add
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls golang.org/x/sync/semaphore.(*Weighted).Release
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls sync.(*Mutex).unlockSlow
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls runtime.selectgo
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls runtime.panicSliceAcap
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls runtime.panicIndex
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls runtime.panicIndex
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls runtime.gopanic
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).initResourceValue.func1 calls runtime.morestack
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).acquire.func1 calls sync.(*Mutex).Unlock
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).acquire.func1 calls runtime.morestack
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).Stat.func1 calls sync.(*Mutex).Unlock
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).Stat.func1 calls runtime.morestack
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).Close.func3 calls github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).destructResourceValue
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).Close.func3 calls runtime.morestack
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).Close.func2 calls sync.(*Mutex).Unlock
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).Close.func2 calls runtime.morestack
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).Close.func1 calls sync.(*WaitGroup).Wait
github.com/jackc/puddle/v2.(*Pool[go.shape.*uint8]).Close.func1 calls runtime.morestack
panic: runtime error: slice bounds out of range [74:69]

goroutine 1 [running]:
cmd/link/internal/ld.typeSymbolMangle({0x49b0589c, 0x4f})
        /usr/local/Cellar/go/1.21.0/libexec/src/cmd/link/internal/ld/lib.go:1012 +0x379
cmd/link/internal/ld.(*Link).mangleTypeSym(0xc000158000)
        /usr/local/Cellar/go/1.21.0/libexec/src/cmd/link/internal/ld/lib.go:959 +0xb9
cmd/link/internal/ld.Main(_, {0x20, 0x20, 0x1, 0x7, 0x10, 0x0, {0xc0000124a9, 0x1, 0x1}, ...})
        /usr/local/Cellar/go/1.21.0/libexec/src/cmd/link/internal/ld/main.go:308 +0x124b
main.main()
        /usr/local/Cellar/go/1.21.0/libexec/src/cmd/link/main.go:72 +0xdfb

go.mod:

module <repo>/<project>

go 1.20

require (
	github.com/aws/aws-lambda-go v1.26.0
	github.com/dustin/go-humanize v1.0.0
	github.com/go-ozzo/ozzo-validation/v4 v4.3.0
	github.com/google/uuid v1.3.0
	github.com/gorilla/websocket v1.5.0
	github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
	github.com/improbable-eng/grpc-web v0.13.0
	github.com/jackc/pgx/v5 v5.4.2
	github.com/jackc/tern/v2 v2.1.1
	github.com/mitchellh/mapstructure v1.5.0
	github.com/patrickmn/go-cache v2.1.0+incompatible
	github.com/rs/cors v1.8.0
	github.com/spf13/viper v1.15.0
	github.com/stretchr/testify v1.8.4
	github.com/tidwall/gjson v1.14.4
	gitlab.com/speedscale/speedscale/analyzer v0.0.0-00010101000000-000000000000
	gitlab.com/speedscale/speedscale/lib v0.0.0-00010101000000-000000000000
	go.einride.tech/aip v0.61.0
	go.uber.org/zap v1.24.0
	golang.org/x/net v0.10.0
	golang.org/x/sync v0.1.0
	google.golang.org/grpc v1.56.2
	google.golang.org/protobuf v1.31.0
	k8s.io/api v0.26.3
	k8s.io/apimachinery v0.26.3
	k8s.io/client-go v0.25.0
	sigs.k8s.io/controller-runtime v0.13.1
)

require (
	cloud.google.com/go/compute v1.20.1 // indirect
	cloud.google.com/go/compute/metadata v0.2.3 // indirect
	github.com/Azure/go-autorest v14.2.0+incompatible // indirect
	github.com/Azure/go-autorest/autorest v0.11.27 // indirect
	github.com/Azure/go-autorest/autorest/adal v0.9.20 // indirect
	github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
	github.com/Azure/go-autorest/logger v0.2.1 // indirect
	github.com/Azure/go-autorest/tracing v0.6.0 // indirect
	github.com/DataDog/sketches-go v1.4.1 // indirect
	github.com/Jeffail/gabs/v2 v2.6.1 // indirect
	github.com/Masterminds/goutils v1.1.1 // indirect
	github.com/Masterminds/semver/v3 v3.2.0 // indirect
	github.com/Masterminds/sprig/v3 v3.2.3 // indirect
	github.com/Masterminds/squirrel v1.5.3 // indirect
	github.com/XiaoMi/pegasus-go-client v0.0.0-20210427083443-f3b6b08bc4c2 // indirect
	github.com/allegro/bigcache/v2 v2.2.5 // indirect
	github.com/antchfx/xmlquery v1.3.9 // indirect
	github.com/antchfx/xpath v1.2.0 // indirect
	github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de // indirect
	github.com/argoproj/argo-rollouts v1.4.1 // indirect
	github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef // indirect
	github.com/aws/aws-sdk-go-v2 v1.17.3 // indirect
	github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.10 // indirect
	github.com/aws/aws-sdk-go-v2/config v1.18.5 // indirect
	github.com/aws/aws-sdk-go-v2/credentials v1.13.5 // indirect
	github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.21 // indirect
	github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.42 // indirect
	github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.27 // indirect
	github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.21 // indirect
	github.com/aws/aws-sdk-go-v2/internal/ini v1.3.28 // indirect
	github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.17 // indirect
	github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.23.1 // indirect
	github.com/aws/aws-sdk-go-v2/service/firehose v1.14.22 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.21 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.21 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.20 // indirect
	github.com/aws/aws-sdk-go-v2/service/s3 v1.29.5 // indirect
	github.com/aws/aws-sdk-go-v2/service/sns v1.18.6 // indirect
	github.com/aws/aws-sdk-go-v2/service/sqs v1.19.15 // indirect
	github.com/aws/aws-sdk-go-v2/service/sso v1.11.27 // indirect
	github.com/aws/aws-sdk-go-v2/service/ssooidc v1.13.10 // indirect
	github.com/aws/aws-sdk-go-v2/service/sts v1.17.7 // indirect
	github.com/aws/smithy-go v1.13.5 // indirect
	github.com/beorn7/perks v1.0.1 // indirect
	github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d // indirect
	github.com/buger/jsonparser v1.1.1 // indirect
	github.com/cenkalti/backoff/v4 v4.2.1 // indirect
	github.com/cespare/xxhash/v2 v2.2.0 // indirect
	github.com/clbanning/mxj v1.8.4 // indirect
	github.com/clbanning/mxj/v2 v2.3.2 // indirect
	github.com/coreos/go-oidc v2.1.0+incompatible // indirect
	github.com/davecgh/go-spew v1.1.1 // indirect
	github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
	github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
	github.com/eko/gocache/v3 v3.1.1 // indirect
	github.com/emicklei/go-restful/v3 v3.8.0 // indirect
	github.com/evanphx/json-patch v5.6.0+incompatible // indirect
	github.com/evanphx/json-patch/v5 v5.6.0 // indirect
	github.com/fsnotify/fsnotify v1.6.0 // indirect
	github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 // indirect
	github.com/go-errors/errors v1.4.2 // indirect
	github.com/go-logr/logr v1.2.3 // indirect
	github.com/go-openapi/jsonpointer v0.19.5 // indirect
	github.com/go-openapi/jsonreference v0.20.0 // indirect
	github.com/go-openapi/swag v0.21.1 // indirect
	github.com/go-playground/locales v0.14.1 // indirect
	github.com/go-playground/universal-translator v0.18.1 // indirect
	github.com/go-playground/validator/v10 v10.12.0 // indirect
	github.com/go-redis/redis/v8 v8.11.5 // indirect
	github.com/go-stack/stack v1.8.0 // indirect
	github.com/gogo/protobuf v1.3.2 // indirect
	github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
	github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
	github.com/golang/protobuf v1.5.3 // indirect
	github.com/gomodule/redigo v1.8.5 // indirect
	github.com/google/gnostic v0.6.9 // indirect
	github.com/google/go-cmp v0.5.9 // indirect
	github.com/google/gofuzz v1.2.0 // indirect
	github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
	github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
	github.com/hashicorp/go-memdb v1.3.2 // indirect
	github.com/hashicorp/golang-lru v0.5.4 // indirect
	github.com/hashicorp/hcl v1.0.0 // indirect
	github.com/huandu/xstrings v1.4.0 // indirect
	github.com/imdario/mergo v0.3.13 // indirect
	github.com/jackc/chunkreader/v2 v2.0.1 // indirect
	github.com/jackc/pgio v1.0.0 // indirect
	github.com/jackc/pgpassfile v1.0.0 // indirect
	github.com/jackc/pgproto3/v2 v2.3.1 // indirect
	github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
	github.com/jackc/puddle/v2 v2.2.0 // indirect
	github.com/jaswdr/faker v1.4.2 // indirect
	github.com/jmespath/go-jmespath v0.4.0 // indirect
	github.com/josharian/intern v1.0.0 // indirect
	github.com/json-iterator/go v1.1.12 // indirect
	github.com/klauspost/compress v1.16.5 // indirect
	github.com/klauspost/pgzip v1.2.5 // indirect
	github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
	github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
	github.com/leodido/go-urn v1.2.2 // indirect
	github.com/magiconair/properties v1.8.7 // indirect
	github.com/mailru/easyjson v0.7.7 // indirect
	github.com/mattn/go-sqlite3 v1.14.14 // indirect
	github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
	github.com/mitchellh/copystructure v1.2.0 // indirect
	github.com/mitchellh/reflectwalk v1.0.2 // indirect
	github.com/moby/spdystream v0.2.0 // indirect
	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
	github.com/modern-go/reflect2 v1.0.2 // indirect
	github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
	github.com/montanaflynn/stats v0.6.6 // indirect
	github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
	github.com/pegasus-kv/thrift v0.13.0 // indirect
	github.com/pelletier/go-toml/v2 v2.0.6 // indirect
	github.com/pkg/errors v0.9.1 // indirect
	github.com/pmezard/go-difflib v1.0.0 // indirect
	github.com/pquerna/cachecontrol v0.1.0 // indirect
	github.com/prometheus/client_golang v1.14.0 // indirect
	github.com/prometheus/client_model v0.3.0 // indirect
	github.com/prometheus/common v0.39.0 // indirect
	github.com/prometheus/procfs v0.8.0 // indirect
	github.com/rbretecher/go-postman-collection v0.8.0 // indirect
	github.com/sergi/go-diff v1.1.0 // indirect
	github.com/sethvargo/go-password v0.2.0 // indirect
	github.com/shopspring/decimal v1.3.1 // indirect
	github.com/sirupsen/logrus v1.9.0 // indirect
	github.com/speedscale/amqp091-go v1.2.0-patched // indirect
	github.com/spf13/afero v1.9.3 // indirect
	github.com/spf13/cast v1.5.0 // indirect
	github.com/spf13/jwalterweatherman v1.1.0 // indirect
	github.com/spf13/pflag v1.0.5 // indirect
	github.com/subosito/gotenv v1.4.2 // indirect
	github.com/tidwall/match v1.1.1 // indirect
	github.com/tidwall/pretty v1.2.0 // indirect
	github.com/tidwall/sjson v1.2.5 // indirect
	github.com/xlab/treeprint v1.1.0 // indirect
	github.com/yudai/gojsondiff v1.0.0 // indirect
	github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
	github.com/zach-klippenstein/goregen v0.0.0-20160303162051-795b5e3961ea // indirect
	go.mongodb.org/mongo-driver v1.4.6 // indirect
	go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
	go.uber.org/atomic v1.9.0 // indirect
	go.uber.org/multierr v1.8.0 // indirect
	golang.org/x/crypto v0.10.0 // indirect
	golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
	golang.org/x/oauth2 v0.8.0 // indirect
	golang.org/x/sys v0.9.0 // indirect
	golang.org/x/term v0.9.0 // indirect
	golang.org/x/text v0.10.0 // indirect
	golang.org/x/time v0.1.0 // indirect
	google.golang.org/appengine v1.6.7 // indirect
	google.golang.org/genproto/googleapis/rpc v0.0.0-20230725213213-b022f6e96895 // indirect
	gopkg.in/inf.v0 v0.9.1 // indirect
	gopkg.in/ini.v1 v1.67.0 // indirect
	gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
	gopkg.in/square/go-jose.v2 v2.5.1 // indirect
	gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 // indirect
	gopkg.in/yaml.v2 v2.4.0 // indirect
	gopkg.in/yaml.v3 v3.0.1 // indirect
	istio.io/api v0.0.0-20210915141110-a591ff3be6be // indirect
	istio.io/client-go v1.11.3 // indirect
	istio.io/gogo-genproto v0.0.0-20210113155706-4daf5697332f // indirect
	k8s.io/apiextensions-apiserver v0.25.0 // indirect
	k8s.io/cli-runtime v0.24.3 // indirect
	k8s.io/klog/v2 v2.80.1 // indirect
	k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
	k8s.io/kubectl v0.24.3 // indirect
	k8s.io/metrics v0.24.3 // indirect
	k8s.io/utils v0.0.0-20230313181309-38a27ef9d749 // indirect
	sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
	sigs.k8s.io/kustomize/api v0.12.1 // indirect
	sigs.k8s.io/kustomize/kyaml v0.13.9 // indirect
	sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
	sigs.k8s.io/yaml v1.3.0 // indirect
)

replace gitlab.com/<repo>/<project>/lib => ../lib

@cherrymui
Copy link
Member

That code is

        i := strings.IndexByte(name, '[')
        j := strings.LastIndexByte(name, ']')
        if j == -1 {
                j = len(name)
        }
        hash := notsha256.Sum256([]byte(name[i+1 : j]))

To have such a slice out of bounds error, the symbol name would be something like ...]...[... with unmatched brackets. I don't see why a symbol would have such a name. Maybe a non-Go symbol?

The linker code could be more defensive on that. It would be good to see an example of such symbol, though.

@swtch1
Copy link
Author

swtch1 commented Aug 17, 2023

I've found something. The program builds if I comment this code

// guard against invalid S3 characters
if strings.ContainsAny(id, "&$@;/:+,?\\{^}%`]\">[~<#|") {
	return fmt.Errorf("invalid")
}

Though I am unable to reproduce the error in a sample program.

@cherrymui
Copy link
Member

cherrymui commented Aug 18, 2023

Thanks. A simple reproducer is

package main

import (
	"fmt"
	"plugin"
	"strings"
)

func F(id string) error {
	if strings.ContainsAny(id, "&$@;/:+,?\\{^}%`]\">[~<#|") {
		return fmt.Errorf("invalid")
	}
	return nil
}

var X string

func main() {
	plugin.Open("XXX")
	F(X)
}

We need to use plugin (or build as a plugin) to trigger the symbol name mangling.

The offensive symbol is go:string."&$@;/:+,?\\{^}%``]\">[~<#|" for the string literal. There is probably no need to mangle that symbol name as string symbols will not be in the final executable's symbol table.

@cherrymui cherrymui removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Aug 18, 2023
@cherrymui cherrymui modified the milestones: Backlog, Go1.22 Aug 18, 2023
@cherrymui cherrymui self-assigned this Aug 18, 2023
@jimmson
Copy link

jimmson commented Aug 18, 2023

Might be related, we are seeing a similar issue: #62131

@cherrymui
Copy link
Member

This error is very specific to the linker. It is unrelated to other index out of bounds errors outside of the linker, including #61060 and #62131. Thanks.

@gopherbot
Copy link

Change https://go.dev/cl/520856 mentions this issue: cmd/link: don't mangle string symbol names

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 18, 2023
@cherrymui
Copy link
Member

@gopherbot please backport this to Go 1.21. It is a regression in 1.21 causing valid programs fail to build. Thanks.

@gopherbot
Copy link

Backport issue(s) opened: #62140 (for 1.21).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@gopherbot
Copy link

Change https://go.dev/cl/520857 mentions this issue: [release-branch.go1.21] cmd/link: don't mangle string symbol names

gopherbot pushed a commit that referenced this issue Aug 23, 2023
String symbol names could contain weird characters as we put the
string literal into the symbol name. So it may appear to need
mangling. However, as string symbols are grouped into a single
"go:string.*" symbol, the individual symbol names actually don't
matter. So don't mangle them.

Also make the mangling code more defensive in case of weird
symbol names.

Updates #62098.
Fixes #62140.

Change-Id: I533012567a9fffab69debda934f426421c7abb04
Reviewed-on: https://go-review.googlesource.com/c/go/+/520856
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
(cherry picked from commit b65e34f)
Reviewed-on: https://go-review.googlesource.com/c/go/+/520857
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants