aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/crash_cgo_test.go
AgeCommit message (Collapse)Author
2021-07-29runtime: avoid possible preemption when returning from Go to CIan Lance Taylor
When returning from Go to C, it was possible for the goroutine to be preempted after calling unlockOSThread. This could happen when there a context function installed by SetCgoTraceback set a non-zero context, leading to a defer call in cgocallbackg1. The defer function wrapper, introduced in 1.17 as part of the regabi support, was not nosplit, and hence was a potential preemption point. If it did get preempted, the G would move to a new M. It would then attempt to return to C code on a different stack, typically leading to a SIGSEGV. Fix this in a simple way by postponing the unlockOSThread until after the other defer. Also check for the failure condition and fail early, rather than waiting for a SIGSEGV. Without the fix to cgocall.go, the test case fails about 50% of the time on my laptop. Fixes #47441 Change-Id: Ib8ca13215bd36cddc2a49e86698824a29c6a68ba Reviewed-on: https://go-review.googlesource.com/c/go/+/338197 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2021-02-20all: go fmt std cmd (but revert vendor)Russ Cox
Make all our package sources use Go 1.17 gofmt format (adding //go:build lines). Part of //go:build change (#41184). See https://golang.org/design/draft-gobuild Change-Id: Ia0534360e4957e58cd9a18429c39d0e32a6addb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/294430 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-11-24runtime: use inlined function name for traceback elisionAustin Clements
Currently, gentraceback decides which frames to print or elide when unwinding inlined frames using only the name of the outermost function. If the outermost function should be elided, then inlined functions will also be elided, even if they shouldn't be. This happens in practice in at least one situation. As of CL 258938, exported Go functions (and functions they call) can now be inlined into the generated _cgoexp_HASH_FN function. The runtime elides _cgoexp_HASH_FN from tracebacks because it doesn't contain a ".". Because of this bug, it also elides anything that was inlined into it. This CL fixes this by synthesizing a funcInfo for the inlined functions to pass to showframe. Fixes #42754. Change-Id: Ie6c663a4a1ac7f0d4beb1aa60bc26fc8cddd0f9d Reviewed-on: https://go-review.googlesource.com/c/go/+/272131 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-10-28runtime: move TestNeedmDeadlock to crash_cgo_test.goIan Lance Taylor
It requires cgo. Also, skip the test on windows and plan9. For #42207 Change-Id: I8522773f93bc3f9826506a41a08b86a083262e31 Reviewed-on: https://go-review.googlesource.com/c/go/+/265778 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-10-20runtime: use GOTRACEBACK=system for TestCgoExecSignalMaskIan Lance Taylor
Try to get a bit more information to understand #42093. For #42093 Change-Id: I818feb08d7561151d52eba3e88c418b55b9f9c1e Reviewed-on: https://go-review.googlesource.com/c/go/+/264018 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-05-11internal/poll, os: loop on EINTRIan Lance Taylor
Historically we've assumed that we can install all signal handlers with the SA_RESTART flag set, and let the system restart slow functions if a signal is received. Therefore, we don't have to worry about EINTR. This is only partially true, and we've added EINTR checks already for connect, and open/read on Darwin, and sendfile on Solaris. Other cases have turned up in #36644, #38033, and #38836. Also, #20400 points out that when Go code is included in a C program, the C program may install its own signal handlers without SA_RESTART. In that case, Go code will see EINTR no matter what it does. So, go ahead and check for EINTR. We don't check in the syscall package; people using syscalls directly may want to check for EINTR themselves. But we do check for EINTR in the higher level APIs in os and net, and retry the system call if we see it. This change looks safe, but of course we may be missing some cases where we need to check for EINTR. As such cases turn up, we can add tests to runtime/testdata/testprogcgo/eintr.go, and fix the code. If there are any such cases, their handling after this change will be no worse than it is today. For #22838 Fixes #20400 Fixes #36644 Fixes #38033 Fixes #38836 Change-Id: I7e46ca8cafed0429c7a2386cc9edc9d9d47a6896 Reviewed-on: https://go-review.googlesource.com/c/go/+/232862 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-04-22runtime: crash on SI_USER SigPanic signalIan Lance Taylor
Clean up the code a little bit to make it clearer: Don't check throwsplit for a SI_USER signal. If throwsplit is set for a SigPanic signal, always throw; discard any other flags. Fixes #36420 Change-Id: Ic9dcd1108603d241f71c040504dfdc6e528f9767 Reviewed-on: https://go-review.googlesource.com/c/go/+/228900 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2020-03-01runtime: deflake CGO traceback testsMark Pulford
The CGO traceback function is called whenever CGO code is executing and a signal is received. This occurs much more frequently now SIGURG is used for preemption. Disable signal preemption to significantly increase the likelihood that a signal results in a profile sample during the test. Updates #37201 Change-Id: Icb1a33ab0754d1a74882a4ee265b4026abe30bdc Reviewed-on: https://go-review.googlesource.com/c/go/+/219417 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-04-16runtime: print more information when testCgoPprof failsJosh Bleecher Snyder
Change-Id: I820dae0303959096f0c434b7e69ecb3bf070df09 Reviewed-on: https://go-review.googlesource.com/c/go/+/172197 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-26runtime: improve sigtramp on aix/ppc64 to handle SIGPROFClément Chigot
R14, R15 must be saved in sigtramp because they might be modified by Go code when a SIGPROF occurs. Fixes #28555 Change-Id: I573541f108d7d6aac8e60d33c649e5db943f3ef5 Reviewed-on: https://go-review.googlesource.com/c/go/+/169117 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-03-19runtime: enable external linker tests for aix/ppc64Clément Chigot
Change-Id: Icc42843adb15c2aba1cfea854fad049c6704344b Reviewed-on: https://go-review.googlesource.com/c/go/+/164014 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-03-19runtime: disable pprof test with cgo on aix/ppc64Clément Chigot
This commit disables new cgo pprof tests and adds an handler in sigtramp to refuse SIGPROF signal. Updates #28555 Change-Id: I152a871f8636e93328d411329104c6f023bd1691 Reviewed-on: https://go-review.googlesource.com/c/go/+/164013 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-12-10runtime: fix CGO traceback frame countMark Pulford
Without this, each additional C frame found via SetCgoTraceback will cause a frame to be dropped from the bottom of the traceback stack. Fixes #29034 Change-Id: I90aa6b2a1dced90c69b64c5dd565fe64a25724a3 Reviewed-on: https://go-review.googlesource.com/c/151917 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-07-04runtime: support capturing C backtrace from signal handler on darwin/amd64Nikhil Benesch
The implementation is mostly copied from the commit that added linux/amd64 support for this feature (https://golang.org/cl/17761). Change-Id: I3f482167620a7a3daf50a48087f8849a30d713bd Reviewed-on: https://go-review.googlesource.com/102438 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-07-02runtime: query thread stack size from OS on WindowsAustin Clements
Currently, on Windows, the thread stack size is set or assumed in many different places. In non-cgo binaries, both the Go linker and the runtime have a copy of the stack size, the Go linker sets the size of the main thread stack, and the runtime sets the size of other thread stacks. In cgo binaries, the external linker sets the main thread stack size, the runtime assumes the size of the main thread stack will be the same as used by the Go linker, and the cgo entry code assumes the same. Furthermore, users can change the main thread stack size using editbin, so the runtime doesn't even really know what size it is, and user C code can create threads with unknown thread stack sizes, which we also assume have the same default stack size. This is all a mess. Fix the corner cases of this and the duplication of knowledge between the linker and the runtime by querying the OS for the stack bounds during thread setup. Furthermore, we unify all of this into just runtime.minit for both cgo and non-cgo binaries and for the main thread, other runtime-created threads, and C-created threads. Updates #20975. Change-Id: I45dbee2b5ea2ae721a85a27680737ff046f9d464 Reviewed-on: https://go-review.googlesource.com/120336 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-05-29all: remove support for macOS 10.9 and earlierBrad Fitzpatrick
Updates #23122 Change-Id: I4c12ec5cb1a1f15d7858f3deab636710c0660e26 Reviewed-on: https://go-review.googlesource.com/115038 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-03-27cmd/go, cmd/link, runtime: enable PIE build mode, cgo race tests on FreeBSDTim Wright
Fixes #24546 Change-Id: I99ebd5bc18e5c5e42eee4689644a7a8b02405f31 Reviewed-on: https://go-review.googlesource.com/102616 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-01-31runtime: fail silently if we unwind over sigpanic into C codeAustin Clements
If we're running C code and the code panics, the runtime will inject a call to sigpanic into the C code just like it would into Go code. However, the return PC from this sigpanic will be in C code. We used to silently abort the traceback if we didn't recognize a return PC, so this went by quietly. Now we're much louder because in general this is a bad thing. However, in this one particular case, it's fine, so if we're in cgo and are looking at the return PC of sigpanic, silence the debug output. Fixes #23576. Change-Id: I03d0c14d4e4d25b29b1f5804f5e9ccc4f742f876 Reviewed-on: https://go-review.googlesource.com/90896 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-12-13all: fix t.Skipf formatsRuss Cox
Found by upcoming cmd/vet change. Change-Id: I7a8264a304b2a4f26f3bd418c1b28cc849889c9b Reviewed-on: https://go-review.googlesource.com/83835 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-12-01runtime: restore the Go-allocated signal stack in unminitAustin Clements
Currently, when we minit on a thread that already has an alternate signal stack (e.g., because the M was an extram being used for a cgo callback, or to handle a signal on a C thread, or because the platform's libc always allocates a signal stack like on Android), we simply drop the Go-allocated gsignal stack on the floor. This is a problem for Ms on the extram list because those Ms may later be reused for a different thread that may not have its own alternate signal stack. On tip, this manifests as a crash in sigaltstack because we clear the gsignal stack bounds in unminit and later try to use those cleared bounds when we re-minit that M. On 1.9 and earlier, we didn't clear the bounds, so this manifests as running more than one signal handler on the same signal stack, which could lead to arbitrary memory corruption. This CL fixes this problem by saving the Go-allocated gsignal stack in a new field in the m struct when overwriting it with a system-provided signal stack, and then restoring the original gsignal stack in unminit. This CL is designed to be easy to back-port to 1.9. It won't quite cherry-pick cleanly, but it should be sufficient to simply ignore the change in mexit (which didn't exist in 1.9). Now that we always have a place to stash the original signal stack in the m struct, there are some simplifications we can make to the signal stack handling. We'll do those in a later CL. Fixes #22930. Change-Id: I55c5a6dd9d97532f131146afdef0b216e1433054 Reviewed-on: https://go-review.googlesource.com/81476 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-11-14runtime: make TestWindowsStackMemory build even with CGO_ENABLED=0 setAlex Brainman
Just copy some code to make TestWindowsStackMemory build when CGO_ENABLED is set to 0. Fixes #22680 Change-Id: I63f9b409a3a97b7718f5d37837ab706d8ed92e81 Reviewed-on: https://go-review.googlesource.com/77430 Reviewed-by: Chris Hines <chris.cs.guy@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-11-04runtime: skip flaky TestWindowsStackMemoryCgoAlex Brainman
Updates #22575 Change-Id: I1f848768934b7024d2ef01db13b9003e9ca608a0 Reviewed-on: https://go-review.googlesource.com/76030 Reviewed-by: Russ Cox <rsc@golang.org>
2017-11-03cmd/link: restore windows stack commit size back to 4KBAlex Brainman
CL 49331 increased windows stack commit size to 2MB by mistake. Revert that change. Fixes #22439 Change-Id: I919e549e87da326f4ba45890b4d32f6d7046186f Reviewed-on: https://go-review.googlesource.com/74490 TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2017-10-30runtime: use -buildmode=pie in testCgoPprofPIE instead of -extldflags=-pieLynn Boger
Errors occur in runtime test testCgoPprofPIE when the test is built by passing -pie to the external linker with code that was not built as PIC. This occurs on ppc64le because non-PIC is the default, and fails only on newer distros where the address range used for programs is high enough to cause relocation overflow. This test should be built with -buildmode=pie since that correctly generates PIC with -pie. Related issues are #21954 and #22126. Updates #22459 Change-Id: Ib641440bc9f94ad2b97efcda14a4b482647be8f7 Reviewed-on: https://go-review.googlesource.com/73970 Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-21runtime: support cgo traceback on PPC64LECherry Zhang
Code essentially mirrors AMD64 implementation. Change-Id: I39f7f099ce11fdc3772df039998cc11947bb22a2 Reviewed-on: https://go-review.googlesource.com/72270 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-11runtime: terminate locked OS thread if its goroutine exitsAustin Clements
runtime.LockOSThread is sometimes used when the caller intends to put the OS thread into an unusual state. In this case, we never want to return this thread to the runtime thread pool. However, currently exiting the goroutine implicitly unlocks its OS thread. Fix this by terminating the locked OS thread when its goroutine exits, rather than simply returning it to the pool. Fixes #20395. Change-Id: I3dcec63b200957709965f7240dc216fa84b62ad9 Reviewed-on: https://go-review.googlesource.com/46038 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2017-09-13cmd/compile: add TestIntendedInlining from runtimeDaniel Martí
Move it from the runtime package, as we will soon add more packages and functions for it to check. The test used the testEnv func, which cleaned certain environment variables from a command, so it was moved to internal/testenv under a more descriptive (and less ambiguous) name. Add a simple godoc to it too. For #21851. Change-Id: I6f39c1f23b45377718355fafe66ffd87047d8ab6 Reviewed-on: https://go-review.googlesource.com/63550 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ilya Tocar <ilya.tocar@intel.com>
2017-08-29runtime: forward crashing signals to late handlersElias Naur
CL 49590 made it possible for external signal handlers to catch signals from a crashing Go process. This CL extends that support to handlers registered after the Go runtime has initialized. Updates #20392 (and possibly fix it). Change-Id: I18eccd5e958a505f4d1782a7fc51c16bd3a4ff9c Reviewed-on: https://go-review.googlesource.com/57291 Run-TryBot: Elias Naur <elias.naur@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-08-10runtime: when dying from a signal use the previous signal handlerElias Naur
Before this CL, whenever the Go runtime wanted to kill its own process with a signal dieFromSignal would reset the signal handler to _SIG_DFL. Unfortunately, if any signal handler were installed before the Go runtime initialized, it wouldn't be invoked either. Instead, use whatever signal handler was installed before initialization. The motivating use case is Crashlytics on Android. Before this CL, Crashlytics would not consider a crash from a panic() since the corresponding SIGABRT never reached its signal handler. Updates #11382 Updates #20392 (perhaps even fixes it) Fixes #19389 Change-Id: I0c8633329433b45cbb3b16571bea227e38e8be2e Reviewed-on: https://go-review.googlesource.com/49590 Run-TryBot: Elias Naur <elias.naur@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-07-13runtime: don't call t.Parallel in TestCgoSignalDeadlockIan Lance Taylor
It seems that when too much other code is running on the system, the testprogcgo code can overrun its timeouts. Updates #18598. Not marking the issue as fixed until it doesn't recur for some time. Change-Id: Ieaf106b41986fdda76b1d027bb9d5e3fb805cc3b Reviewed-on: https://go-review.googlesource.com/48233 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-06-14runtime: don't run TestCgoNumGoroutine on Windows or Plan 9Ian Lance Taylor
The test requires pthreads. Fixes #20666. Change-Id: Icb2400250a80cdad6680cd1ef6c18ef7343d5e29 Reviewed-on: https://go-review.googlesource.com/45701 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-06-07runtime: mark extra M's G as dead when not in useAustin Clements
Currently the extra Ms created for cgo callbacks have a corresponding G that's kept in syscall state with only a call to goexit on its stack. This leads to confusing output from runtime.NumGoroutines and in tracebacks: goroutine 17 [syscall, locked to thread]: runtime.goexit() .../src/runtime/asm_amd64.s:2197 +0x1 Fix this by putting this goroutine into state _Gdead when it's not in use instead of _Gsyscall. To keep the goroutine counts correct, we also add one to sched.ngsys while the goroutine is in _Gdead. The effect of this is as if the goroutine simply doesn't exist when it's not in use. Fixes #16631. Fixes #16714. Change-Id: Ieae08a2febd4b3d00bef5c23fd6ca88fb2bb0087 Reviewed-on: https://go-review.googlesource.com/45030 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-04-25runtime: ignore TestCgoPprofPIE test failures on Alpine (take 2)Brad Fitzpatrick
s/arm64/amd64/ in previous typo CL 41628 Updates #19938 Updates #18243 Change-Id: I282244ee3c94535f229a87b6246382385ff64428 Reviewed-on: https://go-review.googlesource.com/41675 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-04-25runtime: ignore TestCgoPprofPIE test failures on AlpineBrad Fitzpatrick
Updates #19938 Updates #18243 Change-Id: Ib6e704c0a5d596bdfaa6493902d2528bec55bf16 Reviewed-on: https://go-review.googlesource.com/41628 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-02-24runtime: check that pprof accepts but doesn't need executableRuss Cox
The profiles are self-contained now. Check that they work by themselves in the tests that invoke pprof, but also keep checking that the old command lines work. Change-Id: I24c74b5456f0b50473883c3640625c6612f72309 Reviewed-on: https://go-review.googlesource.com/37166 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
2016-12-05runtime: don't skip TestCgoCallbackGC on FreeBSDIan Lance Taylor
Seems to be fixed according to discussion on issue 16396. Fixes #16396. Change-Id: Ibac7037a24280204e48cb4d3000af524f65afd36 Reviewed-on: https://go-review.googlesource.com/33903 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-11-04all: sprinkle t.Parallel on some slow testsBrad Fitzpatrick
I used the slowtests.go tool as described in https://golang.org/cl/32684 on packages that stood out. go test -short std drops from ~56 to ~52 seconds. This isn't a huge win, but it was mostly an exercise. Updates #17751 Change-Id: I9f3402e36a038d71e662d06ce2c1d52f6c4b674d Reviewed-on: https://go-review.googlesource.com/32751 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-10-31Revert "runtime/pprof: write profiles in protobuf format."Michael Matloob
This reverts commit b33030a72754cb55d6ec137e79facacb398c9be4. Reason for revert: We're going to try to get the code in this change submitted in smaller, more carefully reviewed changes. Change-Id: I4175f4b297f0e69fb78b11f9dc0bd82f27865be7 Reviewed-on: https://go-review.googlesource.com/32441 Reviewed-by: Russ Cox <rsc@golang.org>
2016-10-28runtime/pprof: write profiles in protobuf format.Michael Matloob
Original Change by Daria Kolistratova <daria.kolistratova@intel.com> Added functions with suffix proto and stuff from pprof tool to translate to protobuf. Done as the profile proto is more extensible than the legacy pprof format and is pprof's preferred profile format. Large part was taken from https://github.com/google/pprof tool. Tested by hand and compared the result with translated by pprof tool, profiles are identical. Fixes #16093 Change-Id: I2751345b09a66ee2b6aa64be76cba4cd1c326aa6 Reviewed-on: https://go-review.googlesource.com/32257 Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
2016-10-28Revert "runtime/pprof: write profiles in protobuf format."Austin Clements
This reverts commit 7d14401bcbee4a8ff33ac869ef5ebb156a179ab6. Reason for revert: Doesn't build. Change-Id: I766179ab9225109d9232f783326e4d3843254980 Reviewed-on: https://go-review.googlesource.com/32256 Reviewed-by: Russ Cox <rsc@golang.org>
2016-10-28runtime/pprof: write profiles in protobuf format.unknown
Added functions with suffix proto and stuff from pprof tool to translate to protobuf. Done as the profile proto is more extensible than the legacy pprof format and is pprof's preferred profile format. Large part was taken from https://github.com/google/pprof tool. Tested by hand and compared the result with translated by pprof tool, profiles are identical. Fixes #16093 Change-Id: I5acdb2809cab0d16ed4694fdaa7b8ddfd68df11e Reviewed-on: https://go-review.googlesource.com/30556 Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
2016-10-11runtime: record current PC for SIGPROF on non-Go threadIan Lance Taylor
If we get a SIGPROF on a non-Go thread, and the program has not called runtime.SetCgoTraceback so we have no way to collect a stack trace, then record a profile that is just the PC where the signal occurred. That will at least point the user to the right area. Retrieving the PC from the sigctxt in a signal handler on a non-G thread required marking a number of trivial sigctxt methods as nosplit, and, for extra safety, nowritebarrierrec. The test shows that the existing test CgoPprofThread test does not test the stack trace, just the profile signal. Leaving that for later. Change-Id: I8f8f3ff09ac099fc9d9df94b5a9d210ffc20c4ab Reviewed-on: https://go-review.googlesource.com/30252 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
2016-10-06runtime: add threadprof tag for test that starts busy threadIan Lance Taylor
The CgoExternalThreadSIGPROF test starts a thread at constructor time that does a busy loop. That can throw off some other tests. So only build that code if testprogcgo is built with the tag threadprof, and adjust the tests that use that code to pass that build tag. This revealed that the CgoPprofThread test was not testing what it should have, as it never actually started the cpuHog thread. It was passing because of the busy loop thread. Fix it to start the thread as intended. Change-Id: I087a9e4fc734a86be16a287456441afac5676beb Reviewed-on: https://go-review.googlesource.com/30362 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-10-05runtime: don't call cgocallback from signal handlerIan Lance Taylor
Calling cgocallback from a signal handler can fail when using the race detector. Calling cgocallback will lead to a call to newextram which will call oneNewExtraM which will call racegostart. The racegostart function will set up some race detector data structures, and doing that will sometimes call the C memory allocator. If we are running the signal handler from a signal that interrupted the C memory allocator, we will crash or hang. Instead, change the signal handler code to call needm and dropm. The needm function will grab allocated m and g structures and initialize the g to use the current stack--the signal stack. That is all we need to safely call code that allocates memory and checks whether it needs to split the stack. This may temporarily leave us with no m available to run a cgo callback, but that is OK in this case since the code we call will quickly either crash or call dropm to return the m. Implementing this required changing some of the setSignalstackSP functions to avoid a write barrier. These functions never need a write barrier but in some cases generated one anyhow because on some systems the ss_sp field is a pointer. Change-Id: I3893f47c3a66278f85eab7f94c1ab11d4f3be133 Reviewed-on: https://go-review.googlesource.com/30218 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
2016-09-22cmd/compile: don't instrument copy and append in runtimeIan Lance Taylor
Instrumenting copy and append for the race detector changes them to call different functions. In the runtime package the alternate functions are not marked as nosplit. This caused a crash in the SIGPROF handler when invoked on a non-Go thread in a program built with the race detector. In some cases the handler can call copy, the race detector changed that to a call to a non-nosplit function, the function tried to check the stack guard, and crashed because it was running on a non-Go thread. The SIGPROF handler is written carefully to avoid such problems, but hidden function calls are difficult to avoid. Fix this by changing the compiler to not instrument copy and append when compiling the runtime package. Change the runtime package to add explicit race checks for the only code I could find where copy is used to write to user data (append is never used). Change-Id: I11078a66c0aaa459a7d2b827b49f4147922050af Reviewed-on: https://go-review.googlesource.com/29472 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
2016-08-30all: use testing.GoToolPath instead of "go"Keith Randall
This change makes sure that tests are run with the correct version of the go tool. The correct version is the one that we invoked with "go test", not the one that is first in our path. Fixes #16577 Change-Id: If22c8f8c3ec9e7c35d094362873819f2fbb8559b Reviewed-on: https://go-review.googlesource.com/28089 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-18runtime: disable TestCgoCallbackGC on FreeBSDJosh Bleecher Snyder
The trybot flakes are a nuisance. Updates #16396 Change-Id: I8202adb554391676ba82bca44d784c6a81bf2085 Reviewed-on: https://go-review.googlesource.com/27313 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-06-20runtime: set PPROF_TMPDIR before running pprofIan Lance Taylor
Fixes #16121. Change-Id: I7b838fb6fb9f098e6c348d67379fdc81fb0d69a4 Reviewed-on: https://go-review.googlesource.com/24270 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
2016-06-13runtime: collect stack trace if SIGPROF arrives on non-Go threadIan Lance Taylor
Fixes #15994. Change-Id: I5aca91ab53985ac7dcb07ce094ec15eb8ec341f8 Reviewed-on: https://go-review.googlesource.com/23891 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-05-31runtime/pprof, cmd/pprof: fix profiling for PIEIan Lance Taylor
In order to support pprof for position independent executables, pprof needs to adjust the PC addresses stored in the profile by the address at which the program is loaded. The legacy profiling support which we use already supports recording the GNU/Linux /proc/self/maps data immediately after the CPU samples, so do that. Also change the pprof symbolizer to use the information, if available, when looking up addresses in the Go pcline data. Fixes #15714. Change-Id: I4bf679210ef7c51d85cf873c968ce82db8898e3e Reviewed-on: https://go-review.googlesource.com/23525 Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com>