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

pkg/profile: CPU profiler crashes CGO application #31758

Closed
vitalyisaev2 opened this issue Apr 30, 2019 · 3 comments
Closed

pkg/profile: CPU profiler crashes CGO application #31758

vitalyisaev2 opened this issue Apr 30, 2019 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@vitalyisaev2
Copy link

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

$ go version
go version go1.12.4 linux/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
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/isaev/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/isaev/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/isaev/go/src/github.com/vitalyisaev2/pprof_cgo_issue/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-build766056182=/tmp/go-build -gno-record-gcc-switches"

Deps
* OS: Fedora 29
* GCC: 8.3.1
* OpenSSL: 1.1.1b

What did you do?

I have a little application that uses OpenSSL via CGO. It works good in default mode, but crashes with SIGSEGV when I enable CPU profiler (from https://github.com/pkg/profile).

$ ./pprof_cgo_issue -profiler
2019/04/30 12:14:40 profile: cpu profiling enabled, cpu.pprof
Segmentation fault (core dumped)

$ gdb ./pprof_cgo_issue /tmp/core.d685d2a145b4.pprof_cgo_issue.1556626480.20
(gdb) bt
#0  0x00007fb47640c246 in ?? () from /lib64/libgcc_s.so.1
#1  0x00007fb47640cefd in _Unwind_Backtrace () from /lib64/libgcc_s.so.1
#2  0x00000000007322bc in cgoTraceback (parg=0xc0002dd970, parg@entry=<error reading variable: value has been optimized out>) at traceback.c:82
#3  0x00000000007364e6 in x_cgo_callers (sig=27, info=0xc0002ddaf0, context=0xc0002dd9c0, cgoTraceback=<optimized out>, cgoCallers=<optimized out>, sigtramp=0x46a2f0 <runtime.sigtramp>) at gcc_traceback.c:22
#4  <signal handler called>
#5  0x00007fb476614232 in ?? () from /lib64/libcrypto.so.1.1

In order to reproduce, please follow the README from this repo with minimal working example: https://github.com/vitalyisaev2/pprof_cgo_issue

What did you expect to see?

Successful termination of application with cpu.pprof file as a result in the working dir.

What did you see instead?

Segmentation fault.

@lebovski
Copy link

The same problem:

go version
go version go1.12 linux/amd64
* OS: Fedora 29
* GCC: 8.3.1
* OpenSSL: 1.1.1b

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 30, 2019
@ianlancetaylor ianlancetaylor added this to the Go1.13 milestone Apr 30, 2019
@ianlancetaylor
Copy link
Contributor

Thanks for the reproduction case. I can reproduce this on my system.

As far as I can tell the problem is that libcrypto.so.1.1 does not have correct backtrace information. Your program is importing github.com/ianlancetaylor/cgosymbolizer, which tries to do a backtrace through C code to get a better backtrace. It is that backtrace that crashes. If I comment out that import, the program succeeds.

I don't see anything that the Go project can do to fix this problem. The problem seems to lie entirely outside of the Go project, either in libcrypto.so.1.1 (as I suspect) or in the cgosymbolizer code (which I wrote but don't seriously support) or in the backtrace code (which is part of the GCC project). So I'm going to close this issue because there isn't anything we can do. Please comment if you disagree.

@vitalyisaev2
Copy link
Author

@ianlancetaylor thank you!

@golang golang locked and limited conversation to collaborators Apr 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants