aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/race_amd64.s
AgeCommit message (Collapse)Author
2021-05-13all: add //go:build lines to assembly filesTobias Klauser
Don't add them to files in vendor and cmd/vendor though. These will be pulled in by updating the respective dependencies. For #41184 Change-Id: Icc57458c9b3033c347124323f33084c85b224c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/319389 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2021-04-15runtime: unify C->Go ABI transitionsAustin Clements
The previous CL introduced macros for transitions from the Windows ABI to the Go ABI. This CL does the same for SysV and uses them in almost all places where we transition from the C ABI to the Go ABI. Compared to Windows, this transition is much simpler and I didn't find any places that were getting it wrong. But this does let us unify a lot of code nicely and introduces some degree of abstraction around these ABI transitions. Change-Id: Ib6bdecafce587ce18fca4c8300fcf401284a2bcd Reviewed-on: https://go-review.googlesource.com/c/go/+/309930 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2021-04-08cmd/asm,runtime: reduce spellings of GOEXPERIMENTsAustin Clements
Currently, the objabi.Experiment fields use Go-standard CamelCase, the GOEXPERIMENT environment variable flags and build tags use all lowercase, and the asm macros use upper-case with underscores. This CL makes asm use the lowercase names for macros so there is one less spelling, e.g., GOEXPERIMENT_regabiargs. This also makes them consistent with the GOOS_* and GOARCH_* macros, which also use lower case. Change-Id: I305cd89af5e8cd1a89cc148746c034bcfd76db3c Reviewed-on: https://go-review.googlesource.com/c/go/+/307816 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-04-06runtime: use register ABI for race detector functionsCherry Zhang
runtime.raceread/racewrite/racewriterange are functions that are called from compiler instrumented code, follwoing ABIInternal. They are assembly functions defined as ABIInternal in the runtime, in order to avoid wrappers because they need to get the caller's PC. This CL makes them to use the actual internal ABI. Change-Id: Id91d73cf257f7b11a858958d85c38c4aa904d9c3 Reviewed-on: https://go-review.googlesource.com/c/go/+/307812 Trust: Cherry Zhang <cherryyz@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2021-03-18all: explode GOEXPERIMENT=regabi into 5 sub-experimentsAustin Clements
This separates GOEXPERIMENT=regabi into five sub-experiments: regabiwrappers, regabig, regabireflect, regabidefer, and regabiargs. Setting GOEXPERIMENT=regabi now implies the working subset of these (currently, regabiwrappers, regabig, and regabireflect). This simplifies testing, helps derisk the register ABI project, and will also help with performance comparisons. This replaces the -abiwrap flag to the compiler and linker with the regabiwrappers experiment. As part of this, regabiargs now enables registers for all calls in the compiler. Previously, this was statically disabled in regabiEnabledForAllCompilation, but now that we can control it independently, this isn't necessary. For #40724. Change-Id: I5171e60cda6789031f2ef034cc2e7c5d62459122 Reviewed-on: https://go-review.googlesource.com/c/go/+/302070 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> Reviewed-by: David Chase <drchase@google.com>
2021-03-05runtime: remove racefuncenterfpCherry Zhang
No longer needed with previous CL. Change-Id: I7c01f9e0e34ecb9553ef1b3d662f33419fd3a244 Reviewed-on: https://go-review.googlesource.com/c/go/+/297932 Trust: Cherry Zhang <cherryyz@google.com> Reviewed-by: David Chase <drchase@google.com>
2021-02-23runtime: use BX instead of R15 in race detectorKeith Randall
If the race detector were runnable in dynamic linking mode, then R15 would get clobbered. I don't think it is, so maybe not a problem, but can't hurt to clean it up. It also lets CL 283474 pass cleanly when checking the whole stdlib (together with CL 288452). Change-Id: I5a5021ecc7e7b8bed1cd3a7067c39b24c09e0783 Reviewed-on: https://go-review.googlesource.com/c/go/+/289270 Trust: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-02-08[dev.regabi] runtime: use g register in some assembly functions on AMD64Cherry Zhang
Now that we have a g register, just use it. Note: functions that can be called from ABI0 context (e.g. morestack) is unchanged. Functions that switch g is also unchanged, because we need to set the new g in both the register and TLS. TODO: other OSes. Change-Id: I692a82a7caa8417ff620a59676a6275f56747b94 Reviewed-on: https://go-review.googlesource.com/c/go/+/289718 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2021-02-08[dev.regabi] cmd/compile, runtime: reserve R14 as g registers on AMD64Cherry Zhang
This is a proof-of-concept change for using the g register on AMD64. getg is now lowered to R14 in the new ABI. The g register is not yet used in all places where it can be used (e.g. stack bounds check, runtime assembly code). Change-Id: I10123ddf38e31782cf58bafcdff170aee0ff0d1b Reviewed-on: https://go-review.googlesource.com/c/go/+/289196 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: David Chase <drchase@google.com>
2021-02-05[dev.regabi] runtime: zero X15 in racecallCherry Zhang
racecall can be called in ABIInternal context (e.g. raceread calling racecalladdr calling racecall) without wrapper. racecall calls C code, which doesn't preserve our special registers. Set them explicitly in racecall upon returning from C. Change-Id: Ic990479c1fca6bb8a3b151325c7a89be8331a530 Reviewed-on: https://go-review.googlesource.com/c/go/+/289709 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org>
2021-02-05[dev.regabi] runtime: mark racecallbackthunk as ABIInternalCherry Zhang
racecallbackthunk is called from C, and it needs to follow C ABI. The assembly code preserves C callee-save registers. It must not be called via wrappers, which may not preserve those registers. Change-Id: Icd72c399f4424d73c4882860d85057fe2671f6aa Reviewed-on: https://go-review.googlesource.com/c/go/+/289194 Trust: Cherry Zhang <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
2020-11-16runtime: declare arg size/map for race version of sync/atomic functionsCherry Zhang
The argument size and map are used in stack scanning if those functions are deferred. Declare the right argument size and map so they can be scanned correctly. Fixes #42599. Change-Id: I74f9409d574cf7c383f4d8f83e38521026b48861 Reviewed-on: https://go-review.googlesource.com/c/go/+/270079 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2020-10-30reflect,runtime: use internal ABI for selected ASM routines, attempt 2Than McIntosh
[This is a roll-forward of CL 262319, with a fix for some Darwin test failures]. Change the definitions of selected runtime assembly routines from ABI0 (the default) to ABIInternal. The ABIInternal def is intended to indicate that these functions don't follow the existing Go runtime ABI. In addition, convert the assembly reference to runtime.main (from runtime.mainPC) to ABIInternal. Finally, for functions such as "runtime.duffzero" that are called directly from generated code, make sure that the compiler looks up the correct ABI version. This is intended to support the register abi work, however these changes should not have any issues even when GOEXPERIMENT=regabi is not in effect. Updates #27539, #40724. Change-Id: Idf507f1c06176073563845239e1a54dad51a9ea9 Reviewed-on: https://go-review.googlesource.com/c/go/+/266638 Trust: Than McIntosh <thanm@google.com> Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-10-29Revert "reflect,runtime: use internal ABI for selected ASM routines"Than McIntosh
This reverts commit 50af50d136551e2009b2b52e829570536271cdaa. Reason for revert: Causes failures in the runtime package test on Darwin, apparently. Change-Id: I006bc1b3443fa7207e92fb4a93e3fb438d4d3de3 Reviewed-on: https://go-review.googlesource.com/c/go/+/266257 Trust: Than McIntosh <thanm@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-10-29reflect,runtime: use internal ABI for selected ASM routinesThan McIntosh
Change the definitions of selected runtime assembly routines from ABI0 (the default) to ABIInternal. The ABIInternal def is intended to indicate that these functions don't follow the existing Go runtime ABI. In addition, convert the assembly reference to runtime.main (from runtime.mainPC) to ABIInternal. Finally, for functions such as "runtime.duffzero" that are called directly from generated code, make sure that the compiler looks up the correct ABI version. This is intended to support the register abi work, however these changes should not have any issues even when GOEXPERIMENT=regabi is not in effect. Updates #27539, #40724. Change-Id: I9846f8dcaccc95718cf2e61a18b7e924a0677e4c Reviewed-on: https://go-review.googlesource.com/c/go/+/262319 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-10-23runtime: add race detector support for new timersIan Lance Taylor
Since the new timers run on g0, which does not have a race context, we add a race context field to the P, and use that for timer functions. This works since all timer functions are in the standard library. Updates #27707 Change-Id: I8a5b727b4ddc8ca6fc60eb6d6f5e9819245e395b Reviewed-on: https://go-review.googlesource.com/c/go/+/171882 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2019-03-29runtime: rename p racectx field to raceprocctxIan Lance Taylor
Both g and p had a racectx field, but they held different kinds of values. The g field held ThreadState values while the p field held Processor values (to use the names used in the C++ code in the compiler_rt support library). Rename the p field to raceprocctx to reduce potential confusion. Change-Id: Iefba0e259d240171e973054c452c3c15bf3f8f8f Reviewed-on: https://go-review.googlesource.com/c/go/+/169960 Reviewed-by: Dmitry Vyukov <dvyukov@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-06-01all: update comment URLs from HTTP to HTTPS, where possibleTim Cooper
Each URL was manually verified to ensure it did not serve up incorrect content. Change-Id: I4dc846227af95a73ee9a3074d0c379ff0fa955df Reviewed-on: https://go-review.googlesource.com/115798 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
2016-06-29runtime: fix race atomic operations on external memoryDmitry Vyukov
The assembly is broken: it does `MOVQ g(R12), R14` expecting that R12 contains tls address, but it does not do get_tls(R12) before. This magically works on linux: `MOVQ g(R12), R14` is compiled to `mov %fs:0xfffffffffffffff8,%r14` which does not use R12. But it crashes on windows. Add explicit `get_tls(R12)`. Fixes #16206 Change-Id: Ic1f21a6fef2473bcf9147de6646929781c9c1e98 Reviewed-on: https://go-review.googlesource.com/24590 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-05-03runtime: per-P contexts for race detectorDmitry Vyukov
Race runtime also needs local malloc caches and currently uses a mix of per-OS-thread and per-goroutine caches. This leads to increased memory consumption. But more importantly cache of synchronization objects is per-goroutine and we don't always have goroutine context when feeing memory in GC. As the result synchronization object descriptors leak (more precisely, they can be reused if another synchronization object is recreated at the same address, but it does not always help). For example, the added BenchmarkSyncLeak has effectively runaway memory consumption (based on a real long running server). This change updates race runtime with support for per-P contexts. BenchmarkSyncLeak now stabilizes at ~1GB memory consumption. Long term, this will allow us to remove race runtime dependency on glibc (as malloc is the main cornerstone). I've also implemented a different scheme to pass P context to race runtime: scheduler notified race runtime about association between G and P by calling procwire(g, p)/procunwire(g, p). But it turned out to be very messy as we have lots of places where the association changes (e.g. syscalls). So I dropped it in favor of the current scheme: race runtime asks scheduler about the current P. Fixes #14533 Change-Id: Iad10d2f816a44affae1b9fed446b3580eafd8c69 Reviewed-on: https://go-review.googlesource.com/19970 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Dmitry Vyukov <dvyukov@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-01all: make copyright headers consistent with one space after periodBrad Fitzpatrick
This is a subset of https://golang.org/cl/20022 with only the copyright header lines, so the next CL will be smaller and more reviewable. Go policy has been single space after periods in comments for some time. The copyright header template at: https://golang.org/doc/contribute.html#copyright also uses a single space. Make them all consistent. Change-Id: Icc26c6b8495c3820da6b171ca96a74701b4a01b0 Reviewed-on: https://go-review.googlesource.com/20111 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-10-18[dev.ssa] cmd/compile: fill remaining SSA gapsDavid Chase
Changed racewalk/race detector to use FP in a more sensible way. Relaxed checks for CONVNOP when race detecting. Modified tighten to ensure that GetClosurePtr cannot float out of entry block (turns out this cannot be relaxed, DX is sometimes stomped by other code accompanying race detection). Added case for addr(CONVNOP) Modified addr to take "bounded" flag to suppress nilchecks where it is set (usually, by race detector). Cannot leave unimplemented-complainer enabled because it turns out we are optimistically running SSA on every platform. Change-Id: Ife021654ee4065b3ffac62326d09b4b317b9f2e0 Reviewed-on: https://go-review.googlesource.com/15710 Reviewed-by: Keith Randall <khr@golang.org>
2015-02-20runtime: adjust program counters in race detectorDmitry Vyukov
In most cases we pass return PC to race detector, and race runtime subtracts one from them. However, in manual instrumentation in runtime we pass function start PC to race runtime. Race runtime can't distinguish these cases and so it does not subtract one from top PC. This leads to bogus line numbers in some cases. Make it consistent and always pass what looks like a return PC, so that race runtime can subtract one and still get PC in the same function. Also delete two unused functions. Update #8053 Change-Id: I4242dec5e055e460c9a8990eaca1d085ae240ed2 Reviewed-on: https://go-review.googlesource.com/4902 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-02-13runtime: fix stack corruption in race modeDmitry Vyukov
MOVQ RARG0, 0(SP) smashes exactly what was saved by PUSHQ R15. This code managed to work somehow with the current race runtime, but corrupts caller arguments with new race runtime that I am testing. Change-Id: I9ffe8b5eee86451db36e99dbf4d11f320192e576 Reviewed-on: https://go-review.googlesource.com/4810 Reviewed-by: Keith Randall <khr@golang.org>
2015-01-07runtime: fix build for race detectorShenghou Ma
This CL only fixes the build, there are two failing tests: RaceMapBigValAccess1 and RaceMapBigValAccess2 in runtime/race tests. I haven't investigated why yet. Updates #9516. Change-Id: If5bd2f0bee1ee45b1977990ab71e2917aada505f Reviewed-on: https://go-review.googlesource.com/2401 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-01-06runtime, sync/atomic: add write barrier for atomic write of pointerRuss Cox
Add write barrier to atomic operations manipulating pointers. In general an atomic write of a pointer word may indicate racy accesses, so there is no strictly safe way to attempt to keep the shadow copy in sync with the real one. Instead, mark the shadow copy as not used. Redirect sync/atomic pointer routines back to the runtime ones, so that there is only one copy of the write barrier and shadow logic. In time we might consider doing this for most of the sync/atomic functions, but for now only the pointer routines need that treatment. Found with GODEBUG=wbshadow=1 mode. Eventually that will run automatically, but right now it still detects other missing write barriers. Change-Id: I852936b9a111a6cb9079cfaf6bd78b43016c0242 Reviewed-on: https://go-review.googlesource.com/2066 Reviewed-by: Rick Hudson <rlh@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2014-11-20[dev.cc] all: merge default (e4ab8f908aac) into dev.ccRuss Cox
TBR=austin CC=golang-codereviews https://golang.org/cl/179040044
2014-11-20runtime: fix atomic operations on non-heap addressesDmitriy Vyukov
Race detector runtime does not tolerate operations on addresses that was not previously declared with __tsan_map_shadow (namely, data, bss and heap). The corresponding address checks for atomic operations were removed in https://golang.org/cl/111310044 Restore these checks. It's tricker than just not calling into race runtime, because it is the race runtime that makes the atomic operations themselves (if we do not call into race runtime we skip the atomic operation itself as well). So instead we call __tsan_go_ignore_sync_start/end around the atomic operation. This forces race runtime to skip all other processing except than doing the atomic operation itself. Fixes #9136. LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/179030043
2014-11-14[dev.cc] all: merge dev.power64 (7667e41f3ced) into dev.ccRuss Cox
This is to reduce the delta between dev.cc and dev.garbage to just garbage collector changes. These are the files that had merge conflicts and have been edited by hand: malloc.go mem_linux.go mgc.go os1_linux.go proc1.go panic1.go runtime1.go LGTM=austin R=austin CC=golang-codereviews https://golang.org/cl/174180043
2014-11-11[dev.cc] runtime: convert assembly files for C to Go transitionRuss Cox
The main change is that #include "zasm_GOOS_GOARCH.h" is now #include "go_asm.h" and/or #include "go_tls.h". Also, because C StackGuard is now Go _StackGuard, the assembly name changes from const_StackGuard to const__StackGuard. In asm_$GOARCH.s, add new function getg, formerly implemented in C. The renamed atomics now have Go wrappers, to get escape analysis annotations right. Those wrappers are in CL 174860043. LGTM=r, aram R=r, aram CC=austin, dvyukov, golang-codereviews, iant, khr https://golang.org/cl/168510043
2014-10-28[dev.power64] cmd/5a, cmd/6a, cmd/8a, cmd/9a: make labels function-scopedRuss Cox
I removed support for jumping between functions years ago, as part of doing the instruction layout for each function separately. Given that, it makes sense to treat labels as function-scoped. This lets each function have its own 'loop' label, for example. Makes the assembly much cleaner and removes the last reason anyone would reach for the 123(PC) form instead. Note that this is on the dev.power64 branch, but it changes all the assemblers. The change will ship in Go 1.5 (perhaps after being ported into the new assembler). Came up as part of CL 167730043. LGTM=r R=r CC=austin, dave, golang-codereviews, minux https://golang.org/cl/159670043
2014-09-08build: move package sources from src/pkg to srcRuss Cox
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.