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

go build use -asan it panic. #69225

Closed
jokemanfire opened this issue Sep 3, 2024 · 5 comments
Closed

go build use -asan it panic. #69225

jokemanfire opened this issue Sep 3, 2024 · 5 comments

Comments

@jokemanfire
Copy link

jokemanfire commented Sep 3, 2024

Go version

go version go1.21.0 linux/amd64 (master branch also influence)

Output of go env in your module/workspace:

GO111MODULE='auto'
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/{username}/.cache/go-build'
GOENV='/home/{username}/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/{username}/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/{username}/go'
GOPRIVATE=''
GOPROXY='http://goproxy.cn'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/[email protected]/codetest/gotest/test/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build139988242=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I test like this

package main

import "unsafe"

type Person struct {
	Name string
	Age  int
}

func main() {
	peopleSlice := []Person{
		{Name: "Charlie", Age: 35},
		{Name: "Diana", Age: 40},
	}
	addr := unsafe.Pointer(&peopleSlice)
	ptr := uintptr(addr)
	b := (*[0x7FFFFFF]Person)(unsafe.Pointer(ptr))[:]
	println(b)
}

go build -asan

run the binary file , I meet this panic

fatal error: checkptr: pointer arithmetic result points to invalid allocation


goroutine 1 [running]:
runtime.throw({0x470e47?, 0x18?})
        /usr/lib/golang/src/runtime/panic.go:1047 +0x5d fp=0x10c00004e708 sp=0x10c00004e6d8 pc=0x42f09d
runtime.checkptrArithmetic(0x406cf9?, {0x0, 0x0, 0x0?})
        /usr/lib/golang/src/runtime/checkptr.go:69 +0xaa fp=0x10c00004e738 sp=0x10c00004e708 pc=0x40794a
main.main()
        /root/code/test.go:75 +0x153 fp=0x10c00004e780 sp=0x10c00004e738 pc=0x45b1f3
runtime.main()
        /usr/lib/golang/src/runtime/proc.go:250 +0x207 fp=0x10c00004e7e0 sp=0x10c00004e780 pc=0x4319c7
runtime.goexit()
        /usr/lib/golang/src/runtime/asm_amd64.s:1598 +0x1 fp=0x10c00004e7e8 sp=0x10c00004e7e0 pc=0x458041

goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        /usr/lib/golang/src/runtime/proc.go:381 +0xd6 fp=0x10c00004efb0 sp=0x10c00004ef90 pc=0x431df6
runtime.goparkunlock(...)
        /usr/lib/golang/src/runtime/proc.go:387
runtime.forcegchelper()
        /usr/lib/golang/src/runtime/proc.go:305 +0xb0 fp=0x10c00004efe0 sp=0x10c00004efb0 pc=0x431c30
runtime.goexit()
        /usr/lib/golang/src/runtime/asm_amd64.s:1598 +0x1 fp=0x10c00004efe8 sp=0x10c00004efe0 pc=0x458041
created by runtime.init.6
        /usr/lib/golang/src/runtime/proc.go:293 +0x25

goroutine 3 [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        /usr/lib/golang/src/runtime/proc.go:381 +0xd6 fp=0x10c00004f780 sp=0x10c00004f760 pc=0x431df6
runtime.goparkunlock(...)
        /usr/lib/golang/src/runtime/proc.go:387
runtime.bgsweep(0x0?)
        /usr/lib/golang/src/runtime/mgcsweep.go:278 +0x8e fp=0x10c00004f7c8 sp=0x10c00004f780 pc=0x41f42e
runtime.gcenable.func1()
        /usr/lib/golang/src/runtime/mgc.go:178 +0x26 fp=0x10c00004f7e0 sp=0x10c00004f7c8 pc=0x4148e6
runtime.goexit()
        /usr/lib/golang/src/runtime/asm_amd64.s:1598 +0x1 fp=0x10c00004f7e8 sp=0x10c00004f7e0 pc=0x458041
created by runtime.gcenable
        /usr/lib/golang/src/runtime/mgc.go:178 +0x6b

goroutine 4 [GC scavenge wait]:
runtime.gopark(0x10c000074000?, 0x481120?, 0x1?, 0x0?, 0x0?)
        /usr/lib/golang/src/runtime/proc.go:381 +0xd6 fp=0x10c00004ff70 sp=0x10c00004ff50 pc=0x431df6
runtime.goparkunlock(...)
        /usr/lib/golang/src/runtime/proc.go:387
runtime.(*scavengerState).park(0x4cbde0)
        /usr/lib/golang/src/runtime/mgcscavenge.go:400 +0x53 fp=0x10c00004ffa0 sp=0x10c00004ff70 pc=0x41d353
runtime.bgscavenge(0x0?)
        /usr/lib/golang/src/runtime/mgcscavenge.go:628 +0x45 fp=0x10c00004ffc8 sp=0x10c00004ffa0 pc=0x41d925
runtime.gcenable.func2()
        /usr/lib/golang/src/runtime/mgc.go:179 +0x26 fp=0x10c00004ffe0 sp=0x10c00004ffc8 pc=0x414886
runtime.goexit()
        /usr/lib/golang/src/runtime/asm_amd64.s:1598 +0x1 fp=0x10c00004ffe8 sp=0x10c00004ffe0 pc=0x458041
created by runtime.gcenable
        /usr/lib/golang/src/runtime/mgc.go:179 +0xaa

What did you see happen?

It panic.

What did you expect to see?

I want to know why cause this promblem. and how to resolve.

@seankhliao
Copy link
Member

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Sep 3, 2024
@jokemanfire
Copy link
Author

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

sorry mantainer, but i think it is a bug, the pointer arithmetic i think it is valid. But panic

@ianlancetaylor
Copy link
Member

@jokemanfire Your code does not follow the rules for handling pointer values described at https://pkg.go.dev/unsafe#Pointer.

One of the points of -asan mode is to catch errors like this.

@jokemanfire
Copy link
Author

@jokemanfire Your code does not follow the rules for handling pointer values described at https://pkg.go.dev/unsafe#Pointer.

One of the points of -asan mode is to catch errors like this.

Thanks to you,It is indeed quite different from C++.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants