Skip to content

cmd/link: slice bounds out of range #62098

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

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. FrozenDueToAge 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
Member

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
Contributor

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
Contributor

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
Contributor

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 <[email protected]>
Run-TryBot: Cherry Mui <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
(cherry picked from commit b65e34f)
Reviewed-on: https://go-review.googlesource.com/c/go/+/520857
@golang golang locked and limited conversation to collaborators Aug 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge 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