diff options
| author | Russ Cox <rsc@golang.org> | 2021-02-17 16:30:12 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2021-02-17 16:43:48 -0500 |
| commit | 0f210b75f9d8707f4e8a34ce23b778df33e9b501 (patch) | |
| tree | b6a63bf7b4983779b5f36169ae766afe14bbac02 /src/runtime | |
| parent | 1aea1b199f261c95a769ef3a2722a1e6a64a6939 (diff) | |
| parent | 2f0da6d9e29d9b9d5a4d10427ca9f71d12bbacc8 (diff) | |
| download | go-0f210b75f9d8707f4e8a34ce23b778df33e9b501.tar.xz | |
[dev.boringcrypto] all: merge master (2f0da6d) into dev.boringcrypto
Manual edits in src/cmd/compile/internal/reflectdata/reflect.go
to keep build working.
Merge List:
+ 2021-02-17 2f0da6d9e2 go/types: revert "no 'declared but not used' errors for invalid var decls"
+ 2021-02-17 70c37ee7d0 cmd/compile/internal/test: gofmt abiutils_test.go
+ 2021-02-16 84825599dc all: merge branch dev.regabi (d3cd4830ad) into master
+ 2021-02-16 d3cd4830ad [dev.regabi] test: run abi/regabipragma test with -c=1
+ 2021-02-16 03cea563d1 [dev.regabi] all: merge master (5faf941) into dev.regabi
+ 2021-02-16 b8fb049c7a [dev.regabi] cmd/go: copy internal/abi in TestNewReleaseRebuildsStalePackagesInGOPATH
+ 2021-02-16 5faf941df0 internal/goversion: update Version to 1.17
+ 2021-02-16 ed55da46ab [dev.regabi] go/types: overlapping embedded interfaces requires go1.14
+ 2021-02-16 7696c94334 [dev.regabi] go/types: type alias decl requires go1.9
+ 2021-02-16 c2358a1ae7 [dev.regabi] runtime: stub out spillArgs and unspillArgs
+ 2021-02-16 8cfbf34dd9 internal/abi: set register count constants to zero for regabi experiment
+ 2021-02-16 6f3da9d2f6 README: pull gopher image from website
+ 2021-02-16 d28aae26b0 [dev.regabi] cmd/link: recognize internal/abi as runtime package
+ 2021-02-16 098504c73f cmd/link: generate trampoline for inter-dependent packages
+ 2021-02-16 1004a7cb31 runtime/metrics: update documentation to current interface
+ 2021-02-16 6530f2617f doc/go1.16: remove draft notice
+ 2021-02-16 353e111455 doc/go1.16: fix mismatched id attribute
+ 2021-02-16 e0215315f5 [dev.regabi] reflect: support for register ABI on amd64 for reflect.(Value).Call
+ 2021-02-16 f0d23c9dbb internal/poll: netpollcheckerr before sendfile
+ 2021-02-16 0cb3415154 doc: remove all docs not tied to distribution
+ 2021-02-16 626ef08127 doc: remove install.html and install-source.html
+ 2021-02-16 30641e36aa internal/poll: if copy_file_range returns 0, assume it failed
+ 2021-02-15 33d72fd412 doc/faq: update generics entry to reflect accepted proposal
+ 2021-02-15 852ce7c212 cmd/go: provide a more helpful suggestion for "go vet -?"
+ 2021-02-13 66c27093d0 cmd/link: fix typo in link_test.go
+ 2021-02-13 b81efb7ec4 [dev.regabi] go/types: add support for language version checking
+ 2021-02-13 a7e9b4b948 [dev.regabi] go/types: untyped shift counts must fit into uint
+ 2021-02-13 060fa49bd2 [dev.regabi] go/types: refuse excessively long constants
+ 2021-02-12 baa6c75dce [dev.regabi] internal/abi: add new internal/abi package for ABI constants
+ 2021-02-12 d1fd9a8863 [dev.regabi] all: merge master (ff0e93e) into dev.regabi
+ 2021-02-12 ff0e93ea31 doc/go1.16: note that package path elements beginning with '.' are disallowed
+ 2021-02-11 249da7ec02 CONTRIBUTORS: update for the Go 1.16 release
+ 2021-02-11 864d4f1c6b cmd/go: multiple small 'go help' fixes
+ 2021-02-11 26ceae85a8 spec: More precise wording in section on function calls.
+ 2021-02-11 930c2c9a68 cmd/go: reject embedded files that can't be packed into modules
+ 2021-02-11 e5b08e6d5c io/fs: allow backslash in ValidPath, reject in os.DirFS.Open
+ 2021-02-10 ed8079096f cmd/compile: mark concrete call of reflect.(*rtype).Method as REFLECTMETHOD
+ 2021-02-10 59703d53e2 [dev.regabi] cmd/link: stop using ABI aliases if wrapper is enabled
+ 2021-02-09 e9c9683597 cmd/go: suppress errors from 'go get -d' for packages that only conditionally exist
+ 2021-02-09 168d6a49a5 [dev.regabi] go/types: use 512 bits as max. integer precision
+ 2021-02-09 0a62067708 [dev.regabi] go/types: adjust importer to match compiler importer
+ 2021-02-09 1c58fcf7ed [dev.regabi] go/types: handle untyped constant arithmetic overflow
+ 2021-02-09 493363ccff [dev.regabi] go/types: must not import a package called "init"
+ 2021-02-09 e0ac989cf3 archive/tar: detect out of bounds accesses in PAX records resulting from padded lengths
+ 2021-02-09 c48d1503ba [dev.regabi] go/types: report unused packages in source order
+ 2021-02-09 813958f13c [dev.regabi] go/types: factor out sorting of methods
+ 2021-02-09 11d15c171b [dev.regabi] go/types: convert untyped arguments to delete
+ 2021-02-09 c9d6f45fec runtime/metrics: fix a couple of documentation typpos
+ 2021-02-09 cea4e21b52 io/fs: backslash is always a glob meta character
+ 2021-02-08 dc725bfb3c doc/go1.16: mention new vet check for asn1.Unmarshal
+ 2021-02-08 618e3c15bd [dev.regabi] go/types: consistently report nil type as "untyped nil"
+ 2021-02-08 50449de66a [dev.regabi] all: merge master (1901853) into dev.regabi
+ 2021-02-08 7b0dfb177f [dev.regabi] runtime: use g register in some assembly functions on AMD64
+ 2021-02-08 2e60c00f56 [dev.regabi] cmd/internal/obj/x86: use g register in stack bounds check
+ 2021-02-08 22f9e1ccbc [dev.regabi] runtime: initialize special registers before sigpanic
+ 2021-02-08 5d7dc53888 [dev.regabi] cmd/compile, runtime: reserve R14 as g registers on AMD64
+ 2021-02-08 1901853098 runtime/metrics: fix panic in readingAllMetric example
+ 2021-02-08 ed3e4afa12 syscall/plan9: remove spooky fd action at a distance
+ 2021-02-08 a21de9ec73 [dev.regabi] cmd/link: resolve symbol ABI in shared linkage
+ 2021-02-05 724d0720b3 doc/go1.16: add missed heading tag in vet section
+ 2021-02-05 b54cd94d47 embed, io/fs: clarify that leading and trailing slashes are disallowed
+ 2021-02-05 4516afebed testing/fstest: avoid symlink-induced failures in tester
+ 2021-02-05 8fa84772ba [dev.regabi] runtime: delete gosave function
+ 2021-02-05 946351d5a2 [dev.regabi] runtime: zero X15 in racecall
+ 2021-02-05 397a46a10a [dev.regabi] cmd/asm: define g register on AMD64
+ 2021-02-05 e79c2fd428 [dev.regabi] runtime: mark racecallbackthunk as ABIInternal
+ 2021-02-05 7cc6de59f2 [dev.regabi] runtime: don't mark rt0_go ABIInternal
+ 2021-02-05 63de211014 [dev.regabi] runtime/cgo: call setg_gcc in crosscall_amd64
+ 2021-02-04 120b819f45 [dev.regabi] go/types: report error for invalid main function signature
+ 2021-02-04 52d5cb2822 [dev.regabi] cmd/internal/obj: access Attribute atomically
+ 2021-02-04 bc451b5770 [dev.regabi] go/types: port check_test.go ergonomics from dev.typeparams
+ 2021-02-04 afd67f3334 [dev.regabi] go/types: no "declared but not used" errors for invalid var decls
+ 2021-02-04 8869086d8f runtime: fix typo in histogram.go
+ 2021-02-03 401d7e5a24 [dev.regabi] cmd/compile: reserve X15 as zero register on AMD64
+ 2021-02-03 bfc7418e6d [dev.regabi] runtime, syscall, etc.: mark Darwin syscall wrappers as ABIInternal
+ 2021-02-03 e491c6eea9 math/big: fix comment in divRecursiveStep
+ 2021-02-02 23b0c1f76e [dev.regabi] all: merge master (fca94ab) into dev.regabi
+ 2021-02-02 fca94ab3ab spec: improve the example in Type assertions section
+ 2021-02-02 98f8454a73 cmd/link: don't decode type symbol in shared library in deadcode
+ 2021-02-02 1426a571b7 cmd/link: fix off-by-1 error in findShlibSection
+ 2021-02-01 32e789f4fb test: fix incorrectly laid out instructions in issue11656.go
+ 2021-02-01 ca6999e27c [dev.regabi] test: add a test for inlining closures
+ 2021-02-01 0b6cfea634 doc/go1.16: document that on OpenBSD syscalls are now made through libc
+ 2021-02-01 26e29aa15a cmd/link: disable TestPIESize if CGO isn't enabled
+ 2021-02-01 6ac91e460c doc/go1.16: minor markup fixes
+ 2021-01-29 44361140c0 embed: update docs for proposal tweaks
+ 2021-01-29 68058edc39 runtime: document pointer write atomicity for memclrNoHeapPointers
+ 2021-01-28 c8bd8010ff syscall: generate readlen/writelen for openbsd libc
+ 2021-01-28 41bb49b878 cmd/go: revert TestScript/build_trimpath to use ioutil.ReadFile
+ 2021-01-28 725a642c2d runtime: correct syscall10/syscall10X on openbsd/amd64
+ 2021-01-28 4b068cafb5 doc/go1.16: document go/build/constraint package
+ 2021-01-28 376518d77f runtime,syscall: convert syscall on openbsd/arm64 to libc
+ 2021-01-27 aca22bddf2 [dev.regabi] cmd/compile: remove nested functions from expands_calls.go
+ 2021-01-27 667e08ba8c [dev.regabi] cmd/go: Use GOMAXPROCS to limit default build, compile parallelism
+ 2021-01-27 00f2ff5c94 api/go1.16: add go/build/constraint APIs
+ 2021-01-27 35334caf18 crypto/x509: remove leftover CertificateRequest field
+ 2021-01-27 a5a5e2c968 runtime: make sure to remove open-coded defer entries in all cases after a recover
+ 2021-01-27 8cfa01943a runtime: block console ctrlhandler when the signal is handled
+ 2021-01-27 ff9e8364c6 cmd/go: skip issue33139 when the 'cc' script command is unavailable
+ 2021-01-27 cd176b3615 runtime: switch runtime to libc for openbsd/arm64
+ 2021-01-27 6c8fbfbdcf runtime: convert openbsd/arm64 locking to libc
+ 2021-01-27 5cdf0da1bf syscall: clean up mkasm related changes
+ 2021-01-27 210f70e298 doc/go1.16: fix closing brace in .Export format
+ 2021-01-27 0f797f168d math: fix typo in sqrt.go code comment
+ 2021-01-26 9b636feafe [dev.regabi] cmd/compile: missing last patch set for cl286013
+ 2021-01-26 f7dad5eae4 [dev.regabi] cmd/compile: remove leftover code form late call lowering work
+ 2021-01-26 8634a234df runtime,syscall: convert syscall on openbsd/amd64 to libc
+ 2021-01-26 1d5e14632e os: further document limitations around naked file descriptors
+ 2021-01-25 5e4a0cdde3 [dev.regabi] all: merge master (bf0f7c9) into dev.regabi
+ 2021-01-26 cf263e9f77 os: correct names in CreateTemp and MkdirTemp doc comments
+ 2021-01-26 ce8b318624 net/http/fcgi: remove locking added to prevent a test-only race
+ 2021-01-25 bf0f7c9d78 doc/go1.16: mention os.DirFS in os section
+ 2021-01-25 deaf29a8a8 cmd/compile: fix order-of-assignment issue w/ defers
+ 2021-01-25 ad2ca26a52 doc/go1.16: mention os.DirEntry and types moved from os to io/fs
+ 2021-01-25 a51921fa5b doc/go1.16: mention new testing/iotest functions
+ 2021-01-25 e6b6d107f7 doc/go1.16: mention deprecation of io/ioutil
+ 2021-01-25 7eaaf28cae [dev.regabi] cmd/compile: disallow taking address of SSA'd values
+ 2021-01-25 96a276363b doc/go1.16: mention go/build changes
+ 2021-01-25 3d85c69a0b html/template: revert "avoid race when escaping updates template"
+ 2021-01-25 54514c6b28 cmd/go: fix TestScript/cgo_path, cgo_path_space when CC set
+ 2021-01-25 6f5e79f470 [dev.regabi] cmd/compile/internal: specify memory layout
+ 2021-01-25 cabffc199d [dev.regabi] cmd/compile/internal: add internal ABI specification
+ 2021-01-25 6de8443f3b doc/asm: add a section on go_asm.h, clean up go_tls.h section
+ 2021-01-25 6a4739ccc5 [dev.regabi] cmd/compile: enable rational constant arithmetic
+ 2021-01-25 be9612a832 [dev.regabi] os: disable TestDirFS until #42637 is fixed
+ 2021-01-25 8ee3d39838 [dev.regabi] cmd/go: workaround -race issue on ppc64le
+ 2021-01-25 54b251f542 lib/time, time/tzdata: update tzdata to 2021a
+ 2021-01-25 5a76c3d548 [dev.regabi] cmd/compile: modify abiutils for recently updated ABI
+ 2021-01-25 ff82cc971a os: force consistent mtime before running fstest on directory on Windows
+ 2021-01-25 044f937a73 doc/go1.16: fix WalkDir and Walk links
+ 2021-01-25 063c72f06d [dev.regabi] cmd/compile: backport changes from dev.typeparams (9456804)
+ 2021-01-23 b634f5d97a doc/go1.16: add crypto/x509 memory optimization
+ 2021-01-23 9897655c61 doc/go1.16: reword ambiguously parsable sentence
+ 2021-01-23 cd99385ff4 cmd/internal/obj/arm64: fix VMOVQ instruction encoding error
+ 2021-01-23 d05d6fab32 [dev.regabi] cmd/compile: replace ir.Name map with ir.NameSet for SSA 2
+ 2021-01-23 66ee8b158f runtime: restore cgo_import_dynamic for libc.so on openbsd
+ 2021-01-23 48badc5fa8 [dev.regabi] cmd/compile: fix escape analysis problem with closures
+ 2021-01-23 51e1819a8d [dev.regabi] cmd/compile: scan body of closure in tooHairy to check for disallowed nodes
+ 2021-01-22 25c39e4fb5 io/ioutil: fix example test for WriteFile to allow it to run in the playground
+ 2021-01-22 eb21b31e48 runtime: define dummy msanmove
+ 2021-01-22 3a778ff50f runtime: check for g0 stack last in signal handler
+ 2021-01-22 a2cef9b544 cmd/go: don't lookup the path for CC when invoking cgo
+ 2021-01-22 7e0a81d280 [dev.regabi] all: merge master (dab3e5a) into dev.regabi
+ 2021-01-22 dab3e5affe runtime: switch runtime to libc for openbsd/amd64
+ 2021-01-22 a1b53d85da cmd/go: add documentation for test and xtest fields output by go list
+ 2021-01-22 b268b60774 runtime: remove pthread_kill/pthread_self for openbsd
+ 2021-01-22 ec4051763d runtime: fix typo in mgcscavenge.go
+ 2021-01-22 7ece3a7b17 net/http: fix flaky TestDisableKeepAliveUpgrade
+ 2021-01-22 50cba0506f time: clarify Timer.Reset behavior on AfterFunc Timers
+ 2021-01-22 cf10e69f17 doc/go1.16: mention net/http.Transport.GetProxyConnectHeader
+ 2021-01-22 ec1b945265 doc/go1.16: mention path/filepath.WalkDir
+ 2021-01-22 11def3d40b doc/go1.16: mention syscall.AllThreadsSyscall
+ 2021-01-21 07b0235609 doc/go1.16: add notes about package-specific fs.FS changes
+ 2021-01-21 e2b4f1fea5 doc/go1.16: minor formatting fix
+ 2021-01-21 9f43a9e07b doc/go1.16: mention new debug/elf constants
+ 2021-01-21 3c2f11ba5b cmd/go: overwrite program name with full path
+ 2021-01-21 953d1feca9 all: introduce and use internal/execabs
+ 2021-01-21 b186e4d70d cmd/go: add test case for cgo CC setting
+ 2021-01-21 5a8a2265fb cmd/cgo: report exec errors a bit more clearly
+ 2021-01-21 46e2e2e9d9 cmd/go: pass resolved CC, GCCGO to cgo
+ 2021-01-21 3d40895e36 runtime: switch openbsd/arm64 to pthreads
+ 2021-01-21 d95ca91380 crypto/elliptic: fix P-224 field reduction
+ 2021-01-21 d7e71c01ad [dev.regabi] cmd/compile: replace ir.Name map with ir.NameSet for dwarf
+ 2021-01-21 5248f59a22 [dev.regabi] cmd/compile: replace ir.Name map with ir.NameSet for SSA
+ 2021-01-21 970d8b6cb2 [dev.regabi] cmd/compile: replace ir.Name map with ir.NameSet in inlining
+ 2021-01-21 68a4664475 [dev.regabi] cmd/compile: remove tempAssigns in walkCall1
+ 2021-01-21 fd9a391cdd [dev.regabi] cmd/compile: remove CallExpr.Rargs
+ 2021-01-21 19a6db6b63 [dev.regabi] cmd/compile: make sure mkcall* passed non-nil init
+ 2021-01-21 9f036844db [dev.regabi] cmd/compile: use ir.DoChildren directly in inlining
+ 2021-01-21 213c3905e9 [dev.regabi] cmd/compile: use node walked flag to prevent double walk for walkSelect
+ 2021-01-20 1760d736f6 [dev.regabi] cmd/compile: exporting, importing, and inlining functions with OCLOSURE
+ 2021-01-20 ecf4ebf100 cmd/internal/moddeps: check content of all modules in GOROOT
+ 2021-01-20 92cb157cf3 [dev.regabi] cmd/compile: late expansion of return values
+ 2021-01-20 d2d155d1ae runtime: don't adjust timer pp field in timerWaiting status
+ 2021-01-20 803d18fc6c cmd/go: set Incomplete field on go list output if no files match embed
+ 2021-01-20 6e243ce71d cmd/go: have go mod vendor copy embedded files in subdirs
+ 2021-01-20 be28e5abc5 cmd/go: fix mod_get_fallback test
+ 2021-01-20 928bda4f4a runtime: convert openbsd/amd64 locking to libc
+ 2021-01-19 824f2d635c cmd/go: allow go fmt to complete when embedded file is missing
+ 2021-01-19 0575e35e50 cmd/compile: require 'go 1.16' go.mod line for //go:embed
+ 2021-01-19 9423d50d53 [dev.regabi] cmd/compile: use '%q' for printing rune values less than 128
+ 2021-01-19 ccb2e90688 cmd/link: exit before Asmb2 if error
+ 2021-01-19 ca5774a5a5 embed: treat uninitialized FS as empty
+ 2021-01-19 d047c91a6c cmd/link,runtime: switch openbsd/amd64 to pthreads
+ 2021-01-19 61debffd97 runtime: factor out usesLibcall
+ 2021-01-19 9fed39d281 runtime: factor out mStackIsSystemAllocated
+ 2021-01-19 a2f825c542 [dev.regabi] cmd/compile: directly create go.map and go.track symbols
+ 2021-01-19 4a4212c0e5 [dev.regabi] cmd/compile: refactor Linksym creation
+ 2021-01-19 4f5c603c0f [dev.regabi] cmd/compile: cleanup callTargetLSym
+ 2021-01-18 dbab079835 runtime: free Windows event handles after last lock is dropped
+ 2021-01-18 5a8fbb0d2d os: do not close syscall.Stdin in TestReadStdin
+ 2021-01-18 422f38fb6c [dev.regabi] cmd/compile: move stack objects to liveness
+ 2021-01-18 6113db0bb4 [dev.regabi] cmd/compile: convert OPANIC argument to interface{} during typecheck
+ 2021-01-18 4c835f9169 [dev.regabi] cmd/compile: use LinksymOffsetExpr in TypePtr/ItabAddr
+ 2021-01-18 0ffa1ead6e [dev.regabi] cmd/compile: use *obj.LSym instead of *ir.Name for staticdata functions
+ 2021-01-17 7e0fa38aad [dev.regabi] cmd/compile: remove unneeded packages from ir.Pkgs
+ 2021-01-17 99a5db11ac [dev.regabi] cmd/compile: use LinksymOffsetExpr in walkConvInterface
+ 2021-01-17 87845d14f9 [dev.regabi] cmd/compile: add ir.TailCallStmt
+ 2021-01-17 e3027c6828 [dev.regabi] cmd/compile: fix linux-amd64-noopt builder
+ 2021-01-17 59ff93fe64 [dev.regabi] cmd/compile: rename NameOffsetExpr to LinksymOffsetExpr
+ 2021-01-17 82b9cae700 [dev.regabi] cmd/compile: change ir.NameOffsetExpr to use *obj.LSym instead of *Name
+ 2021-01-17 88956fc4b1 [dev.regabi] cmd/compile: stop analyze NameOffsetExpr.Name_ in escape analysis
+ 2021-01-17 7ce2a8383d [dev.regabi] cmd/compile: simplify stack temp initialization
+ 2021-01-17 ba0e8a92fa [dev.regabi] cmd/compile: refactor temp construction in walk
+ 2021-01-17 78e5aabcdb [dev.regabi] cmd/compile: replace Node.HasCall with walk.mayCall
+ 2021-01-16 6de9423445 [dev.regabi] cmd/compile: cleanup OAS2FUNC ordering
+ 2021-01-16 a956a0e909 [dev.regabi] cmd/compile, runtime: fix up comments/error messages from recent renames
+ 2021-01-16 ab3b67abfd [dev.regabi] cmd/compile: remove ONEWOBJ
+ 2021-01-16 c9b1445ac8 [dev.regabi] cmd/compile: remove TypeAssertExpr {Src,Dst}Type fields
+ 2021-01-15 682a1d2176 runtime: detect errors in DuplicateHandle
+ 2021-01-15 9f83418b83 cmd/link: remove GOROOT write in TestBuildForTvOS
+ 2021-01-15 ec9470162f cmd/compile: allow embed into any string or byte slice type
+ 2021-01-15 54198b04db cmd/compile: disallow embed of var inside func
+ 2021-01-15 b386c735e7 cmd/go: fix go generate docs
+ 2021-01-15 bb5075a525 syscall: remove RtlGenRandom and move it into internal/syscall
+ 2021-01-15 1deae0b597 os: invoke processKiller synchronously in testKillProcess
+ 2021-01-15 03a875137f [dev.regabi] cmd/compile: unexport reflectdata.WriteType
+ 2021-01-15 14537e6e54 [dev.regabi] cmd/compile: move stkobj symbol generation to SSA
+ 2021-01-15 ab523fc510 [dev.regabi] cmd/compile: don't promote Byval CaptureVars if Addrtaken
+ 2021-01-15 ff196c3e84 crypto/x509: update iOS bundled roots to version 55188.40.9
+ 2021-01-15 b7a698c73f [dev.regabi] test: disable test on windows because expected contains path separators.
+ 2021-01-15 4be7af23f9 [dev.regabi] cmd/compile: fix ICE during ir.Dump
+ 2021-01-14 e125ccd10e cmd/go: in 'go mod edit', validate versions given to -retract and -exclude
+ 2021-01-14 eb330020dc cmd/dist, cmd/go: pass -arch for C compilation on Darwin
+ 2021-01-14 84e8a06f62 cmd/cgo: remove unnecessary space in cgo export header
+ 2021-01-14 0c86b999c3 cmd/test2json: document passing -test.paniconexit0
+ 2021-01-14 9135795891 cmd/go/internal/load: report positions for embed errors
+ 2021-01-14 35b9c66601 [dev.regabi] cmd/compile,cmd/link: additional code review suggestions for CL 270863
+ 2021-01-14 d9b79e53bb cmd/compile: fix wrong complement for arm64 floating-point comparisons
+ 2021-01-14 c73232d08f cmd/go/internal/load: refactor setErrorPos to PackageError.setPos
+ 2021-01-14 6aa28d3e06 go/build: report positions for go:embed directives
+ 2021-01-14 9734fd482d [dev.regabi] cmd/compile: use node walked flag to prevent double walk for walkSwitch
+ 2021-01-14 f97983249a [dev.regabi] cmd/compile: move more PAUTOHEAP to SSA construction
+ 2021-01-14 4476300425 [dev.regabi] cmd/compile: use byte for CallExpr.Use
+ 2021-01-14 5a5ab24689 [dev.regabi] cmd/compile: do not rely on CallExpr.Rargs for detect already walked calls
+ 2021-01-14 983ac4b086 [dev.regabi] cmd/compile: fix ICE when initializing blank vars
+ 2021-01-13 7eb31d999c cmd/go: add hints to more missing sum error messages
+ 2021-01-13 d6d4673728 [dev.regabi] cmd/compile: fix GOEXPERIMENT=regabi builder
+ 2021-01-13 c41b999ad4 [dev.regabi] cmd/compile: refactor abiutils from "gc" into new "abi"
+ 2021-01-13 861707a8c8 [dev.regabi] cmd/compile: added limited //go:registerparams pragma for new ABI dev
+ 2021-01-13 c1370e918f [dev.regabi] cmd/compile: add code to support register ABI spills around morestack calls
+ 2021-01-13 2abd24f3b7 [dev.regabi] test: make run.go error messages slightly more informative
+ 2021-01-13 9a19481acb [dev.regabi] cmd/compile: make ordering for InvertFlags more stable
+ 2021-01-12 d9acf6f3a3 [dev.regabi] cmd/compile: remove Func.ClosureType
+ 2021-01-12 41352fd401 [dev.regabi] cmd/compile: transform closures during walk
+ 2021-01-12 d6ad88b4db [dev.regabi] cmd/compile: compile functions before closures
+ 2021-01-12 432f9ffb11 [dev.regabi] cmd/compile: unindent compileFunctions
+ 2021-01-12 cc90e7a51e [dev.regabi] cmd/compile: always use the compile queue
+ 2021-01-12 cd5b74d2df [dev.regabi] cmd/compile: call NeedFuncSym in InitLSym
+ 2021-01-12 ba76567bc2 cmd/go/internal/modload: delete unused *mvsReqs.next method
+ 2021-01-12 665def2c11 encoding/asn1: document unmarshaling behavior for IMPLICIT string fields
+ 2021-01-12 95acd8121b [dev.regabi] cmd/compile: remove Name.Typegen
+ 2021-01-12 12ee55ba7b [dev.regabi] cmd/compile: stop using Vargen for import/export
+ 2021-01-12 b4d2a0445b [dev.regabi] cmd/compile: refactor closure var setup/teardown
+ 2021-01-12 f57f484053 [dev.regabi] cmd/compile: decouple escape analysis from Name.Vargen
+ 2021-01-11 81ea89adf3 cmd/go: fix non-script staleness checks interacting badly with GOFLAGS
+ 2021-01-11 759309029f doc: update editors.html for Go 1.16
+ 2021-01-11 c3b4c7093a cmd/internal/objfile: don't require runtime.symtab symbol for XCOFF
+ 2021-01-10 7fd84c6e46 [dev.regabi] cmd/compile: remove OCLOSUREREAD
+ 2021-01-10 c9c26d7ffb [dev.regabi] cmd/compile: use ClosureVars for method value wrappers
+ 2021-01-10 950cf4d46c [dev.regabi] cmd/compile: bind closure vars during SSA constructions
+ 2021-01-10 8b2efa990b [dev.regabi] cmd/compile: deref PAUTOHEAPs during SSA construction
+ 2021-01-08 59bfc18e34 cmd/go: add hint to read 'go help vcs' to GOVCS errors
+ 2021-01-08 6ee9b118a2 [dev.regabi] cmd/compile: remove fmt_test code; it has outlived its usefulness
+ 2021-01-08 cd6f3a54e4 cmd/go: revise 'go help' documentation for modules
+ 2021-01-08 6192b98751 cmd/go: make hints in error messages more consistent
+ 2021-01-08 25886cf4bd cmd/go: preserve sums for indirect deps fetched by 'go mod download'
+ 2021-01-08 6250833911 runtime/metrics: mark histogram metrics as cumulative
+ 2021-01-08 8f6a9acbb3 runtime/metrics: remove unused StopTheWorld Description field
+ 2021-01-08 6598c65646 cmd/compile: fix exponential-time init-cycle reporting
+ 2021-01-08 fefad1dc85 test: fix timeout code for invoking compiler
+ 2021-01-08 6728118e0a cmd/go: pass signals forward during "go tool"
+ 2021-01-08 e65c543f3c go/build/constraint: add parser for build tag constraint expressions
+ 2021-01-08 0c5afc4fb7 testing/fstest,os: clarify racy behavior of TestFS
+ 2021-01-08 32afcc9436 runtime/metrics: change unit on *-by-size metrics to match bucket unit
+ 2021-01-08 c6513bca5a io/fs: minor corrections to Glob doc
+ 2021-01-08 b241938e04 [dev.regabi] cmd/compile: fix some methods error text
+ 2021-01-08 304f769ffc cmd/compile: don't short-circuit copies whose source is volatile
+ 2021-01-08 ae97717133 runtime,runtime/metrics: use explicit histogram boundaries
+ 2021-01-08 a9ccd2d795 go/build: skip string literal while findEmbed
+ 2021-01-08 d92f8add32 archive/tar: fix typo in comment
+ 2021-01-08 cab1202183 cmd/link: accept extra blocks in TestFallocate
+ 2021-01-08 ee4d32249b io/fs: minor corrections to Glob release date
+ 2021-01-08 54bd1ccce2 cmd: update to latest golang.org/x/tools
+ 2021-01-07 9ec21a8f34 Revert "reflect: support multiple keys in struct tags"
+ 2021-01-07 091414b5b7 io/fs: correct WalkDirFunc documentation
+ 2021-01-07 9b55088d6b doc/go1.16: add release note for disallowing non-ASCII import paths
+ 2021-01-07 fa90aaca7d cmd/compile: fix late expand_calls leaf type for OpStructSelect/OpArraySelect
+ 2021-01-07 7cee66d4cb cmd/go: add documentation for Embed fields in go list output
+ 2021-01-07 e60cffa4ca html/template: attach functions to namespace
+ 2021-01-07 6da2d3b7d7 cmd/link: fix typo in asm.go
+ 2021-01-07 df81a15819 runtime: check mips64 VDSO clock_gettime return code
+ 2021-01-06 4787e906cf crypto/x509: rollback new CertificateRequest fields
+ 2021-01-06 c9658bee93 cmd/go: make module suggestion more friendly
+ 2021-01-06 4c668b25c6 runtime/metrics: fix panic message for Float64Histogram
+ 2021-01-06 d2131704a6 net/http/httputil: fix deadlock in DumpRequestOut
+ 2021-01-05 3e1e13ce6d cmd/go: set cfg.BuildMod to "readonly" by default with no module root
+ 2021-01-05 0b0d004983 cmd/go: pass embedcfg to gccgo if supported
+ 2021-01-05 cb05a0aa6a [dev.regabi] cmd/compile: remove toolstash scaffolding
+ 2021-01-05 9821838832 [dev.regabi] cmd/compile: remove CaptureVars
+ 2021-01-05 fd43831f44 [dev.regabi] cmd/compile: reimplement capture analysis
+ 2021-01-05 fb69c67cad [dev.regabi] test: enable finalizer tests on !amd64
+ 2021-01-05 1b85e7c057 cmd/go: don't scan gccgo standard library packages for imports
+ 2021-01-05 81f4f0e912 [dev.regabi] cmd/compile: remove race-y check in Name.Canonical
+ 2021-01-05 6b37b15d95 runtime: don't take allglock in tracebackothers
+ 2021-01-05 4a9d9adea4 [dev.regabi] cmd/compile: remove initname function
+ 2021-01-05 77365c5ed7 [dev.regabi] cmd/compile: add Name.Canonical and move Byval
+ 2021-01-05 e09783cbc0 [dev.regabi] cmd/compile: make ir.StaticValue safer
+ 2021-01-05 9aa950c407 [dev.regabi] cmd/compile: make ir.OuterValue safer
+ 2021-01-05 eb626409d1 [dev.regabi] cmd/compile: simplify CaptureVars
+ 2021-01-05 c28ca67a96 [dev.regabi] cmd/compile: fix ir.Dump for []*CaseClause, etc
+ 2021-01-04 9eef49cfa6 math/rand: fix typo in comment
+ 2021-01-04 b01fb2af9e testing/fstest: fix typo in error message
+ 2021-01-04 f24e40c14a [dev.regabi] cmd/compile: remove Name.Class_ accessors
+ 2021-01-04 d89705e087 [dev.regabi] cmd/compile: fix re-export of parameters
+ 2021-01-04 290b4154b7 [dev.regabi] cmd/compile: fix ICE due to large uint64 constants
+ 2021-01-04 a30fd52884 [dev.regabi] cmd/compile: use ir.NewNameAt in SubstArgTypes
+ 2021-01-03 8fc44cf0fa [dev.regabi] cmd/compile: remove a couple CloneName calls
+ 2021-01-03 907a4bfdc7 [dev.regabi] cmd/compile: fix map assignment order
+ 2021-01-03 f2e6dab048 [dev.regabi] cmd/compile: remove walkReturn "common case" path
+ 2021-01-03 d36a6bf44d [dev.regabi] cmd/compile: improve walkReturn common case
+ 2021-01-03 a317067d65 [dev.regabi] cmd/compile: improve ascompatee
+ 2021-01-03 5d80a590a2 [dev.regabi] cmd/compile: simplify walkReturn
+ 2021-01-03 bb1b6c95c2 [dev.regabi] cmd/compile: remove Node.{,Set}Walkdef
+ 2021-01-03 57c426c9a5 [dev.regabi] cmd/compile: tighten typecheckdef to *ir.Name
+ 2021-01-03 b1747756e3 [dev.regabi] cmd/compile: reorganize escape analysis somewhat
+ 2021-01-02 f2538033c0 [dev.regabi] cmd/compile: remove Nodes.Set [generated]
+ 2021-01-02 2f2d4b4e68 [dev.regabi] cmd/compile: remove {Ptr,Set}Init from Node interface
+ 2021-01-01 3dd5867605 doc: 2021 is the Year of the Gopher
+ 2021-01-01 1544a03198 [dev.regabi] cmd/compile: refactor redundant type conversion [generated]
+ 2021-01-01 7958a23ea3 [dev.regabi] cmd/compile: use *ir.Name where possible in inl.go
+ 2021-01-01 bfa97ba48f [dev.regabi] test: add another closure test case
+ 2021-01-01 67ad695416 [dev.regabi] cmd/compile: split escape analysis state
+ 2021-01-01 fad9a8b528 [dev.regabi] cmd/compile: simplify inlining of closures
+ 2021-01-01 7d55669847 [dev.regabi] cmd/compile: simplify dwarfgen.declPos
+ 2021-01-01 9ed1577779 [dev.regabi] cmd/compile: remove Func.ClosureEnter
+ 2021-01-01 ece345aa69 [dev.regabi] cmd/compile: expand documentation for Func.Closure{Vars,Enter}
+ 2021-01-01 6ddbc75efd [dev.regabi] cmd/compile: earlier deadcode removal
+ 2021-01-01 68e6fa4f68 [dev.regabi] cmd/compile: fix package-initialization order
+ 2021-01-01 3a4474cdfd [dev.regabi] cmd/compile: some more manual shuffling
+ 2021-01-01 0f1d2129c4 [dev.regabi] cmd/compile: reshuffle type-checking code [generated]
+ 2021-01-01 b8fd3440cd [dev.regabi] cmd/compile: report unused variables during typecheck
+ 2021-01-01 fd22df9905 [dev.regabi] cmd/compile: remove idempotent Name() calls [generated]
+ 2020-12-31 dfbcff80c6 [dev.regabi] cmd/compile: make copyExpr return *ir.Name directly
+ 2020-12-31 77fd81a3e6 [dev.regabi] cmd/compile: use names for keep alive variables in function call
+ 2020-12-31 8fe1197654 [dev.regabi] cmd/compile: remove Name.orig
+ 2020-12-31 477b049060 [dev.regabi] cmd/compile: fix printing of method expressions
+ 2020-12-31 95ce805d14 io/fs: remove darwin/arm64 special condition
+ 2020-12-30 20d0991b86 lib/time, time/tzdata: update tzdata to 2020f
+ 2020-12-30 ed301733bb misc/cgo/testcarchive: remove special flags for Darwin/ARM
+ 2020-12-30 0ae2e032f2 misc/cgo/test: enable TestCrossPackageTests on darwin/arm64
+ 2020-12-30 178c667db2 [dev.regabi] cmd/compile: fix OSLICEARR comments
+ 2020-12-30 f0d99def5b [dev.regabi] cmd/compile: add newline to ir.Dump
+ 2020-12-30 451693af71 [dev.regabi] cmd/compile: simplify typecheckdef
+ 2020-12-30 0c1a899a6c [dev.regabi] cmd/compile: fix defined-pointer method call check
+ 2020-12-30 f9b67f76a5 [dev.regabi] cmd/compile: change ir.DoChildren to use bool result type
+ 2020-12-30 499851bac8 [dev.regabi] cmd/compile: generalize ir/mknode.go
+ 2020-12-30 82ab3d1448 [dev.regabi] cmd/compile: use *ir.Name for Decl.X
+ 2020-12-30 9958b7ed3e [dev.regabi] cmd/compile: unexport ir.FmtNode
+ 2020-12-29 780b4de16b misc/ios: fix wording for command line instructions
+ 2020-12-29 b4a71c95d2 doc/go1.16: reference misc/ios/README for how to build iOS programs
+ 2020-12-29 f83e0f6616 misc/ios: add to README how to build ios executables
+ 2020-12-29 f5816624cd [dev.regabi] cmd/compile: change AddrExpr.Alloc to AddrExpr.Prealloc
+ 2020-12-29 850aa7c60c [dev.regabi] cmd/compile: use *ir.Name instead of ir.Node for CaseClause.Var
+ 2020-12-29 37babc97bb [dev.regabi] cmd/compile: allow visitor visits *ir.Name
+ 2020-12-29 5cf3c87fa6 [dev.regabi] cmd/compile: generate case/comm clause functions in mknode.go
+ 2020-12-29 b3e1ec97fd [dev.regabi] cmd/compile: move new addrtaken bit back to the old name
+ 2020-12-29 0620c674dd [dev.regabi] cmd/compile: remove original addrtaken bit
+ 2020-12-29 0523d525ae [dev.regabi] cmd/compile: separate out address taken computation from typechecker
+ 2020-12-29 9ea272e5ec [dev.regabi] cmd/compile: simplify ir.Func somewhat
+ 2020-12-29 e40cb4d4ae [dev.regabi] cmd/compile: remove more unused code
+ 2020-12-29 6f30c95048 [dev.regabi] cmd/compile: remove unneeded indirection
+ 2020-12-29 171fc6f223 [dev.regabi] cmd/compile: remove workarounds for go/constant issues
+ 2020-12-29 33801cdc62 [dev.regabi] cmd/compile: use Ntype where possible
+ 2020-12-29 82ad3083f8 [dev.regabi] cmd/compile: remove typ from AssignOpStmt
+ 2020-12-29 e34c44a7c4 [dev.regabi] cmd/compile: refactoring typecheck arith
+ 2020-12-29 a5ec920160 [dev.regabi] cmd/compile: more Linksym cleanup
+ 2020-12-29 ec59b197d5 [dev.regabi] cmd/compile: rewrite to use linksym helpers [generated]
+ 2020-12-29 25c613c02d [dev.regabi] cmd/compile: add Linksym helpers
+ 2020-12-29 289da2b33e [dev.regabi] cmd/compile: move Node.Opt to Name
+ 2020-12-29 6acbae4fcc [dev.regabi] cmd/compile: address some ir TODOs
+ 2020-12-29 4629f6a51d [dev.regabi] cmd/compile: merge {Selector,CallPart,Method}Expr
+ 2020-12-29 e563715b30 [dev.regabi] cmd/compile: remove Sym.Importdef
+ 2020-12-29 3f370b75fb [dev.regabi] cmd/compile: cleanup //go:generate directives
+ 2020-12-28 4fd9455882 io/fs: fix typo in comment
+ 2020-12-28 07569dac4e [dev.regabi] all: merge master (1d78139) into dev.regabi
+ 2020-12-28 76136be027 [dev.regabi] cmd/compile: check for recursive import in ImportBody
+ 2020-12-28 fda7ec3a3f [dev.regabi] cmd/compile: remove Name.IsDDD, etc
+ 2020-12-28 098a6490b9 [dev.regabi] cmd/compile: remove Declare in makepartialcall
+ 2020-12-28 137f0d2e06 [dev.regabi] cmd/compile: remove unnecessary Name.Sym call
+ 2020-12-28 3383b5c74a [dev.regabi] cmd/compile: flatten dependency graph [generated]
+ 2020-12-28 f8afb8216a [dev.regabi] cmd/compile: rename CommStmt and CaseStmt [generated]
+ 2020-12-28 5f3bd59a0d [dev.regabi] cmd/compile: remove some unneeded code in package ir
+ 2020-12-28 3bdafb0d82 [dev.regabi] cmd/compile: remove CommStmt.List
+ 2020-12-28 2ecf52b841 [dev.regabi] cmd/compile: separate CommStmt from CaseStmt
+ 2020-12-28 ed9772e130 [dev.regabi] cmd/compile: add explicit file name in types generation
+ 2020-12-28 a59d26603f [dev.regabi] cmd/compile: use []*CaseStmt in {Select,Switch}Stmt
+ 2020-12-28 fbc4458c06 [dev.regabi] cmd/compile: simplify some tree traversal code
+ 2020-12-28 6c67677541 [dev.regabi] cmd/compile: simplify FuncName and PkgFuncName
+ 2020-12-28 676d794b81 [dev.regabi] cmd/compile: remove refersToCommonName
+ 2020-12-28 c98548e110 [dev.regabi] cmd/compile: merge ascompatee, ascompatee1, and reorder3
+ 2020-12-28 4c215c4fa9 [dev.regabi] cmd/compile: simplify and optimize reorder3
+ 2020-12-28 e6c973198d [dev.regabi] cmd/compile: stop mangling SelectorExpr.Sel for ODOTMETH
+ 2020-12-28 135ce1c485 [dev.regabi] cmd/compile: desugar OMETHEXPR into ONAME during walk
+ 2020-12-28 0f732f8c91 [dev.regabi] cmd/compile: minor walkExpr cleanups
+ 2020-12-28 0de8eafd98 [dev.regabi] cmd/compile: remove SelectorExpr.Offset field
+ 2020-12-28 a4f335f420 [dev.regabi] cmd/compile: always use a Field for ODOTPTR expressions
+ 2020-12-26 1d78139128 runtime/cgo: fix Android build with NDK 22
+ 2020-12-25 2018b68a65 net/mail: don't use MDT in test
+ 2020-12-25 e4f293d853 [dev.regabi] cmd/compile: fix OCALLMETH desugaring
+ 2020-12-25 1d9a1f67d5 [dev.regabi] cmd/compile: don't emit reflect data for method types
+ 2020-12-25 396b6c2e7c [dev.regabi] cmd/compile: cleanup assignment typechecking
+ 2020-12-25 e24d2f3d05 [dev.regabi] cmd/compile: remove typ from RangeStmt
+ 2020-12-25 2785c691c2 [dev.regabi] cmd/compile: cleanup devirtualization docs
+ 2020-12-25 4b1d0fe66f [dev.regabi] cmd/compile: new devirtualization pkg [generated]
+ 2020-12-24 082cc8b7d9 [dev.regabi] cmd/compile: change ir.IsAssignable -> ir.IsAddressable
+ 2020-12-24 27b248b307 [dev.regabi] cmd/compile: separate range stmt Vars to Key, Value nodes
+ 2020-12-23 40818038bf [dev.regabi] cmd/compile: change CaseStmt.Vars to Var
+ 2020-12-23 b116404444 runtime: shift timeHistogram buckets and allow negative durations
+ 2020-12-23 8db7e2fecd runtime: fix allocs-by-size and frees-by-size buckets
+ 2020-12-23 fb96f07e1a runtime: fix nStackRoots comment about stack roots
+ 2020-12-23 d1502b3c72 lib/time, time/tzdata: update tzdata to 2020e
+ 2020-12-23 30c99cbb7a cmd/go: add the Retract field to 'go help mod edit' definition of the GoMod struct
+ 2020-12-23 49d0b239cb doc: fix a typo in contribute.html
+ 2020-12-23 9eeed291bc [dev.regabi] cmd/compile: eliminate usage of ir.Node in liveness
+ 2020-12-23 d1d64e4cea [dev.regabi] cmd/compile: split SliceExpr.List into separate fields
+ 2020-12-23 98a73030b0 cmd/go: in 'go get', promote named implicit dependencies to explicit
+ 2020-12-23 d19018e8f1 [dev.regabi] cmd/compile: split SliceHeaderExpr.LenCap into separate fields
+ 2020-12-23 53f082b0ee [dev.regabi] cmd/compile: cleanup export code further
+ 2020-12-23 31267f82e1 [dev.regabi] cmd/compile: simplify function/interface/struct typechecking
+ 2020-12-23 addade2cce [dev.regabi] cmd/compile: prefer types constructors over typecheck
+ 2020-12-23 18ebfb49e9 [dev.regabi] cmd/compile: cleanup noder
+ 2020-12-23 87a592b356 [dev.regabi] cmd/compile: cleanup import/export code
+ 2020-12-23 5898025026 [dev.regabi] cmd/compile: update mkbuiltin.go to use new type constructors
+ 2020-12-23 63c96c2ee7 [dev.regabi] cmd/compile: update mkbuiltin.go and re-enable TestBuiltin
+ 2020-12-23 37f138df6b [dev.regabi] cmd/compile: split out package test [generated]
+ 2020-12-23 3d8a3cb06b [dev.regabi] cmd/compile: split out package pkginit [generated]
+ 2020-12-23 3f04d964ab [dev.regabi] cmd/compile: split up walkexpr1, walkstmt [generated]
+ 2020-12-23 e4895ab4c0 [dev.regabi] cmd/compile: split out package walk [generated]
+ 2020-12-23 01fd2d05c8 [dev.regabi] cmd/compile: split out package dwarfgen [generated]
+ 2020-12-23 6c34d2f420 [dev.regabi] cmd/compile: split out package ssagen [generated]
+ 2020-12-23 de65151e50 [dev.regabi] cmd/compile: split out package reflectdata [generated]
+ 2020-12-23 4dfb5d91a8 [dev.regabi] cmd/compile: split out package staticdata [generated]
+ 2020-12-23 fbc82f03b1 [dev.regabi] cmd/compile: split out package noder [generated]
+ 2020-12-23 de454eef5f [dev.regabi] cmd/compile: split out package escape [generated]
+ 2020-12-23 071ab0a14c [dev.regabi] cmd/compile: split out package liveness [generated]
+ 2020-12-23 0ced54062e [dev.regabi] cmd/compile: split out package objw [generated]
+ 2020-12-23 575fd6ff0a [dev.regabi] cmd/compile: split out package inline [generated]
+ 2020-12-23 0256ba99a8 [dev.regabi] cmd/compile: split up typecheck1 [generated]
+ 2020-12-23 b9693d7627 [dev.regabi] cmd/compile: split out package typecheck [generated]
+ 2020-12-23 dac0de3748 [dev.regabi] cmd/compile: move type size calculations into package types [generated]
+ 2020-12-23 527a1895d6 [dev.regabi] cmd/compile: move helpers into package ir [generated]
+ 2020-12-23 65c4c6dfb2 [dev.regabi] cmd/compile: group known symbols, packages, names [generated]
+ 2020-12-23 9ee309255a [dev.regabi] cmd/compile: move helpers into package types [generated]
+ 2020-12-23 ead4957892 [dev.regabi] cmd/compile: move helpers into package base [generated]
+ 2020-12-23 440308ffd7 [dev.regabi] cmd/compile: simplify Nodes usage [generated]
+ 2020-12-23 f9d373720e [dev.regabi] cmd/compile: remove Left, Right etc methods [generated]
+ 2020-12-23 14d667341f [dev.regabi] cmd/compile: remove Node.Left etc [generated]
+ 2020-12-23 6f27d29be0 [dev.regabi] cmd/compile: remove ir.Nod [generated]
+ 2020-12-23 fd6ba1c8a2 os/signal: fix a deadlock with syscall.AllThreadsSyscall() use
+ 2020-12-23 69cf39089f [dev.regabi] cmd/compile: do not die in early base.FlushErrors
+ 2020-12-23 6d03cde88a [dev.regabi] cmd/dist: automatically bootstrap cmd subdirs
+ 2020-12-23 b0b0d98283 runtime: linux iscgo support for not blocking nptl signals
+ 2020-12-23 d1d1099c91 [dev.regabi] cmd/compile: fixes for big rewrite
+ 2020-12-22 223331fc0c cmd/go/internal/modload: add hint for missing implicit dependency
+ 2020-12-22 ec741b0447 [dev.regabi] all: merge master (c9fb4eb) into dev.regabi
+ 2020-12-22 acc32ea124 [dev.regabi] codereview.cfg: add config for dev.regabi
+ 2020-12-22 c9fb4eb0a2 cmd/link: handle grouped resource sections
+ 2020-12-22 c40934b33d [dev.regabi] cmd/compile: adjust one case in walkexpr
+ 2020-12-22 280e7fd1ee [dev.regabi] cmd/compile: only access Func method on concrete types
+ 2020-12-22 51ba53f5c2 [dev.regabi] cmd/compile: separate misc for gc split
+ 2020-12-22 572f168ed2 [dev.regabi] cmd/compile: separate various from Main
+ 2020-12-22 3b12c6dc08 [dev.regabi] cmd/compile: separate typecheck more cleanly
+ 2020-12-22 7c8f5356ab [dev.regabi] cmd/compile: separate dowidth better
+ 2020-12-22 c06a354bcc test: trigger SIGSEGV instead of SIGTRAP in issue11656.go
+ 2020-12-22 0aa9b4709a cmd/pack: r command create output file if not exist
+ 2020-12-22 cb28c96be8 [dev.regabi] cmd/compile,cmd/link: initial support for ABI wrappers
+ 2020-12-22 c8610e4700 [dev.regabi] cmd/compile: add ir.BasicLit to represent literals
+ 2020-12-22 3512cde10a [dev.regabi] cmd/compile: stop reusing Ntype for OSLICELIT length
+ 2020-12-22 2755361e6a [dev.regabi] cmd/compile: change noder.declNames to returns ir.Names
+ 2020-12-22 301af2cb71 [dev.regabi] runtime/race: adjust test pattern match for ABI wrapper
+ 2020-12-22 4d27c4c223 runtime: correct error handling in several FreeBSD syscall wrappers
+ 2020-12-22 9b6147120a cmd/pack: treat compiler's -linkobj output as "compiler object"
+ 2020-12-22 306b2451c8 [dev.regabi] runtime: fix ABI targets in runtime.panic{Index,Slice} shims
+ 2020-12-21 bc7e4d9257 syscall: don't generate ptrace on iOS
+ 2020-12-21 94cfeca0a5 [dev.regabi] cmd/compile: stop using ONONAME with Name
+ 2020-12-21 cb4898a77d [dev.regabi] cmd/compile: simplify declaration importing
+ 2020-12-21 06915ac14d [dev.regabi] cmd/compile: move itabname call out of implements
+ 2020-12-21 6cff874c47 runtime/metrics: add Read examples
+ 2020-12-21 4e8f681eff Merge "[dev.regabi] all: merge master into dev.regabi" into dev.regabi
+ 2020-12-21 1a523c8ab0 [dev.regabi] cmd/compile: separate nowritebarrierrec from main
+ 2020-12-21 e999c17022 [dev.regabi] cmd/compile: separate ssa from other phases
+ 2020-12-21 4836e28ac0 [dev.regabi] cmd/compile: separate noder more cleanly
+ 2020-12-21 85ce6ecfe3 [dev.regabi] cmd/compile: separate exportsym more cleanly
+ 2020-12-21 1a3b036b83 [dev.regabi] cmd/compile: collect global compilation state
+ 2020-12-21 2153a99914 [dev.regabi] cmd/compile: setup to move Addrconst, Patch into cmd/internal/obj
+ 2020-12-21 0bb0baf683 [dev.regabi] cmd/compile: cleanup for concrete types - more
+ 2020-12-21 ca8e17164e [dev.regabi] all: merge master into dev.regabi
+ 2020-12-21 8438a5779b runtime: use _exit on darwin
+ 2020-12-21 cb95819cf6 runtime: detect netbsd netpoll overrun in sysmon
+ 2020-12-21 53c984d976 runtime: skip wakep call in wakeNetPoller on Plan 9
+ 2020-12-21 9abbe27710 test: skip issue11656.go on mips/mips64/ppc64
+ 2020-12-20 89b44b4e2b cmd/compile: recognize reassignments involving receives
+ 2020-12-19 55b58018f4 test: for issue11656 try to execute trap, not call it
+ 2020-12-18 626cc7c02d test: permit "exponent too large" error
+ 2020-12-18 139cd0e12f go/build: make TestDependencies work again
+ 2020-12-18 2de7866470 os: remove dependency on strings package
+ 2020-12-18 c45313bf45 [dev.regabi] cmd/compile: remove prealloc map
+ 2020-12-18 ffb0cb7044 [dev.regabi] cmd/compile: remove uses of Name.Offset, Name.copy
+ 2020-12-18 c76be2a24e [dev.regabi] cmd/compile: add ONAMEOFFSET, delete to-be-deleted fields
+ 2020-12-18 4e8f1e139f [dev.regabi] cmd/compile: cleanup for concrete types - sinit
+ 2020-12-18 27aba22651 [dev.regabi] cmd/compile: cleanup for concrete types - walk
+ 2020-12-18 0b9cb63b8d [dev.regabi] cmd/compile: rename ir.Find to ir.Any and update uses
+ 2020-12-18 ae652a4ac9 os/signal: fix flaky tests for NotifyContext.
+ 2020-12-18 740851baca cmd/link: avoid use of -T when linking with lld
+ 2020-12-18 f1778c28a9 test: recognize and use gc build tag
+ 2020-12-17 8fcf318123 api/go1.16: remove crypto/tls APIs that are moved to Go 1.17
+ 2020-12-17 520f3b72db crypto/tls: revert "add HandshakeContext method to Conn"
+ 2020-12-17 2ff33f5e44 api: promote next to go1.16
+ 2020-12-17 aeedc9f804 [dev.regabi] cmd/compile: remove OSELRECV
+ 2020-12-17 0328c3b660 [dev.regabi] cmd/compile: use OSELRECV2 for all <-c variants
+ 2020-12-17 88e1415d08 [dev.regabi] cmd/compile: add type assertion in regabi test
+ 2020-12-17 9c384e881e [dev.regabi] cmd/compile: cleanup for concrete types - mop-up
+ 2020-12-17 be64c8bece [dev.regabi] cmd/compile: cleanup for concrete types - noder
+ 2020-12-17 5024396563 [dev.regabi] cmd/compile: cleanup for concrete types - subr
+ 2020-12-17 dd67b13d07 [dev.regabi] cmd/compile: cleanup for concrete types - range, select, swt
+ 2020-12-17 42fec2ded4 [dev.regabi] cmd/compile: cleanup for concrete types - const
+ 2020-12-17 389ae3d5ba [dev.regabi] cmd/compile: cleanup for concrete types - inl
+ 2020-12-17 5fe64298a4 [dev.regabi] cmd/compile: cleanup for concrete types - import/export
+ 2020-12-17 aa55d4e54b [dev.regabi] cmd/compile: cleanup for concrete types - escape
+ 2020-12-17 846740c17f [dev.regabi] cmd/compile: cleanup for concrete types - ssa
+ 2020-12-17 bf9bbbd6ed [dev.regabi] cmd/compile: cleanup for concrete types - order
+ 2020-12-17 4ac6a6317b [dev.regabi] cmd/compile: cleanup for concrete types - typecheck
+ 2020-12-17 f6efa3d4a4 [dev.regabi] cmd/compile: simplify ir.Find, replace ir.Inspect with ir.Visit
+ 2020-12-17 f6d2834f8f [dev.regabi] cmd/compile: limit Implicit method to nodes where it is defined
+ 2020-12-17 7fde0d2b50 [dev.regabi] cmd/compile: remove use of Initorder, Offset Node fields for initorder
+ 2020-12-17 114af2a044 [dev.regabi] cmd/compile: change Nodes to be a slice
+ 2020-12-17 4dfc7333f4 [dev.regabi] cmd/compile: update ir/fmt for concrete types
+ 2020-12-17 a997543292 [dev.regabi] cmd/compile: fix potential closure waste in Order
+ 2020-12-17 578fbbe3aa [dev.regabi] cmd/compile: rewrite some generic ir.Nod calls
+ 2020-12-17 5ae70b85c6 [dev.regabi] cmd/compile: cleanup preparing for concrete types, 2
+ 2020-12-17 fa06894b36 [dev.regabi] cmd/compile: cleanup preparing for concrete types
+ 2020-12-17 5a4db102b2 html/template: avoid race when escaping updates template
+ 2020-12-16 b0f01e17f8 go/types: report error for invalid (but empty) expr switch
+ 2020-12-16 5abda2618b cmd/link: handle large relocation addend on darwin/arm64
+ 2020-12-16 a318d56c1e cmd/link: pass arch-specific flags to external linker when testing supported flag
+ 2020-12-16 f4e7a6b905 cmd/internal/goobj: fix buglet in object file reader
+ 2020-12-16 75e16f5127 doc/go1.16: add link to reflect.StructTag
+ 2020-12-16 08b5091d03 net: close connection in localServer teardown
+ 2020-12-16 8981092d71 cmd/link: ignore SEH marking on PE objects
+ 2020-12-15 731bb54038 test: update for gofrontend error message changes
+ 2020-12-15 129bb1917b doc/go1.15: mention 1.15.3 cgo restriction on empty structs
+ 2020-12-15 685a322fe4 test: match gofrontend error messages
+ 2020-12-15 3d6467824c test: only require issue11674 errors with gc compiler
+ 2020-12-15 7cdc84a15b test: remove bug429 (duplicates runtime.TestSimpleDeadlock)
+ 2020-12-15 412dc2f4d3 test: adjust issue11371 to fit in required precision
+ 2020-12-15 8e2d74b705 test: only check for issue11362 error with gc
+ 2020-12-15 f8ac237032 test: import file name for issue19028
+ 2020-12-15 a508840c67 doc/go1.16: fix path, path/filepath release notes
+ 2020-12-15 5046cb8a6e doc/go1.16: fix formatting in net, net/http and net/http/httputil sections
+ 2020-12-15 3298300ddf text/template: error on range over send channel
+ 2020-12-15 4c2d66f642 [dev.regabi] cmd/compile: use ir.Ident for imported identifiers
+ 2020-12-15 305d93ef84 [dev.regabi] cmd/compile: type check externdcl earlier
+ 2020-12-15 9f16620f46 [dev.regabi] cmd/compile: fix latent Sym.SetPkgDef issue
+ 2020-12-15 5a25a3fd1d test: recognize gofrontend error messages
+ 2020-12-14 fea898a4b0 [dev.regabi] cmd/compile: intercept the making of OADDR nodes
+ 2020-12-14 663cd862ed cmd/link: do not mark resource section as writable
+ 2020-12-14 48dfa2b2dc cmd/link: deal with ADDR32NB relocations the same way as ADDR32 on arm
+ 2020-12-14 033390d9ad cmd/link: recognize arm header of PE objects
+ 2020-12-14 48906a6d57 net/http/pprof: don't treat os.Args as format string in Cmdline handler
+ 2020-12-14 6e3cc5c56f go/types: report invalid ... in conversions
+ 2020-12-14 278b9a8a4a io/fs: fix package reference in FS godoc
+ 2020-12-14 617383377f [dev.regabi] cmd/compile: reorg generated array hash loop
+ 2020-12-14 d06794da4a doc/go1.16: add missing <code> tag
+ 2020-12-14 dea6d94a44 math/big: add test for recursive division panic
+ 2020-12-14 2f5b1a3974 test: make a race detector test robust to timing variations
+ 2020-12-14 c81343ce3a net/http: attempt deadlock fix in TestDisableKeepAliveUpgrade
+ 2020-12-14 828746ec57 debug/dwarf: don't try to parse addr/rnglists header
+ 2020-12-14 be10af7c4e test: match gofrontend error messages
+ 2020-12-14 89f38323fa [dev.regabi] cmd/compile: add register ABI analysis utilities
+ 2020-12-14 ce61ccca8f test: match gofrontend error messages
+ 2020-12-14 a58be734ea cmd/compile: fix incorrect shift count type with s390x rules
+ 2020-12-14 8ce37e4110 [dev.regabi] cmd/compile: fix noopt builder
+ 2020-12-14 7e17b46c58 [dev.regabi] cmd/compile/internal/types: add IsScalar query method
+ 2020-12-14 2b76429eb0 [dev.regabi] cmd/compile: refactor type initialization code into helper
+ 2020-12-14 9c5241e520 [dev.regabi] cmd/compile: remove unnecessary String methods
+ 2020-12-14 267975dc47 Merge branch 'master' into dev.regabi
+ 2020-12-14 64d8846aae cmd/go: print hint when 'go install' run without version outside module
+ 2020-12-14 451b6b38fd cmd/go: refactor error reporting in internal/load
+ 2020-12-14 0a02371b05 cmd/compile: set correct type for OpIData
+ 2020-12-11 41d8e61a6b doc: make clear that Go 1.4 is not required for bootstrap
+ 2020-12-11 14305527f6 cmd/compile: fix select statement evaluation order corner case
+ 2020-12-11 1341a3decd cmd/go: add documentation for the -overlay flag
+ 2020-12-11 e508c1c67b cmd/link/internal/loadelf: support additional ELF relocations on mips64
+ 2020-12-11 58e381b0b2 cmd/vet: vendor in x/tools, update structtag vet check
+ 2020-12-10 e012d0dc34 syscall: drop references to Unix epoch in Timeval/Timespec docs
+ 2020-12-10 1fe891a937 doc/go1.16: add vet release note for CL 235677
+ 2020-12-10 6d3d3fb37f doc/go1.16: address some remaining high-level TODOs
+ 2020-12-10 6a64f6dc31 cmd/go: encode backslash and newline in response files
+ 2020-12-10 985d91666c runtime/metrics: add a note about floating-point values to package docs
+ 2020-12-10 e0d20e52ee runtime/metrics: expand Read documention with caveats
+ 2020-12-10 d0f40d2922 runtime/metrics: add ordering line to supported metrics docs
+ 2020-12-10 6d2b3351f6 test: match gofrontend error messages
+ 2020-12-10 e5522c882d std: update golang.org/x/net to 20201209123823-ac852fbbde11
+ 2020-12-10 422dc83baa database/sql: fix typo in comment
+ 2020-12-10 56b783ad94 cmd/go, cmd/asm: pass -linkshared to assembler for shared linkage builds
+ 2020-12-10 b110733327 cmd/link: reject too-large relocation addend on darwin/arm64
+ 2020-12-10 0aba8f24cb cmd/link: truncate file after code signature
+ 2020-12-10 6c64b6db68 cmd/compile: don't constant fold divide by zero
+ 2020-12-09 89f465c2b5 go/types: avoid endless recursion in the Comparable predicate
+ 2020-12-09 f1980efb92 all: update to use os.ReadDir where appropriate
+ 2020-12-09 4f1b0a44cb all: update to use os.ReadFile, os.WriteFile, os.CreateTemp, os.MkdirTemp
+ 2020-12-09 63bc23b545 [dev.regabi] cmd/compile: first start towards using Ident
+ 2020-12-09 eae8fd519b [dev.regabi] cmd/compile: iexport debug crumbs for toolstash
+ 2020-12-09 837b35cc55 [dev.regabi] cmd/compile: adjust IR representations
+ 2020-12-09 0c49440664 [dev.regabi] cmd/compile: arrange for walkstmt, walkexpr, to return from switch cases
+ 2020-12-09 4090af83c5 [dev.regabi] cmd/compile: use reflection in ir.Dump
+ 2020-12-09 e2d278bfeb [dev.regabi] cmd/compile: two small fixes
+ 2020-12-09 5627a4dc30 runtime/metrics: simplify test to support more environments
+ 2020-12-09 db6032dd0c cmd/compile: fix message typo
+ 2020-12-09 854a2f8e01 net/http: add connections back that haven't been canceled
+ 2020-12-09 6fa06d960b runtime: prevent stack growth after fork in runtime.sigfillset
+ 2020-12-09 ae9b442df2 doc: add description of new framepointer vet check
+ 2020-12-08 31496cfde5 cmd/vet: vendor in x/tools, enable framepointer vet check
+ 2020-12-08 01b76d5fbc go/types: correct error position for inherited const init expressions
+ 2020-12-08 48d6275952 doc/go1.16: improve channel race detector changes description
+ 2020-12-08 dbf2fc8cff [dev.regabi] cmd/compile: replace many uses of ir.Node with *ir.Name
+ 2020-12-08 bb31c75343 [dev.regabi] cmd/compile: ir.Node is no longer an ssa.Aux
+ 2020-12-08 6db970e20a [dev.regabi] cmd/compile: rewrite Aux uses of ir.Node to *ir.Name [generated]
+ 2020-12-08 1c8943a6ad [dev.regabi] cmd/compile: introduce FwdRefAux for wrapping ir.Node as ssa.Aux
+ 2020-12-08 9c91cab0da runtime: correct sigfwd on openbsd/mips64
+ 2020-12-08 dcec658f6c [dev.regabi] cmd/compile: change LocalSlot.N to *ir.Name
+ 2020-12-08 1a98ab0e2d [dev.regabi] cmd/compile: add ssa.Aux tag interface for Value.Aux
+ 2020-12-07 6362d01c15 doc/go1.16: update linker stats
+ 2020-12-07 9b8c272558 reflect: document multiple keys in struct tags
+ 2020-12-07 63722da46b [dev.regabi] cmd/compile: fix comment
+ 2020-12-07 7ad6596c47 io/fs: fix Sub method error text
+ 2020-12-07 6d783e7440 [dev.regabi] cmd/compile: export all Node fields [generated]
+ 2020-12-07 2de0af3b1b [dev.regabi] cmd/compile: prepare mknode for rename of Func.body
+ 2020-12-07 724374f859 [dev.regabi] cmd/compile: rewrite stale format strings
+ 2020-12-07 61889ba680 [dev.regabi] cmd/compile: simplify fmtmap
+ 2020-12-07 6ea2b8c54c [dev.regabi] cmd/compile: clean up and document formatting
+ 2020-12-07 bb4a37bd93 [dev.regabi] cmd/compile: move Type, Sym printing to package types [generated]
+ 2020-12-07 70155cca81 [dev.regabi] cmd/compile: untangle FmtFlag, FmtMode
+ 2020-12-07 3904a62829 [dev.regabi] cmd/compile: remove mode.Sprintf etc in printer
+ 2020-12-07 fb17dfa43d [dev.regabi] cmd/compile: narrow interface between ir and types
+ 2020-12-07 3b25f3c150 [dev.regabi] cmd/compile: simplify Op, Node, Nodes printing
+ 2020-12-07 8ce2605c5b [dev.regabi] cmd/compile: untangle ir.Dump printing
+ 2020-12-07 158c9dd131 [dev.regabi] cmd/compile: reorganize ir/fmt.go
+ 2020-12-07 a79742f39a [dev.regabi] cmd/compile: remove "short" node header mode
+ 2020-12-07 ef5964dd6b [dev.regabi] cmd/compile: arrange for typecheck1 to end in switch
+ 2020-12-07 dcc640e839 [dev.regabi] test: add exhaustive test of evaluated but not used
+ 2020-12-07 2cec6c4a8c [dev.regabi] cmd/compile: generate Node methods using program
+ 2020-12-07 50cdb2d8e9 runtime/cgo: fix building on musl
+ 2020-12-07 8d34585171 doc/go1.16: announce openbsd/mips64 port
+ 2020-12-07 9c0e2db051 test: add new test that gofrontend failed to handle
+ 2020-12-07 7f9a2bc2bc doc/go1.16: fix typo
+ 2020-12-07 ac0ba6707c doc/go1.16: add missing </a> tag
+ 2020-12-07 c155931974 internal/cpu: add darwin/arm64 CPU feature detection support
+ 2020-12-07 d90b199e9c [dev.regabi] cmd/compile: silence errors about missing blank methods
+ 2020-12-07 e10c94af26 doc/go1.16: document riscv64 port changes
+ 2020-12-06 e885df2731 [dev.regabi] cmd/compile: change iexport to avoid map[ir.Node]
+ 2020-12-06 2d4c95565a [dev.regabi] cmd/compile: change nowritebarrierrec to use map[*ir.Func]
+ 2020-12-06 1b5eed8982 [dev.regabi] cmd/compile: replace NodeQueue with NameQueue
+ 2020-12-06 6c5967e528 [dev.regabi] cmd/compile: change NodeSet to NameSet
+ 2020-12-05 3b2a578166 internal/cpu: fix typo in cpu_arm64.go
+ 2020-12-05 be9379f8a8 syscall: correct CertOpenStore to expect a 0 return value on failure
+ 2020-12-04 4de4480dc3 doc/go1.16: cleanup crypto release notes
+ 2020-12-04 0b99ea3b16 cmd/vendor: sync pprof@v0.0.0-20201203190320-1bf35d6f28c2
+ 2020-12-04 46b6e70e3b [dev.regabi] cmd/compile: replace ir.Node with *ir.Name in Order
+ 2020-12-04 b75f51c645 [dev.regabi] cmd/compile: replace ir.Node with *ir.Name in Liveness
+ 2020-12-04 133b03e1c3 [dev.regabi] cmd/compile: rewrite code to use DeclaredBy
+ 2020-12-04 d9cb84c84b [dev.regabi] cmd/compile: add SameSource, Uses, and DeclaredBy helpers
+ 2020-12-04 edf60be151 doc/go1.16: document no language changes
+ 2020-12-04 5dbd2e8e44 [dev.regabi] cmd/compile: remove DeepCopyNode interface
+ 2020-12-04 9ab3d854ad [dev.regabi] cmd/compile: avoid general traversal in deadcode
+ 2020-12-04 bb5aa2b664 [dev.regabi] cmd/compile: implement editChildren for nodes
+ 2020-12-04 4725c3ffd1 [dev.regabi] cmd/compile: implement doChildren for nodes
+ 2020-12-04 18f2df7e81 [dev.regabi] cmd/compile: implement copy for nodes
+ 2020-12-04 d855b30fe4 [dev.regabi] cmd/compile: use ir.EditChildren for inline rewriting
+ 2020-12-04 b9df26d7a8 [dev.regabi] cmd/compile: use ir.Find for "search" traversals
+ 2020-12-04 0d1b44c645 [dev.regabi] cmd/compile: introduce IR visitors
+ 2020-12-04 7fcf5b994c [dev.regabi] cmd/compile: replace inlcopy with ir.DeepCopy
+ 2020-12-04 989a3f5041 [dev.regabi] cmd/compile: adjustments to Copy and DeepCopy
+ 2020-12-04 99ecfcae31 [dev.regabi] cmd/compile: swap inlining order of if then vs else blocks
+ 2020-12-04 478bde3a43 io/fs: add Sub
+ 2020-12-04 5d4569197e cmd/go/internal/modload: fix minor errors in comments
+ 2020-12-04 21cfadf0dc runtime: avoid receiving preemotion signal while exec'ing
+ 2020-12-04 7358064508 doc/go1.16: preannounce dropping macOS 10.12 support
+ 2020-12-04 37588ffcb2 cmd/go, embed: exclude .* and _* from embedded directory trees
+ 2020-12-04 b67b7ddabc doc/go1.16: add reflect changes to release notes
+ 2020-12-04 cc386bd05a doc/go1.16: fix broken <code> tag
+ 2020-12-04 84cb51d7d7 [dev.regabi] cmd/compile: eliminate more SetOrig
+ 2020-12-04 2c2980aa0c doc/go1.16: pre-announce GODEBUG=x509ignoreCN=0 removal in Go 1.17
+ 2020-12-03 37a32a1833 cmd/compile: make sure address of offset(SP) is rematerializeable
+ 2020-12-03 b78b427be5 runtime, time: strictly enforce when, period constraints
+ 2020-12-03 b635e4b808 time, runtime: don't set timer when = 0
+ 2020-12-03 4eb7ceba06 doc/go1.16: update runtime and compiler sections
+ 2020-12-03 bacb307b80 test: match gofrontend error messages
+ 2020-12-03 7f5a3196c9 cmd/go/internal/modload: rename constants to reflect that lazy loading is not yet implemented
+ 2020-12-03 351bc2f38c [dev.regabi] cmd/compile: store types.Field on {Selector,CallPart}Expr
+ 2020-12-03 bdc9a837e9 doc/go1.16: add path, path/filepath changes to release notes
+ 2020-12-03 9b0e8a2c95 doc/go1.16: tidy darwin/arm64 port section
+ 2020-12-03 b1369d5862 math/big: remove the s390x assembly for shlVU and shrVU
+ 2020-12-03 a2058bac21 [dev.regabi] cmd/compile: add ConstExpr
+ 2020-12-03 beb5e05404 [dev.regabi] cmd/compile: refactoring prep for ConstExpr
+ 2020-12-03 7e81135be7 [dev.regabi] cmd/compile: rename addinit(n, init) to initExpr(init, n)
+ 2020-12-03 6e30fc10fc [dev.regabi] all: merge master (d0c0dc682c1f) into dev.regabi
+ 2020-12-03 dda2991c2e internal/cpu: disable FMA when OSXSAVE is not enabled on x86
+ 2020-12-03 58768ae15b test: match gccgo error messages
+ 2020-12-03 59b8916d48 [dev.regabi] cmd/compile: handle OCONVNOP better in ssa
+ 2020-12-03 932733d421 doc/go1.16: document embed, io/fs, runtime/metrics
+ 2020-12-03 c519b156fc doc/go1.16: more release notes
+ 2020-12-03 5246fa5e75 mime/multipart: handle ReadForm(math.MaxInt64) better
+ 2020-12-03 07cba70d57 cmd/compile, runtime: use __msan_memmove for moving data, split msanread to fields
+ 2020-12-03 d0c0dc682c doc/go1.16: document os package changes
+ 2020-12-03 00e5727790 [dev.regabi] cmd/compile: remove okAs
+ 2020-12-03 5a3b6796cd [dev.regabi] cmd/compile: remove extra typ field in Name struct
+ 2020-12-03 da54dfb6a1 doc/go1.16: document new behavior of asn1.Unmarshal on invalid argument
+ 2020-12-03 78e442ea79 doc/go1.16: add encoding/json note for tag change
+ 2020-12-02 f26f227f66 doc/go1.16: add crypto/tls Config.Clone note
+ 2020-12-02 64bc656aed [dev.regabi] cmd/compile: use explicit block statements for init
+ 2020-12-02 48838c35dc go/parser: ignore subdirectories in ParseDir
+ 2020-12-02 2d0258d495 crypto/ed25519/internal/edwards25519: fix typo in comments
+ 2020-12-02 ecc8d15bc5 [dev.regabi] cmd/compile: delete OEMPTY
+ 2020-12-02 ec5f349b22 [dev.regabi] cmd/compile: merge OBLOCK and OEMPTY
+ 2020-12-02 05ddb879c7 cmd/go: fix TestNewReleaseRebuildsStalePackagesInGOPATH
+ 2020-12-02 ac38af2f3d cmd/go: stop tests from using network during -short
+ 2020-12-02 3d913a9266 os: add ReadFile, WriteFile, CreateTemp (was TempFile), MkdirTemp (was TempDir) from io/ioutil
+ 2020-12-02 5984ea7197 doc: update signal.Notify example to use buffered channel
+ 2020-12-02 10240b9d6b cmd/go: fix unbuffered channel passed to signal.Notify
+ 2020-12-02 c32140fa94 all: update to use filepath.WalkDir instead of filepath.Walk
+ 2020-12-02 0433845ad1 cmd/asm, cmd/internal/obj/riscv: fix branch pseudo-instructions
+ 2020-12-02 c769d393de [dev.regabi] cmd/compile: add ir.NewDeclNameAt
+ 2020-12-02 c10b0ad628 [dev.regabi] cmd/compile: add Pkg parameter to type constructors
+ 2020-12-02 42e46f4ae0 [dev.regabi] cmd/compile: comment out //go:linkname warning
+ 2020-12-02 77a71e0057 [dev.regabi] cmd/compile: add Interface, Signature, and Struct constructors
+ 2020-12-02 15085f8974 [dev.regabi] cmd/compile: tweak hash bucket type descriptor
+ 2020-12-02 73e796cb00 test: match gofrontend error messages
+ 2020-12-01 cf7aa585ac cmd/link: invalidate kernel cache on darwin
+ 2020-12-01 8cd35e00bd cmd/internal/buildid: update Mach-O code signature when rewriting buildid
+ 2020-12-01 6f84993e90 cmd/link: code-sign on darwin/arm64
+ 2020-12-01 4826abb6c2 cmd/compile: do not assume TST and TEQ set V on arm
+ 2020-12-01 283d65413d encoding/json: revert "add "json: " prefix to SyntaxError messages"
+ 2020-12-01 1408d26ccc [dev.regabi] cmd/compile: cleanup some leftover cruft
+ 2020-12-01 7fca39aa05 cmd/internal/buildid: exclude Mach-O code signature in hash calculation
+ 2020-12-01 7430266af4 cmd/internal/codesign: new package
+ 2020-12-01 20e251864b cmd: update golang.org/x/mod to v0.4.0
+ 2020-12-01 933ce97bba cmd/go: don't print deprecation notice for 'go get exe'
+ 2020-12-01 50b16f9de5 net/http: allow upgrading non keepalive connections
+ 2020-12-01 212d385a2f net/http: ignore connection closes once done with the connection
+ 2020-12-01 4ef78b09c9 doc/go1.16: add runtime/debug changes to release notes
+ 2020-12-01 ae3bfba626 doc/go1.16: add text/template changes to release notes
+ 2020-12-01 5ffa275f3c [dev.regabi] cmd/compile: first pass at abstracting Type
+ 2020-12-01 dd4a52c2a5 doc/go1.16: add multiple release notes for the go command
+ 2020-12-01 6ca23a45fe [dev.regabi] cmd/compile: only save ONAMEs on Curfn.Dcl
+ 2020-12-01 a17c5e2fce [dev.regabi] cmd/compile: add NewBasic and cleanup universe
+ 2020-12-01 f37aa5e4e2 [dev.regabi] cmd/compile: add NewNamed
+ 2020-12-01 63a6f08b39 [dev.regabi] cmd/compile: move setUnderlying to package types
+ 2020-12-01 f2311462ab [dev.regabi] cmd/compile: cleanup type-checking of defined types
+ 2020-12-01 2d6ff998ed [dev.regabi] cmd/compile: process //go:linknames after declarations
+ 2020-12-01 ecff7628ea [dev.regabi] cmd/compile: unexport Node.RawCopy
+ 2020-12-01 4da41fb3f8 [dev.regabi] cmd/compile: use ir.Copy instead of direct use of RawCopy
+ 2020-12-01 dadfc80bc1 [dev.regabi] cmd/compile: improve findTypeLoop
+ 2020-12-01 f5978a0958 cmd/internal/obj/riscv: add tests for BGE/BGEU/BLT/BLTU
+ 2020-12-01 a36ba090fd cmd/link/internal/amd64: always generate R_X86_64_PLT32 for SDYNIMPORT calls
+ 2020-12-01 f3741bdf7c doc/go1.16: add crypto/x509 note about Verify on Windows
+ 2020-12-01 45f3b646d4 [dev.regabi] cmd/compile: add OSTMTEXPR Op
+ 2020-12-01 9a5a11adfa [dev.regabi] cmd/compile: add custom expression Node implementations
+ 2020-12-01 0ecf769633 cmd/compile: do not mark OpSP, OpSB pos for debugging
+ 2020-12-01 0f9f27287b [dev.regabi] cmd/compile: remove types.InitSyms
+ 2020-11-30 41ad4dec99 [dev.regabi] cmd/compile: fix -h
+ 2020-11-30 ffa68716a0 [dev.regabi] cmd/compile: add custom statement Node implementations
+ 2020-11-30 2bc814cd18 [dev.regabi] cmd/compile: clean up ONEW node
+ 2020-11-30 b7f67b75d2 [dev.regabi] cmd/compile: clean up in preparation for expression Nodes
+ 2020-11-30 5fc192af56 [dev.regabi] cmd/compile: clean up Order.copyExpr TODO
+ 2020-11-30 7c9b6b1ca2 [dev.regabi] cmd/compile: clean up in preparation for statement Nodes
+ 2020-11-30 7f688d18c0 runtime: mlock signal stack on macOS/ARM64
+ 2020-11-30 c6de5d8d1f [dev.regabi] cmd/compile: simplify export data representation of nil
+ 2020-11-30 d2b436d95d cmd/go: fix infinite loop in modload.keepSums
+ 2020-11-30 4f42a9b76b net: add note about disabling loopback in ListenMulticastUDP()
+ 2020-11-30 7b192f33cf cmd/go: remove trailing whitespace from test script
+ 2020-11-30 848dff6dda test: update gofrontend expected errors
+ 2020-11-30 a45e12fd4b test: recognize gofrontend error messages
+ 2020-11-30 d6abf298cf test: recognize new gofrontend error message
+ 2020-11-30 ae1a337809 [dev.regabi] cmd/compile: remove ODCLFIELD and ODDD ops
+ 2020-11-30 4e7685ef1a [dev.regabi] cmd/compile: add custom type syntax Node implementations
+ 2020-11-30 d40869fced [dev.regabi] cmd/compile: move gc.treecopy to ir.DeepCopy
+ 2020-11-30 f0001e8867 [dev.regabi] cmd/compile: add OTSLICE Op
+ 2020-11-30 1b84aabb01 [dev.regabi] cmd/compile: move typenod, typenodl to ir.TypeNode, ir.TypeNodeAt [generated]
+ 2020-11-30 e5c6463e20 [dev.regabi] cmd/compile: add ir.CallPartExpr
+ 2020-11-30 4eaef981b5 [dev.regabi] cmd/compile: add ir.Closure, ir.ClosureRead
+ 2020-11-30 e84b27bec5 [dev.regabi] cmd/compile: clean up Name and Func uses
+ 2020-11-30 c4bd0b7474 [dev.regabi] cmd/compile: make ir.Func the ODCLFUNC Node implementation
+ 2020-11-30 65ae15ac5d [dev.regabi] cmd/compile: move func code from node.go to func.go
+ 2020-11-30 862f638a89 [dev.regabi] cmd/compile: make ir.Name the ONAME Node implementation
+ 2020-11-30 f6106d195d [dev.regabi] cmd/compile: add ir.PkgName
+ 2020-11-30 420809ab08 [dev.regabi] cmd/compile: move name code from node.go to name.go
+ 2020-11-30 be3d8b40b5 [dev.regabi] cmd/compile: ir.BranchStmt, add ir.EmptyStmt, ir.LabelStmt
+ 2020-11-30 b09dbc6913 [dev.regabi] cmd/compile: remove SetOp(OEMPTY) calls
+ 2020-11-30 171787efcd [dev.regabi] cmd/compile: remove Orig, SetOrig from Node interface
+ 2020-11-30 79a3d5ce15 [dev.regabi] cmd/compile: setup for new Node implementations
+ 2020-11-30 0c65a2f317 [dev.regabi] cmd/compile: drop Node.HasOpt method
+ 2020-11-30 65f4ec2fae [dev.regabi] cmd/compile: cleanup label handling
+ 2020-11-30 c193279e2c os: return proper user directories on iOS
+ 2020-11-30 294c214cca runtime: gofmt
+ 2020-11-30 e5da18df52 os/exec: constrain thread usage in leaked descriptor test on illumos
+ 2020-11-28 4ce0a7cea6 runtime/pprof: ignore test failures on windows/arm
+ 2020-11-28 358d35455d bufio: make string(int) conversion safer
+ 2020-11-28 b94346e69b test: match gofrontend error messages
+ 2020-11-27 cb84d831c9 cmd/link: mark windows/arm as all PIE
+ 2020-11-27 0252cfd84d runtime: adjust address calculation in identifying abort on windows/arm
+ 2020-11-27 91f77ca2f8 runtime: return 0 from C function in test
+ 2020-11-26 926994fd7c log: make Default doc comment consistent with package doc
+ 2020-11-26 f0ff6d4a67 reflect: fix Value.Convert for int-to-string conversions (regression)
+ 2020-11-25 88e33f6ecb [dev.regabi] cmd/compile: fix latent import/export issue with break/continue
+ 2020-11-25 40f5bc4d55 [dev.regabi] merge master 4481ad6eb6 into dev.regabi
+ 2020-11-25 4481ad6eb6 doc/go1.16: consolidate stdlib changes in "Minor changes" section
+ 2020-11-25 ef603bead5 cmd/dist: restore GOARM=7 default for android/arm
+ 2020-11-25 41f3af9d04 [dev.regabi] cmd/compile: replace *Node type with an interface Node [generated]
+ 2020-11-25 4d0d9c2c5c [dev.regabi] cmd/compile: introduce ir.INode interface for *ir.Node
+ 2020-11-25 c26aead50c [dev.regabi] cmd/compile: convert types.Node (a pointer) to types.IRNode (an interface)
+ 2020-11-25 acb4d1cef1 [dev.regabi] cmd/compile: use Node getters and setters [generated]
+ 2020-11-25 41ab6689ed [dev.regabi] cmd/compile: rewrite a few ++/--/+=/-= to prep for getters/setters [generated]
+ 2020-11-25 048debb224 [dev.regabi] cmd/compile: remove gc ↔ ssa cycle hacks
+ 2020-11-25 84e2bd611f [dev.regabi] cmd/compile: introduce cmd/compile/internal/ir [generated]
+ 2020-11-25 331b8b4797 [dev.regabi] cmd/compile: move okforconst into its own declaration
+ 2020-11-25 26b66fd60b [dev.regabi] cmd/compile: introduce cmd/compile/internal/base [generated]
+ 2020-11-25 eb3086e5a8 [dev.regabi] cmd/compile: finish cleanup of Debug parsing
+ 2020-11-25 3c240f5d17 [dev.regabi] cmd/compile: clean up debug flag (-d) handling [generated]
+ 2020-11-25 9dc2350d8c doc/go1.16: add time/tzdata release note for CL 261877
+ 2020-11-25 756661c82a [dev.regabi] cmd/compile: finish cleanup of Flag initialization
+ 2020-11-25 b9365488f0 cmd/internal/objabi: assume GOARM=7 on Android
+ 2020-11-25 df68e01b68 runtime: check channel's elemsize before calling race detector
+ 2020-11-25 259fd8adbb [dev.regabi] cmd/compile: fix reporting of overflow
+ 2020-11-25 1d3baf20dc regexp/syntax: add note about Unicode character classes
+ 2020-11-25 18573aea3c [dev.regabi] cmd/compile: clean up flag handling [generated]
+ 2020-11-25 6e583d65ab [dev.regabi] cmd/compile: simplify fmt handling of Nodes
+ 2020-11-25 d166ef6876 [dev.regabi] cmd/compile: add Node field getters and setters
+ 2020-11-25 750b3729dc go/constant: MakeFloat64(0) must return a value of Float kind
+ 2020-11-25 9262909764 [dev.regabi] cmd/compile: rewrite problematic use of Node fields
+ 2020-11-25 9e0e43d84d [dev.regabi] cmd/compile: remove uses of dummy
+ 2020-11-25 4a6b4fd139 [dev.regabi] add FatalfAt and fix Fatalf docs
+ 2020-11-25 484449c641 [dev.regabi] cmd/compile: remove file mistakenly added by CL 272248
+ 2020-11-25 1308f11897 cmd/link: add relocation type R_AARCH64_LDST16_ABS_LO12_NC for arm64
+ 2020-11-25 f6dcc975f7 go/constant: make constant.Make produce "smallest" const representation
+ 2020-11-25 7d72951229 [dev.regabi] cmd/compile: replace Val with go/constant.Value
+ 2020-11-24 e8de596f04 runtime: use inlined function name for traceback elision
+ 2020-11-24 ba2adc21e8 runtime/testdata/testprogcgo: refactor CrashTraceback
+ 2020-11-24 6826287c6b [dev.regabi] cmd/compile: replace evconst with non-mutating version
+ 2020-11-24 c22bc745c3 [dev.regabi] cmd/compile: delete n.List after collapsing OADDSTR to OLITERAL
+ 2020-11-24 ee6132a698 [dev.regabi] cmd/compile: introduce OMETHEXPR instead of overloading ONAME
+ 2020-11-24 4f9d54e41d [dev.regabi] cmd/compile: add OMETHEXPR
+ 2020-11-24 fd11a32c92 [dev.regabi] cmd/compile: clean up Node.Func
+ 2020-11-24 8e2106327c [dev.regabi] cmd/compile: clean up tests to know less about Node
+ 2020-11-24 65dcd15c72 doc/go1.16: fill in Go 1.16 release note TODOs using relnote
+ 2020-11-24 742c05e3bc [dev.regabi] cmd/compile: prep refactoring for switching to go/constant
+ 2020-11-24 015423a15b [dev.regabi] strconv: add to bootstrap packages
+ 2020-11-24 c767d73227 [dev.regabi] cmd/compile: remove CTRUNE
+ 2020-11-24 6dae48fb0b [dev.regabi] cmd/compile: refactor type/value assertions
+ 2020-11-24 88a9e2f9ad [dev.regabi] cmd/compile: replace CTNIL with ONIL
+ 2020-11-24 4af2decf30 [dev.regabi] cmd/compile: add (unused) ONIL constant
+ 2020-11-24 668e3a598f [dev.regabi] cmd/compile: cleanup type switch typechecking
+ 2020-11-24 96f3fb7244 [dev.regabi] go/constant: avoid heap allocations in match
+ 2020-11-24 1abb12fc97 [dev.regabi] go/constant: optimize BitLen
+ 2020-11-24 228b732ad9 [dev.regabi] cmd/compile: prepare for package ir
+ 2020-11-24 e37597f7f0 [dev.regabi] cmd/compile: rename a few 'base' identifiers
+ 2020-11-24 357c576878 [dev.regabi] cmd/compile: clean up error API
+ 2020-11-24 5fd949e4bd [dev.regabi] cmd/compile: initialize importMap lazily
+ 2020-11-24 7b144ed4f7 [dev.regabi] cmd/compile: rewrite concurrentFlagOk to be clearer
+ 2020-11-24 6965b01ea2 runtime: allow for usleep2HighRes to run without TLS setup
+ 2020-11-24 7dc5d909fb cmd/compile: set OpLoad argument type interface{} correctly
+ 2020-11-24 c754f25241 [dev.regabi] cmd/compile/internal/types: remove Func.Nname
+ 2020-11-24 c50c7a8c06 [dev.regabi] cmd/compile/internal/gc: refactor to use stop using Func.Nname
+ 2020-11-24 d5928847de [dev.regabi] cmd/compile/internal/gc: prep for Func.Nname removal refactoring
+ 2020-11-24 b30c7a8044 [dev.regabi] cmd/compile/internal/gc: add MethodName for getting referenced method
+ 2020-11-24 e1047302bd [dev.regabi] cmd/compile/internal/types: add pos/sym/typ params to NewField
+ 2020-11-24 762eda346a go/types: fix incorrect string(int) conversion (regression)
+ 2020-11-23 48a1a51898 runtime/metrics: tweak wording of stack and unused memory metrics
+ 2020-11-23 d902791b50 sync: use 386 instead of x86-32 to refer to the 32 bit x86 architecture
+ 2020-11-21 9ea6364a5e cmd/compile: add test for 42753
+ 2020-11-21 f7342596da syscall: add DLLError.Unwrap function
+ 2020-11-21 f93ef07b11 cmd/go/internal/modload: remove the Reqs function
+ 2020-11-21 3f5a97514b cmd/go/internal/modload: remove a stale comment for EditBuildList
+ 2020-11-20 78e59bb1f7 cmd/go: support the -overlay flag for go mod commands
+ 2020-11-20 c47eac7db0 cmd/cgo, cmd/internal/pkgpath: support gofrontend mangler v3
+ 2020-11-20 3fd4917472 doc: fix misspelling of “initialization” in diagnostics.html
+ 2020-11-20 676f0a45ed cmd/go: support overlaying go.mod files
+ 2020-11-20 a19c925eda cmd/go: recommend 'go get' command to switch from retracted versions
+ 2020-11-20 c306fd6d0b cmd/compile: allow loading single field of typed-interface{} OpIData
+ 2020-11-20 5e58ae43be cmd/go: report changes and resolved versions in 'go get'
+ 2020-11-20 012efc67f2 cmd/go/internal/modload: ignore selected version in checkRetractions
+ 2020-11-20 9264067a41 cmd/go: remove ListModules call in runGet
+ 2020-11-20 cb3f84ad25 cmd/go/internal/modload: eliminate LoadedModules
+ 2020-11-20 8bbd8294d0 cmd/go/internal/work: remove a redundant call to modload.LoadedModules
+ 2020-11-20 66c0264506 net, internal/poll: reset value before adding in minor kernel version
+ 2020-11-20 0dcc7d6ea8 go/types: use correct error position
+ 2020-11-20 c72a448881 go/types: fix error message for consistency
+ 2020-11-20 7eed73f36f go/types, go/constant: handle infinities as unknown values
+ 2020-11-19 f3ce010b33 io/fs: make WalkDirFunc parameter name consistent with doc comment
+ 2020-11-19 59f5fdac5d runtime/metrics: clarify Read's documentation
+ 2020-11-19 add45938b5 runtime/metrics: clarify memory and GC metrics documentation
+ 2020-11-19 498d8d5371 cmd/go/internal/work: avoid modload.Selected in 'go install pkg@version'
+ 2020-11-19 e73697b710 cmd/go: fix failing gccgo cases in TestScript/build_overlay
+ 2020-11-19 cb674b5c13 cmd/compile,cmd/asm: fix function pointer call perf regression on ppc64
+ 2020-11-19 c31540364c cmd/compile: flag "-d=dumpptrs" to print Node ptrs in Dump output
+ 2020-11-19 4d048194cd runtime: support new callbackasm1 calling convention on windows/arm
+ 2020-11-19 5ba1c3f290 cmd/go/internal/modload: remove SetBuildList
+ 2020-11-19 ff2824d4b3 cmd/go/internal/modcmd: eliminate a call to modload.LoadedModules
+ 2020-11-19 0bb6115dd6 internal/fmtsort: sort the unsafe pointers in map
+ 2020-11-19 96b943a483 go/types: report an error for invalid constant values
+ 2020-11-18 35693d037f cmd/compile: fix miscompilation during inlining
+ 2020-11-18 5b0ec1a6ac cmd/compile: fix panic in field tracking logic
+ 2020-11-18 b4f3d52f6a sync: document RWMutex race semantics
+ 2020-11-18 b63db7f724 runtime: give test child time to block
+ 2020-11-18 ae76f6e962 runtime: use clock_gettime instead of gettimeofday on darwin
+ 2020-11-18 ee1b51294a runtime: use pipe2 syscall for Pipe in tests
+ 2020-11-18 d3072b8383 cmd/go: in 'go get', only load retractions for resolved versions
+ 2020-11-18 b194b5151f cmd/link: recompute heapPos after copyHeap
+ 2020-11-18 64ef84881f cmd/go: fix retract interval syntax in 'go help mod edit'
+ 2020-11-18 399b5d14d4 cmd/compile: stop MOVW-ing -1 as SRA shift amount in mips
+ 2020-11-18 a14e7bf6d4 go/ast: document invalid comment end positions with CRLF line endings
+ 2020-11-18 bcfaeca58c time: in NewTicker, document that the 1st tick comes after d
+ 2020-11-17 041a4e4c34 go/types: add test case for incorrect map index expression
+ 2020-11-17 05082c90d5 cmd/compile: clean up buggy DWARF inlined info PC ranges
+ 2020-11-17 01df2febf5 cmd/go: allow querying other versions of the main module
+ 2020-11-17 0968d2d599 cmd/go/internal/modget: clarify error for 'go get' without arguments
+ 2020-11-17 3e56bad13b cmd/go: revert "in 'go get', only load retractions for resolved versions"
+ 2020-11-17 0ae3b7cb74 cmd/compile: fix rules regression with shifts on PPC64
+ 2020-11-16 869e2957b9 cmd/go: update 'go help mod init'
+ 2020-11-16 97700baf8b cmd/go: in 'go get', only load retractions for resolved versions
+ 2020-11-16 38367d098e cmd/link/internal/ld: dedup shared libraries on openbsd
+ 2020-11-16 d834ecec86 runtime/race: reject runtime fatal error in tests
+ 2020-11-16 0932dc2118 runtime: declare arg size/map for race version of sync/atomic functions
+ 2020-11-16 d70a33a40b cmd/go/internal/work: add missing newline to go version note
+ 2020-11-16 c7233dd063 cmd/go: permit wrongly rejected -Wl,-O... linker flags
+ 2020-11-16 f2eea4c1dc cmd/compile: mask SLL,SRL,SRAconst shift amount
+ 2020-11-14 92c732e901 cmd/compile: fix load of interface{}-typed OpIData in expand_calls
+ 2020-11-14 782cf560db cmd/go: permit CGO_LDFLAGS to appear in //go:ldflag
+ 2020-11-13 4f63e0a1f8 cmd/compile: update comments only for Node types and some functions
+ 2020-11-13 86954d5246 cmd/compile: mark plugin-exported types as used in interface
+ 2020-11-13 f423d616b1 cmd/cgo: fix initialization of empty argument types
+ 2020-11-13 35455fff0e runtime: swap the order of raceacquire() and racerelease()
+ 2020-11-13 31f71506d7 syscall: use correct type for TIOCSPGRP/TIOCGPGRP
+ 2020-11-12 30ba798093 cmd/go: use overlaid path contents in build cache
+ 2020-11-12 f016172dbe cmd/go: pass in overlaid paths for .s files
+ 2020-11-12 60b1253293 cmd/go: pass in overlaid file paths to C compiler
+ 2020-11-12 062e0e5ce6 cmd/go, cmd/cgo: don't let bogus symbol set cgo_ldflag
+ 2020-11-12 1e1fa5903b math/big: fix shift for recursive division
+ 2020-11-12 b34b0aaf69 cmd/go: skip TestScript/build_plugin_non_main on platforms that do not support -buildmode=plugin
+ 2020-11-12 c167635a6e cmd/compile: gofmt
+ 2020-11-12 e75aef80ca cmd/go: migrate away from semver.Max
+ 2020-11-12 9ef65ff137 cmd/compile: do not emit an extra debug_line entry for the end of seq addr
+ 2020-11-12 4bc5f6f45f cmd/link: put DYLD_INFO at beginning of LINKEDIT segment on darwin
+ 2020-11-12 d7974c31d0 os: gofmt
+ 2020-11-11 141fa337ad bytes: add example for (*Buffer).Bytes
+ 2020-11-11 f2e58c6d42 syscall: improve TestSetuidEtc() /proc/ parsing against races
+ 2020-11-11 4c174a7ba6 testing: reduce memory allocation in Helper
+ 2020-11-11 b641f0dcf4 os: clarify that IsExist and friends do not use errors.Is
+ 2020-11-11 26a860706a doc/go1.16: add crypto/x509 CSR release note
+ 2020-11-11 28437546f4 cmd/go: don't copy cgo files to objdir when overlay is present
+ 2020-11-11 c906608406 io/fs: fix reference to WalkFunc
+ 2020-11-11 f2e186b877 all: update vendored dependencies for Go 1.16 release
+ 2020-11-10 8f2db14cd3 cmd/go: release note for -mod=readonly by default
+ 2020-11-10 b2ef159db2 cmd/go: introduce the GOVERSION env variable
+ 2020-11-10 1948c00b6e doc/go1.16: add release notes for darwin ports
+ 2020-11-10 da3957ad0d Revert "cmd/go: don't copy cgo files to objdir when overlay is present"
+ 2020-11-10 0e0a872a76 runtime: add lock rank partial order edge pollDesc -> spanSetSpine
+ 2020-11-10 c68745b130 runtime: add lock rank partial order edge sweep -> mspanSpecial
+ 2020-11-10 e3de852f3e cmd/go: don't copy cgo files to objdir when overlay is present
+ 2020-11-10 189931296f cmd/internal/obj/s390x: fix SYNC instruction encoding
+ 2020-11-10 81322b9191 runtime/race: remove race from TestNoRaceAfterFunc2
+ 2020-11-10 1c7650aa93 internal/poll: use copy_file_range only on Linux kernel >= 5.3
+ 2020-11-10 1642cd78b5 cmd/go: update test_race_install expected output for CL 266368
Change-Id: I7ce5350ac9d0647236f1061a540c6751fb9faae9
Diffstat (limited to 'src/runtime')
175 files changed, 4420 insertions, 1886 deletions
diff --git a/src/runtime/asm.s b/src/runtime/asm.s index 27d8df9e06..72c744925d 100644 --- a/src/runtime/asm.s +++ b/src/runtime/asm.s @@ -11,3 +11,8 @@ DATA runtime·no_pointers_stackmap+0x00(SB)/4, $2 DATA runtime·no_pointers_stackmap+0x04(SB)/4, $0 GLOBL runtime·no_pointers_stackmap(SB),RODATA, $8 + +#ifndef GOARCH_amd64 +TEXT ·sigpanic0<ABIInternal>(SB),NOSPLIT,$0-0 + JMP ·sigpanic<ABIInternal>(SB) +#endif diff --git a/src/runtime/asm_386.s b/src/runtime/asm_386.s index fa3b1be339..471451df28 100644 --- a/src/runtime/asm_386.s +++ b/src/runtime/asm_386.s @@ -273,25 +273,6 @@ TEXT runtime·asminit(SB),NOSPLIT,$0-0 * go-routine */ -// void gosave(Gobuf*) -// save state in Gobuf; setjmp -TEXT runtime·gosave(SB), NOSPLIT, $0-4 - MOVL buf+0(FP), AX // gobuf - LEAL buf+0(FP), BX // caller's SP - MOVL BX, gobuf_sp(AX) - MOVL 0(SP), BX // caller's PC - MOVL BX, gobuf_pc(AX) - MOVL $0, gobuf_ret(AX) - // Assert ctxt is zero. See func save. - MOVL gobuf_ctxt(AX), BX - TESTL BX, BX - JZ 2(PC) - CALL runtime·badctxt(SB) - get_tls(CX) - MOVL g(CX), BX - MOVL BX, gobuf_g(AX) - RET - // void gogo(Gobuf*) // restore state from Gobuf; longjmp TEXT runtime·gogo(SB), NOSPLIT, $8-4 @@ -477,7 +458,7 @@ TEXT runtime·morestack_noctxt(SB),NOSPLIT,$0-0 JMP runtime·morestack(SB) // reflectcall: call a function with the given argument list -// func call(argtype *_type, f *FuncVal, arg *byte, argsize, retoffset uint32). +// func call(stackArgsType *_type, f *FuncVal, stackArgs *byte, stackArgsSize, stackRetOffset, frameSize uint32, regArgs *abi.RegArgs). // we don't have variable-sized frames, so we use a small number // of constant-sized-frame functions to encode a few bits of size in the pc. // Caution: ugly multiline assembly macros in your future! @@ -489,8 +470,8 @@ TEXT runtime·morestack_noctxt(SB),NOSPLIT,$0-0 JMP AX // Note: can't just "JMP NAME(SB)" - bad inlining results. -TEXT ·reflectcall(SB), NOSPLIT, $0-20 - MOVL argsize+12(FP), CX +TEXT ·reflectcall(SB), NOSPLIT, $0-28 + MOVL frameSize+20(FP), CX DISPATCH(runtime·call16, 16) DISPATCH(runtime·call32, 32) DISPATCH(runtime·call64, 64) @@ -522,11 +503,11 @@ TEXT ·reflectcall(SB), NOSPLIT, $0-20 JMP AX #define CALLFN(NAME,MAXSIZE) \ -TEXT NAME(SB), WRAPPER, $MAXSIZE-20; \ +TEXT NAME(SB), WRAPPER, $MAXSIZE-28; \ NO_LOCAL_POINTERS; \ /* copy arguments to stack */ \ - MOVL argptr+8(FP), SI; \ - MOVL argsize+12(FP), CX; \ + MOVL stackArgs+8(FP), SI; \ + MOVL stackArgsSize+12(FP), CX; \ MOVL SP, DI; \ REP;MOVSB; \ /* call function */ \ @@ -535,10 +516,10 @@ TEXT NAME(SB), WRAPPER, $MAXSIZE-20; \ PCDATA $PCDATA_StackMapIndex, $0; \ CALL AX; \ /* copy return values back */ \ - MOVL argtype+0(FP), DX; \ - MOVL argptr+8(FP), DI; \ - MOVL argsize+12(FP), CX; \ - MOVL retoffset+16(FP), BX; \ + MOVL stackArgsType+0(FP), DX; \ + MOVL stackArgs+8(FP), DI; \ + MOVL stackArgsSize+12(FP), CX; \ + MOVL stackRetOffset+16(FP), BX; \ MOVL SP, SI; \ ADDL BX, DI; \ ADDL BX, SI; \ @@ -550,11 +531,12 @@ TEXT NAME(SB), WRAPPER, $MAXSIZE-20; \ // separate function so it can allocate stack space for the arguments // to reflectcallmove. It does not follow the Go ABI; it expects its // arguments in registers. -TEXT callRet<>(SB), NOSPLIT, $16-0 +TEXT callRet<>(SB), NOSPLIT, $20-0 MOVL DX, 0(SP) MOVL DI, 4(SP) MOVL SI, 8(SP) MOVL CX, 12(SP) + MOVL $0, 16(SP) CALL runtime·reflectcallmove(SB) RET diff --git a/src/runtime/asm_amd64.s b/src/runtime/asm_amd64.s index 196252e1dd..05422c9699 100644 --- a/src/runtime/asm_amd64.s +++ b/src/runtime/asm_amd64.s @@ -84,9 +84,7 @@ GLOBL _rt0_amd64_lib_argc<>(SB),NOPTR, $8 DATA _rt0_amd64_lib_argv<>(SB)/8, $0 GLOBL _rt0_amd64_lib_argv<>(SB),NOPTR, $8 -// Defined as ABIInternal since it does not use the stack-based Go ABI (and -// in addition there are no calls to this entry point from Go code). -TEXT runtime·rt0_go<ABIInternal>(SB),NOSPLIT,$0 +TEXT runtime·rt0_go(SB),NOSPLIT,$0 // copy arguments forward on an even stack MOVQ DI, AX // argc MOVQ SI, BX // argv @@ -181,6 +179,10 @@ needtls: // skip TLS setup on Darwin JMP ok #endif +#ifdef GOOS_openbsd + // skip TLS setup on OpenBSD + JMP ok +#endif LEAQ runtime·m0+m_tls(SB), DI CALL runtime·settls(SB) @@ -252,26 +254,6 @@ TEXT runtime·asminit(SB),NOSPLIT,$0-0 * go-routine */ -// func gosave(buf *gobuf) -// save state in Gobuf; setjmp -TEXT runtime·gosave(SB), NOSPLIT, $0-8 - MOVQ buf+0(FP), AX // gobuf - LEAQ buf+0(FP), BX // caller's SP - MOVQ BX, gobuf_sp(AX) - MOVQ 0(SP), BX // caller's PC - MOVQ BX, gobuf_pc(AX) - MOVQ $0, gobuf_ret(AX) - MOVQ BP, gobuf_bp(AX) - // Assert ctxt is zero. See func save. - MOVQ gobuf_ctxt(AX), BX - TESTQ BX, BX - JZ 2(PC) - CALL runtime·badctxt(SB) - get_tls(CX) - MOVQ g(CX), BX - MOVQ BX, gobuf_g(AX) - RET - // func gogo(buf *gobuf) // restore state from Gobuf; longjmp TEXT runtime·gogo(SB), NOSPLIT, $16-8 @@ -280,6 +262,7 @@ TEXT runtime·gogo(SB), NOSPLIT, $16-8 MOVQ 0(DX), CX // make sure g != nil get_tls(CX) MOVQ DX, g(CX) + MOVQ DX, R14 // set the g register MOVQ gobuf_sp(BX), SP // restore SP MOVQ gobuf_ret(BX), AX MOVQ gobuf_ctxt(BX), DX @@ -316,6 +299,7 @@ TEXT runtime·mcall(SB), NOSPLIT, $0-8 MOVQ $runtime·badmcall(SB), AX JMP AX MOVQ SI, g(CX) // g = m->g0 + MOVQ SI, R14 // set the g register MOVQ (g_sched+gobuf_sp)(SI), SP // sp = m->g0->sched.sp PUSHQ AX MOVQ DI, DX @@ -362,6 +346,7 @@ TEXT runtime·systemstack(SB), NOSPLIT, $0-8 // switch to g0 MOVQ DX, g(CX) + MOVQ DX, R14 // set the g register MOVQ (g_sched+gobuf_sp)(DX), BX // make it look like mstart called systemstack on g0, to stop traceback SUBQ $8, BX @@ -460,8 +445,77 @@ TEXT runtime·morestack_noctxt(SB),NOSPLIT,$0 MOVL $0, DX JMP runtime·morestack(SB) +// REFLECTCALL_USE_REGABI is not defined. It must be defined in conjunction with the +// register constants in the internal/abi package. + +#ifdef REFLECTCALL_USE_REGABI +// spillArgs stores return values from registers to a *internal/abi.RegArgs in R12. +TEXT spillArgs<>(SB),NOSPLIT,$0-0 + MOVQ AX, 0(R12) + MOVQ BX, 8(R12) + MOVQ CX, 16(R12) + MOVQ DI, 24(R12) + MOVQ SI, 32(R12) + MOVQ R8, 40(R12) + MOVQ R9, 48(R12) + MOVQ R10, 56(R12) + MOVQ R11, 64(R12) + MOVQ X0, 72(R12) + MOVQ X1, 80(R12) + MOVQ X2, 88(R12) + MOVQ X3, 96(R12) + MOVQ X4, 104(R12) + MOVQ X5, 112(R12) + MOVQ X6, 120(R12) + MOVQ X7, 128(R12) + MOVQ X8, 136(R12) + MOVQ X9, 144(R12) + MOVQ X10, 152(R12) + MOVQ X11, 160(R12) + MOVQ X12, 168(R12) + MOVQ X13, 176(R12) + MOVQ X14, 184(R12) + RET + +// unspillArgs loads args into registers from a *internal/abi.RegArgs in R12. +TEXT unspillArgs<>(SB),NOSPLIT,$0-0 + MOVQ 0(R12), AX + MOVQ 8(R12), BX + MOVQ 16(R12), CX + MOVQ 24(R12), DI + MOVQ 32(R12), SI + MOVQ 40(R12), R8 + MOVQ 48(R12), R9 + MOVQ 56(R12), R10 + MOVQ 64(R12), R11 + MOVQ 72(R12), X0 + MOVQ 80(R12), X1 + MOVQ 88(R12), X2 + MOVQ 96(R12), X3 + MOVQ 104(R12), X4 + MOVQ 112(R12), X5 + MOVQ 120(R12), X6 + MOVQ 128(R12), X7 + MOVQ 136(R12), X8 + MOVQ 144(R12), X9 + MOVQ 152(R12), X10 + MOVQ 160(R12), X11 + MOVQ 168(R12), X12 + MOVQ 176(R12), X13 + MOVQ 184(R12), X14 + RET +#else +// spillArgs stores return values from registers to a pointer in R12. +TEXT spillArgs<>(SB),NOSPLIT,$0-0 + RET + +// unspillArgs loads args into registers from a pointer in R12. +TEXT unspillArgs<>(SB),NOSPLIT,$0-0 + RET +#endif + // reflectcall: call a function with the given argument list -// func call(argtype *_type, f *FuncVal, arg *byte, argsize, retoffset uint32). +// func call(stackArgsType *_type, f *FuncVal, stackArgs *byte, stackArgsSize, stackRetOffset, frameSize uint32, regArgs *abi.RegArgs). // we don't have variable-sized frames, so we use a small number // of constant-sized-frame functions to encode a few bits of size in the pc. // Caution: ugly multiline assembly macros in your future! @@ -473,8 +527,8 @@ TEXT runtime·morestack_noctxt(SB),NOSPLIT,$0 JMP AX // Note: can't just "JMP NAME(SB)" - bad inlining results. -TEXT ·reflectcall<ABIInternal>(SB), NOSPLIT, $0-32 - MOVLQZX argsize+24(FP), CX +TEXT ·reflectcall<ABIInternal>(SB), NOSPLIT, $0-48 + MOVLQZX frameSize+32(FP), CX DISPATCH(runtime·call16, 16) DISPATCH(runtime·call32, 32) DISPATCH(runtime·call64, 64) @@ -506,23 +560,28 @@ TEXT ·reflectcall<ABIInternal>(SB), NOSPLIT, $0-32 JMP AX #define CALLFN(NAME,MAXSIZE) \ -TEXT NAME(SB), WRAPPER, $MAXSIZE-32; \ +TEXT NAME(SB), WRAPPER, $MAXSIZE-48; \ NO_LOCAL_POINTERS; \ /* copy arguments to stack */ \ - MOVQ argptr+16(FP), SI; \ - MOVLQZX argsize+24(FP), CX; \ + MOVQ stackArgs+16(FP), SI; \ + MOVLQZX stackArgsSize+24(FP), CX; \ MOVQ SP, DI; \ REP;MOVSB; \ + /* set up argument registers */ \ + MOVQ regArgs+40(FP), R12; \ + CALL unspillArgs<>(SB); \ /* call function */ \ MOVQ f+8(FP), DX; \ PCDATA $PCDATA_StackMapIndex, $0; \ - MOVQ (DX), AX; \ - CALL AX; \ - /* copy return values back */ \ - MOVQ argtype+0(FP), DX; \ - MOVQ argptr+16(FP), DI; \ - MOVLQZX argsize+24(FP), CX; \ - MOVLQZX retoffset+28(FP), BX; \ + MOVQ (DX), R12; \ + CALL R12; \ + /* copy register return values back */ \ + MOVQ regArgs+40(FP), R12; \ + CALL spillArgs<>(SB); \ + MOVLQZX stackArgsSize+24(FP), CX; \ + MOVLQZX stackRetOffset+28(FP), BX; \ + MOVQ stackArgs+16(FP), DI; \ + MOVQ stackArgsType+0(FP), DX; \ MOVQ SP, SI; \ ADDQ BX, DI; \ ADDQ BX, SI; \ @@ -534,12 +593,13 @@ TEXT NAME(SB), WRAPPER, $MAXSIZE-32; \ // separate function so it can allocate stack space for the arguments // to reflectcallmove. It does not follow the Go ABI; it expects its // arguments in registers. -TEXT callRet<>(SB), NOSPLIT, $32-0 +TEXT callRet<>(SB), NOSPLIT, $40-0 NO_LOCAL_POINTERS MOVQ DX, 0(SP) MOVQ DI, 8(SP) MOVQ SI, 16(SP) MOVQ CX, 24(SP) + MOVQ R12, 32(SP) CALL runtime·reflectcallmove(SB) RET @@ -600,18 +660,20 @@ TEXT runtime·jmpdefer(SB), NOSPLIT, $0-16 MOVQ 0(DX), BX JMP BX // but first run the deferred function -// Save state of caller into g->sched. Smashes R8, R9. +// Save state of caller into g->sched. Smashes R9. TEXT gosave<>(SB),NOSPLIT,$0 - get_tls(R8) - MOVQ g(R8), R8 +#ifndef GOEXPERIMENT_REGABI + get_tls(R14) + MOVQ g(R14), R14 +#endif MOVQ 0(SP), R9 - MOVQ R9, (g_sched+gobuf_pc)(R8) + MOVQ R9, (g_sched+gobuf_pc)(R14) LEAQ 8(SP), R9 - MOVQ R9, (g_sched+gobuf_sp)(R8) - MOVQ $0, (g_sched+gobuf_ret)(R8) - MOVQ BP, (g_sched+gobuf_bp)(R8) + MOVQ R9, (g_sched+gobuf_sp)(R14) + MOVQ $0, (g_sched+gobuf_ret)(R14) + MOVQ BP, (g_sched+gobuf_bp)(R14) // Assert ctxt is zero. See func save. - MOVQ (g_sched+gobuf_ctxt)(R8), R9 + MOVQ (g_sched+gobuf_ctxt)(R14), R9 TESTQ R9, R9 JZ 2(PC) CALL runtime·badctxt(SB) @@ -842,6 +904,7 @@ settls: TEXT setg_gcc<>(SB),NOSPLIT,$0 get_tls(AX) MOVQ DI, g(AX) + MOVQ DI, R14 // set the g register RET TEXT runtime·abort(SB),NOSPLIT,$0-0 @@ -1378,6 +1441,18 @@ TEXT runtime·addmoduledata(SB),NOSPLIT,$0-0 POPQ R15 RET +// Initialize special registers then jump to sigpanic. +// This function is injected from the signal handler for panicking +// signals. It is quite painful to set X15 in the signal context, +// so we do it here. +TEXT ·sigpanic0<ABIInternal>(SB),NOSPLIT,$0-0 +#ifdef GOEXPERIMENT_REGABI + get_tls(R14) + MOVQ g(R14), R14 + XORPS X15, X15 +#endif + JMP ·sigpanic<ABIInternal>(SB) + // gcWriteBarrier performs a heap pointer write and informs the GC. // // gcWriteBarrier does NOT follow the Go ABI. It takes two arguments: @@ -1386,24 +1461,28 @@ TEXT runtime·addmoduledata(SB),NOSPLIT,$0-0 // It clobbers FLAGS. It does not clobber any general-purpose registers, // but may clobber others (e.g., SSE registers). // Defined as ABIInternal since it does not use the stack-based Go ABI. -TEXT runtime·gcWriteBarrier<ABIInternal>(SB),NOSPLIT,$120 +TEXT runtime·gcWriteBarrier<ABIInternal>(SB),NOSPLIT,$112 // Save the registers clobbered by the fast path. This is slightly // faster than having the caller spill these. - MOVQ R14, 104(SP) - MOVQ R13, 112(SP) + MOVQ R12, 96(SP) + MOVQ R13, 104(SP) // TODO: Consider passing g.m.p in as an argument so they can be shared // across a sequence of write barriers. +#ifdef GOEXPERIMENT_REGABI + MOVQ g_m(R14), R13 +#else get_tls(R13) MOVQ g(R13), R13 MOVQ g_m(R13), R13 +#endif MOVQ m_p(R13), R13 - MOVQ (p_wbBuf+wbBuf_next)(R13), R14 + MOVQ (p_wbBuf+wbBuf_next)(R13), R12 // Increment wbBuf.next position. - LEAQ 16(R14), R14 - MOVQ R14, (p_wbBuf+wbBuf_next)(R13) - CMPQ R14, (p_wbBuf+wbBuf_end)(R13) + LEAQ 16(R12), R12 + MOVQ R12, (p_wbBuf+wbBuf_next)(R13) + CMPQ R12, (p_wbBuf+wbBuf_end)(R13) // Record the write. - MOVQ AX, -16(R14) // Record value + MOVQ AX, -16(R12) // Record value // Note: This turns bad pointer writes into bad // pointer reads, which could be confusing. We could avoid // reading from obviously bad pointers, which would @@ -1411,12 +1490,12 @@ TEXT runtime·gcWriteBarrier<ABIInternal>(SB),NOSPLIT,$120 // patch this up in the signal handler, or use XCHG to // combine the read and the write. MOVQ (DI), R13 - MOVQ R13, -8(R14) // Record *slot + MOVQ R13, -8(R12) // Record *slot // Is the buffer full? (flags set in CMPQ above) JEQ flush ret: - MOVQ 104(SP), R14 - MOVQ 112(SP), R13 + MOVQ 96(SP), R12 + MOVQ 104(SP), R13 // Do the write. MOVQ AX, (DI) RET @@ -1446,10 +1525,10 @@ flush: MOVQ R9, 64(SP) MOVQ R10, 72(SP) MOVQ R11, 80(SP) - MOVQ R12, 88(SP) + // R12 already saved // R13 already saved - // R14 already saved - MOVQ R15, 96(SP) + // R14 is g + MOVQ R15, 88(SP) // This takes arguments DI and AX CALL runtime·wbBufFlush(SB) @@ -1465,8 +1544,7 @@ flush: MOVQ 64(SP), R9 MOVQ 72(SP), R10 MOVQ 80(SP), R11 - MOVQ 88(SP), R12 - MOVQ 96(SP), R15 + MOVQ 88(SP), R15 JMP ret // gcWriteBarrierCX is gcWriteBarrier, but with args in DI and CX. @@ -1728,67 +1806,67 @@ TEXT runtime·debugCallPanicked(SB),NOSPLIT,$16-16 TEXT runtime·panicIndex<ABIInternal>(SB),NOSPLIT,$0-16 MOVQ AX, x+0(FP) MOVQ CX, y+8(FP) - JMP runtime·goPanicIndex(SB) + JMP runtime·goPanicIndex<ABIInternal>(SB) TEXT runtime·panicIndexU<ABIInternal>(SB),NOSPLIT,$0-16 MOVQ AX, x+0(FP) MOVQ CX, y+8(FP) - JMP runtime·goPanicIndexU(SB) + JMP runtime·goPanicIndexU<ABIInternal>(SB) TEXT runtime·panicSliceAlen<ABIInternal>(SB),NOSPLIT,$0-16 MOVQ CX, x+0(FP) MOVQ DX, y+8(FP) - JMP runtime·goPanicSliceAlen(SB) + JMP runtime·goPanicSliceAlen<ABIInternal>(SB) TEXT runtime·panicSliceAlenU<ABIInternal>(SB),NOSPLIT,$0-16 MOVQ CX, x+0(FP) MOVQ DX, y+8(FP) - JMP runtime·goPanicSliceAlenU(SB) + JMP runtime·goPanicSliceAlenU<ABIInternal>(SB) TEXT runtime·panicSliceAcap<ABIInternal>(SB),NOSPLIT,$0-16 MOVQ CX, x+0(FP) MOVQ DX, y+8(FP) - JMP runtime·goPanicSliceAcap(SB) + JMP runtime·goPanicSliceAcap<ABIInternal>(SB) TEXT runtime·panicSliceAcapU<ABIInternal>(SB),NOSPLIT,$0-16 MOVQ CX, x+0(FP) MOVQ DX, y+8(FP) - JMP runtime·goPanicSliceAcapU(SB) + JMP runtime·goPanicSliceAcapU<ABIInternal>(SB) TEXT runtime·panicSliceB<ABIInternal>(SB),NOSPLIT,$0-16 MOVQ AX, x+0(FP) MOVQ CX, y+8(FP) - JMP runtime·goPanicSliceB(SB) + JMP runtime·goPanicSliceB<ABIInternal>(SB) TEXT runtime·panicSliceBU<ABIInternal>(SB),NOSPLIT,$0-16 MOVQ AX, x+0(FP) MOVQ CX, y+8(FP) - JMP runtime·goPanicSliceBU(SB) + JMP runtime·goPanicSliceBU<ABIInternal>(SB) TEXT runtime·panicSlice3Alen<ABIInternal>(SB),NOSPLIT,$0-16 MOVQ DX, x+0(FP) MOVQ BX, y+8(FP) - JMP runtime·goPanicSlice3Alen(SB) + JMP runtime·goPanicSlice3Alen<ABIInternal>(SB) TEXT runtime·panicSlice3AlenU<ABIInternal>(SB),NOSPLIT,$0-16 MOVQ DX, x+0(FP) MOVQ BX, y+8(FP) - JMP runtime·goPanicSlice3AlenU(SB) + JMP runtime·goPanicSlice3AlenU<ABIInternal>(SB) TEXT runtime·panicSlice3Acap<ABIInternal>(SB),NOSPLIT,$0-16 MOVQ DX, x+0(FP) MOVQ BX, y+8(FP) - JMP runtime·goPanicSlice3Acap(SB) + JMP runtime·goPanicSlice3Acap<ABIInternal>(SB) TEXT runtime·panicSlice3AcapU<ABIInternal>(SB),NOSPLIT,$0-16 MOVQ DX, x+0(FP) MOVQ BX, y+8(FP) - JMP runtime·goPanicSlice3AcapU(SB) + JMP runtime·goPanicSlice3AcapU<ABIInternal>(SB) TEXT runtime·panicSlice3B<ABIInternal>(SB),NOSPLIT,$0-16 MOVQ CX, x+0(FP) MOVQ DX, y+8(FP) - JMP runtime·goPanicSlice3B(SB) + JMP runtime·goPanicSlice3B<ABIInternal>(SB) TEXT runtime·panicSlice3BU<ABIInternal>(SB),NOSPLIT,$0-16 MOVQ CX, x+0(FP) MOVQ DX, y+8(FP) - JMP runtime·goPanicSlice3BU(SB) + JMP runtime·goPanicSlice3BU<ABIInternal>(SB) TEXT runtime·panicSlice3C<ABIInternal>(SB),NOSPLIT,$0-16 MOVQ AX, x+0(FP) MOVQ CX, y+8(FP) - JMP runtime·goPanicSlice3C(SB) + JMP runtime·goPanicSlice3C<ABIInternal>(SB) TEXT runtime·panicSlice3CU<ABIInternal>(SB),NOSPLIT,$0-16 MOVQ AX, x+0(FP) MOVQ CX, y+8(FP) - JMP runtime·goPanicSlice3CU(SB) + JMP runtime·goPanicSlice3CU<ABIInternal>(SB) #ifdef GOOS_android // Use the free TLS_SLOT_APP slot #2 on Android Q. diff --git a/src/runtime/asm_arm.s b/src/runtime/asm_arm.s index c54b4eb006..23619b1408 100644 --- a/src/runtime/asm_arm.s +++ b/src/runtime/asm_arm.s @@ -206,23 +206,6 @@ TEXT runtime·asminit(SB),NOSPLIT,$0-0 * go-routine */ -// void gosave(Gobuf*) -// save state in Gobuf; setjmp -TEXT runtime·gosave(SB),NOSPLIT|NOFRAME,$0-4 - MOVW buf+0(FP), R0 - MOVW R13, gobuf_sp(R0) - MOVW LR, gobuf_pc(R0) - MOVW g, gobuf_g(R0) - MOVW $0, R11 - MOVW R11, gobuf_lr(R0) - MOVW R11, gobuf_ret(R0) - // Assert ctxt is zero. See func save. - MOVW gobuf_ctxt(R0), R0 - CMP R0, R11 - B.EQ 2(PC) - CALL runtime·badctxt(SB) - RET - // void gogo(Gobuf*) // restore state from Gobuf; longjmp TEXT runtime·gogo(SB),NOSPLIT,$8-4 @@ -421,7 +404,7 @@ TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0 B runtime·morestack(SB) // reflectcall: call a function with the given argument list -// func call(argtype *_type, f *FuncVal, arg *byte, argsize, retoffset uint32). +// func call(stackArgsType *_type, f *FuncVal, stackArgs *byte, stackArgsSize, stackRetOffset, frameSize uint32, regArgs *abi.RegArgs). // we don't have variable-sized frames, so we use a small number // of constant-sized-frame functions to encode a few bits of size in the pc. // Caution: ugly multiline assembly macros in your future! @@ -432,8 +415,8 @@ TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0 MOVW $NAME(SB), R1; \ B (R1) -TEXT ·reflectcall(SB),NOSPLIT|NOFRAME,$0-20 - MOVW argsize+12(FP), R0 +TEXT ·reflectcall(SB),NOSPLIT|NOFRAME,$0-28 + MOVW frameSize+20(FP), R0 DISPATCH(runtime·call16, 16) DISPATCH(runtime·call32, 32) DISPATCH(runtime·call64, 64) @@ -465,11 +448,11 @@ TEXT ·reflectcall(SB),NOSPLIT|NOFRAME,$0-20 B (R1) #define CALLFN(NAME,MAXSIZE) \ -TEXT NAME(SB), WRAPPER, $MAXSIZE-20; \ +TEXT NAME(SB), WRAPPER, $MAXSIZE-28; \ NO_LOCAL_POINTERS; \ /* copy arguments to stack */ \ - MOVW argptr+8(FP), R0; \ - MOVW argsize+12(FP), R2; \ + MOVW stackArgs+8(FP), R0; \ + MOVW stackArgsSize+12(FP), R2; \ ADD $4, R13, R1; \ CMP $0, R2; \ B.EQ 5(PC); \ @@ -483,10 +466,10 @@ TEXT NAME(SB), WRAPPER, $MAXSIZE-20; \ PCDATA $PCDATA_StackMapIndex, $0; \ BL (R0); \ /* copy return values back */ \ - MOVW argtype+0(FP), R4; \ - MOVW argptr+8(FP), R0; \ - MOVW argsize+12(FP), R2; \ - MOVW retoffset+16(FP), R3; \ + MOVW stackArgsType+0(FP), R4; \ + MOVW stackArgs+8(FP), R0; \ + MOVW stackArgsSize+12(FP), R2; \ + MOVW stackArgsRetOffset+16(FP), R3; \ ADD $4, R13, R1; \ ADD R3, R1; \ ADD R3, R0; \ @@ -498,11 +481,13 @@ TEXT NAME(SB), WRAPPER, $MAXSIZE-20; \ // separate function so it can allocate stack space for the arguments // to reflectcallmove. It does not follow the Go ABI; it expects its // arguments in registers. -TEXT callRet<>(SB), NOSPLIT, $16-0 +TEXT callRet<>(SB), NOSPLIT, $20-0 MOVW R4, 4(R13) MOVW R0, 8(R13) MOVW R1, 12(R13) MOVW R2, 16(R13) + MOVW $0, R7 + MOVW R7, 20(R13) BL runtime·reflectcallmove(SB) RET diff --git a/src/runtime/asm_arm64.s b/src/runtime/asm_arm64.s index a09172f0c9..0ab92be1e4 100644 --- a/src/runtime/asm_arm64.s +++ b/src/runtime/asm_arm64.s @@ -113,23 +113,6 @@ TEXT runtime·asminit(SB),NOSPLIT|NOFRAME,$0-0 * go-routine */ -// void gosave(Gobuf*) -// save state in Gobuf; setjmp -TEXT runtime·gosave(SB), NOSPLIT|NOFRAME, $0-8 - MOVD buf+0(FP), R3 - MOVD RSP, R0 - MOVD R0, gobuf_sp(R3) - MOVD R29, gobuf_bp(R3) - MOVD LR, gobuf_pc(R3) - MOVD g, gobuf_g(R3) - MOVD ZR, gobuf_lr(R3) - MOVD ZR, gobuf_ret(R3) - // Assert ctxt is zero. See func save. - MOVD gobuf_ctxt(R3), R0 - CBZ R0, 2(PC) - CALL runtime·badctxt(SB) - RET - // void gogo(Gobuf*) // restore state from Gobuf; longjmp TEXT runtime·gogo(SB), NOSPLIT, $24-8 @@ -329,7 +312,7 @@ TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0 B runtime·morestack(SB) // reflectcall: call a function with the given argument list -// func call(argtype *_type, f *FuncVal, arg *byte, argsize, retoffset uint32). +// func call(stackArgsType *_type, f *FuncVal, stackArgs *byte, stackArgsSize, stackRetOffset, frameSize uint32, regArgs *abi.RegArgs). // we don't have variable-sized frames, so we use a small number // of constant-sized-frame functions to encode a few bits of size in the pc. // Caution: ugly multiline assembly macros in your future! @@ -342,8 +325,8 @@ TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0 B (R27) // Note: can't just "B NAME(SB)" - bad inlining results. -TEXT ·reflectcall(SB), NOSPLIT|NOFRAME, $0-32 - MOVWU argsize+24(FP), R16 +TEXT ·reflectcall(SB), NOSPLIT|NOFRAME, $0-48 + MOVWU frameSize+32(FP), R16 DISPATCH(runtime·call16, 16) DISPATCH(runtime·call32, 32) DISPATCH(runtime·call64, 64) @@ -375,11 +358,11 @@ TEXT ·reflectcall(SB), NOSPLIT|NOFRAME, $0-32 B (R0) #define CALLFN(NAME,MAXSIZE) \ -TEXT NAME(SB), WRAPPER, $MAXSIZE-24; \ +TEXT NAME(SB), WRAPPER, $MAXSIZE-48; \ NO_LOCAL_POINTERS; \ /* copy arguments to stack */ \ - MOVD arg+16(FP), R3; \ - MOVWU argsize+24(FP), R4; \ + MOVD stackArgs+16(FP), R3; \ + MOVWU stackArgsSize+24(FP), R4; \ ADD $8, RSP, R5; \ BIC $0xf, R4, R6; \ CBZ R6, 6(PC); \ @@ -405,10 +388,10 @@ TEXT NAME(SB), WRAPPER, $MAXSIZE-24; \ PCDATA $PCDATA_StackMapIndex, $0; \ BL (R0); \ /* copy return values back */ \ - MOVD argtype+0(FP), R7; \ - MOVD arg+16(FP), R3; \ - MOVWU n+24(FP), R4; \ - MOVWU retoffset+28(FP), R6; \ + MOVD stackArgsType+0(FP), R7; \ + MOVD stackArgs+16(FP), R3; \ + MOVWU stackArgsSize+24(FP), R4; \ + MOVWU stackRetOffset+28(FP), R6; \ ADD $8, RSP, R5; \ ADD R6, R5; \ ADD R6, R3; \ @@ -420,11 +403,12 @@ TEXT NAME(SB), WRAPPER, $MAXSIZE-24; \ // separate function so it can allocate stack space for the arguments // to reflectcallmove. It does not follow the Go ABI; it expects its // arguments in registers. -TEXT callRet<>(SB), NOSPLIT, $40-0 +TEXT callRet<>(SB), NOSPLIT, $48-0 MOVD R7, 8(RSP) MOVD R3, 16(RSP) MOVD R5, 24(RSP) MOVD R4, 32(RSP) + MOVD $0, 40(RSP) BL runtime·reflectcallmove(SB) RET diff --git a/src/runtime/asm_mips64x.s b/src/runtime/asm_mips64x.s index 19781f7885..694950663a 100644 --- a/src/runtime/asm_mips64x.s +++ b/src/runtime/asm_mips64x.s @@ -89,21 +89,6 @@ TEXT runtime·asminit(SB),NOSPLIT|NOFRAME,$0-0 * go-routine */ -// void gosave(Gobuf*) -// save state in Gobuf; setjmp -TEXT runtime·gosave(SB), NOSPLIT|NOFRAME, $0-8 - MOVV buf+0(FP), R1 - MOVV R29, gobuf_sp(R1) - MOVV R31, gobuf_pc(R1) - MOVV g, gobuf_g(R1) - MOVV R0, gobuf_lr(R1) - MOVV R0, gobuf_ret(R1) - // Assert ctxt is zero. See func save. - MOVV gobuf_ctxt(R1), R1 - BEQ R1, 2(PC) - JAL runtime·badctxt(SB) - RET - // void gogo(Gobuf*) // restore state from Gobuf; longjmp TEXT runtime·gogo(SB), NOSPLIT, $16-8 @@ -279,7 +264,7 @@ TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0 JMP runtime·morestack(SB) // reflectcall: call a function with the given argument list -// func call(argtype *_type, f *FuncVal, arg *byte, argsize, retoffset uint32). +// func call(stackArgsType *_type, f *FuncVal, stackArgs *byte, stackArgsSize, stackRetOffset, frameSize uint32, regArgs *abi.RegArgs). // we don't have variable-sized frames, so we use a small number // of constant-sized-frame functions to encode a few bits of size in the pc. // Caution: ugly multiline assembly macros in your future! @@ -292,8 +277,8 @@ TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0 JMP (R4) // Note: can't just "BR NAME(SB)" - bad inlining results. -TEXT ·reflectcall(SB), NOSPLIT|NOFRAME, $0-32 - MOVWU argsize+24(FP), R1 +TEXT ·reflectcall(SB), NOSPLIT|NOFRAME, $0-48 + MOVWU frameSize+32(FP), R1 DISPATCH(runtime·call16, 16) DISPATCH(runtime·call32, 32) DISPATCH(runtime·call64, 64) @@ -325,11 +310,11 @@ TEXT ·reflectcall(SB), NOSPLIT|NOFRAME, $0-32 JMP (R4) #define CALLFN(NAME,MAXSIZE) \ -TEXT NAME(SB), WRAPPER, $MAXSIZE-24; \ +TEXT NAME(SB), WRAPPER, $MAXSIZE-48; \ NO_LOCAL_POINTERS; \ /* copy arguments to stack */ \ - MOVV arg+16(FP), R1; \ - MOVWU argsize+24(FP), R2; \ + MOVV stackArgs+16(FP), R1; \ + MOVWU stackArgsSize+24(FP), R2; \ MOVV R29, R3; \ ADDV $8, R3; \ ADDV R3, R2; \ @@ -345,10 +330,10 @@ TEXT NAME(SB), WRAPPER, $MAXSIZE-24; \ PCDATA $PCDATA_StackMapIndex, $0; \ JAL (R4); \ /* copy return values back */ \ - MOVV argtype+0(FP), R5; \ - MOVV arg+16(FP), R1; \ - MOVWU n+24(FP), R2; \ - MOVWU retoffset+28(FP), R4; \ + MOVV stackArgsType+0(FP), R5; \ + MOVV stackArgs+16(FP), R1; \ + MOVWU stackArgsSize+24(FP), R2; \ + MOVWU stackRetOffset+28(FP), R4; \ ADDV $8, R29, R3; \ ADDV R4, R3; \ ADDV R4, R1; \ @@ -360,11 +345,12 @@ TEXT NAME(SB), WRAPPER, $MAXSIZE-24; \ // separate function so it can allocate stack space for the arguments // to reflectcallmove. It does not follow the Go ABI; it expects its // arguments in registers. -TEXT callRet<>(SB), NOSPLIT, $32-0 +TEXT callRet<>(SB), NOSPLIT, $40-0 MOVV R5, 8(R29) MOVV R1, 16(R29) MOVV R3, 24(R29) MOVV R2, 32(R29) + MOVV $0, 40(R29) JAL runtime·reflectcallmove(SB) RET diff --git a/src/runtime/asm_mipsx.s b/src/runtime/asm_mipsx.s index ee87d81436..8e5753d255 100644 --- a/src/runtime/asm_mipsx.s +++ b/src/runtime/asm_mipsx.s @@ -90,21 +90,6 @@ TEXT runtime·asminit(SB),NOSPLIT,$0-0 * go-routine */ -// void gosave(Gobuf*) -// save state in Gobuf; setjmp -TEXT runtime·gosave(SB),NOSPLIT|NOFRAME,$0-4 - MOVW buf+0(FP), R1 - MOVW R29, gobuf_sp(R1) - MOVW R31, gobuf_pc(R1) - MOVW g, gobuf_g(R1) - MOVW R0, gobuf_lr(R1) - MOVW R0, gobuf_ret(R1) - // Assert ctxt is zero. See func save. - MOVW gobuf_ctxt(R1), R1 - BEQ R1, 2(PC) - JAL runtime·badctxt(SB) - RET - // void gogo(Gobuf*) // restore state from Gobuf; longjmp TEXT runtime·gogo(SB),NOSPLIT,$8-4 @@ -280,7 +265,7 @@ TEXT runtime·morestack_noctxt(SB),NOSPLIT,$0-0 JMP runtime·morestack(SB) // reflectcall: call a function with the given argument list -// func call(argtype *_type, f *FuncVal, arg *byte, argsize, retoffset uint32). +// func call(stackArgsType *_type, f *FuncVal, stackArgs *byte, stackArgsSize, stackRetOffset, frameSize uint32, regArgs *abi.RegArgs). // we don't have variable-sized frames, so we use a small number // of constant-sized-frame functions to encode a few bits of size in the pc. @@ -291,8 +276,8 @@ TEXT runtime·morestack_noctxt(SB),NOSPLIT,$0-0 MOVW $NAME(SB), R4; \ JMP (R4) -TEXT ·reflectcall(SB),NOSPLIT|NOFRAME,$0-20 - MOVW argsize+12(FP), R1 +TEXT ·reflectcall(SB),NOSPLIT|NOFRAME,$0-28 + MOVW frameSize+20(FP), R1 DISPATCH(runtime·call16, 16) DISPATCH(runtime·call32, 32) @@ -325,11 +310,11 @@ TEXT ·reflectcall(SB),NOSPLIT|NOFRAME,$0-20 JMP (R4) #define CALLFN(NAME,MAXSIZE) \ -TEXT NAME(SB),WRAPPER,$MAXSIZE-20; \ +TEXT NAME(SB),WRAPPER,$MAXSIZE-28; \ NO_LOCAL_POINTERS; \ /* copy arguments to stack */ \ - MOVW arg+8(FP), R1; \ - MOVW argsize+12(FP), R2; \ + MOVW stackArgs+8(FP), R1; \ + MOVW stackArgsSize+12(FP), R2; \ MOVW R29, R3; \ ADDU $4, R3; \ ADDU R3, R2; \ @@ -345,10 +330,10 @@ TEXT NAME(SB),WRAPPER,$MAXSIZE-20; \ PCDATA $PCDATA_StackMapIndex, $0; \ JAL (R4); \ /* copy return values back */ \ - MOVW argtype+0(FP), R5; \ - MOVW arg+8(FP), R1; \ - MOVW n+12(FP), R2; \ - MOVW retoffset+16(FP), R4; \ + MOVW stackArgsType+0(FP), R5; \ + MOVW stackArgs+8(FP), R1; \ + MOVW stackArgsSize+12(FP), R2; \ + MOVW stackRetOffset+16(FP), R4; \ ADDU $4, R29, R3; \ ADDU R4, R3; \ ADDU R4, R1; \ @@ -360,11 +345,12 @@ TEXT NAME(SB),WRAPPER,$MAXSIZE-20; \ // separate function so it can allocate stack space for the arguments // to reflectcallmove. It does not follow the Go ABI; it expects its // arguments in registers. -TEXT callRet<>(SB), NOSPLIT, $16-0 +TEXT callRet<>(SB), NOSPLIT, $20-0 MOVW R5, 4(R29) MOVW R1, 8(R29) MOVW R3, 12(R29) MOVW R2, 16(R29) + MOVW $0, 20(R29) JAL runtime·reflectcallmove(SB) RET diff --git a/src/runtime/asm_ppc64x.s b/src/runtime/asm_ppc64x.s index dc34c0e4c8..834023cce1 100644 --- a/src/runtime/asm_ppc64x.s +++ b/src/runtime/asm_ppc64x.s @@ -128,23 +128,6 @@ TEXT runtime·reginit(SB),NOSPLIT|NOFRAME,$0-0 * go-routine */ -// void gosave(Gobuf*) -// save state in Gobuf; setjmp -TEXT runtime·gosave(SB), NOSPLIT|NOFRAME, $0-8 - MOVD buf+0(FP), R3 - MOVD R1, gobuf_sp(R3) - MOVD LR, R31 - MOVD R31, gobuf_pc(R3) - MOVD g, gobuf_g(R3) - MOVD R0, gobuf_lr(R3) - MOVD R0, gobuf_ret(R3) - // Assert ctxt is zero. See func save. - MOVD gobuf_ctxt(R3), R3 - CMP R0, R3 - BEQ 2(PC) - BL runtime·badctxt(SB) - RET - // void gogo(Gobuf*) // restore state from Gobuf; longjmp TEXT runtime·gogo(SB), NOSPLIT, $16-8 @@ -356,7 +339,7 @@ TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0 BR runtime·morestack(SB) // reflectcall: call a function with the given argument list -// func call(argtype *_type, f *FuncVal, arg *byte, argsize, retoffset uint32). +// func call(stackArgsType *_type, f *FuncVal, stackArgs *byte, stackArgsSize, stackRetOffset, frameSize uint32, regArgs *abi.RegArgs). // we don't have variable-sized frames, so we use a small number // of constant-sized-frame functions to encode a few bits of size in the pc. // Caution: ugly multiline assembly macros in your future! @@ -370,8 +353,8 @@ TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0 BR (CTR) // Note: can't just "BR NAME(SB)" - bad inlining results. -TEXT ·reflectcall(SB), NOSPLIT|NOFRAME, $0-32 - MOVWZ argsize+24(FP), R3 +TEXT ·reflectcall(SB), NOSPLIT|NOFRAME, $0-48 + MOVWZ frameSize+32(FP), R3 DISPATCH(runtime·call16, 16) DISPATCH(runtime·call32, 32) DISPATCH(runtime·call64, 64) @@ -404,11 +387,11 @@ TEXT ·reflectcall(SB), NOSPLIT|NOFRAME, $0-32 BR (CTR) #define CALLFN(NAME,MAXSIZE) \ -TEXT NAME(SB), WRAPPER, $MAXSIZE-24; \ +TEXT NAME(SB), WRAPPER, $MAXSIZE-48; \ NO_LOCAL_POINTERS; \ /* copy arguments to stack */ \ - MOVD arg+16(FP), R3; \ - MOVWZ argsize+24(FP), R4; \ + MOVD stackArgs+16(FP), R3; \ + MOVWZ stackArgsSize+24(FP), R4; \ MOVD R1, R5; \ CMP R4, $8; \ BLT tailsetup; \ @@ -456,10 +439,10 @@ callfn: \ MOVD 24(R1), R2; \ #endif \ /* copy return values back */ \ - MOVD argtype+0(FP), R7; \ - MOVD arg+16(FP), R3; \ - MOVWZ n+24(FP), R4; \ - MOVWZ retoffset+28(FP), R6; \ + MOVD stackArgsType+0(FP), R7; \ + MOVD stackArgs+16(FP), R3; \ + MOVWZ stackArgsSize+24(FP), R4; \ + MOVWZ stackRetOffset+28(FP), R6; \ ADD $FIXED_FRAME, R1, R5; \ ADD R6, R5; \ ADD R6, R3; \ @@ -471,11 +454,12 @@ callfn: \ // separate function so it can allocate stack space for the arguments // to reflectcallmove. It does not follow the Go ABI; it expects its // arguments in registers. -TEXT callRet<>(SB), NOSPLIT, $32-0 +TEXT callRet<>(SB), NOSPLIT, $40-0 MOVD R7, FIXED_FRAME+0(R1) MOVD R3, FIXED_FRAME+8(R1) MOVD R5, FIXED_FRAME+16(R1) MOVD R4, FIXED_FRAME+24(R1) + MOVD $0, FIXED_FRAME+32(R1) BL runtime·reflectcallmove(SB) RET diff --git a/src/runtime/asm_riscv64.s b/src/runtime/asm_riscv64.s index 01b42dc3de..31e324d677 100644 --- a/src/runtime/asm_riscv64.s +++ b/src/runtime/asm_riscv64.s @@ -297,21 +297,6 @@ TEXT runtime·mcall(SB), NOSPLIT|NOFRAME, $0-8 JALR RA, T1 JMP runtime·badmcall2(SB) -// func gosave(buf *gobuf) -// save state in Gobuf; setjmp -TEXT runtime·gosave(SB), NOSPLIT|NOFRAME, $0-8 - MOV buf+0(FP), T1 - MOV X2, gobuf_sp(T1) - MOV RA, gobuf_pc(T1) - MOV g, gobuf_g(T1) - MOV ZERO, gobuf_lr(T1) - MOV ZERO, gobuf_ret(T1) - // Assert ctxt is zero. See func save. - MOV gobuf_ctxt(T1), T1 - BEQ T1, ZERO, 2(PC) - CALL runtime·badctxt(SB) - RET - // Save state of caller into g->sched. Smashes X31. TEXT gosave<>(SB),NOSPLIT|NOFRAME,$0 MOV X1, (g_sched+gobuf_pc)(g) @@ -374,7 +359,7 @@ TEXT runtime·asminit(SB),NOSPLIT|NOFRAME,$0-0 RET // reflectcall: call a function with the given argument list -// func call(argtype *_type, f *FuncVal, arg *byte, argsize, retoffset uint32). +// func call(stackArgsType *_type, f *FuncVal, stackArgs *byte, stackArgsSize, stackRetOffset, frameSize uint32, regArgs *abi.RegArgs). // we don't have variable-sized frames, so we use a small number // of constant-sized-frame functions to encode a few bits of size in the pc. // Caution: ugly multiline assembly macros in your future! @@ -386,13 +371,13 @@ TEXT runtime·asminit(SB),NOSPLIT|NOFRAME,$0-0 JALR ZERO, T2 // Note: can't just "BR NAME(SB)" - bad inlining results. -// func call(argtype *rtype, fn, arg unsafe.Pointer, n uint32, retoffset uint32) +// func call(stackArgsType *rtype, fn, stackArgs unsafe.Pointer, stackArgsSize, stackRetOffset, frameSize uint32, regArgs *abi.RegArgs). TEXT reflect·call(SB), NOSPLIT, $0-0 JMP ·reflectcall(SB) -// func reflectcall(argtype *_type, fn, arg unsafe.Pointer, argsize uint32, retoffset uint32) -TEXT ·reflectcall(SB), NOSPLIT|NOFRAME, $0-32 - MOVWU argsize+24(FP), T0 +// func call(stackArgsType *_type, fn, stackArgs unsafe.Pointer, stackArgsSize, stackRetOffset, frameSize uint32, regArgs *abi.RegArgs). +TEXT ·reflectcall(SB), NOSPLIT|NOFRAME, $0-48 + MOVWU frameSize+32(FP), T0 DISPATCH(runtime·call16, 16) DISPATCH(runtime·call32, 32) DISPATCH(runtime·call64, 64) @@ -424,11 +409,11 @@ TEXT ·reflectcall(SB), NOSPLIT|NOFRAME, $0-32 JALR ZERO, T2 #define CALLFN(NAME,MAXSIZE) \ -TEXT NAME(SB), WRAPPER, $MAXSIZE-24; \ +TEXT NAME(SB), WRAPPER, $MAXSIZE-48; \ NO_LOCAL_POINTERS; \ /* copy arguments to stack */ \ - MOV arg+16(FP), A1; \ - MOVWU argsize+24(FP), A2; \ + MOV stackArgs+16(FP), A1; \ + MOVWU stackArgsSize+24(FP), A2; \ MOV X2, A3; \ ADD $8, A3; \ ADD A3, A2; \ @@ -444,10 +429,10 @@ TEXT NAME(SB), WRAPPER, $MAXSIZE-24; \ PCDATA $PCDATA_StackMapIndex, $0; \ JALR RA, A4; \ /* copy return values back */ \ - MOV argtype+0(FP), A5; \ - MOV arg+16(FP), A1; \ - MOVWU n+24(FP), A2; \ - MOVWU retoffset+28(FP), A4; \ + MOV stackArgsType+0(FP), A5; \ + MOV stackArgs+16(FP), A1; \ + MOVWU stackArgsSize+24(FP), A2; \ + MOVWU stackRetOffset+28(FP), A4; \ ADD $8, X2, A3; \ ADD A4, A3; \ ADD A4, A1; \ @@ -459,11 +444,12 @@ TEXT NAME(SB), WRAPPER, $MAXSIZE-24; \ // separate function so it can allocate stack space for the arguments // to reflectcallmove. It does not follow the Go ABI; it expects its // arguments in registers. -TEXT callRet<>(SB), NOSPLIT, $32-0 +TEXT callRet<>(SB), NOSPLIT, $40-0 MOV A5, 8(X2) MOV A1, 16(X2) MOV A3, 24(X2) MOV A2, 32(X2) + MOV $0, 40(X2) CALL runtime·reflectcallmove(SB) RET diff --git a/src/runtime/asm_s390x.s b/src/runtime/asm_s390x.s index 7baef37324..fbd185c353 100644 --- a/src/runtime/asm_s390x.s +++ b/src/runtime/asm_s390x.s @@ -174,21 +174,6 @@ TEXT runtime·asminit(SB),NOSPLIT|NOFRAME,$0-0 * go-routine */ -// void gosave(Gobuf*) -// save state in Gobuf; setjmp -TEXT runtime·gosave(SB), NOSPLIT, $-8-8 - MOVD buf+0(FP), R3 - MOVD R15, gobuf_sp(R3) - MOVD LR, gobuf_pc(R3) - MOVD g, gobuf_g(R3) - MOVD $0, gobuf_lr(R3) - MOVD $0, gobuf_ret(R3) - // Assert ctxt is zero. See func save. - MOVD gobuf_ctxt(R3), R3 - CMPBEQ R3, $0, 2(PC) - BL runtime·badctxt(SB) - RET - // void gogo(Gobuf*) // restore state from Gobuf; longjmp TEXT runtime·gogo(SB), NOSPLIT, $16-8 @@ -368,7 +353,7 @@ TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0 BR runtime·morestack(SB) // reflectcall: call a function with the given argument list -// func call(argtype *_type, f *FuncVal, arg *byte, argsize, retoffset uint32). +// func call(stackArgsType *_type, f *FuncVal, stackArgs *byte, stackArgsSize, stackRetOffset, frameSize uint32, regArgs *abi.RegArgs). // we don't have variable-sized frames, so we use a small number // of constant-sized-frame functions to encode a few bits of size in the pc. // Caution: ugly multiline assembly macros in your future! @@ -381,8 +366,8 @@ TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0 BR (R5) // Note: can't just "BR NAME(SB)" - bad inlining results. -TEXT ·reflectcall(SB), NOSPLIT, $-8-32 - MOVWZ argsize+24(FP), R3 +TEXT ·reflectcall(SB), NOSPLIT, $-8-48 + MOVWZ frameSize+32(FP), R3 DISPATCH(runtime·call16, 16) DISPATCH(runtime·call32, 32) DISPATCH(runtime·call64, 64) @@ -414,11 +399,11 @@ TEXT ·reflectcall(SB), NOSPLIT, $-8-32 BR (R5) #define CALLFN(NAME,MAXSIZE) \ -TEXT NAME(SB), WRAPPER, $MAXSIZE-24; \ +TEXT NAME(SB), WRAPPER, $MAXSIZE-48; \ NO_LOCAL_POINTERS; \ /* copy arguments to stack */ \ - MOVD arg+16(FP), R4; \ - MOVWZ argsize+24(FP), R5; \ + MOVD stackArgs+16(FP), R4; \ + MOVWZ stackArgsSize+24(FP), R5; \ MOVD $stack-MAXSIZE(SP), R6; \ loopArgs: /* copy 256 bytes at a time */ \ CMP R5, $256; \ @@ -439,11 +424,11 @@ callFunction: \ PCDATA $PCDATA_StackMapIndex, $0; \ BL (R8); \ /* copy return values back */ \ - MOVD argtype+0(FP), R7; \ - MOVD arg+16(FP), R6; \ - MOVWZ n+24(FP), R5; \ + MOVD stackArgsType+0(FP), R7; \ + MOVD stackArgs+16(FP), R6; \ + MOVWZ stackArgsSize+24(FP), R5; \ MOVD $stack-MAXSIZE(SP), R4; \ - MOVWZ retoffset+28(FP), R1; \ + MOVWZ stackRetOffset+28(FP), R1; \ ADD R1, R4; \ ADD R1, R6; \ SUB R1, R5; \ @@ -454,11 +439,12 @@ callFunction: \ // separate function so it can allocate stack space for the arguments // to reflectcallmove. It does not follow the Go ABI; it expects its // arguments in registers. -TEXT callRet<>(SB), NOSPLIT, $32-0 +TEXT callRet<>(SB), NOSPLIT, $40-0 MOVD R7, 8(R15) MOVD R6, 16(R15) MOVD R4, 24(R15) MOVD R5, 32(R15) + MOVD $0, 40(R15) BL runtime·reflectcallmove(SB) RET diff --git a/src/runtime/asm_wasm.s b/src/runtime/asm_wasm.s index fcb780f1dc..cf3d961b74 100644 --- a/src/runtime/asm_wasm.s +++ b/src/runtime/asm_wasm.s @@ -296,14 +296,14 @@ TEXT ·asmcgocall(SB), NOSPLIT, $0-0 JMP NAME(SB); \ End -TEXT ·reflectcall(SB), NOSPLIT, $0-32 +TEXT ·reflectcall(SB), NOSPLIT, $0-48 I64Load fn+8(FP) I64Eqz If CALLNORESUME runtime·sigpanic<ABIInternal>(SB) End - MOVW argsize+24(FP), R0 + MOVW frameSize+32(FP), R0 DISPATCH(runtime·call16, 16) DISPATCH(runtime·call32, 32) @@ -335,18 +335,18 @@ TEXT ·reflectcall(SB), NOSPLIT, $0-32 JMP runtime·badreflectcall(SB) #define CALLFN(NAME, MAXSIZE) \ -TEXT NAME(SB), WRAPPER, $MAXSIZE-32; \ +TEXT NAME(SB), WRAPPER, $MAXSIZE-48; \ NO_LOCAL_POINTERS; \ - MOVW argsize+24(FP), R0; \ + MOVW stackArgsSize+24(FP), R0; \ \ Get R0; \ I64Eqz; \ Not; \ If; \ Get SP; \ - I64Load argptr+16(FP); \ + I64Load stackArgs+16(FP); \ I32WrapI64; \ - I64Load argsize+24(FP); \ + I64Load stackArgsSize+24(FP); \ I64Const $3; \ I64ShrU; \ I32WrapI64; \ @@ -359,12 +359,12 @@ TEXT NAME(SB), WRAPPER, $MAXSIZE-32; \ I64Load $0; \ CALL; \ \ - I64Load32U retoffset+28(FP); \ + I64Load32U stackRetOffset+28(FP); \ Set R0; \ \ - MOVD argtype+0(FP), RET0; \ + MOVD stackArgsType+0(FP), RET0; \ \ - I64Load argptr+16(FP); \ + I64Load stackArgs+16(FP); \ Get R0; \ I64Add; \ Set RET1; \ @@ -375,7 +375,7 @@ TEXT NAME(SB), WRAPPER, $MAXSIZE-32; \ I64Add; \ Set RET2; \ \ - I64Load32U argsize+24(FP); \ + I64Load32U stackArgsSize+24(FP); \ Get R0; \ I64Sub; \ Set RET3; \ @@ -387,12 +387,13 @@ TEXT NAME(SB), WRAPPER, $MAXSIZE-32; \ // separate function so it can allocate stack space for the arguments // to reflectcallmove. It does not follow the Go ABI; it expects its // arguments in registers. -TEXT callRet<>(SB), NOSPLIT, $32-0 +TEXT callRet<>(SB), NOSPLIT, $40-0 NO_LOCAL_POINTERS MOVD RET0, 0(SP) MOVD RET1, 8(SP) MOVD RET2, 16(SP) MOVD RET3, 24(SP) + MOVD $0, 32(SP) CALL runtime·reflectcallmove(SB) RET diff --git a/src/runtime/cgo/gcc_amd64.S b/src/runtime/cgo/gcc_amd64.S index 17d9d47ef4..d75f864666 100644 --- a/src/runtime/cgo/gcc_amd64.S +++ b/src/runtime/cgo/gcc_amd64.S @@ -30,9 +30,14 @@ EXT(crosscall_amd64): pushq %r15 #if defined(_WIN64) + movq %r8, %rdi /* arg of setg_gcc */ + call *%rdx /* setg_gcc */ call *%rcx /* fn */ #else - call *%rdi /* fn */ + movq %rdi, %rbx + movq %rdx, %rdi /* arg of setg_gcc */ + call *%rsi /* setg_gcc */ + call *%rbx /* fn */ #endif popq %r15 diff --git a/src/runtime/cgo/gcc_darwin_amd64.c b/src/runtime/cgo/gcc_darwin_amd64.c index 51410d5026..d5b7fd8fd8 100644 --- a/src/runtime/cgo/gcc_darwin_amd64.c +++ b/src/runtime/cgo/gcc_darwin_amd64.c @@ -9,13 +9,16 @@ #include "libcgo_unix.h" static void* threadentry(void*); +static void (*setg_gcc)(void*); void -x_cgo_init(G *g) +x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase) { pthread_attr_t attr; size_t size; + setg_gcc = setg; + pthread_attr_init(&attr); pthread_attr_getstacksize(&attr, &size); g->stacklo = (uintptr)&attr - size + 4096; @@ -57,10 +60,6 @@ threadentry(void *v) ts = *(ThreadStart*)v; free(v); - // Move the g pointer into the slot reserved in thread local storage. - // Constant must match the one in cmd/link/internal/ld/sym.go. - asm volatile("movq %0, %%gs:0x30" :: "r"(ts.g)); - - crosscall_amd64(ts.fn); + crosscall_amd64(ts.fn, setg_gcc, (void*)ts.g); return nil; } diff --git a/src/runtime/cgo/gcc_dragonfly_amd64.c b/src/runtime/cgo/gcc_dragonfly_amd64.c index d25db91900..0003414bf8 100644 --- a/src/runtime/cgo/gcc_dragonfly_amd64.c +++ b/src/runtime/cgo/gcc_dragonfly_amd64.c @@ -61,11 +61,6 @@ threadentry(void *v) ts = *(ThreadStart*)v; free(v); - /* - * Set specific keys. - */ - setg_gcc((void*)ts.g); - - crosscall_amd64(ts.fn); + crosscall_amd64(ts.fn, setg_gcc, (void*)ts.g); return nil; } diff --git a/src/runtime/cgo/gcc_freebsd_amd64.c b/src/runtime/cgo/gcc_freebsd_amd64.c index 514a2f8a23..6071ec3909 100644 --- a/src/runtime/cgo/gcc_freebsd_amd64.c +++ b/src/runtime/cgo/gcc_freebsd_amd64.c @@ -69,11 +69,6 @@ threadentry(void *v) free(v); _cgo_tsan_release(); - /* - * Set specific keys. - */ - setg_gcc((void*)ts.g); - - crosscall_amd64(ts.fn); + crosscall_amd64(ts.fn, setg_gcc, (void*)ts.g); return nil; } diff --git a/src/runtime/cgo/gcc_linux_386.c b/src/runtime/cgo/gcc_linux_386.c index ece9f933c5..70c942aeb8 100644 --- a/src/runtime/cgo/gcc_linux_386.c +++ b/src/runtime/cgo/gcc_linux_386.c @@ -12,7 +12,7 @@ static void *threadentry(void*); static void (*setg_gcc)(void*); // This will be set in gcc_android.c for android-specific customization. -void (*x_cgo_inittls)(void **tlsg, void **tlsbase); +void (*x_cgo_inittls)(void **tlsg, void **tlsbase) __attribute__((common)); void x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase) diff --git a/src/runtime/cgo/gcc_linux_amd64.c b/src/runtime/cgo/gcc_linux_amd64.c index 9134e0df92..c25e7e769b 100644 --- a/src/runtime/cgo/gcc_linux_amd64.c +++ b/src/runtime/cgo/gcc_linux_amd64.c @@ -14,7 +14,7 @@ static void* threadentry(void*); static void (*setg_gcc)(void*); // This will be set in gcc_android.c for android-specific customization. -void (*x_cgo_inittls)(void **tlsg, void **tlsbase); +void (*x_cgo_inittls)(void **tlsg, void **tlsbase) __attribute__((common)); void x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase) @@ -89,11 +89,6 @@ threadentry(void *v) free(v); _cgo_tsan_release(); - /* - * Set specific keys. - */ - setg_gcc((void*)ts.g); - - crosscall_amd64(ts.fn); + crosscall_amd64(ts.fn, setg_gcc, (void*)ts.g); return nil; } diff --git a/src/runtime/cgo/gcc_linux_arm.c b/src/runtime/cgo/gcc_linux_arm.c index 61855b96b2..5bc0fee90d 100644 --- a/src/runtime/cgo/gcc_linux_arm.c +++ b/src/runtime/cgo/gcc_linux_arm.c @@ -10,7 +10,7 @@ static void *threadentry(void*); -void (*x_cgo_inittls)(void **tlsg, void **tlsbase); +void (*x_cgo_inittls)(void **tlsg, void **tlsbase) __attribute__((common)); static void (*setg_gcc)(void*); void diff --git a/src/runtime/cgo/gcc_linux_arm64.c b/src/runtime/cgo/gcc_linux_arm64.c index 261c884ac9..17ff274fbb 100644 --- a/src/runtime/cgo/gcc_linux_arm64.c +++ b/src/runtime/cgo/gcc_linux_arm64.c @@ -12,7 +12,7 @@ static void *threadentry(void*); -void (*x_cgo_inittls)(void **tlsg, void **tlsbase); +void (*x_cgo_inittls)(void **tlsg, void **tlsbase) __attribute__((common)); static void (*setg_gcc)(void*); void diff --git a/src/runtime/cgo/gcc_netbsd_amd64.c b/src/runtime/cgo/gcc_netbsd_amd64.c index dc966fc45b..9f4b031a08 100644 --- a/src/runtime/cgo/gcc_netbsd_amd64.c +++ b/src/runtime/cgo/gcc_netbsd_amd64.c @@ -62,11 +62,6 @@ threadentry(void *v) ts = *(ThreadStart*)v; free(v); - /* - * Set specific keys. - */ - setg_gcc((void*)ts.g); - // On NetBSD, a new thread inherits the signal stack of the // creating thread. That confuses minit, so we remove that // signal stack here before calling the regular mstart. It's @@ -78,6 +73,6 @@ threadentry(void *v) ss.ss_flags = SS_DISABLE; sigaltstack(&ss, nil); - crosscall_amd64(ts.fn); + crosscall_amd64(ts.fn, setg_gcc, (void*)ts.g); return nil; } diff --git a/src/runtime/cgo/gcc_openbsd_amd64.c b/src/runtime/cgo/gcc_openbsd_amd64.c index 34319fb0b8..09d2750f3a 100644 --- a/src/runtime/cgo/gcc_openbsd_amd64.c +++ b/src/runtime/cgo/gcc_openbsd_amd64.c @@ -60,11 +60,6 @@ threadentry(void *v) ts = *(ThreadStart*)v; free(v); - /* - * Set specific keys. - */ - setg_gcc((void*)ts.g); - - crosscall_amd64(ts.fn); + crosscall_amd64(ts.fn, setg_gcc, (void*)ts.g); return nil; } diff --git a/src/runtime/cgo/gcc_solaris_amd64.c b/src/runtime/cgo/gcc_solaris_amd64.c index 079bd12898..e89e844b1e 100644 --- a/src/runtime/cgo/gcc_solaris_amd64.c +++ b/src/runtime/cgo/gcc_solaris_amd64.c @@ -72,11 +72,6 @@ threadentry(void *v) ts = *(ThreadStart*)v; free(v); - /* - * Set specific keys. - */ - setg_gcc((void*)ts.g); - - crosscall_amd64(ts.fn); + crosscall_amd64(ts.fn, setg_gcc, (void*)ts.g); return nil; } diff --git a/src/runtime/cgo/gcc_windows_amd64.c b/src/runtime/cgo/gcc_windows_amd64.c index 0f8c817f0e..25cfd086dd 100644 --- a/src/runtime/cgo/gcc_windows_amd64.c +++ b/src/runtime/cgo/gcc_windows_amd64.c @@ -12,10 +12,12 @@ #include "libcgo_windows.h" static void threadentry(void*); +static void (*setg_gcc)(void*); void -x_cgo_init(G *g) +x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase) { + setg_gcc = setg; } @@ -46,10 +48,8 @@ threadentry(void *v) */ asm volatile ( "movq %0, %%gs:0x28\n" // MOVL tls0, 0x28(GS) - "movq %%gs:0x28, %%rax\n" // MOVQ 0x28(GS), tmp - "movq %1, 0(%%rax)\n" // MOVQ g, 0(GS) - :: "r"(ts.tls), "r"(ts.g) : "%rax" + :: "r"(ts.tls) ); - crosscall_amd64(ts.fn); + crosscall_amd64(ts.fn, setg_gcc, (void*)ts.g); } diff --git a/src/runtime/cgo/libcgo.h b/src/runtime/cgo/libcgo.h index aba500a301..af4960e7e9 100644 --- a/src/runtime/cgo/libcgo.h +++ b/src/runtime/cgo/libcgo.h @@ -66,7 +66,7 @@ uintptr_t _cgo_wait_runtime_init_done(void); /* * Call fn in the 6c world. */ -void crosscall_amd64(void (*fn)(void)); +void crosscall_amd64(void (*fn)(void), void (*setg_gcc)(void*), void *g); /* * Call fn in the 8c world. diff --git a/src/runtime/cgo/linux_syscall.c b/src/runtime/cgo/linux_syscall.c index c8e91918a1..56f3d67d8b 100644 --- a/src/runtime/cgo/linux_syscall.c +++ b/src/runtime/cgo/linux_syscall.c @@ -10,7 +10,7 @@ #include <grp.h> #include <sys/types.h> -#include <sys/unistd.h> +#include <unistd.h> #include <errno.h> #include "libcgo.h" diff --git a/src/runtime/chan.go b/src/runtime/chan.go index 859f36c914..ba56e2cc40 100644 --- a/src/runtime/chan.go +++ b/src/runtime/chan.go @@ -215,8 +215,7 @@ func chansend(c *hchan, ep unsafe.Pointer, block bool, callerpc uintptr) bool { // Space is available in the channel buffer. Enqueue the element to send. qp := chanbuf(c, c.sendx) if raceenabled { - raceacquire(qp) - racerelease(qp) + racenotify(c, c.sendx, nil) } typedmemmove(c.elemtype, qp, ep) c.sendx++ @@ -298,11 +297,8 @@ func send(c *hchan, sg *sudog, ep unsafe.Pointer, unlockf func(), skip int) { // Pretend we go through the buffer, even though // we copy directly. Note that we need to increment // the head/tail locations only when raceenabled. - qp := chanbuf(c, c.recvx) - raceacquire(qp) - racerelease(qp) - raceacquireg(sg.g, qp) - racereleaseg(sg.g, qp) + racenotify(c, c.recvx, nil) + racenotify(c, c.recvx, sg) c.recvx++ if c.recvx == c.dataqsiz { c.recvx = 0 @@ -535,8 +531,7 @@ func chanrecv(c *hchan, ep unsafe.Pointer, block bool) (selected, received bool) // Receive directly from queue qp := chanbuf(c, c.recvx) if raceenabled { - raceacquire(qp) - racerelease(qp) + racenotify(c, c.recvx, nil) } if ep != nil { typedmemmove(c.elemtype, ep, qp) @@ -625,10 +620,8 @@ func recv(c *hchan, sg *sudog, ep unsafe.Pointer, unlockf func(), skip int) { // queue is full, those are both the same slot. qp := chanbuf(c, c.recvx) if raceenabled { - raceacquire(qp) - racerelease(qp) - raceacquireg(sg.g, qp) - racereleaseg(sg.g, qp) + racenotify(c, c.recvx, nil) + racenotify(c, c.recvx, sg) } // copy data from queue to receiver if ep != nil { @@ -839,3 +832,38 @@ func racesync(c *hchan, sg *sudog) { racereleaseg(sg.g, chanbuf(c, 0)) raceacquire(chanbuf(c, 0)) } + +// Notify the race detector of a send or receive involving buffer entry idx +// and a channel c or its communicating partner sg. +// This function handles the special case of c.elemsize==0. +func racenotify(c *hchan, idx uint, sg *sudog) { + // We could have passed the unsafe.Pointer corresponding to entry idx + // instead of idx itself. However, in a future version of this function, + // we can use idx to better handle the case of elemsize==0. + // A future improvement to the detector is to call TSan with c and idx: + // this way, Go will continue to not allocating buffer entries for channels + // of elemsize==0, yet the race detector can be made to handle multiple + // sync objects underneath the hood (one sync object per idx) + qp := chanbuf(c, idx) + // When elemsize==0, we don't allocate a full buffer for the channel. + // Instead of individual buffer entries, the race detector uses the + // c.buf as the only buffer entry. This simplification prevents us from + // following the memory model's happens-before rules (rules that are + // implemented in racereleaseacquire). Instead, we accumulate happens-before + // information in the synchronization object associated with c.buf. + if c.elemsize == 0 { + if sg == nil { + raceacquire(qp) + racerelease(qp) + } else { + raceacquireg(sg.g, qp) + racereleaseg(sg.g, qp) + } + } else { + if sg == nil { + racereleaseacquire(qp) + } else { + racereleaseacquireg(sg.g, qp) + } + } +} diff --git a/src/runtime/crash_cgo_test.go b/src/runtime/crash_cgo_test.go index 0680d07a32..140c170ddc 100644 --- a/src/runtime/crash_cgo_test.go +++ b/src/runtime/crash_cgo_test.go @@ -254,6 +254,24 @@ func TestCgoCrashTraceback(t *testing.T) { } } +func TestCgoCrashTracebackGo(t *testing.T) { + t.Parallel() + switch platform := runtime.GOOS + "/" + runtime.GOARCH; platform { + case "darwin/amd64": + case "linux/amd64": + case "linux/ppc64le": + default: + t.Skipf("not yet supported on %s", platform) + } + got := runTestProg(t, "testprogcgo", "CrashTracebackGo") + for i := 1; i <= 3; i++ { + want := fmt.Sprintf("main.h%d", i) + if !strings.Contains(got, want) { + t.Errorf("missing %s", want) + } + } +} + func TestCgoTracebackContext(t *testing.T) { t.Parallel() got := runTestProg(t, "testprogcgo", "TracebackContext") diff --git a/src/runtime/crash_test.go b/src/runtime/crash_test.go index 5e22b7593e..e5bd7973b7 100644 --- a/src/runtime/crash_test.go +++ b/src/runtime/crash_test.go @@ -9,7 +9,6 @@ import ( "flag" "fmt" "internal/testenv" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -117,7 +116,7 @@ func buildTestProg(t *testing.T, binary string, flags ...string) (string, error) testprog.Lock() defer testprog.Unlock() if testprog.dir == "" { - dir, err := ioutil.TempDir("", "go-build") + dir, err := os.MkdirTemp("", "go-build") if err != nil { t.Fatalf("failed to create temp directory: %v", err) } @@ -295,6 +294,18 @@ func TestRecursivePanic4(t *testing.T) { } +func TestRecursivePanic5(t *testing.T) { + output := runTestProg(t, "testprog", "RecursivePanic5") + want := `first panic +second panic +panic: third panic +` + if !strings.HasPrefix(output, want) { + t.Fatalf("output does not start with %q:\n%s", want, output) + } + +} + func TestGoexitCrash(t *testing.T) { // External linking brings in cgo, causing deadlock detection not working. testenv.MustInternalLink(t) diff --git a/src/runtime/crash_unix_test.go b/src/runtime/crash_unix_test.go index 6c42cb9a3d..803b031873 100644 --- a/src/runtime/crash_unix_test.go +++ b/src/runtime/crash_unix_test.go @@ -10,7 +10,6 @@ import ( "bytes" "internal/testenv" "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -85,13 +84,13 @@ func TestCrashDumpsAllThreads(t *testing.T) { t.Parallel() - dir, err := ioutil.TempDir("", "go-build") + dir, err := os.MkdirTemp("", "go-build") if err != nil { t.Fatalf("failed to create temp directory: %v", err) } defer os.RemoveAll(dir) - if err := ioutil.WriteFile(filepath.Join(dir, "main.go"), []byte(crashDumpsAllThreadsSource), 0666); err != nil { + if err := os.WriteFile(filepath.Join(dir, "main.go"), []byte(crashDumpsAllThreadsSource), 0666); err != nil { t.Fatalf("failed to create Go file: %v", err) } @@ -232,13 +231,20 @@ func TestPanicSystemstack(t *testing.T) { } defer pr.Close() - // Wait for "x\nx\n" to indicate readiness. + // Wait for "x\nx\n" to indicate almost-readiness. buf := make([]byte, 4) _, err = io.ReadFull(pr, buf) if err != nil || string(buf) != "x\nx\n" { t.Fatal("subprocess failed; output:\n", string(buf)) } + // The child blockers print "x\n" and then block on a lock. Receiving + // those bytes only indicates that the child is _about to block_. Since + // we don't have a way to know when it is fully blocked, sleep a bit to + // make us less likely to lose the race and signal before the child + // blocks. + time.Sleep(100 * time.Millisecond) + // Send SIGQUIT. if err := cmd.Process.Signal(syscall.SIGQUIT); err != nil { t.Fatal("signaling subprocess: ", err) diff --git a/src/runtime/debug/heapdump_test.go b/src/runtime/debug/heapdump_test.go index de1ec27d21..768934d05d 100644 --- a/src/runtime/debug/heapdump_test.go +++ b/src/runtime/debug/heapdump_test.go @@ -5,7 +5,6 @@ package debug_test import ( - "io/ioutil" "os" "runtime" . "runtime/debug" @@ -16,7 +15,7 @@ func TestWriteHeapDumpNonempty(t *testing.T) { if runtime.GOOS == "js" { t.Skipf("WriteHeapDump is not available on %s.", runtime.GOOS) } - f, err := ioutil.TempFile("", "heapdumptest") + f, err := os.CreateTemp("", "heapdumptest") if err != nil { t.Fatalf("TempFile failed: %v", err) } @@ -45,7 +44,7 @@ func TestWriteHeapDumpFinalizers(t *testing.T) { if runtime.GOOS == "js" { t.Skipf("WriteHeapDump is not available on %s.", runtime.GOOS) } - f, err := ioutil.TempFile("", "heapdumptest") + f, err := os.CreateTemp("", "heapdumptest") if err != nil { t.Fatalf("TempFile failed: %v", err) } diff --git a/src/runtime/debug_test.go b/src/runtime/debug_test.go index 722e81121f..a0b3f84382 100644 --- a/src/runtime/debug_test.go +++ b/src/runtime/debug_test.go @@ -17,7 +17,7 @@ package runtime_test import ( "fmt" - "io/ioutil" + "os" "regexp" "runtime" "runtime/debug" @@ -95,7 +95,7 @@ func debugCallTKill(tid int) error { // Linux-specific. func skipUnderDebugger(t *testing.T) { pid := syscall.Getpid() - status, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/status", pid)) + status, err := os.ReadFile(fmt.Sprintf("/proc/%d/status", pid)) if err != nil { t.Logf("couldn't get proc tracer: %s", err) return diff --git a/src/runtime/defer_test.go b/src/runtime/defer_test.go index 5ac0814564..9a40ea1984 100644 --- a/src/runtime/defer_test.go +++ b/src/runtime/defer_test.go @@ -410,3 +410,31 @@ func rec1(max int) { rec1(max - 1) } } + +func TestIssue43921(t *testing.T) { + defer func() { + expect(t, 1, recover()) + }() + func() { + // Prevent open-coded defers + for { + defer func() {}() + break + } + + defer func() { + defer func() { + expect(t, 4, recover()) + }() + panic(4) + }() + panic(1) + + }() +} + +func expect(t *testing.T, n int, err interface{}) { + if n != err { + t.Fatalf("have %v, want %v", err, n) + } +} diff --git a/src/runtime/defs_freebsd_386.go b/src/runtime/defs_freebsd_386.go index 767755425c..f822934d58 100644 --- a/src/runtime/defs_freebsd_386.go +++ b/src/runtime/defs_freebsd_386.go @@ -13,10 +13,11 @@ const ( ) const ( - _EINTR = 0x4 - _EFAULT = 0xe - _EAGAIN = 0x23 - _ENOSYS = 0x4e + _EINTR = 0x4 + _EFAULT = 0xe + _EAGAIN = 0x23 + _ENOSYS = 0x4e + _ETIMEDOUT = 0x3c _O_NONBLOCK = 0x4 _O_CLOEXEC = 0x100000 diff --git a/src/runtime/defs_freebsd_amd64.go b/src/runtime/defs_freebsd_amd64.go index 5a833426fd..0b696cf227 100644 --- a/src/runtime/defs_freebsd_amd64.go +++ b/src/runtime/defs_freebsd_amd64.go @@ -13,10 +13,11 @@ const ( ) const ( - _EINTR = 0x4 - _EFAULT = 0xe - _EAGAIN = 0x23 - _ENOSYS = 0x4e + _EINTR = 0x4 + _EFAULT = 0xe + _EAGAIN = 0x23 + _ENOSYS = 0x4e + _ETIMEDOUT = 0x3c _O_NONBLOCK = 0x4 _O_CLOEXEC = 0x100000 diff --git a/src/runtime/defs_freebsd_arm.go b/src/runtime/defs_freebsd_arm.go index b55dfd88cf..b6f3e790cf 100644 --- a/src/runtime/defs_freebsd_arm.go +++ b/src/runtime/defs_freebsd_arm.go @@ -13,10 +13,11 @@ const ( ) const ( - _EINTR = 0x4 - _EFAULT = 0xe - _EAGAIN = 0x23 - _ENOSYS = 0x4e + _EINTR = 0x4 + _EFAULT = 0xe + _EAGAIN = 0x23 + _ENOSYS = 0x4e + _ETIMEDOUT = 0x3c _O_NONBLOCK = 0x4 _O_CLOEXEC = 0x100000 diff --git a/src/runtime/defs_freebsd_arm64.go b/src/runtime/defs_freebsd_arm64.go index 5b9d504ba6..0759a1238f 100644 --- a/src/runtime/defs_freebsd_arm64.go +++ b/src/runtime/defs_freebsd_arm64.go @@ -13,10 +13,11 @@ const ( ) const ( - _EINTR = 0x4 - _EFAULT = 0xe - _EAGAIN = 0x23 - _ENOSYS = 0x4e + _EINTR = 0x4 + _EFAULT = 0xe + _EAGAIN = 0x23 + _ENOSYS = 0x4e + _ETIMEDOUT = 0x3c _O_NONBLOCK = 0x4 _O_CLOEXEC = 0x100000 diff --git a/src/runtime/defs_openbsd.go b/src/runtime/defs_openbsd.go index 53e9d59a3c..ff7e21c71e 100644 --- a/src/runtime/defs_openbsd.go +++ b/src/runtime/defs_openbsd.go @@ -54,6 +54,13 @@ const ( SA_RESTART = C.SA_RESTART SA_ONSTACK = C.SA_ONSTACK + PTHREAD_CREATE_DETACHED = C.PTHREAD_CREATE_DETACHED + + F_SETFD = C.F_SETFD + F_GETFL = C.F_GETFL + F_SETFL = C.F_SETFL + FD_CLOEXEC = C.FD_CLOEXEC + SIGHUP = C.SIGHUP SIGINT = C.SIGINT SIGQUIT = C.SIGQUIT @@ -129,3 +136,10 @@ type Timeval C.struct_timeval type Itimerval C.struct_itimerval type KeventT C.struct_kevent + +type Pthread C.pthread_t +type PthreadAttr C.pthread_attr_t +type PthreadCond C.pthread_cond_t +type PthreadCondAttr C.pthread_condattr_t +type PthreadMutex C.pthread_mutex_t +type PthreadMutexAttr C.pthread_mutexattr_t diff --git a/src/runtime/defs_openbsd_amd64.go b/src/runtime/defs_openbsd_amd64.go index c187a98ae0..46f1245201 100644 --- a/src/runtime/defs_openbsd_amd64.go +++ b/src/runtime/defs_openbsd_amd64.go @@ -30,6 +30,13 @@ const ( _SA_RESTART = 0x2 _SA_ONSTACK = 0x1 + _PTHREAD_CREATE_DETACHED = 0x1 + + _F_SETFD = 0x2 + _F_GETFL = 0x3 + _F_SETFL = 0x4 + _FD_CLOEXEC = 0x1 + _SIGHUP = 0x1 _SIGINT = 0x2 _SIGQUIT = 0x3 @@ -177,3 +184,10 @@ type keventt struct { data int64 udata *byte } + +type pthread uintptr +type pthreadattr uintptr +type pthreadcond uintptr +type pthreadcondattr uintptr +type pthreadmutex uintptr +type pthreadmutexattr uintptr diff --git a/src/runtime/defs_openbsd_arm64.go b/src/runtime/defs_openbsd_arm64.go index 628f4bc5a5..d2b947feb2 100644 --- a/src/runtime/defs_openbsd_arm64.go +++ b/src/runtime/defs_openbsd_arm64.go @@ -31,6 +31,13 @@ const ( _SA_RESTART = 0x2 _SA_ONSTACK = 0x1 + _PTHREAD_CREATE_DETACHED = 0x1 + + _F_SETFD = 0x2 + _F_GETFL = 0x3 + _F_SETFL = 0x4 + _FD_CLOEXEC = 0x1 + _SIGHUP = 0x1 _SIGINT = 0x2 _SIGQUIT = 0x3 @@ -157,3 +164,10 @@ type keventt struct { data int64 udata *byte } + +type pthread uintptr +type pthreadattr uintptr +type pthreadcond uintptr +type pthreadcondattr uintptr +type pthreadmutex uintptr +type pthreadmutexattr uintptr diff --git a/src/runtime/duff_amd64.s b/src/runtime/duff_amd64.s index 2ff5bf6dbc..df010f5853 100644 --- a/src/runtime/duff_amd64.s +++ b/src/runtime/duff_amd64.s @@ -5,100 +5,100 @@ #include "textflag.h" TEXT runtime·duffzero<ABIInternal>(SB), NOSPLIT, $0-0 - MOVUPS X0,(DI) - MOVUPS X0,16(DI) - MOVUPS X0,32(DI) - MOVUPS X0,48(DI) + MOVUPS X15,(DI) + MOVUPS X15,16(DI) + MOVUPS X15,32(DI) + MOVUPS X15,48(DI) LEAQ 64(DI),DI - MOVUPS X0,(DI) - MOVUPS X0,16(DI) - MOVUPS X0,32(DI) - MOVUPS X0,48(DI) + MOVUPS X15,(DI) + MOVUPS X15,16(DI) + MOVUPS X15,32(DI) + MOVUPS X15,48(DI) LEAQ 64(DI),DI - MOVUPS X0,(DI) - MOVUPS X0,16(DI) - MOVUPS X0,32(DI) - MOVUPS X0,48(DI) + MOVUPS X15,(DI) + MOVUPS X15,16(DI) + MOVUPS X15,32(DI) + MOVUPS X15,48(DI) LEAQ 64(DI),DI - MOVUPS X0,(DI) - MOVUPS X0,16(DI) - MOVUPS X0,32(DI) - MOVUPS X0,48(DI) + MOVUPS X15,(DI) + MOVUPS X15,16(DI) + MOVUPS X15,32(DI) + MOVUPS X15,48(DI) LEAQ 64(DI),DI - MOVUPS X0,(DI) - MOVUPS X0,16(DI) - MOVUPS X0,32(DI) - MOVUPS X0,48(DI) + MOVUPS X15,(DI) + MOVUPS X15,16(DI) + MOVUPS X15,32(DI) + MOVUPS X15,48(DI) LEAQ 64(DI),DI - MOVUPS X0,(DI) - MOVUPS X0,16(DI) - MOVUPS X0,32(DI) - MOVUPS X0,48(DI) + MOVUPS X15,(DI) + MOVUPS X15,16(DI) + MOVUPS X15,32(DI) + MOVUPS X15,48(DI) LEAQ 64(DI),DI - MOVUPS X0,(DI) - MOVUPS X0,16(DI) - MOVUPS X0,32(DI) - MOVUPS X0,48(DI) + MOVUPS X15,(DI) + MOVUPS X15,16(DI) + MOVUPS X15,32(DI) + MOVUPS X15,48(DI) LEAQ 64(DI),DI - MOVUPS X0,(DI) - MOVUPS X0,16(DI) - MOVUPS X0,32(DI) - MOVUPS X0,48(DI) + MOVUPS X15,(DI) + MOVUPS X15,16(DI) + MOVUPS X15,32(DI) + MOVUPS X15,48(DI) LEAQ 64(DI),DI - MOVUPS X0,(DI) - MOVUPS X0,16(DI) - MOVUPS X0,32(DI) - MOVUPS X0,48(DI) + MOVUPS X15,(DI) + MOVUPS X15,16(DI) + MOVUPS X15,32(DI) + MOVUPS X15,48(DI) LEAQ 64(DI),DI - MOVUPS X0,(DI) - MOVUPS X0,16(DI) - MOVUPS X0,32(DI) - MOVUPS X0,48(DI) + MOVUPS X15,(DI) + MOVUPS X15,16(DI) + MOVUPS X15,32(DI) + MOVUPS X15,48(DI) LEAQ 64(DI),DI - MOVUPS X0,(DI) - MOVUPS X0,16(DI) - MOVUPS X0,32(DI) - MOVUPS X0,48(DI) + MOVUPS X15,(DI) + MOVUPS X15,16(DI) + MOVUPS X15,32(DI) + MOVUPS X15,48(DI) LEAQ 64(DI),DI - MOVUPS X0,(DI) - MOVUPS X0,16(DI) - MOVUPS X0,32(DI) - MOVUPS X0,48(DI) + MOVUPS X15,(DI) + MOVUPS X15,16(DI) + MOVUPS X15,32(DI) + MOVUPS X15,48(DI) LEAQ 64(DI),DI - MOVUPS X0,(DI) - MOVUPS X0,16(DI) - MOVUPS X0,32(DI) - MOVUPS X0,48(DI) + MOVUPS X15,(DI) + MOVUPS X15,16(DI) + MOVUPS X15,32(DI) + MOVUPS X15,48(DI) LEAQ 64(DI),DI - MOVUPS X0,(DI) - MOVUPS X0,16(DI) - MOVUPS X0,32(DI) - MOVUPS X0,48(DI) + MOVUPS X15,(DI) + MOVUPS X15,16(DI) + MOVUPS X15,32(DI) + MOVUPS X15,48(DI) LEAQ 64(DI),DI - MOVUPS X0,(DI) - MOVUPS X0,16(DI) - MOVUPS X0,32(DI) - MOVUPS X0,48(DI) + MOVUPS X15,(DI) + MOVUPS X15,16(DI) + MOVUPS X15,32(DI) + MOVUPS X15,48(DI) LEAQ 64(DI),DI - MOVUPS X0,(DI) - MOVUPS X0,16(DI) - MOVUPS X0,32(DI) - MOVUPS X0,48(DI) + MOVUPS X15,(DI) + MOVUPS X15,16(DI) + MOVUPS X15,32(DI) + MOVUPS X15,48(DI) LEAQ 64(DI),DI RET diff --git a/src/runtime/env_plan9.go b/src/runtime/env_plan9.go index b7ea863735..f1ac4760a7 100644 --- a/src/runtime/env_plan9.go +++ b/src/runtime/env_plan9.go @@ -23,8 +23,8 @@ const ( // to the (possibly shared) Plan 9 environment, so that Setenv and Getenv // conform to the same Posix semantics as on other operating systems. // For Plan 9 shared environment semantics, instead of Getenv(key) and -// Setenv(key, value), one can use ioutil.ReadFile("/env/" + key) and -// ioutil.WriteFile("/env/" + key, value, 0666) respectively. +// Setenv(key, value), one can use os.ReadFile("/env/" + key) and +// os.WriteFile("/env/" + key, value, 0666) respectively. //go:nosplit func goenvs() { buf := make([]byte, envBufSize) diff --git a/src/runtime/export_pipe2_test.go b/src/runtime/export_pipe2_test.go new file mode 100644 index 0000000000..9d580d3313 --- /dev/null +++ b/src/runtime/export_pipe2_test.go @@ -0,0 +1,15 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build freebsd linux netbsd openbsd solaris + +package runtime + +func Pipe() (r, w int32, errno int32) { + r, w, errno = pipe2(0) + if errno == _ENOSYS { + return pipe() + } + return r, w, errno +} diff --git a/src/runtime/export_pipe_test.go b/src/runtime/export_pipe_test.go new file mode 100644 index 0000000000..8f66770fb9 --- /dev/null +++ b/src/runtime/export_pipe_test.go @@ -0,0 +1,9 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build aix darwin dragonfly + +package runtime + +var Pipe = pipe diff --git a/src/runtime/export_test.go b/src/runtime/export_test.go index 44551dcaf1..22fef3134f 100644 --- a/src/runtime/export_test.go +++ b/src/runtime/export_test.go @@ -1201,12 +1201,12 @@ type TimeHistogram timeHistogram // Counts returns the counts for the given bucket, subBucket indices. // Returns true if the bucket was valid, otherwise returns the counts -// for the overflow bucket and false. +// for the underflow bucket and false. func (th *TimeHistogram) Count(bucket, subBucket uint) (uint64, bool) { t := (*timeHistogram)(th) i := bucket*TimeHistNumSubBuckets + subBucket if i >= uint(len(t.counts)) { - return t.overflow, false + return t.underflow, false } return t.counts[i], true } diff --git a/src/runtime/export_unix_test.go b/src/runtime/export_unix_test.go index 621488eaba..307c63fd68 100644 --- a/src/runtime/export_unix_test.go +++ b/src/runtime/export_unix_test.go @@ -9,7 +9,6 @@ package runtime import "unsafe" var NonblockingPipe = nonblockingPipe -var Pipe = pipe var SetNonblock = setNonblock var Closeonexec = closeonexec diff --git a/src/runtime/histogram.go b/src/runtime/histogram.go index 4020969eb9..da4910d341 100644 --- a/src/runtime/histogram.go +++ b/src/runtime/histogram.go @@ -7,6 +7,7 @@ package runtime import ( "runtime/internal/atomic" "runtime/internal/sys" + "unsafe" ) const ( @@ -25,7 +26,7 @@ const ( // The number of super-buckets (timeHistNumSuperBuckets), on the // other hand, defines the range. To reserve room for sub-buckets, // bit timeHistSubBucketBits is the first bit considered for - // super-buckets, so super-bucket indicies are adjusted accordingly. + // super-buckets, so super-bucket indices are adjusted accordingly. // // As an example, consider 45 super-buckets with 16 sub-buckets. // @@ -69,17 +70,21 @@ const ( // for concurrent use. It is also safe to read all the values // atomically. type timeHistogram struct { - counts [timeHistNumSuperBuckets * timeHistNumSubBuckets]uint64 - overflow uint64 + counts [timeHistNumSuperBuckets * timeHistNumSubBuckets]uint64 + + // underflow counts all the times we got a negative duration + // sample. Because of how time works on some platforms, it's + // possible to measure negative durations. We could ignore them, + // but we record them anyway because it's better to have some + // signal that it's happening than just missing samples. + underflow uint64 } // record adds the given duration to the distribution. -// -// Although the duration is an int64 to facilitate ease-of-use -// with e.g. nanotime, the duration must be non-negative. func (h *timeHistogram) record(duration int64) { if duration < 0 { - throw("timeHistogram encountered negative duration") + atomic.Xadd64(&h.underflow, 1) + return } // The index of the exponential bucket is just the index // of the highest set bit adjusted for how many bits we @@ -92,29 +97,47 @@ func (h *timeHistogram) record(duration int64) { superBucket = uint(sys.Len64(uint64(duration))) - timeHistSubBucketBits if superBucket*timeHistNumSubBuckets >= uint(len(h.counts)) { // The bucket index we got is larger than what we support, so - // add into the special overflow bucket. - atomic.Xadd64(&h.overflow, 1) - return + // include this count in the highest bucket, which extends to + // infinity. + superBucket = timeHistNumSuperBuckets - 1 + subBucket = timeHistNumSubBuckets - 1 + } else { + // The linear subbucket index is just the timeHistSubBucketsBits + // bits after the top bit. To extract that value, shift down + // the duration such that we leave the top bit and the next bits + // intact, then extract the index. + subBucket = uint((duration >> (superBucket - 1)) % timeHistNumSubBuckets) } - // The linear subbucket index is just the timeHistSubBucketsBits - // bits after the top bit. To extract that value, shift down - // the duration such that we leave the top bit and the next bits - // intact, then extract the index. - subBucket = uint((duration >> (superBucket - 1)) % timeHistNumSubBuckets) } else { subBucket = uint(duration) } atomic.Xadd64(&h.counts[superBucket*timeHistNumSubBuckets+subBucket], 1) } +const ( + fInf = 0x7FF0000000000000 + fNegInf = 0xFFF0000000000000 +) + +func float64Inf() float64 { + inf := uint64(fInf) + return *(*float64)(unsafe.Pointer(&inf)) +} + +func float64NegInf() float64 { + inf := uint64(fNegInf) + return *(*float64)(unsafe.Pointer(&inf)) +} + // timeHistogramMetricsBuckets generates a slice of boundaries for // the timeHistogram. These boundaries are represented in seconds, // not nanoseconds like the timeHistogram represents durations. func timeHistogramMetricsBuckets() []float64 { - b := make([]float64, timeHistTotalBuckets-1) + b := make([]float64, timeHistTotalBuckets+1) + b[0] = float64NegInf() for i := 0; i < timeHistNumSuperBuckets; i++ { superBucketMin := uint64(0) - // The (inclusive) minimum for the first bucket is 0. + // The (inclusive) minimum for the first non-negative bucket is 0. if i > 0 { // The minimum for the second bucket will be // 1 << timeHistSubBucketBits, indicating that all @@ -128,7 +151,7 @@ func timeHistogramMetricsBuckets() []float64 { // index to combine it with the bucketMin. subBucketShift := uint(0) if i > 1 { - // The first two buckets are exact with respect to integers, + // The first two super buckets are exact with respect to integers, // so we'll never have to shift the sub-bucket index. Thereafter, // we shift up by 1 with each subsequent bucket. subBucketShift = uint(i - 2) @@ -141,8 +164,9 @@ func timeHistogramMetricsBuckets() []float64 { // Convert the subBucketMin which is in nanoseconds to a float64 seconds value. // These values will all be exactly representable by a float64. - b[i*timeHistNumSubBuckets+j] = float64(subBucketMin) / 1e9 + b[i*timeHistNumSubBuckets+j+1] = float64(subBucketMin) / 1e9 } } + b[len(b)-1] = float64Inf() return b } diff --git a/src/runtime/histogram_test.go b/src/runtime/histogram_test.go index 5f5b28f784..dbc64fa559 100644 --- a/src/runtime/histogram_test.go +++ b/src/runtime/histogram_test.go @@ -5,6 +5,7 @@ package runtime_test import ( + "math" . "runtime" "testing" ) @@ -32,8 +33,8 @@ func TestTimeHistogram(t *testing.T) { h.Record(base + v) } } - // Hit the overflow bucket. - h.Record(int64(^uint64(0) >> 1)) + // Hit the underflow bucket. + h.Record(int64(-1)) // Check to make sure there's exactly one count in each // bucket. @@ -41,7 +42,7 @@ func TestTimeHistogram(t *testing.T) { for j := uint(0); j < TimeHistNumSubBuckets; j++ { c, ok := h.Count(i, j) if !ok { - t.Errorf("hit overflow bucket unexpectedly: (%d, %d)", i, j) + t.Errorf("hit underflow bucket unexpectedly: (%d, %d)", i, j) } else if c != 1 { t.Errorf("bucket (%d, %d) has count that is not 1: %d", i, j, c) } @@ -49,10 +50,21 @@ func TestTimeHistogram(t *testing.T) { } c, ok := h.Count(TimeHistNumSuperBuckets, 0) if ok { - t.Errorf("expected to hit overflow bucket: (%d, %d)", TimeHistNumSuperBuckets, 0) + t.Errorf("expected to hit underflow bucket: (%d, %d)", TimeHistNumSuperBuckets, 0) } if c != 1 { - t.Errorf("overflow bucket has count that is not 1: %d", c) + t.Errorf("underflow bucket has count that is not 1: %d", c) } + + // Check overflow behavior. + // By hitting a high value, we should just be adding into the highest bucket. + h.Record(math.MaxInt64) + c, ok = h.Count(TimeHistNumSuperBuckets-1, TimeHistNumSubBuckets-1) + if !ok { + t.Error("hit underflow bucket in highest bucket unexpectedly") + } else if c != 2 { + t.Errorf("highest has count that is not 2: %d", c) + } + dummyTimeHistogram = TimeHistogram{} } diff --git a/src/runtime/internal/sys/gengoos.go b/src/runtime/internal/sys/gengoos.go index 2a4bf0c3b4..9bbc48d94f 100644 --- a/src/runtime/internal/sys/gengoos.go +++ b/src/runtime/internal/sys/gengoos.go @@ -9,8 +9,8 @@ package main import ( "bytes" "fmt" - "io/ioutil" "log" + "os" "strconv" "strings" ) @@ -18,7 +18,7 @@ import ( var gooses, goarches []string func main() { - data, err := ioutil.ReadFile("../../../go/build/syslist.go") + data, err := os.ReadFile("../../../go/build/syslist.go") if err != nil { log.Fatal(err) } @@ -68,7 +68,7 @@ func main() { } fmt.Fprintf(&buf, "const Goos%s = %d\n", strings.Title(goos), value) } - err := ioutil.WriteFile("zgoos_"+target+".go", buf.Bytes(), 0666) + err := os.WriteFile("zgoos_"+target+".go", buf.Bytes(), 0666) if err != nil { log.Fatal(err) } @@ -90,7 +90,7 @@ func main() { } fmt.Fprintf(&buf, "const Goarch%s = %d\n", strings.Title(goarch), value) } - err := ioutil.WriteFile("zgoarch_"+target+".go", buf.Bytes(), 0666) + err := os.WriteFile("zgoarch_"+target+".go", buf.Bytes(), 0666) if err != nil { log.Fatal(err) } diff --git a/src/runtime/lockrank.go b/src/runtime/lockrank.go index 0a52e8ed3d..b3c01ba104 100644 --- a/src/runtime/lockrank.go +++ b/src/runtime/lockrank.go @@ -213,7 +213,7 @@ var lockPartialOrder [][]lockRank = [][]lockRank{ lockRankNotifyList: {}, lockRankTraceBuf: {lockRankSysmon, lockRankScavenge}, lockRankTraceStrings: {lockRankTraceBuf}, - lockRankMspanSpecial: {lockRankSysmon, lockRankScavenge, lockRankAssistQueue, lockRankCpuprof, lockRankSched, lockRankAllg, lockRankAllp, lockRankTimers, lockRankItab, lockRankReflectOffs, lockRankHchan, lockRankNotifyList, lockRankTraceBuf, lockRankTraceStrings}, + lockRankMspanSpecial: {lockRankSysmon, lockRankScavenge, lockRankAssistQueue, lockRankCpuprof, lockRankSweep, lockRankSched, lockRankAllg, lockRankAllp, lockRankTimers, lockRankItab, lockRankReflectOffs, lockRankHchan, lockRankNotifyList, lockRankTraceBuf, lockRankTraceStrings}, lockRankProf: {lockRankSysmon, lockRankScavenge, lockRankAssistQueue, lockRankCpuprof, lockRankSweep, lockRankSched, lockRankAllg, lockRankAllp, lockRankTimers, lockRankItab, lockRankReflectOffs, lockRankNotifyList, lockRankTraceBuf, lockRankTraceStrings, lockRankHchan}, lockRankGcBitsArenas: {lockRankSysmon, lockRankScavenge, lockRankAssistQueue, lockRankCpuprof, lockRankSched, lockRankAllg, lockRankTimers, lockRankItab, lockRankReflectOffs, lockRankNotifyList, lockRankTraceBuf, lockRankTraceStrings, lockRankHchan}, lockRankRoot: {}, @@ -224,7 +224,7 @@ var lockPartialOrder [][]lockRank = [][]lockRank{ lockRankRwmutexW: {}, lockRankRwmutexR: {lockRankSysmon, lockRankRwmutexW}, - lockRankSpanSetSpine: {lockRankSysmon, lockRankScavenge, lockRankForcegc, lockRankAssistQueue, lockRankCpuprof, lockRankSweep, lockRankSched, lockRankAllg, lockRankAllp, lockRankTimers, lockRankItab, lockRankReflectOffs, lockRankNotifyList, lockRankTraceBuf, lockRankTraceStrings, lockRankHchan}, + lockRankSpanSetSpine: {lockRankSysmon, lockRankScavenge, lockRankForcegc, lockRankAssistQueue, lockRankCpuprof, lockRankSweep, lockRankPollDesc, lockRankSched, lockRankAllg, lockRankAllp, lockRankTimers, lockRankItab, lockRankReflectOffs, lockRankNotifyList, lockRankTraceBuf, lockRankTraceStrings, lockRankHchan}, lockRankGscan: {lockRankSysmon, lockRankScavenge, lockRankForcegc, lockRankSweepWaiters, lockRankAssistQueue, lockRankCpuprof, lockRankSweep, lockRankSched, lockRankTimers, lockRankItab, lockRankReflectOffs, lockRankHchan, lockRankFin, lockRankTraceBuf, lockRankTraceStrings, lockRankRoot, lockRankNotifyList, lockRankProf, lockRankGcBitsArenas, lockRankTrace, lockRankTraceStackTab, lockRankNetpollInit, lockRankSpanSetSpine}, lockRankStackpool: {lockRankSysmon, lockRankScavenge, lockRankSweepWaiters, lockRankAssistQueue, lockRankCpuprof, lockRankSweep, lockRankSched, lockRankPollDesc, lockRankTimers, lockRankItab, lockRankReflectOffs, lockRankHchan, lockRankFin, lockRankNotifyList, lockRankTraceBuf, lockRankTraceStrings, lockRankProf, lockRankGcBitsArenas, lockRankRoot, lockRankTrace, lockRankTraceStackTab, lockRankNetpollInit, lockRankRwmutexR, lockRankSpanSetSpine, lockRankGscan}, lockRankStackLarge: {lockRankSysmon, lockRankAssistQueue, lockRankSched, lockRankItab, lockRankHchan, lockRankProf, lockRankGcBitsArenas, lockRankRoot, lockRankSpanSetSpine, lockRankGscan}, diff --git a/src/runtime/mbarrier.go b/src/runtime/mbarrier.go index 2b5affce52..4994347bde 100644 --- a/src/runtime/mbarrier.go +++ b/src/runtime/mbarrier.go @@ -14,6 +14,7 @@ package runtime import ( + "internal/abi" "runtime/internal/sys" "unsafe" ) @@ -223,11 +224,18 @@ func reflect_typedmemmovepartial(typ *_type, dst, src unsafe.Pointer, off, size // stack map of reflectcall is wrong. // //go:nosplit -func reflectcallmove(typ *_type, dst, src unsafe.Pointer, size uintptr) { +func reflectcallmove(typ *_type, dst, src unsafe.Pointer, size uintptr, regs *abi.RegArgs) { if writeBarrier.needed && typ != nil && typ.ptrdata != 0 && size >= sys.PtrSize { bulkBarrierPreWrite(uintptr(dst), uintptr(src), size) } memmove(dst, src, size) + + // Move pointers returned in registers to a place where the GC can see them. + for i := range regs.Ints { + if regs.ReturnIsPtr.Get(i) { + regs.Ptrs[i] = unsafe.Pointer(regs.Ints[i]) + } + } } //go:nosplit diff --git a/src/runtime/memclr_386.s b/src/runtime/memclr_386.s index 65f7196312..5e090ef09e 100644 --- a/src/runtime/memclr_386.s +++ b/src/runtime/memclr_386.s @@ -9,6 +9,8 @@ // NOTE: Windows externalthreadhandler expects memclr to preserve DX. +// See memclrNoHeapPointers Go doc for important implementation constraints. + // func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) TEXT runtime·memclrNoHeapPointers(SB), NOSPLIT, $0-8 MOVL ptr+0(FP), DI diff --git a/src/runtime/memclr_amd64.s b/src/runtime/memclr_amd64.s index d79078fd00..37fe9745b1 100644 --- a/src/runtime/memclr_amd64.s +++ b/src/runtime/memclr_amd64.s @@ -9,6 +9,8 @@ // NOTE: Windows externalthreadhandler expects memclr to preserve DX. +// See memclrNoHeapPointers Go doc for important implementation constraints. + // func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) TEXT runtime·memclrNoHeapPointers(SB), NOSPLIT, $0-16 MOVQ ptr+0(FP), DI diff --git a/src/runtime/memclr_arm.s b/src/runtime/memclr_arm.s index 7326b8be34..f113a1aa2d 100644 --- a/src/runtime/memclr_arm.s +++ b/src/runtime/memclr_arm.s @@ -30,6 +30,8 @@ #define N R12 #define TMP R12 /* N and TMP don't overlap */ +// See memclrNoHeapPointers Go doc for important implementation constraints. + // func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) TEXT runtime·memclrNoHeapPointers(SB),NOSPLIT,$0-8 MOVW ptr+0(FP), TO diff --git a/src/runtime/memclr_arm64.s b/src/runtime/memclr_arm64.s index a56a6dfb85..bef77651e4 100644 --- a/src/runtime/memclr_arm64.s +++ b/src/runtime/memclr_arm64.s @@ -4,6 +4,8 @@ #include "textflag.h" +// See memclrNoHeapPointers Go doc for important implementation constraints. + // func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) TEXT runtime·memclrNoHeapPointers(SB),NOSPLIT,$0-16 MOVD ptr+0(FP), R0 diff --git a/src/runtime/memclr_mips64x.s b/src/runtime/memclr_mips64x.s index 4c2292eae8..d7a3251e20 100644 --- a/src/runtime/memclr_mips64x.s +++ b/src/runtime/memclr_mips64x.s @@ -7,6 +7,8 @@ #include "go_asm.h" #include "textflag.h" +// See memclrNoHeapPointers Go doc for important implementation constraints. + // func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) TEXT runtime·memclrNoHeapPointers(SB),NOSPLIT,$0-16 MOVV ptr+0(FP), R1 diff --git a/src/runtime/memclr_mipsx.s b/src/runtime/memclr_mipsx.s index 1561a23dbe..eb2a8a7219 100644 --- a/src/runtime/memclr_mipsx.s +++ b/src/runtime/memclr_mipsx.s @@ -14,6 +14,8 @@ #define MOVWLO MOVWL #endif +// See memclrNoHeapPointers Go doc for important implementation constraints. + // func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) TEXT runtime·memclrNoHeapPointers(SB),NOSPLIT,$0-8 MOVW n+4(FP), R2 diff --git a/src/runtime/memclr_plan9_386.s b/src/runtime/memclr_plan9_386.s index 5b880ae86f..54701a9453 100644 --- a/src/runtime/memclr_plan9_386.s +++ b/src/runtime/memclr_plan9_386.s @@ -4,6 +4,8 @@ #include "textflag.h" +// See memclrNoHeapPointers Go doc for important implementation constraints. + // func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) TEXT runtime·memclrNoHeapPointers(SB), NOSPLIT, $0-8 MOVL ptr+0(FP), DI diff --git a/src/runtime/memclr_plan9_amd64.s b/src/runtime/memclr_plan9_amd64.s index ad383cd6b3..8c6a1cc780 100644 --- a/src/runtime/memclr_plan9_amd64.s +++ b/src/runtime/memclr_plan9_amd64.s @@ -4,6 +4,8 @@ #include "textflag.h" +// See memclrNoHeapPointers Go doc for important implementation constraints. + // func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) TEXT runtime·memclrNoHeapPointers(SB),NOSPLIT,$0-16 MOVQ ptr+0(FP), DI diff --git a/src/runtime/memclr_ppc64x.s b/src/runtime/memclr_ppc64x.s index 072963f756..7512620894 100644 --- a/src/runtime/memclr_ppc64x.s +++ b/src/runtime/memclr_ppc64x.s @@ -6,6 +6,8 @@ #include "textflag.h" +// See memclrNoHeapPointers Go doc for important implementation constraints. + // func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) TEXT runtime·memclrNoHeapPointers(SB), NOSPLIT|NOFRAME, $0-16 MOVD ptr+0(FP), R3 diff --git a/src/runtime/memclr_riscv64.s b/src/runtime/memclr_riscv64.s index ba7704e805..54ddaa4560 100644 --- a/src/runtime/memclr_riscv64.s +++ b/src/runtime/memclr_riscv64.s @@ -4,6 +4,8 @@ #include "textflag.h" +// See memclrNoHeapPointers Go doc for important implementation constraints. + // void runtime·memclrNoHeapPointers(void*, uintptr) TEXT runtime·memclrNoHeapPointers(SB),NOSPLIT,$0-16 MOV ptr+0(FP), T1 diff --git a/src/runtime/memclr_s390x.s b/src/runtime/memclr_s390x.s index dd14a441cc..fa657ef66e 100644 --- a/src/runtime/memclr_s390x.s +++ b/src/runtime/memclr_s390x.s @@ -4,6 +4,8 @@ #include "textflag.h" +// See memclrNoHeapPointers Go doc for important implementation constraints. + // func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) TEXT runtime·memclrNoHeapPointers(SB),NOSPLIT|NOFRAME,$0-16 MOVD ptr+0(FP), R4 diff --git a/src/runtime/memclr_wasm.s b/src/runtime/memclr_wasm.s index 68ffe2f67b..5a053049f8 100644 --- a/src/runtime/memclr_wasm.s +++ b/src/runtime/memclr_wasm.s @@ -4,6 +4,8 @@ #include "textflag.h" +// See memclrNoHeapPointers Go doc for important implementation constraints. + // func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) TEXT runtime·memclrNoHeapPointers(SB), NOSPLIT, $0-16 MOVD ptr+0(FP), R0 diff --git a/src/runtime/memmove_linux_amd64_test.go b/src/runtime/memmove_linux_amd64_test.go index d0e8b42a5a..b3ccd907b9 100644 --- a/src/runtime/memmove_linux_amd64_test.go +++ b/src/runtime/memmove_linux_amd64_test.go @@ -5,7 +5,6 @@ package runtime_test import ( - "io/ioutil" "os" "reflect" "syscall" @@ -18,7 +17,7 @@ import ( func TestMemmoveOverflow(t *testing.T) { t.Parallel() // Create a temporary file. - tmp, err := ioutil.TempFile("", "go-memmovetest") + tmp, err := os.CreateTemp("", "go-memmovetest") if err != nil { t.Fatal(err) } diff --git a/src/runtime/metrics.go b/src/runtime/metrics.go index d3c0341aee..3e8dbda0ca 100644 --- a/src/runtime/metrics.go +++ b/src/runtime/metrics.go @@ -41,10 +41,28 @@ func initMetrics() { if metricsInit { return } - sizeClassBuckets = make([]float64, _NumSizeClasses) - for i := range sizeClassBuckets { - sizeClassBuckets[i] = float64(class_to_size[i]) + + sizeClassBuckets = make([]float64, _NumSizeClasses, _NumSizeClasses+1) + // Skip size class 0 which is a stand-in for large objects, but large + // objects are tracked separately (and they actually get placed in + // the last bucket, not the first). + sizeClassBuckets[0] = 1 // The smallest allocation is 1 byte in size. + for i := 1; i < _NumSizeClasses; i++ { + // Size classes have an inclusive upper-bound + // and exclusive lower bound (e.g. 48-byte size class is + // (32, 48]) whereas we want and inclusive lower-bound + // and exclusive upper-bound (e.g. 48-byte size class is + // [33, 49). We can achieve this by shifting all bucket + // boundaries up by 1. + // + // Also, a float64 can precisely represent integers with + // value up to 2^53 and size classes are relatively small + // (nowhere near 2^48 even) so this will give us exact + // boundaries. + sizeClassBuckets[i] = float64(class_to_size[i] + 1) } + sizeClassBuckets = append(sizeClassBuckets, float64Inf()) + timeHistBuckets = timeHistogramMetricsBuckets() metrics = map[string]metricData{ "/gc/cycles/automatic:gc-cycles": { @@ -68,23 +86,27 @@ func initMetrics() { out.scalar = in.sysStats.gcCyclesDone }, }, - "/gc/heap/allocs-by-size:objects": { + "/gc/heap/allocs-by-size:bytes": { deps: makeStatDepSet(heapStatsDep), compute: func(in *statAggregate, out *metricValue) { hist := out.float64HistOrInit(sizeClassBuckets) hist.counts[len(hist.counts)-1] = uint64(in.heapStats.largeAllocCount) - for i := range hist.buckets { - hist.counts[i] = uint64(in.heapStats.smallAllocCount[i]) + // Cut off the first index which is ostensibly for size class 0, + // but large objects are tracked separately so it's actually unused. + for i, count := range in.heapStats.smallAllocCount[1:] { + hist.counts[i] = uint64(count) } }, }, - "/gc/heap/frees-by-size:objects": { + "/gc/heap/frees-by-size:bytes": { deps: makeStatDepSet(heapStatsDep), compute: func(in *statAggregate, out *metricValue) { hist := out.float64HistOrInit(sizeClassBuckets) hist.counts[len(hist.counts)-1] = uint64(in.heapStats.largeFreeCount) - for i := range hist.buckets { - hist.counts[i] = uint64(in.heapStats.smallFreeCount[i]) + // Cut off the first index which is ostensibly for size class 0, + // but large objects are tracked separately so it's actually unused. + for i, count := range in.heapStats.smallFreeCount[1:] { + hist.counts[i] = uint64(count) } }, }, @@ -105,9 +127,12 @@ func initMetrics() { "/gc/pauses:seconds": { compute: func(_ *statAggregate, out *metricValue) { hist := out.float64HistOrInit(timeHistBuckets) - hist.counts[len(hist.counts)-1] = atomic.Load64(&memstats.gcPauseDist.overflow) - for i := range hist.buckets { - hist.counts[i] = atomic.Load64(&memstats.gcPauseDist.counts[i]) + // The bottom-most bucket, containing negative values, is tracked + // as a separately as underflow, so fill that in manually and then + // iterate over the rest. + hist.counts[0] = atomic.Load64(&memstats.gcPauseDist.underflow) + for i := range memstats.gcPauseDist.counts { + hist.counts[i+1] = atomic.Load64(&memstats.gcPauseDist.counts[i]) } }, }, @@ -426,8 +451,8 @@ func (v *metricValue) float64HistOrInit(buckets []float64) *metricFloat64Histogr v.pointer = unsafe.Pointer(hist) } hist.buckets = buckets - if len(hist.counts) != len(hist.buckets)+1 { - hist.counts = make([]uint64, len(buckets)+1) + if len(hist.counts) != len(hist.buckets)-1 { + hist.counts = make([]uint64, len(buckets)-1) } return hist } diff --git a/src/runtime/metrics/description.go b/src/runtime/metrics/description.go index bc2e0882db..1175156104 100644 --- a/src/runtime/metrics/description.go +++ b/src/runtime/metrics/description.go @@ -23,6 +23,11 @@ type Description struct { // Examples of units might be "seconds", "bytes", "bytes/second", "cpu-seconds", // "byte*cpu-seconds", and "bytes/second/second". // + // For histograms, multiple units may apply. For instance, the units of the buckets and + // the count. By convention, for histograms, the units of the count are always "samples" + // with the type of sample evident by the metric's name, while the unit in the name + // specifies the buckets' unit. + // // A complete name might look like "/memory/heap/free:bytes". Name string @@ -41,10 +46,6 @@ type Description struct { // // This flag thus indicates whether or not it's useful to compute a rate from this value. Cumulative bool - - // StopTheWorld is whether or not the metric requires a stop-the-world - // event in order to collect it. - StopTheWorld bool } // The English language descriptions below must be kept in sync with the @@ -58,7 +59,7 @@ var allDesc = []Description{ }, { Name: "/gc/cycles/forced:gc-cycles", - Description: "Count of completed forced GC cycles.", + Description: "Count of completed GC cycles forced by the application.", Kind: KindUint64, Cumulative: true, }, @@ -69,14 +70,16 @@ var allDesc = []Description{ Cumulative: true, }, { - Name: "/gc/heap/allocs-by-size:objects", + Name: "/gc/heap/allocs-by-size:bytes", Description: "Distribution of all objects allocated by approximate size.", Kind: KindFloat64Histogram, + Cumulative: true, }, { - Name: "/gc/heap/frees-by-size:objects", + Name: "/gc/heap/frees-by-size:bytes", Description: "Distribution of all objects freed by approximate size.", Kind: KindFloat64Histogram, + Cumulative: true, }, { Name: "/gc/heap/goal:bytes", @@ -92,30 +95,35 @@ var allDesc = []Description{ Name: "/gc/pauses:seconds", Description: "Distribution individual GC-related stop-the-world pause latencies.", Kind: KindFloat64Histogram, + Cumulative: true, }, { - Name: "/memory/classes/heap/free:bytes", - Description: "Memory that is available for allocation, and may be returned to the underlying system.", - Kind: KindUint64, + Name: "/memory/classes/heap/free:bytes", + Description: "Memory that is completely free and eligible to be returned to the underlying system, " + + "but has not been. This metric is the runtime's estimate of free address space that is backed by " + + "physical memory.", + Kind: KindUint64, }, { Name: "/memory/classes/heap/objects:bytes", - Description: "Memory occupied by live objects and dead objects that have not yet been collected.", + Description: "Memory occupied by live objects and dead objects that have not yet been marked free by the garbage collector.", Kind: KindUint64, }, { - Name: "/memory/classes/heap/released:bytes", - Description: "Memory that has been returned to the underlying system.", - Kind: KindUint64, + Name: "/memory/classes/heap/released:bytes", + Description: "Memory that is completely free and has been returned to the underlying system. This " + + "metric is the runtime's estimate of free address space that is still mapped into the process, " + + "but is not backed by physical memory.", + Kind: KindUint64, }, { Name: "/memory/classes/heap/stacks:bytes", - Description: "Memory allocated from the heap that is occupied by stacks.", + Description: "Memory allocated from the heap that is reserved for stack space, whether or not it is currently in-use.", Kind: KindUint64, }, { Name: "/memory/classes/heap/unused:bytes", - Description: "Memory that is unavailable for allocation, but cannot be returned to the underlying system.", + Description: "Memory that is reserved for heap objects but is not currently used to hold heap objects.", Kind: KindUint64, }, { diff --git a/src/runtime/metrics/description_test.go b/src/runtime/metrics/description_test.go index e966a281a1..fd1fd46efc 100644 --- a/src/runtime/metrics/description_test.go +++ b/src/runtime/metrics/description_test.go @@ -7,9 +7,7 @@ package metrics_test import ( "bufio" "os" - "path/filepath" "regexp" - "runtime" "runtime/metrics" "strings" "testing" @@ -26,17 +24,9 @@ func TestDescriptionNameFormat(t *testing.T) { } func extractMetricDocs(t *testing.T) map[string]string { - if runtime.GOOS == "android" { - t.Skip("no access to Go source on android") - } - - // Get doc.go. - _, filename, _, _ := runtime.Caller(0) - filename = filepath.Join(filepath.Dir(filename), "doc.go") - - f, err := os.Open(filename) + f, err := os.Open("doc.go") if err != nil { - t.Fatal(err) + t.Fatalf("failed to open doc.go in runtime/metrics package: %v", err) } const ( stateSearch = iota // look for list of metrics @@ -53,7 +43,7 @@ func extractMetricDocs(t *testing.T) map[string]string { line := strings.TrimSpace(s.Text()) switch state { case stateSearch: - if line == "Supported metrics" { + if line == "Below is the full list of supported metrics, ordered lexicographically." { state = stateNextMetric } case stateNextMetric: @@ -90,7 +80,7 @@ func extractMetricDocs(t *testing.T) map[string]string { } } if state == stateSearch { - t.Fatalf("failed to find supported metrics docs in %s", filename) + t.Fatalf("failed to find supported metrics docs in %s", f.Name()) } return result } diff --git a/src/runtime/metrics/doc.go b/src/runtime/metrics/doc.go index e340f3d0dd..7f790afc12 100644 --- a/src/runtime/metrics/doc.go +++ b/src/runtime/metrics/doc.go @@ -16,13 +16,12 @@ Interface Metrics are designated by a string key, rather than, for example, a field name in a struct. The full list of supported metrics is always available in the slice of Descriptions returned by All. Each Description also includes useful information -about the metric, such as how to display it (e.g. gauge vs. counter) and how difficult -or disruptive it is to obtain it (e.g. do you need to stop the world?). +about the metric. Thus, users of this API are encouraged to sample supported metrics defined by the slice returned by All to remain compatible across Go versions. Of course, situations arise where reading specific metrics is critical. For these cases, users are -encouranged to use build tags, and although metrics may be deprecated and removed, +encouraged to use build tags, and although metrics may be deprecated and removed, users should consider this to be an exceptional and rare event, coinciding with a very large change in a particular Go implementation. @@ -42,21 +41,29 @@ did also, and a new key should be introduced. For more details on the precise definition of the metric key's path and unit formats, see the documentation of the Name field of the Description struct. +A note about floats + +This package supports metrics whose values have a floating-point representation. In +order to improve ease-of-use, this package promises to never produce the following +classes of floating-point values: NaN, infinity. + Supported metrics +Below is the full list of supported metrics, ordered lexicographically. + /gc/cycles/automatic:gc-cycles Count of completed GC cycles generated by the Go runtime. /gc/cycles/forced:gc-cycles - Count of completed forced GC cycles. + Count of completed GC cycles forced by the application. /gc/cycles/total:gc-cycles Count of all completed GC cycles. - /gc/heap/allocs-by-size:objects + /gc/heap/allocs-by-size:bytes Distribution of all objects allocated by approximate size. - /gc/heap/frees-by-size:objects + /gc/heap/frees-by-size:bytes Distribution of all objects freed by approximate size. /gc/heap/goal:bytes @@ -69,22 +76,28 @@ Supported metrics Distribution individual GC-related stop-the-world pause latencies. /memory/classes/heap/free:bytes - Memory that is available for allocation, and may be returned - to the underlying system. + Memory that is completely free and eligible to be returned to + the underlying system, but has not been. This metric is the + runtime's estimate of free address space that is backed by + physical memory. /memory/classes/heap/objects:bytes Memory occupied by live objects and dead objects that have - not yet been collected. + not yet been marked free by the garbage collector. /memory/classes/heap/released:bytes - Memory that has been returned to the underlying system. + Memory that is completely free and has been returned to + the underlying system. This metric is the runtime's estimate of + free address space that is still mapped into the process, but + is not backed by physical memory. /memory/classes/heap/stacks:bytes - Memory allocated from the heap that is occupied by stacks. + Memory allocated from the heap that is reserved for stack + space, whether or not it is currently in-use. /memory/classes/heap/unused:bytes - Memory that is unavailable for allocation, but cannot be - returned to the underlying system. + Memory that is reserved for heap objects but is not currently + used to hold heap objects. /memory/classes/metadata/mcache/free:bytes Memory that is reserved for runtime mcache structures, but diff --git a/src/runtime/metrics/example_test.go b/src/runtime/metrics/example_test.go new file mode 100644 index 0000000000..624d9d8a6b --- /dev/null +++ b/src/runtime/metrics/example_test.go @@ -0,0 +1,96 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package metrics_test + +import ( + "fmt" + "runtime/metrics" +) + +func ExampleRead_readingOneMetric() { + // Name of the metric we want to read. + const myMetric = "/memory/classes/heap/free:bytes" + + // Create a sample for the metric. + sample := make([]metrics.Sample, 1) + sample[0].Name = myMetric + + // Sample the metric. + metrics.Read(sample) + + // Check if the metric is actually supported. + // If it's not, the resulting value will always have + // kind KindBad. + if sample[0].Value.Kind() == metrics.KindBad { + panic(fmt.Sprintf("metric %q no longer supported", myMetric)) + } + + // Handle the result. + // + // It's OK to assume a particular Kind for a metric; + // they're guaranteed not to change. + freeBytes := sample[0].Value.Uint64() + + fmt.Printf("free but not released memory: %d\n", freeBytes) +} + +func ExampleRead_readingAllMetrics() { + // Get descriptions for all supported metrics. + descs := metrics.All() + + // Create a sample for each metric. + samples := make([]metrics.Sample, len(descs)) + for i := range samples { + samples[i].Name = descs[i].Name + } + + // Sample the metrics. Re-use the samples slice if you can! + metrics.Read(samples) + + // Iterate over all results. + for _, sample := range samples { + // Pull out the name and value. + name, value := sample.Name, sample.Value + + // Handle each sample. + switch value.Kind() { + case metrics.KindUint64: + fmt.Printf("%s: %d\n", name, value.Uint64()) + case metrics.KindFloat64: + fmt.Printf("%s: %f\n", name, value.Float64()) + case metrics.KindFloat64Histogram: + // The histogram may be quite large, so let's just pull out + // a crude estimate for the median for the sake of this example. + fmt.Printf("%s: %f\n", name, medianBucket(value.Float64Histogram())) + case metrics.KindBad: + // This should never happen because all metrics are supported + // by construction. + panic("bug in runtime/metrics package!") + default: + // This may happen as new metrics get added. + // + // The safest thing to do here is to simply log it somewhere + // as something to look into, but ignore it for now. + // In the worst case, you might temporarily miss out on a new metric. + fmt.Printf("%s: unexpected metric Kind: %v\n", name, value.Kind()) + } + } +} + +func medianBucket(h *metrics.Float64Histogram) float64 { + total := uint64(0) + for _, count := range h.Counts { + total += count + } + thresh := total / 2 + total = 0 + for i, count := range h.Counts { + total += count + if total >= thresh { + return h.Buckets[i] + } + } + panic("should not happen") +} diff --git a/src/runtime/metrics/histogram.go b/src/runtime/metrics/histogram.go index e1364e1e26..956422bf84 100644 --- a/src/runtime/metrics/histogram.go +++ b/src/runtime/metrics/histogram.go @@ -6,25 +6,28 @@ package metrics // Float64Histogram represents a distribution of float64 values. type Float64Histogram struct { - // Counts contains the weights for each histogram bucket. The length of - // Counts is equal to the length of Buckets (in the metric description) - // plus one to account for the implicit minimum bucket. + // Counts contains the weights for each histogram bucket. // - // Given N buckets, the following is the mathematical relationship between - // Counts and Buckets. - // count[0] is the weight of the range (-inf, bucket[0]) - // count[n] is the weight of the range [bucket[n], bucket[n+1]), for 0 < n < N-1 - // count[N-1] is the weight of the range [bucket[N-1], inf) + // Given N buckets, Count[n] is the weight of the range + // [bucket[n], bucket[n+1]), for 0 <= n < N. Counts []uint64 - // Buckets contains the boundaries between histogram buckets, in increasing order. + // Buckets contains the boundaries of the histogram buckets, in increasing order. // - // Because this slice contains boundaries, there are len(Buckets)+1 counts: - // a count for all values less than the first boundary, a count covering each - // [slice[i], slice[i+1]) interval, and a count for all values greater than or - // equal to the last boundary. + // Buckets[0] is the inclusive lower bound of the minimum bucket while + // Buckets[len(Buckets)-1] is the exclusive upper bound of the maximum bucket. + // Hence, there are len(Buckets)-1 counts. Furthermore, len(Buckets) != 1, always, + // since at least two boundaries are required to describe one bucket (and 0 + // boundaries are used to describe 0 buckets). + // + // Buckets[0] is permitted to have value -Inf and Buckets[len(Buckets)-1] is + // permitted to have value Inf. // // For a given metric name, the value of Buckets is guaranteed not to change // between calls until program exit. + // + // This slice value is permitted to alias with other Float64Histograms' Buckets + // fields, so the values within should only ever be read. If they need to be + // modified, the user must make a copy. Buckets []float64 } diff --git a/src/runtime/metrics/sample.go b/src/runtime/metrics/sample.go index b4b0979aa6..4cf8cdf799 100644 --- a/src/runtime/metrics/sample.go +++ b/src/runtime/metrics/sample.go @@ -14,7 +14,7 @@ type Sample struct { // Name is the name of the metric sampled. // // It must correspond to a name in one of the metric descriptions - // returned by Descriptions. + // returned by All. Name string // Value is the value of the metric sample. @@ -27,11 +27,21 @@ func runtime_readMetrics(unsafe.Pointer, int, int) // Read populates each Value field in the given slice of metric samples. // // Desired metrics should be present in the slice with the appropriate name. -// The user of this API is encouraged to re-use the same slice between calls. +// The user of this API is encouraged to re-use the same slice between calls for +// efficiency, but is not required to do so. // -// Metric values with names not appearing in the value returned by Descriptions -// will have the value populated as KindBad to indicate that the name is -// unknown. +// Note that re-use has some caveats. Notably, Values should not be read or +// manipulated while a Read with that value is outstanding; that is a data race. +// This property includes pointer-typed Values (for example, Float64Histogram) +// whose underlying storage will be reused by Read when possible. To safely use +// such values in a concurrent setting, all data must be deep-copied. +// +// It is safe to execute multiple Read calls concurrently, but their arguments +// must share no underlying memory. When in doubt, create a new []Sample from +// scratch, which is always safe, though may be inefficient. +// +// Sample values with names not appearing in All will have their Value populated +// as KindBad to indicate that the name is unknown. func Read(m []Sample) { runtime_readMetrics(unsafe.Pointer(&m[0]), len(m), cap(m)) } diff --git a/src/runtime/metrics/value.go b/src/runtime/metrics/value.go index 0b056b4ea8..ed9a33d87c 100644 --- a/src/runtime/metrics/value.go +++ b/src/runtime/metrics/value.go @@ -33,7 +33,7 @@ type Value struct { pointer unsafe.Pointer // contains non-scalar values. } -// Kind returns the a tag representing the kind of value this is. +// Kind returns the tag representing the kind of value this is. func (v Value) Kind() ValueKind { return v.kind } @@ -63,7 +63,7 @@ func (v Value) Float64() float64 { // If v.Kind() != KindFloat64Histogram, this method panics. func (v Value) Float64Histogram() *Float64Histogram { if v.kind != KindFloat64Histogram { - panic("called Float64 on non-float64 metric value") + panic("called Float64Histogram on non-Float64Histogram metric value") } return (*Float64Histogram)(v.pointer) } diff --git a/src/runtime/metrics_test.go b/src/runtime/metrics_test.go index 167edd57fd..8a3cf019bd 100644 --- a/src/runtime/metrics_test.go +++ b/src/runtime/metrics_test.go @@ -70,6 +70,34 @@ func TestReadMetrics(t *testing.T) { checkUint64(t, name, samples[i].Value.Uint64(), mstats.BuckHashSys) case "/memory/classes/total:bytes": checkUint64(t, name, samples[i].Value.Uint64(), mstats.Sys) + case "/gc/heap/allocs-by-size:bytes": + hist := samples[i].Value.Float64Histogram() + // Skip size class 0 in BySize, because it's always empty and not represented + // in the histogram. + for i, sc := range mstats.BySize[1:] { + if b, s := hist.Buckets[i+1], float64(sc.Size+1); b != s { + t.Errorf("bucket does not match size class: got %f, want %f", b, s) + // The rest of the checks aren't expected to work anyway. + continue + } + if c, m := hist.Counts[i], sc.Mallocs; c != m { + t.Errorf("histogram counts do not much BySize for class %d: got %d, want %d", i, c, m) + } + } + case "/gc/heap/frees-by-size:bytes": + hist := samples[i].Value.Float64Histogram() + // Skip size class 0 in BySize, because it's always empty and not represented + // in the histogram. + for i, sc := range mstats.BySize[1:] { + if b, s := hist.Buckets[i+1], float64(sc.Size+1); b != s { + t.Errorf("bucket does not match size class: got %f, want %f", b, s) + // The rest of the checks aren't expected to work anyway. + continue + } + if c, f := hist.Counts[i], sc.Frees; c != f { + t.Errorf("histogram counts do not much BySize for class %d: got %d, want %d", i, c, f) + } + } case "/gc/heap/objects:objects": checkUint64(t, name, samples[i].Value.Uint64(), mstats.HeapObjects) case "/gc/heap/goal:bytes": @@ -133,9 +161,9 @@ func TestReadMetricsConsistency(t *testing.T) { totalVirtual.got = samples[i].Value.Uint64() case "/gc/heap/objects:objects": objects.total = samples[i].Value.Uint64() - case "/gc/heap/allocs-by-size:objects": + case "/gc/heap/allocs-by-size:bytes": objects.alloc = samples[i].Value.Float64Histogram() - case "/gc/heap/frees-by-size:objects": + case "/gc/heap/frees-by-size:bytes": objects.free = samples[i].Value.Float64Histogram() case "/gc/cycles:gc-cycles": gc.numGC = samples[i].Value.Uint64() @@ -154,6 +182,12 @@ func TestReadMetricsConsistency(t *testing.T) { if totalVirtual.got != totalVirtual.want { t.Errorf(`"/memory/classes/total:bytes" does not match sum of /memory/classes/**: got %d, want %d`, totalVirtual.got, totalVirtual.want) } + if b, c := len(objects.alloc.Buckets), len(objects.alloc.Counts); b != c+1 { + t.Errorf("allocs-by-size has wrong bucket or counts length: %d buckets, %d counts", b, c) + } + if b, c := len(objects.free.Buckets), len(objects.free.Counts); b != c+1 { + t.Errorf("frees-by-size has wrong bucket or counts length: %d buckets, %d counts", b, c) + } if len(objects.alloc.Buckets) != len(objects.free.Buckets) { t.Error("allocs-by-size and frees-by-size buckets don't match in length") } else if len(objects.alloc.Counts) != len(objects.free.Counts) { diff --git a/src/runtime/mfinal.go b/src/runtime/mfinal.go index f4dbd77252..7d0313be12 100644 --- a/src/runtime/mfinal.go +++ b/src/runtime/mfinal.go @@ -7,6 +7,7 @@ package runtime import ( + "internal/abi" "runtime/internal/atomic" "runtime/internal/sys" "unsafe" @@ -219,7 +220,11 @@ func runfinq() { throw("bad kind in runfinq") } fingRunning = true - reflectcall(nil, unsafe.Pointer(f.fn), frame, uint32(framesz), uint32(framesz)) + // Pass a dummy RegArgs for now. + // + // TODO(mknyszek): Pass arguments in registers. + var regs abi.RegArgs + reflectcall(nil, unsafe.Pointer(f.fn), frame, uint32(framesz), uint32(framesz), uint32(framesz), ®s) fingRunning = false // Drop finalizer queue heap references diff --git a/src/runtime/mgcmark.go b/src/runtime/mgcmark.go index 5a24cdac88..46fae5de72 100644 --- a/src/runtime/mgcmark.go +++ b/src/runtime/mgcmark.go @@ -101,8 +101,7 @@ func gcMarkRootPrepare() { // Gs may be created after this point, but it's okay that we // ignore them because they begin life without any roots, so // there's nothing to scan, and any roots they create during - // the concurrent phase will be scanned during mark - // termination. + // the concurrent phase will be caught by the write barrier. work.nStackRoots = int(atomic.Loaduintptr(&allglen)) work.markrootNext = 0 @@ -133,7 +132,6 @@ fail: println("gp", gp, "goid", gp.goid, "status", readgstatus(gp), "gcscandone", gp.gcscandone) - unlock(&allglock) // Avoid self-deadlock with traceback. throw("scan missed a g") } diff --git a/src/runtime/mgcscavenge.go b/src/runtime/mgcscavenge.go index 38f09309dc..a7c5bc49b8 100644 --- a/src/runtime/mgcscavenge.go +++ b/src/runtime/mgcscavenge.go @@ -562,7 +562,7 @@ func (p *pageAlloc) scavengeUnreserve(r addrRange, gen uint32) { func (p *pageAlloc) scavengeOne(work addrRange, max uintptr, mayUnlock bool) (uintptr, addrRange) { assertLockHeld(p.mheapLock) - // Defensively check if we've recieved an empty address range. + // Defensively check if we've received an empty address range. // If so, just return. if work.size() == 0 { // Nothing to do. diff --git a/src/runtime/mkduff.go b/src/runtime/mkduff.go index 6ddf0256e9..ef297f073e 100644 --- a/src/runtime/mkduff.go +++ b/src/runtime/mkduff.go @@ -27,8 +27,8 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "log" + "os" ) func main() { @@ -54,7 +54,7 @@ func gen(arch string, tags, zero, copy func(io.Writer)) { fmt.Fprintln(&buf) copy(&buf) - if err := ioutil.WriteFile("duff_"+arch+".s", buf.Bytes(), 0644); err != nil { + if err := os.WriteFile("duff_"+arch+".s", buf.Bytes(), 0644); err != nil { log.Fatalln(err) } } @@ -62,15 +62,15 @@ func gen(arch string, tags, zero, copy func(io.Writer)) { func notags(w io.Writer) { fmt.Fprintln(w) } func zeroAMD64(w io.Writer) { - // X0: zero + // X15: zero // DI: ptr to memory to be zeroed // DI is updated as a side effect. - fmt.Fprintln(w, "TEXT runtime·duffzero(SB), NOSPLIT, $0-0") + fmt.Fprintln(w, "TEXT runtime·duffzero<ABIInternal>(SB), NOSPLIT, $0-0") for i := 0; i < 16; i++ { - fmt.Fprintln(w, "\tMOVUPS\tX0,(DI)") - fmt.Fprintln(w, "\tMOVUPS\tX0,16(DI)") - fmt.Fprintln(w, "\tMOVUPS\tX0,32(DI)") - fmt.Fprintln(w, "\tMOVUPS\tX0,48(DI)") + fmt.Fprintln(w, "\tMOVUPS\tX15,(DI)") + fmt.Fprintln(w, "\tMOVUPS\tX15,16(DI)") + fmt.Fprintln(w, "\tMOVUPS\tX15,32(DI)") + fmt.Fprintln(w, "\tMOVUPS\tX15,48(DI)") fmt.Fprintln(w, "\tLEAQ\t64(DI),DI") // We use lea instead of add, to avoid clobbering flags fmt.Fprintln(w) } @@ -84,7 +84,7 @@ func copyAMD64(w io.Writer) { // // This is equivalent to a sequence of MOVSQ but // for some reason that is 3.5x slower than this code. - fmt.Fprintln(w, "TEXT runtime·duffcopy(SB), NOSPLIT, $0-0") + fmt.Fprintln(w, "TEXT runtime·duffcopy<ABIInternal>(SB), NOSPLIT, $0-0") for i := 0; i < 64; i++ { fmt.Fprintln(w, "\tMOVUPS\t(SI), X0") fmt.Fprintln(w, "\tADDQ\t$16, SI") diff --git a/src/runtime/mkfastlog2table.go b/src/runtime/mkfastlog2table.go index 305c84a7c1..d650292394 100644 --- a/src/runtime/mkfastlog2table.go +++ b/src/runtime/mkfastlog2table.go @@ -12,9 +12,9 @@ package main import ( "bytes" "fmt" - "io/ioutil" "log" "math" + "os" ) func main() { @@ -36,7 +36,7 @@ func main() { } fmt.Fprintln(&buf, "}") - if err := ioutil.WriteFile("fastlog2table.go", buf.Bytes(), 0644); err != nil { + if err := os.WriteFile("fastlog2table.go", buf.Bytes(), 0644); err != nil { log.Fatalln(err) } } diff --git a/src/runtime/mksizeclasses.go b/src/runtime/mksizeclasses.go index 1a210953a4..b92d1fed5f 100644 --- a/src/runtime/mksizeclasses.go +++ b/src/runtime/mksizeclasses.go @@ -35,7 +35,6 @@ import ( "fmt" "go/format" "io" - "io/ioutil" "log" "os" ) @@ -65,7 +64,7 @@ func main() { if *stdout { _, err = os.Stdout.Write(out) } else { - err = ioutil.WriteFile("sizeclasses.go", out, 0666) + err = os.WriteFile("sizeclasses.go", out, 0666) } if err != nil { log.Fatal(err) diff --git a/src/runtime/mmap.go b/src/runtime/mmap.go index 9fe31cb416..1b1848b79e 100644 --- a/src/runtime/mmap.go +++ b/src/runtime/mmap.go @@ -2,14 +2,15 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !aix +// +build !darwin +// +build !js +// +build !linux !amd64 +// +build !linux !arm64 +// +build !openbsd // +build !plan9 // +build !solaris // +build !windows -// +build !linux !amd64 -// +build !linux !arm64 -// +build !js -// +build !darwin -// +build !aix package runtime diff --git a/src/runtime/msan.go b/src/runtime/msan.go index c0f3957e28..6a5960b0a8 100644 --- a/src/runtime/msan.go +++ b/src/runtime/msan.go @@ -50,8 +50,12 @@ func msanmalloc(addr unsafe.Pointer, sz uintptr) //go:noescape func msanfree(addr unsafe.Pointer, sz uintptr) -// These are called from msan_amd64.s +//go:noescape +func msanmove(dst, src unsafe.Pointer, sz uintptr) + +// These are called from msan_GOARCH.s //go:cgo_import_static __msan_read_go //go:cgo_import_static __msan_write_go //go:cgo_import_static __msan_malloc_go //go:cgo_import_static __msan_free_go +//go:cgo_import_static __msan_memmove diff --git a/src/runtime/msan0.go b/src/runtime/msan0.go index 117c5e5789..374d13f30b 100644 --- a/src/runtime/msan0.go +++ b/src/runtime/msan0.go @@ -16,7 +16,8 @@ const msanenabled = false // Because msanenabled is false, none of these functions should be called. -func msanread(addr unsafe.Pointer, sz uintptr) { throw("msan") } -func msanwrite(addr unsafe.Pointer, sz uintptr) { throw("msan") } -func msanmalloc(addr unsafe.Pointer, sz uintptr) { throw("msan") } -func msanfree(addr unsafe.Pointer, sz uintptr) { throw("msan") } +func msanread(addr unsafe.Pointer, sz uintptr) { throw("msan") } +func msanwrite(addr unsafe.Pointer, sz uintptr) { throw("msan") } +func msanmalloc(addr unsafe.Pointer, sz uintptr) { throw("msan") } +func msanfree(addr unsafe.Pointer, sz uintptr) { throw("msan") } +func msanmove(dst, src unsafe.Pointer, sz uintptr) { throw("msan") } diff --git a/src/runtime/msan_amd64.s b/src/runtime/msan_amd64.s index cbe739df53..669e9ca73f 100644 --- a/src/runtime/msan_amd64.s +++ b/src/runtime/msan_amd64.s @@ -58,6 +58,15 @@ TEXT runtime·msanfree(SB), NOSPLIT, $0-16 MOVQ $__msan_free_go(SB), AX JMP msancall<>(SB) +// func runtime·msanmove(dst, src unsafe.Pointer, sz uintptr) +TEXT runtime·msanmove(SB), NOSPLIT, $0-24 + MOVQ dst+0(FP), RARG0 + MOVQ src+8(FP), RARG1 + MOVQ size+16(FP), RARG2 + // void __msan_memmove(void *dst, void *src, uintptr_t sz); + MOVQ $__msan_memmove(SB), AX + JMP msancall<>(SB) + // Switches SP to g0 stack and calls (AX). Arguments already set. TEXT msancall<>(SB), NOSPLIT, $0-0 get_tls(R12) diff --git a/src/runtime/msan_arm64.s b/src/runtime/msan_arm64.s index 5e29f1aefb..f19906cfc8 100644 --- a/src/runtime/msan_arm64.s +++ b/src/runtime/msan_arm64.s @@ -9,6 +9,7 @@ #define RARG0 R0 #define RARG1 R1 +#define RARG2 R2 #define FARG R3 // func runtime·domsanread(addr unsafe.Pointer, sz uintptr) @@ -45,6 +46,15 @@ TEXT runtime·msanfree(SB), NOSPLIT, $0-16 MOVD $__msan_free_go(SB), FARG JMP msancall<>(SB) +// func runtime·msanmove(dst, src unsafe.Pointer, sz uintptr) +TEXT runtime·msanmove(SB), NOSPLIT, $0-24 + MOVD dst+0(FP), RARG0 + MOVD src+8(FP), RARG1 + MOVD size+16(FP), RARG2 + // void __msan_memmove(void *dst, void *src, uintptr_t sz); + MOVD $__msan_memmove(SB), FARG + JMP msancall<>(SB) + // Switches SP to g0 stack and calls (FARG). Arguments already set. TEXT msancall<>(SB), NOSPLIT, $0-0 MOVD RSP, R19 // callee-saved diff --git a/src/runtime/os2_aix.go b/src/runtime/os2_aix.go index 428ff7f225..abd1010be9 100644 --- a/src/runtime/os2_aix.go +++ b/src/runtime/os2_aix.go @@ -18,11 +18,11 @@ import ( //go:cgo_import_dynamic libc___n_pthreads __n_pthreads "libpthread.a/shr_xpg5_64.o" //go:cgo_import_dynamic libc___mod_init __mod_init "libc.a/shr_64.o" -//go:linkname libc___n_pthreads libc___n_pthread +//go:linkname libc___n_pthreads libc___n_pthreads //go:linkname libc___mod_init libc___mod_init var ( - libc___n_pthread, + libc___n_pthreads, libc___mod_init libFunc ) diff --git a/src/runtime/os3_solaris.go b/src/runtime/os3_solaris.go index d6e36fbfbb..6ba11afd93 100644 --- a/src/runtime/os3_solaris.go +++ b/src/runtime/os3_solaris.go @@ -227,6 +227,11 @@ func unminit() { unminitSignals() } +// Called from exitm, but not from drop, to undo the effect of thread-owned +// resources in minit, semacreate, or elsewhere. Do not take locks after calling this. +func mdestroy(mp *m) { +} + func sigtramp() //go:nosplit diff --git a/src/runtime/os_aix.go b/src/runtime/os_aix.go index 0c501be96a..303f0876de 100644 --- a/src/runtime/os_aix.go +++ b/src/runtime/os_aix.go @@ -180,6 +180,11 @@ func unminit() { unminitSignals() } +// Called from exitm, but not from drop, to undo the effect of thread-owned +// resources in minit, semacreate, or elsewhere. Do not take locks after calling this. +func mdestroy(mp *m) { +} + // tstart is a function descriptor to _tstart defined in assembly. var tstart funcDescriptor diff --git a/src/runtime/os_darwin.go b/src/runtime/os_darwin.go index 3f5bb7cf96..9ca17c20df 100644 --- a/src/runtime/os_darwin.go +++ b/src/runtime/os_darwin.go @@ -130,6 +130,18 @@ func osinit() { physPageSize = getPageSize() } +func sysctlbynameInt32(name []byte) (int32, int32) { + out := int32(0) + nout := unsafe.Sizeof(out) + ret := sysctlbyname(&name[0], (*byte)(unsafe.Pointer(&out)), &nout, nil, 0) + return ret, out +} + +//go:linkname internal_cpu_getsysctlbyname internal/cpu.getsysctlbyname +func internal_cpu_getsysctlbyname(name []byte) (int32, int32) { + return sysctlbynameInt32(name) +} + const ( _CTL_HW = 6 _HW_NCPU = 3 @@ -283,6 +295,12 @@ func libpreinit() { func mpreinit(mp *m) { mp.gsignal = malg(32 * 1024) // OS X wants >= 8K mp.gsignal.m = mp + if GOOS == "darwin" && GOARCH == "arm64" { + // mlock the signal stack to work around a kernel bug where it may + // SIGILL when the signal stack is not faulted in while a signal + // arrives. See issue 42774. + mlock(unsafe.Pointer(mp.gsignal.stack.hi-physPageSize), physPageSize) + } } // Called to initialize a new m (including the bootstrap m). @@ -307,6 +325,11 @@ func unminit() { } } +// Called from exitm, but not from drop, to undo the effect of thread-owned +// resources in minit, semacreate, or elsewhere. Do not take locks after calling this. +func mdestroy(mp *m) { +} + //go:nosplit func osyield() { usleep(1) diff --git a/src/runtime/os_dragonfly.go b/src/runtime/os_dragonfly.go index 6578fcbeb1..383df54bd4 100644 --- a/src/runtime/os_dragonfly.go +++ b/src/runtime/os_dragonfly.go @@ -203,6 +203,11 @@ func unminit() { unminitSignals() } +// Called from exitm, but not from drop, to undo the effect of thread-owned +// resources in minit, semacreate, or elsewhere. Do not take locks after calling this. +func mdestroy(mp *m) { +} + func sigtramp() type sigactiont struct { diff --git a/src/runtime/os_freebsd.go b/src/runtime/os_freebsd.go index 730973a202..09065ccb68 100644 --- a/src/runtime/os_freebsd.go +++ b/src/runtime/os_freebsd.go @@ -166,7 +166,7 @@ func futexsleep1(addr *uint32, val uint32, ns int64) { utp = &ut } ret := sys_umtx_op(addr, _UMTX_OP_WAIT_UINT_PRIVATE, val, unsafe.Sizeof(*utp), utp) - if ret >= 0 || ret == -_EINTR { + if ret >= 0 || ret == -_EINTR || ret == -_ETIMEDOUT { return } print("umtx_wait addr=", addr, " val=", val, " ret=", ret, "\n") @@ -208,7 +208,6 @@ func newosproc(mp *m) { var oset sigset sigprocmask(_SIG_SETMASK, &sigset_all, &oset) - // TODO: Check for error. ret := thr_new(¶m, int32(unsafe.Sizeof(param))) sigprocmask(_SIG_SETMASK, &oset, nil) if ret < 0 { @@ -320,6 +319,11 @@ func unminit() { unminitSignals() } +// Called from exitm, but not from drop, to undo the effect of thread-owned +// resources in minit, semacreate, or elsewhere. Do not take locks after calling this. +func mdestroy(mp *m) { +} + func sigtramp() type sigactiont struct { diff --git a/src/runtime/os_js.go b/src/runtime/os_js.go index 94983b358d..24261e88a2 100644 --- a/src/runtime/os_js.go +++ b/src/runtime/os_js.go @@ -72,7 +72,7 @@ func clearSignalHandlers() { } //go:nosplit -func sigblock() { +func sigblock(exiting bool) { } // Called to initialize a new m (including the bootstrap m). @@ -84,6 +84,11 @@ func minit() { func unminit() { } +// Called from exitm, but not from drop, to undo the effect of thread-owned +// resources in minit, semacreate, or elsewhere. Do not take locks after calling this. +func mdestroy(mp *m) { +} + func osinit() { ncpu = 1 getg().m.procid = 2 diff --git a/src/runtime/os_linux.go b/src/runtime/os_linux.go index 371db73502..058c7daf9c 100644 --- a/src/runtime/os_linux.go +++ b/src/runtime/os_linux.go @@ -301,6 +301,24 @@ func getHugePageSize() uintptr { func osinit() { ncpu = getproccount() physHugePageSize = getHugePageSize() + if iscgo { + // #42494 glibc and musl reserve some signals for + // internal use and require they not be blocked by + // the rest of a normal C runtime. When the go runtime + // blocks...unblocks signals, temporarily, the blocked + // interval of time is generally very short. As such, + // these expectations of *libc code are mostly met by + // the combined go+cgo system of threads. However, + // when go causes a thread to exit, via a return from + // mstart(), the combined runtime can deadlock if + // these signals are blocked. Thus, don't block these + // signals when exiting threads. + // - glibc: SIGCANCEL (32), SIGSETXID (33) + // - musl: SIGTIMER (32), SIGCANCEL (33), SIGSYNCCALL (34) + sigdelset(&sigsetAllExiting, 32) + sigdelset(&sigsetAllExiting, 33) + sigdelset(&sigsetAllExiting, 34) + } osArchInit() } @@ -357,6 +375,11 @@ func unminit() { unminitSignals() } +// Called from exitm, but not from drop, to undo the effect of thread-owned +// resources in minit, semacreate, or elsewhere. Do not take locks after calling this. +func mdestroy(mp *m) { +} + //#ifdef GOARCH_386 //#define sa_handler k_sa_handler //#endif diff --git a/src/runtime/os_linux_be64.go b/src/runtime/os_linux_be64.go index 14fbad5d5f..9860002ee4 100644 --- a/src/runtime/os_linux_be64.go +++ b/src/runtime/os_linux_be64.go @@ -38,6 +38,7 @@ func sigdelset(mask *sigset, i int) { *mask &^= 1 << (uint(i) - 1) } +//go:nosplit func sigfillset(mask *uint64) { *mask = ^uint64(0) } diff --git a/src/runtime/os_linux_generic.go b/src/runtime/os_linux_generic.go index 14810e3cc3..e1d0952ddf 100644 --- a/src/runtime/os_linux_generic.go +++ b/src/runtime/os_linux_generic.go @@ -38,6 +38,7 @@ func sigdelset(mask *sigset, i int) { (*mask)[(i-1)/32] &^= 1 << ((uint32(i) - 1) & 31) } +//go:nosplit func sigfillset(mask *uint64) { *mask = ^uint64(0) } diff --git a/src/runtime/os_linux_mips64x.go b/src/runtime/os_linux_mips64x.go index 4ff66f9538..815a83a04b 100644 --- a/src/runtime/os_linux_mips64x.go +++ b/src/runtime/os_linux_mips64x.go @@ -48,6 +48,7 @@ func sigdelset(mask *sigset, i int) { (*mask)[(i-1)/64] &^= 1 << ((uint32(i) - 1) & 63) } +//go:nosplit func sigfillset(mask *[2]uint64) { (*mask)[0], (*mask)[1] = ^uint64(0), ^uint64(0) } diff --git a/src/runtime/os_linux_mipsx.go b/src/runtime/os_linux_mipsx.go index 87962ed982..00fb02e4bf 100644 --- a/src/runtime/os_linux_mipsx.go +++ b/src/runtime/os_linux_mipsx.go @@ -42,6 +42,7 @@ func sigdelset(mask *sigset, i int) { (*mask)[(i-1)/32] &^= 1 << ((uint32(i) - 1) & 31) } +//go:nosplit func sigfillset(mask *[4]uint32) { (*mask)[0], (*mask)[1], (*mask)[2], (*mask)[3] = ^uint32(0), ^uint32(0), ^uint32(0), ^uint32(0) } diff --git a/src/runtime/os_netbsd.go b/src/runtime/os_netbsd.go index f7f90cedc1..2b742a3711 100644 --- a/src/runtime/os_netbsd.go +++ b/src/runtime/os_netbsd.go @@ -290,6 +290,11 @@ func unminit() { unminitSignals() } +// Called from exitm, but not from drop, to undo the effect of thread-owned +// resources in minit, semacreate, or elsewhere. Do not take locks after calling this. +func mdestroy(mp *m) { +} + func sigtramp() type sigactiont struct { diff --git a/src/runtime/os_openbsd.go b/src/runtime/os_openbsd.go index d7960f4c91..6259b96c22 100644 --- a/src/runtime/os_openbsd.go +++ b/src/runtime/os_openbsd.go @@ -6,7 +6,6 @@ package runtime import ( "runtime/internal/atomic" - "runtime/internal/sys" "unsafe" ) @@ -14,60 +13,6 @@ type mOS struct { waitsemacount uint32 } -//go:noescape -func setitimer(mode int32, new, old *itimerval) - -//go:noescape -func sigaction(sig uint32, new, old *sigactiont) - -//go:noescape -func sigaltstack(new, old *stackt) - -//go:noescape -func obsdsigprocmask(how int32, new sigset) sigset - -//go:nosplit -//go:nowritebarrierrec -func sigprocmask(how int32, new, old *sigset) { - n := sigset(0) - if new != nil { - n = *new - } - r := obsdsigprocmask(how, n) - if old != nil { - *old = r - } -} - -//go:noescape -func sysctl(mib *uint32, miblen uint32, out *byte, size *uintptr, dst *byte, ndst uintptr) int32 - -func raiseproc(sig uint32) - -func getthrid() int32 -func thrkill(tid int32, sig int) - -//go:noescape -func tfork(param *tforkt, psize uintptr, mm *m, gg *g, fn uintptr) int32 - -//go:noescape -func thrsleep(ident uintptr, clock_id int32, tsp *timespec, lock uintptr, abort *uint32) int32 - -//go:noescape -func thrwakeup(ident uintptr, n int32) int32 - -func osyield() - -func kqueue() int32 - -//go:noescape -func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32 - -func pipe() (r, w int32, errno int32) -func pipe2(flags int32) (r, w int32, errno int32) -func closeonexec(fd int32) -func setNonblock(fd int32) - const ( _ESRCH = 3 _EWOULDBLOCK = _EAGAIN @@ -183,36 +128,6 @@ func semawakeup(mp *m) { } } -// May run with m.p==nil, so write barriers are not allowed. -//go:nowritebarrier -func newosproc(mp *m) { - stk := unsafe.Pointer(mp.g0.stack.hi) - if false { - print("newosproc stk=", stk, " m=", mp, " g=", mp.g0, " id=", mp.id, " ostk=", &mp, "\n") - } - - // Stack pointer must point inside stack area (as marked with MAP_STACK), - // rather than at the top of it. - param := tforkt{ - tf_tcb: unsafe.Pointer(&mp.tls[0]), - tf_tid: nil, // minit will record tid - tf_stack: uintptr(stk) - sys.PtrSize, - } - - var oset sigset - sigprocmask(_SIG_SETMASK, &sigset_all, &oset) - ret := tfork(¶m, unsafe.Sizeof(param), mp, mp.g0, funcPC(mstart)) - sigprocmask(_SIG_SETMASK, &oset, nil) - - if ret < 0 { - print("runtime: failed to create new OS thread (have ", mcount()-1, " already; errno=", -ret, ")\n") - if ret == -_EAGAIN { - println("runtime: may need to increase max user processes (ulimit -p)") - } - throw("runtime.newosproc") - } -} - func osinit() { ncpu = getncpu() physPageSize = getPageSize() @@ -257,6 +172,11 @@ func unminit() { unminitSignals() } +// Called from exitm, but not from drop, to undo the effect of thread-owned +// resources in minit, semacreate, or elsewhere. Do not take locks after calling this. +func mdestroy(mp *m) { +} + func sigtramp() type sigactiont struct { diff --git a/src/runtime/os_openbsd_libc.go b/src/runtime/os_openbsd_libc.go new file mode 100644 index 0000000000..2edb0358b0 --- /dev/null +++ b/src/runtime/os_openbsd_libc.go @@ -0,0 +1,58 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build openbsd,amd64 openbsd,arm64 + +package runtime + +import ( + "unsafe" +) + +var failThreadCreate = []byte("runtime: failed to create new OS thread\n") + +// mstart_stub provides glue code to call mstart from pthread_create. +func mstart_stub() + +// May run with m.p==nil, so write barriers are not allowed. +//go:nowritebarrierrec +func newosproc(mp *m) { + if false { + print("newosproc m=", mp, " g=", mp.g0, " id=", mp.id, " ostk=", &mp, "\n") + } + + // Initialize an attribute object. + var attr pthreadattr + if err := pthread_attr_init(&attr); err != 0 { + write(2, unsafe.Pointer(&failThreadCreate[0]), int32(len(failThreadCreate))) + exit(1) + } + + // Find out OS stack size for our own stack guard. + var stacksize uintptr + if pthread_attr_getstacksize(&attr, &stacksize) != 0 { + write(2, unsafe.Pointer(&failThreadCreate[0]), int32(len(failThreadCreate))) + exit(1) + } + mp.g0.stack.hi = stacksize // for mstart + + // Tell the pthread library we won't join with this thread. + if pthread_attr_setdetachstate(&attr, _PTHREAD_CREATE_DETACHED) != 0 { + write(2, unsafe.Pointer(&failThreadCreate[0]), int32(len(failThreadCreate))) + exit(1) + } + + // Finally, create the thread. It starts at mstart_stub, which does some low-level + // setup and then calls mstart. + var oset sigset + sigprocmask(_SIG_SETMASK, &sigset_all, &oset) + err := pthread_create(&attr, funcPC(mstart_stub), unsafe.Pointer(mp)) + sigprocmask(_SIG_SETMASK, &oset, nil) + if err != 0 { + write(2, unsafe.Pointer(&failThreadCreate[0]), int32(len(failThreadCreate))) + exit(1) + } + + pthread_attr_destroy(&attr) +} diff --git a/src/runtime/os_openbsd_syscall.go b/src/runtime/os_openbsd_syscall.go new file mode 100644 index 0000000000..16ff2b8e25 --- /dev/null +++ b/src/runtime/os_openbsd_syscall.go @@ -0,0 +1,46 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build openbsd,!amd64 +// +build openbsd,!arm64 + +package runtime + +import ( + "runtime/internal/sys" + "unsafe" +) + +//go:noescape +func tfork(param *tforkt, psize uintptr, mm *m, gg *g, fn uintptr) int32 + +// May run with m.p==nil, so write barriers are not allowed. +//go:nowritebarrier +func newosproc(mp *m) { + stk := unsafe.Pointer(mp.g0.stack.hi) + if false { + print("newosproc stk=", stk, " m=", mp, " g=", mp.g0, " id=", mp.id, " ostk=", &mp, "\n") + } + + // Stack pointer must point inside stack area (as marked with MAP_STACK), + // rather than at the top of it. + param := tforkt{ + tf_tcb: unsafe.Pointer(&mp.tls[0]), + tf_tid: nil, // minit will record tid + tf_stack: uintptr(stk) - sys.PtrSize, + } + + var oset sigset + sigprocmask(_SIG_SETMASK, &sigset_all, &oset) + ret := tfork(¶m, unsafe.Sizeof(param), mp, mp.g0, funcPC(mstart)) + sigprocmask(_SIG_SETMASK, &oset, nil) + + if ret < 0 { + print("runtime: failed to create new OS thread (have ", mcount()-1, " already; errno=", -ret, ")\n") + if ret == -_EAGAIN { + println("runtime: may need to increase max user processes (ulimit -p)") + } + throw("runtime.newosproc") + } +} diff --git a/src/runtime/os_openbsd_syscall1.go b/src/runtime/os_openbsd_syscall1.go new file mode 100644 index 0000000000..b0bef4c504 --- /dev/null +++ b/src/runtime/os_openbsd_syscall1.go @@ -0,0 +1,15 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build openbsd,!amd64,!arm64 + +package runtime + +//go:noescape +func thrsleep(ident uintptr, clock_id int32, tsp *timespec, lock uintptr, abort *uint32) int32 + +//go:noescape +func thrwakeup(ident uintptr, n int32) int32 + +func osyield() diff --git a/src/runtime/os_openbsd_syscall2.go b/src/runtime/os_openbsd_syscall2.go new file mode 100644 index 0000000000..ab940510af --- /dev/null +++ b/src/runtime/os_openbsd_syscall2.go @@ -0,0 +1,95 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build openbsd,!amd64,!arm64 + +package runtime + +import ( + "unsafe" +) + +//go:noescape +func sigaction(sig uint32, new, old *sigactiont) + +func kqueue() int32 + +//go:noescape +func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32 + +func raiseproc(sig uint32) + +func getthrid() int32 +func thrkill(tid int32, sig int) + +// read calls the read system call. +// It returns a non-negative number of bytes written or a negative errno value. +func read(fd int32, p unsafe.Pointer, n int32) int32 + +func closefd(fd int32) int32 + +func exit(code int32) +func usleep(usec uint32) + +// write calls the write system call. +// It returns a non-negative number of bytes written or a negative errno value. +//go:noescape +func write1(fd uintptr, p unsafe.Pointer, n int32) int32 + +//go:noescape +func open(name *byte, mode, perm int32) int32 + +// return value is only set on linux to be used in osinit() +func madvise(addr unsafe.Pointer, n uintptr, flags int32) int32 + +// exitThread terminates the current thread, writing *wait = 0 when +// the stack is safe to reclaim. +// +//go:noescape +func exitThread(wait *uint32) + +//go:noescape +func obsdsigprocmask(how int32, new sigset) sigset + +//go:nosplit +//go:nowritebarrierrec +func sigprocmask(how int32, new, old *sigset) { + n := sigset(0) + if new != nil { + n = *new + } + r := obsdsigprocmask(how, n) + if old != nil { + *old = r + } +} + +func pipe() (r, w int32, errno int32) +func pipe2(flags int32) (r, w int32, errno int32) + +//go:noescape +func setitimer(mode int32, new, old *itimerval) + +//go:noescape +func sysctl(mib *uint32, miblen uint32, out *byte, size *uintptr, dst *byte, ndst uintptr) int32 + +// mmap calls the mmap system call. It is implemented in assembly. +// We only pass the lower 32 bits of file offset to the +// assembly routine; the higher bits (if required), should be provided +// by the assembly routine as 0. +// The err result is an OS error code such as ENOMEM. +func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) (p unsafe.Pointer, err int) + +// munmap calls the munmap system call. It is implemented in assembly. +func munmap(addr unsafe.Pointer, n uintptr) + +func nanotime1() int64 + +//go:noescape +func sigaltstack(new, old *stackt) + +func closeonexec(fd int32) +func setNonblock(fd int32) + +func walltime1() (sec int64, nsec int32) diff --git a/src/runtime/os_plan9.go b/src/runtime/os_plan9.go index 62aecea060..2a84a73716 100644 --- a/src/runtime/os_plan9.go +++ b/src/runtime/os_plan9.go @@ -195,7 +195,7 @@ func msigrestore(sigmask sigset) { func clearSignalHandlers() { } -func sigblock() { +func sigblock(exiting bool) { } // Called to initialize a new m (including the bootstrap m). @@ -213,6 +213,11 @@ func minit() { func unminit() { } +// Called from exitm, but not from drop, to undo the effect of thread-owned +// resources in minit, semacreate, or elsewhere. Do not take locks after calling this. +func mdestroy(mp *m) { +} + var sysstat = []byte("/dev/sysstat\x00") func getproccount() int32 { diff --git a/src/runtime/os_windows.go b/src/runtime/os_windows.go index ffb087f9db..e6b22e3167 100644 --- a/src/runtime/os_windows.go +++ b/src/runtime/os_windows.go @@ -46,6 +46,7 @@ const ( //go:cgo_import_dynamic runtime._SetThreadPriority SetThreadPriority%2 "kernel32.dll" //go:cgo_import_dynamic runtime._SetUnhandledExceptionFilter SetUnhandledExceptionFilter%1 "kernel32.dll" //go:cgo_import_dynamic runtime._SetWaitableTimer SetWaitableTimer%6 "kernel32.dll" +//go:cgo_import_dynamic runtime._Sleep Sleep%1 "kernel32.dll" //go:cgo_import_dynamic runtime._SuspendThread SuspendThread%1 "kernel32.dll" //go:cgo_import_dynamic runtime._SwitchToThread SwitchToThread%0 "kernel32.dll" //go:cgo_import_dynamic runtime._TlsAlloc TlsAlloc%0 "kernel32.dll" @@ -97,6 +98,7 @@ var ( _SetThreadPriority, _SetUnhandledExceptionFilter, _SetWaitableTimer, + _Sleep, _SuspendThread, _SwitchToThread, _TlsAlloc, @@ -886,29 +888,30 @@ func clearSignalHandlers() { } //go:nosplit -func sigblock() { +func sigblock(exiting bool) { } // Called to initialize a new m (including the bootstrap m). // Called on the new thread, cannot allocate memory. func minit() { var thandle uintptr - stdcall7(_DuplicateHandle, currentProcess, currentThread, currentProcess, uintptr(unsafe.Pointer(&thandle)), 0, 0, _DUPLICATE_SAME_ACCESS) + if stdcall7(_DuplicateHandle, currentProcess, currentThread, currentProcess, uintptr(unsafe.Pointer(&thandle)), 0, 0, _DUPLICATE_SAME_ACCESS) == 0 { + print("runtime.minit: duplicatehandle failed; errno=", getlasterror(), "\n") + throw("runtime.minit: duplicatehandle failed") + } + + mp := getg().m + lock(&mp.threadLock) + mp.thread = thandle // Configure usleep timer, if possible. - var timer uintptr - if haveHighResTimer { - timer = createHighResTimer() - if timer == 0 { + if mp.highResTimer == 0 && haveHighResTimer { + mp.highResTimer = createHighResTimer() + if mp.highResTimer == 0 { print("runtime: CreateWaitableTimerEx failed; errno=", getlasterror(), "\n") throw("CreateWaitableTimerEx when creating timer failed") } } - - mp := getg().m - lock(&mp.threadLock) - mp.thread = thandle - mp.highResTimer = timer unlock(&mp.threadLock) // Query the true stack base from the OS. Currently we're @@ -944,13 +947,29 @@ func minit() { func unminit() { mp := getg().m lock(&mp.threadLock) - stdcall1(_CloseHandle, mp.thread) - mp.thread = 0 + if mp.thread != 0 { + stdcall1(_CloseHandle, mp.thread) + mp.thread = 0 + } + unlock(&mp.threadLock) +} + +// Called from exitm, but not from drop, to undo the effect of thread-owned +// resources in minit, semacreate, or elsewhere. Do not take locks after calling this. +//go:nosplit +func mdestroy(mp *m) { if mp.highResTimer != 0 { stdcall1(_CloseHandle, mp.highResTimer) mp.highResTimer = 0 } - unlock(&mp.threadLock) + if mp.waitsema != 0 { + stdcall1(_CloseHandle, mp.waitsema) + mp.waitsema = 0 + } + if mp.resumesema != 0 { + stdcall1(_CloseHandle, mp.resumesema) + mp.resumesema = 0 + } } // Calling stdcall on os stack. @@ -1077,6 +1096,11 @@ func ctrlhandler1(_type uint32) uint32 { } if sigsend(s) { + if s == _SIGTERM { + // Windows terminates the process after this handler returns. + // Block indefinitely to give signal handlers a chance to clean up. + stdcall1(_Sleep, uintptr(_INFINITE)) + } return 1 } return 0 @@ -1134,8 +1158,12 @@ func profileloop1(param uintptr) uint32 { } // Acquire our own handle to the thread. var thread uintptr - stdcall7(_DuplicateHandle, currentProcess, mp.thread, currentProcess, uintptr(unsafe.Pointer(&thread)), 0, 0, _DUPLICATE_SAME_ACCESS) + if stdcall7(_DuplicateHandle, currentProcess, mp.thread, currentProcess, uintptr(unsafe.Pointer(&thread)), 0, 0, _DUPLICATE_SAME_ACCESS) == 0 { + print("runtime.profileloop1: duplicatehandle failed; errno=", getlasterror(), "\n") + throw("runtime.profileloop1: duplicatehandle failed") + } unlock(&mp.threadLock) + // mp may exit between the DuplicateHandle // above and the SuspendThread. The handle // will remain valid, but SuspendThread may @@ -1214,7 +1242,10 @@ func preemptM(mp *m) { return } var thread uintptr - stdcall7(_DuplicateHandle, currentProcess, mp.thread, currentProcess, uintptr(unsafe.Pointer(&thread)), 0, 0, _DUPLICATE_SAME_ACCESS) + if stdcall7(_DuplicateHandle, currentProcess, mp.thread, currentProcess, uintptr(unsafe.Pointer(&thread)), 0, 0, _DUPLICATE_SAME_ACCESS) == 0 { + print("runtime.preemptM: duplicatehandle failed; errno=", getlasterror(), "\n") + throw("runtime.preemptM: duplicatehandle failed") + } unlock(&mp.threadLock) // Prepare thread context buffer. This must be aligned to 16 bytes. diff --git a/src/runtime/panic.go b/src/runtime/panic.go index aed17d6fc6..e320eaa596 100644 --- a/src/runtime/panic.go +++ b/src/runtime/panic.go @@ -5,6 +5,7 @@ package runtime import ( + "internal/abi" "runtime/internal/atomic" "runtime/internal/sys" "unsafe" @@ -874,7 +875,13 @@ func reflectcallSave(p *_panic, fn, arg unsafe.Pointer, argsize uint32) { p.pc = getcallerpc() p.sp = unsafe.Pointer(getcallersp()) } - reflectcall(nil, fn, arg, argsize, argsize) + // Pass a dummy RegArgs for now since no function actually implements + // the register-based ABI. + // + // TODO(mknyszek): Implement this properly, setting up arguments in + // registers as necessary in the caller. + var regs abi.RegArgs + reflectcall(nil, fn, arg, argsize, argsize, argsize, ®s) if p != nil { p.pc = 0 p.sp = unsafe.Pointer(nil) @@ -968,7 +975,9 @@ func gopanic(e interface{}) { } } else { p.argp = unsafe.Pointer(getargp(0)) - reflectcall(nil, unsafe.Pointer(d.fn), deferArgs(d), uint32(d.siz), uint32(d.siz)) + + var regs abi.RegArgs + reflectcall(nil, unsafe.Pointer(d.fn), deferArgs(d), uint32(d.siz), uint32(d.siz), uint32(d.siz), ®s) } p.argp = nil @@ -1000,37 +1009,42 @@ func gopanic(e interface{}) { } atomic.Xadd(&runningPanicDefers, -1) - if done { - // Remove any remaining non-started, open-coded - // defer entries after a recover, since the - // corresponding defers will be executed normally - // (inline). Any such entry will become stale once - // we run the corresponding defers inline and exit - // the associated stack frame. - d := gp._defer - var prev *_defer - for d != nil { - if d.openDefer { - if d.started { - // This defer is started but we - // are in the middle of a - // defer-panic-recover inside of - // it, so don't remove it or any - // further defer entries - break - } - if prev == nil { - gp._defer = d.link - } else { - prev.link = d.link - } - newd := d.link - freedefer(d) - d = newd + // Remove any remaining non-started, open-coded + // defer entries after a recover, since the + // corresponding defers will be executed normally + // (inline). Any such entry will become stale once + // we run the corresponding defers inline and exit + // the associated stack frame. + d := gp._defer + var prev *_defer + if !done { + // Skip our current frame, if not done. It is + // needed to complete any remaining defers in + // deferreturn() + prev = d + d = d.link + } + for d != nil { + if d.started { + // This defer is started but we + // are in the middle of a + // defer-panic-recover inside of + // it, so don't remove it or any + // further defer entries + break + } + if d.openDefer { + if prev == nil { + gp._defer = d.link } else { - prev = d - d = d.link + prev.link = d.link } + newd := d.link + freedefer(d) + d = newd + } else { + prev = d + d = d.link } } diff --git a/src/runtime/pprof/pprof_test.go b/src/runtime/pprof/pprof_test.go index 43307aeab9..b6ee160e84 100644 --- a/src/runtime/pprof/pprof_test.go +++ b/src/runtime/pprof/pprof_test.go @@ -13,7 +13,6 @@ import ( "internal/profile" "internal/testenv" "io" - "io/ioutil" "math/big" "os" "os/exec" @@ -286,6 +285,10 @@ func testCPUProfile(t *testing.T, matches matchFunc, need []string, avoid []stri if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" { broken = true } + case "windows": + if runtime.GOARCH == "arm" { + broken = true // See https://golang.org/issues/42862 + } } maxDuration := 5 * time.Second @@ -1175,7 +1178,7 @@ func TestLabelRace(t *testing.T) { // Check that there is no deadlock when the program receives SIGPROF while in // 64bit atomics' critical section. Used to happen on mips{,le}. See #20146. func TestAtomicLoadStore64(t *testing.T) { - f, err := ioutil.TempFile("", "profatomic") + f, err := os.CreateTemp("", "profatomic") if err != nil { t.Fatalf("TempFile: %v", err) } @@ -1204,7 +1207,7 @@ func TestAtomicLoadStore64(t *testing.T) { func TestTracebackAll(t *testing.T) { // With gccgo, if a profiling signal arrives at the wrong time // during traceback, it may crash or hang. See issue #29448. - f, err := ioutil.TempFile("", "proftraceback") + f, err := os.CreateTemp("", "proftraceback") if err != nil { t.Fatalf("TempFile: %v", err) } diff --git a/src/runtime/pprof/proto.go b/src/runtime/pprof/proto.go index 8519af6985..bdb4454b6e 100644 --- a/src/runtime/pprof/proto.go +++ b/src/runtime/pprof/proto.go @@ -9,7 +9,7 @@ import ( "compress/gzip" "fmt" "io" - "io/ioutil" + "os" "runtime" "strconv" "time" @@ -575,7 +575,7 @@ func (b *profileBuilder) emitLocation() uint64 { // It saves the address ranges of the mappings in b.mem for use // when emitting locations. func (b *profileBuilder) readMapping() { - data, _ := ioutil.ReadFile("/proc/self/maps") + data, _ := os.ReadFile("/proc/self/maps") parseProcSelfMaps(data, b.addMapping) if len(b.mem) == 0 { // pprof expects a map entry, so fake one. b.addMappingEntry(0, 0, 0, "", "", true) diff --git a/src/runtime/pprof/proto_test.go b/src/runtime/pprof/proto_test.go index 3043d5353f..5eb1aab140 100644 --- a/src/runtime/pprof/proto_test.go +++ b/src/runtime/pprof/proto_test.go @@ -10,7 +10,6 @@ import ( "fmt" "internal/profile" "internal/testenv" - "io/ioutil" "os" "os/exec" "reflect" @@ -78,7 +77,7 @@ func testPCs(t *testing.T) (addr1, addr2 uint64, map1, map2 *profile.Mapping) { switch runtime.GOOS { case "linux", "android", "netbsd": // Figure out two addresses from /proc/self/maps. - mmap, err := ioutil.ReadFile("/proc/self/maps") + mmap, err := os.ReadFile("/proc/self/maps") if err != nil { t.Fatal(err) } diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 0319de5fde..73a789c189 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -490,8 +490,29 @@ func lockedOSThread() bool { } var ( - allgs []*g + // allgs contains all Gs ever created (including dead Gs), and thus + // never shrinks. + // + // Access via the slice is protected by allglock or stop-the-world. + // Readers that cannot take the lock may (carefully!) use the atomic + // variables below. allglock mutex + allgs []*g + + // allglen and allgptr are atomic variables that contain len(allg) and + // &allg[0] respectively. Proper ordering depends on totally-ordered + // loads and stores. Writes are protected by allglock. + // + // allgptr is updated before allglen. Readers should read allglen + // before allgptr to ensure that allglen is always <= len(allgptr). New + // Gs appended during the race can be missed. For a consistent view of + // all Gs, allglock must be held. + // + // allgptr copies should always be stored as a concrete type or + // unsafe.Pointer, not uintptr, to ensure that GC can still reach it + // even if it points to a stale array. + allglen uintptr + allgptr **g ) func allgadd(gp *g) { @@ -501,10 +522,25 @@ func allgadd(gp *g) { lock(&allglock) allgs = append(allgs, gp) - allglen = uintptr(len(allgs)) + if &allgs[0] != allgptr { + atomicstorep(unsafe.Pointer(&allgptr), unsafe.Pointer(&allgs[0])) + } + atomic.Storeuintptr(&allglen, uintptr(len(allgs))) unlock(&allglock) } +// atomicAllG returns &allgs[0] and len(allgs) for use with atomicAllGIndex. +func atomicAllG() (**g, uintptr) { + length := atomic.Loaduintptr(&allglen) + ptr := (**g)(atomic.Loadp(unsafe.Pointer(&allgptr))) + return ptr, length +} + +// atomicAllGIndex returns ptr[i] with the allgptr returned from atomicAllG. +func atomicAllGIndex(ptr **g, i uintptr) *g { + return *(**g)(add(unsafe.Pointer(ptr), i*sys.PtrSize)) +} + const ( // Number of goroutine ids to grab from sched.goidgen to local per-P cache at once. // 16 seems to provide enough amortization, but other than that it's mostly arbitrary number. @@ -1170,6 +1206,33 @@ func startTheWorldWithSema(emitTraceEvent bool) int64 { return startTime } +// usesLibcall indicates whether this runtime performs system calls +// via libcall. +func usesLibcall() bool { + switch GOOS { + case "aix", "darwin", "illumos", "ios", "solaris", "windows": + return true + case "openbsd": + return GOARCH == "amd64" || GOARCH == "arm64" + } + return false +} + +// mStackIsSystemAllocated indicates whether this runtime starts on a +// system-allocated stack. +func mStackIsSystemAllocated() bool { + switch GOOS { + case "aix", "darwin", "plan9", "illumos", "ios", "solaris", "windows": + return true + case "openbsd": + switch GOARCH { + case "amd64", "arm64": + return true + } + } + return false +} + // mstart is the entry-point for new Ms. // // This must not split the stack because we may not even have stack @@ -1188,6 +1251,11 @@ func mstart() { // Initialize stack bounds from system stack. // Cgo may have left stack size in stack.hi. // minit may update the stack bounds. + // + // Note: these bounds may not be very accurate. + // We set hi to &size, but there are things above + // it. The 1024 is supposed to compensate this, + // but is somewhat arbitrary. size := _g_.stack.hi if size == 0 { size = 8192 * sys.StackGuardMultiplier @@ -1204,8 +1272,7 @@ func mstart() { mstart1() // Exit this thread. - switch GOOS { - case "windows", "solaris", "illumos", "plan9", "darwin", "ios", "aix": + if mStackIsSystemAllocated() { // Windows, Solaris, illumos, Darwin, AIX and Plan 9 always system-allocate // the stack, but put it in _g_.stack before mstart, // so the logic above hasn't set osStack yet. @@ -1313,7 +1380,7 @@ func mexit(osStack bool) { throw("locked m0 woke up") } - sigblock() + sigblock(true) unminit() // Free the gsignal stack. @@ -1363,7 +1430,7 @@ found: checkdead() unlock(&sched.lock) - if GOOS == "darwin" { + if GOOS == "darwin" || GOOS == "ios" { // Make sure pendingPreemptSignals is correct when an M exits. // For #41702. if atomic.Load(&m.signalPending) != 0 { @@ -1371,6 +1438,10 @@ found: } } + // Destroy all allocated resources. After this is called, we may no + // longer take any locks. + mdestroy(m) + if osStack { // Return from mstart and let the system thread // library free the g0 stack and terminate the thread. @@ -1515,6 +1586,7 @@ func syscall_runtime_doAllThreadsSyscall(fn func(bool) bool) { if netpollinited() { netpollBreak() } + sigRecvPrepareForFixup() _g_ := getg() if raceenabled { // For m's running without racectx, we loan out the @@ -1683,7 +1755,7 @@ func allocm(_p_ *p, fn func(), id int64) *m { // In case of cgo or Solaris or illumos or Darwin, pthread_create will make us a stack. // Windows and Plan 9 will layout sched stack on OS stack. - if iscgo || GOOS == "solaris" || GOOS == "illumos" || GOOS == "windows" || GOOS == "plan9" || GOOS == "darwin" || GOOS == "ios" { + if iscgo || mStackIsSystemAllocated() { mp.g0 = malg(-1) } else { mp.g0 = malg(8192 * sys.StackGuardMultiplier) @@ -1754,7 +1826,7 @@ func needm() { // starting a new m to run Go code via newosproc. var sigmask sigset sigsave(&sigmask) - sigblock() + sigblock(false) // Lock extra list, take head, unlock popped list. // nilokay=false is safe here because of the invariant above, @@ -1903,7 +1975,7 @@ func dropm() { // Setg(nil) clears g, which is the signal handler's cue not to run Go handlers. // It's important not to try to handle a signal between those two steps. sigmask := mp.sigmask - sigblock() + sigblock(false) unminit() mnext := lockextra(true) @@ -2882,7 +2954,9 @@ func wakeNetPoller(when int64) { } else { // There are no threads in the network poller, try to get // one there so it can handle new timers. - wakep() + if GOOS != "plan9" { // Temporary workaround - see issue #42303. + wakep() + } } } @@ -3774,7 +3848,7 @@ func beforefork() { // group. See issue #18600. gp.m.locks++ sigsave(&gp.m.sigmask) - sigblock() + sigblock(false) // This function is called before fork in syscall package. // Code between fork and exec must not allocate memory nor even try to grow stack. @@ -3852,7 +3926,7 @@ func syscall_runtime_BeforeExec() { // On Darwin, wait for all pending preemption signals to // be received. See issue #41702. - if GOOS == "darwin" { + if GOOS == "darwin" || GOOS == "ios" { for int32(atomic.Load(&pendingPreemptSignals)) > 0 { osyield() } @@ -4263,7 +4337,7 @@ func badunlockosthread() { } func gcount() int32 { - n := int32(allglen) - sched.gFree.n - int32(atomic.Load(&sched.ngsys)) + n := int32(atomic.Loaduintptr(&allglen)) - sched.gFree.n - int32(atomic.Load(&sched.ngsys)) for _, _p_ := range allp { n -= _p_.gFree.n } @@ -4429,7 +4503,7 @@ func sigprof(pc, sp, lr uintptr, gp *g, mp *m) { // Normal traceback is impossible or has failed. // See if it falls into several common cases. n = 0 - if (GOOS == "windows" || GOOS == "solaris" || GOOS == "illumos" || GOOS == "darwin" || GOOS == "ios" || GOOS == "aix") && mp.libcallg != 0 && mp.libcallpc != 0 && mp.libcallsp != 0 { + if usesLibcall() && mp.libcallg != 0 && mp.libcallpc != 0 && mp.libcallsp != 0 { // Libcall, i.e. runtime syscall on windows. // Collect Go stack that leads to the call. n = gentraceback(mp.libcallpc, mp.libcallsp, 0, mp.libcallg.ptr(), 0, &stk[0], len(stk), nil, nil, 0) @@ -4967,7 +5041,6 @@ func checkdead() { case _Grunnable, _Grunning, _Gsyscall: - unlock(&allglock) print("runtime: checkdead: find g ", gp.goid, " in status ", s, "\n") throw("checkdead: runnable g") } @@ -5128,6 +5201,26 @@ func sysmon() { } } mDoFixup() + if GOOS == "netbsd" { + // netpoll is responsible for waiting for timer + // expiration, so we typically don't have to worry + // about starting an M to service timers. (Note that + // sleep for timeSleepUntil above simply ensures sysmon + // starts running again when that timer expiration may + // cause Go code to run again). + // + // However, netbsd has a kernel bug that sometimes + // misses netpollBreak wake-ups, which can lead to + // unbounded delays servicing timers. If we detect this + // overrun, then startm to get something to handle the + // timer. + // + // See issue 42515 and + // https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=50094. + if next, _ := timeSleepUntil(); next < now { + startm(nil, false) + } + } if atomic.Load(&scavenge.sysmonWake) != 0 { // Kick the scavenger awake if someone requested it. wakeScavenger() diff --git a/src/runtime/race.go b/src/runtime/race.go index 53910f991c..79fd21765d 100644 --- a/src/runtime/race.go +++ b/src/runtime/race.go @@ -268,6 +268,9 @@ var __tsan_acquire byte //go:linkname __tsan_release __tsan_release var __tsan_release byte +//go:linkname __tsan_release_acquire __tsan_release_acquire +var __tsan_release_acquire byte + //go:linkname __tsan_release_merge __tsan_release_merge var __tsan_release_merge byte @@ -293,6 +296,7 @@ var __tsan_report_count byte //go:cgo_import_static __tsan_free //go:cgo_import_static __tsan_acquire //go:cgo_import_static __tsan_release +//go:cgo_import_static __tsan_release_acquire //go:cgo_import_static __tsan_release_merge //go:cgo_import_static __tsan_go_ignore_sync_begin //go:cgo_import_static __tsan_go_ignore_sync_end @@ -536,6 +540,19 @@ func racereleaseg(gp *g, addr unsafe.Pointer) { } //go:nosplit +func racereleaseacquire(addr unsafe.Pointer) { + racereleaseacquireg(getg(), addr) +} + +//go:nosplit +func racereleaseacquireg(gp *g, addr unsafe.Pointer) { + if getg().raceignore != 0 || !isvalidaddr(addr) { + return + } + racecall(&__tsan_release_acquire, gp.racectx, uintptr(addr), 0, 0) +} + +//go:nosplit func racereleasemerge(addr unsafe.Pointer) { racereleasemergeg(getg(), addr) } diff --git a/src/runtime/race/output_test.go b/src/runtime/race/output_test.go index b4b8936c7c..17dc32013f 100644 --- a/src/runtime/race/output_test.go +++ b/src/runtime/race/output_test.go @@ -7,8 +7,8 @@ package race_test import ( + "fmt" "internal/testenv" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -19,7 +19,7 @@ import ( ) func TestOutput(t *testing.T) { - pkgdir, err := ioutil.TempDir("", "go-build-race-output") + pkgdir, err := os.MkdirTemp("", "go-build-race-output") if err != nil { t.Fatal(err) } @@ -34,7 +34,7 @@ func TestOutput(t *testing.T) { t.Logf("test %v runs only on %v, skipping: ", test.name, test.goos) continue } - dir, err := ioutil.TempDir("", "go-build") + dir, err := os.MkdirTemp("", "go-build") if err != nil { t.Fatalf("failed to create temp directory: %v", err) } @@ -72,9 +72,24 @@ func TestOutput(t *testing.T) { "GORACE="+test.gorace, ) got, _ := cmd.CombinedOutput() - if !regexp.MustCompile(test.re).MatchString(string(got)) { - t.Fatalf("failed test case %v, expect:\n%v\ngot:\n%s", - test.name, test.re, got) + matched := false + for _, re := range test.re { + if regexp.MustCompile(re).MatchString(string(got)) { + matched = true + break + } + } + if !matched { + exp := fmt.Sprintf("expect:\n%v\n", test.re[0]) + if len(test.re) > 1 { + exp = fmt.Sprintf("expected one of %d patterns:\n", + len(test.re)) + for k, re := range test.re { + exp += fmt.Sprintf("pattern %d:\n%v\n", k, re) + } + } + t.Fatalf("failed test case %v, %sgot:\n%s", + test.name, exp, got) } } } @@ -85,7 +100,7 @@ var tests = []struct { goos string gorace string source string - re string + re []string }{ {"simple", "run", "", "atexit_sleep_ms=0", ` package main @@ -108,7 +123,7 @@ func racer(x *int, done chan bool) { store(x, 42) done <- true } -`, `================== +`, []string{`================== WARNING: DATA RACE Write at 0x[0-9,a-f]+ by goroutine [0-9]: main\.store\(\) @@ -130,7 +145,7 @@ Goroutine [0-9] \(running\) created at: ================== Found 1 data race\(s\) exit status 66 -`}, +`}}, {"exitcode", "run", "", "atexit_sleep_ms=0 exitcode=13", ` package main @@ -144,7 +159,7 @@ func main() { x = 43 <-done } -`, `exit status 13`}, +`, []string{`exit status 13`}}, {"strip_path_prefix", "run", "", "atexit_sleep_ms=0 strip_path_prefix=/main.", ` package main @@ -158,9 +173,9 @@ func main() { x = 43 <-done } -`, ` +`, []string{` go:7 \+0x[0-9,a-f]+ -`}, +`}}, {"halt_on_error", "run", "", "atexit_sleep_ms=0 halt_on_error=1", ` package main @@ -174,10 +189,10 @@ func main() { x = 43 <-done } -`, ` +`, []string{` ================== exit status 66 -`}, +`}}, {"test_fails_on_race", "test", "", "atexit_sleep_ms=0", ` package main_test @@ -194,12 +209,12 @@ func TestFail(t *testing.T) { <-done t.Log(t.Failed()) } -`, ` +`, []string{` ================== --- FAIL: TestFail \(0...s\) .*main_test.go:14: true .*testing.go:.*: race detected during execution of test -FAIL`}, +FAIL`}}, {"slicebytetostring_pc", "run", "", "atexit_sleep_ms=0", ` package main @@ -212,11 +227,11 @@ func main() { data[0] = 1 <-done } -`, ` +`, []string{` runtime\.slicebytetostring\(\) .*/runtime/string\.go:.* main\.main\.func1\(\) - .*/main.go:7`}, + .*/main.go:7`}}, // Test for https://golang.org/issue/33309 {"midstack_inlining_traceback", "run", "linux", "atexit_sleep_ms=0", ` @@ -242,7 +257,7 @@ func g(c chan int) { func h(c chan int) { c <- x } -`, `================== +`, []string{`================== WARNING: DATA RACE Read at 0x[0-9,a-f]+ by goroutine [0-9]: main\.h\(\) @@ -262,7 +277,7 @@ Goroutine [0-9] \(running\) created at: ================== Found 1 data race\(s\) exit status 66 -`}, +`}}, // Test for https://golang.org/issue/17190 {"external_cgo_thread", "run", "linux", "atexit_sleep_ms=0", ` @@ -285,22 +300,23 @@ static inline void startThread(cb* c) { */ import "C" -import "time" - +var done chan bool var racy int //export goCallback func goCallback() { racy++ + done <- true } func main() { + done = make(chan bool) var c C.cb C.startThread(&c) - time.Sleep(time.Second) racy++ + <- done } -`, `================== +`, []string{`================== WARNING: DATA RACE Read at 0x[0-9,a-f]+ by main goroutine: main\.main\(\) @@ -311,11 +327,27 @@ Previous write at 0x[0-9,a-f]+ by goroutine [0-9]: .*/main\.go:27 \+0x[0-9,a-f]+ _cgoexp_[0-9a-z]+_goCallback\(\) .*_cgo_gotypes\.go:[0-9]+ \+0x[0-9,a-f]+ + _cgoexp_[0-9a-z]+_goCallback\(\) + <autogenerated>:1 \+0x[0-9,a-f]+ Goroutine [0-9] \(running\) created at: runtime\.newextram\(\) .*/runtime/proc.go:[0-9]+ \+0x[0-9,a-f]+ -==================`}, +==================`, + `================== +WARNING: DATA RACE +Read at 0x[0-9,a-f]+ by .*: + main\..* + .*/main\.go:[0-9]+ \+0x[0-9,a-f]+(?s).* + +Previous write at 0x[0-9,a-f]+ by .*: + main\..* + .*/main\.go:[0-9]+ \+0x[0-9,a-f]+(?s).* + +Goroutine [0-9] \(running\) created at: + runtime\.newextram\(\) + .*/runtime/proc.go:[0-9]+ \+0x[0-9,a-f]+ +==================`}}, {"second_test_passes", "test", "", "atexit_sleep_ms=0", ` package main_test import "testing" @@ -333,9 +365,82 @@ func TestFail(t *testing.T) { func TestPass(t *testing.T) { } -`, ` +`, []string{` ================== --- FAIL: TestFail \(0...s\) .*testing.go:.*: race detected during execution of test -FAIL`}, +FAIL`}}, + {"mutex", "run", "", "atexit_sleep_ms=0", ` +package main +import ( + "sync" + "fmt" +) +func main() { + c := make(chan bool, 1) + threads := 1 + iterations := 20000 + data := 0 + var wg sync.WaitGroup + for i := 0; i < threads; i++ { + wg.Add(1) + go func() { + defer wg.Done() + for i := 0; i < iterations; i++ { + c <- true + data += 1 + <- c + } + }() + } + for i := 0; i < iterations; i++ { + c <- true + data += 1 + <- c + } + wg.Wait() + if (data == iterations*(threads+1)) { fmt.Println("pass") } +}`, []string{`pass`}}, + // Test for https://github.com/golang/go/issues/37355 + {"chanmm", "run", "", "atexit_sleep_ms=0", ` +package main +import ( + "sync" + "time" +) +func main() { + c := make(chan bool, 1) + var data uint64 + var wg sync.WaitGroup + wg.Add(2) + c <- true + go func() { + defer wg.Done() + c <- true + }() + go func() { + defer wg.Done() + time.Sleep(time.Second) + <-c + data = 2 + }() + data = 1 + <-c + wg.Wait() + _ = data +} +`, []string{`================== +WARNING: DATA RACE +Write at 0x[0-9,a-f]+ by goroutine [0-9]: + main\.main\.func2\(\) + .*/main\.go:21 \+0x[0-9,a-f]+ + +Previous write at 0x[0-9,a-f]+ by main goroutine: + main\.main\(\) + .*/main\.go:23 \+0x[0-9,a-f]+ + +Goroutine [0-9] \(running\) created at: + main\.main\(\) + .*/main.go:[0-9]+ \+0x[0-9,a-f]+ +==================`}}, } diff --git a/src/runtime/race/race_test.go b/src/runtime/race/race_test.go index a0b8531b42..d433af6bd0 100644 --- a/src/runtime/race/race_test.go +++ b/src/runtime/race/race_test.go @@ -177,6 +177,10 @@ func runTests(t *testing.T) ([]byte, error) { ) // There are races: we expect tests to fail and the exit code to be non-zero. out, _ := cmd.CombinedOutput() + if bytes.Contains(out, []byte("fatal error:")) { + // But don't expect runtime to crash. + return out, fmt.Errorf("runtime fatal error") + } return out, nil } diff --git a/src/runtime/race/testdata/atomic_test.go b/src/runtime/race/testdata/atomic_test.go index 769c8d7398..4ce72604a4 100644 --- a/src/runtime/race/testdata/atomic_test.go +++ b/src/runtime/race/testdata/atomic_test.go @@ -299,3 +299,27 @@ func TestNoRaceAtomicCrash(t *testing.T) { }() atomic.AddInt32(nilptr, 1) } + +func TestNoRaceDeferAtomicStore(t *testing.T) { + // Test that when an atomic function is deferred directly, the + // GC scans it correctly. See issue 42599. + type foo struct { + bar int64 + } + + var doFork func(f *foo, depth int) + doFork = func(f *foo, depth int) { + atomic.StoreInt64(&f.bar, 1) + defer atomic.StoreInt64(&f.bar, 0) + if depth > 0 { + for i := 0; i < 2; i++ { + f2 := &foo{} + go doFork(f2, depth-1) + } + } + runtime.GC() + } + + f := &foo{} + doFork(f, 11) +} diff --git a/src/runtime/race/testdata/chan_test.go b/src/runtime/race/testdata/chan_test.go index 3e57b8221c..e39ad4f99c 100644 --- a/src/runtime/race/testdata/chan_test.go +++ b/src/runtime/race/testdata/chan_test.go @@ -763,3 +763,25 @@ func TestNoRaceCloseHappensBeforeRead(t *testing.T) { <-read } } + +// Test that we call the proper race detector function when c.elemsize==0. +// See https://github.com/golang/go/issues/42598 +func TestNoRaceElemetSize0(t *testing.T) { + var x, y int + var c = make(chan struct{}, 2) + c <- struct{}{} + c <- struct{}{} + go func() { + x += 1 + <-c + }() + go func() { + y += 1 + <-c + }() + time.Sleep(10 * time.Millisecond) + c <- struct{}{} + c <- struct{}{} + x += 1 + y += 1 +} diff --git a/src/runtime/race/testdata/io_test.go b/src/runtime/race/testdata/io_test.go index 30a121bee4..c5055f7837 100644 --- a/src/runtime/race/testdata/io_test.go +++ b/src/runtime/race/testdata/io_test.go @@ -6,7 +6,6 @@ package race_test import ( "fmt" - "io/ioutil" "net" "net/http" "os" @@ -18,7 +17,7 @@ import ( func TestNoRaceIOFile(t *testing.T) { x := 0 - path, _ := ioutil.TempDir("", "race_test") + path, _ := os.MkdirTemp("", "race_test") fname := filepath.Join(path, "data") go func() { x = 42 diff --git a/src/runtime/race/testdata/sync_test.go b/src/runtime/race/testdata/sync_test.go index 2b2d95d76b..b5fcd6c4cf 100644 --- a/src/runtime/race/testdata/sync_test.go +++ b/src/runtime/race/testdata/sync_test.go @@ -126,11 +126,11 @@ func TestNoRaceAfterFunc1(t *testing.T) { func TestNoRaceAfterFunc2(t *testing.T) { var x int + _ = x timer := time.AfterFunc(10, func() { x = 1 }) defer timer.Stop() - _ = x } func TestNoRaceAfterFunc3(t *testing.T) { diff --git a/src/runtime/race0.go b/src/runtime/race0.go index 6f26afa854..180f707b1a 100644 --- a/src/runtime/race0.go +++ b/src/runtime/race0.go @@ -32,6 +32,8 @@ func raceacquireg(gp *g, addr unsafe.Pointer) { th func raceacquirectx(racectx uintptr, addr unsafe.Pointer) { throw("race") } func racerelease(addr unsafe.Pointer) { throw("race") } func racereleaseg(gp *g, addr unsafe.Pointer) { throw("race") } +func racereleaseacquire(addr unsafe.Pointer) { throw("race") } +func racereleaseacquireg(gp *g, addr unsafe.Pointer) { throw("race") } func racereleasemerge(addr unsafe.Pointer) { throw("race") } func racereleasemergeg(gp *g, addr unsafe.Pointer) { throw("race") } func racefingo() { throw("race") } diff --git a/src/runtime/race_amd64.s b/src/runtime/race_amd64.s index 4a86b3371a..c3b7bbfbfe 100644 --- a/src/runtime/race_amd64.s +++ b/src/runtime/race_amd64.s @@ -146,8 +146,10 @@ TEXT runtime·racewriterangepc1(SB), NOSPLIT, $0-24 // If addr (RARG1) is out of range, do nothing. // Otherwise, setup goroutine context and invoke racecall. Other arguments already set. TEXT racecalladdr<>(SB), NOSPLIT, $0-0 +#ifndef GOEXPERIMENT_REGABI get_tls(R12) MOVQ g(R12), R14 +#endif MOVQ g_racectx(R14), RARG0 // goroutine context // Check that addr is within [arenastart, arenaend) or within [racedatastart, racedataend). CMPQ RARG1, runtime·racearenastart(SB) @@ -183,8 +185,10 @@ TEXT runtime·racefuncenter(SB), NOSPLIT, $0-8 // R11 = caller's return address TEXT racefuncenter<>(SB), NOSPLIT, $0-0 MOVQ DX, R15 // save function entry context (for closures) +#ifndef GOEXPERIMENT_REGABI get_tls(R12) MOVQ g(R12), R14 +#endif MOVQ g_racectx(R14), RARG0 // goroutine context MOVQ R11, RARG1 // void __tsan_func_enter(ThreadState *thr, void *pc); @@ -197,8 +201,10 @@ TEXT racefuncenter<>(SB), NOSPLIT, $0-0 // func runtime·racefuncexit() // Called from instrumented code. TEXT runtime·racefuncexit(SB), NOSPLIT, $0-0 +#ifndef GOEXPERIMENT_REGABI get_tls(R12) MOVQ g(R12), R14 +#endif MOVQ g_racectx(R14), RARG0 // goroutine context // void __tsan_func_exit(ThreadState *thr); MOVQ $__tsan_func_exit(SB), AX @@ -207,110 +213,136 @@ TEXT runtime·racefuncexit(SB), NOSPLIT, $0-0 // Atomic operations for sync/atomic package. // Load -TEXT sync∕atomic·LoadInt32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·LoadInt32(SB), NOSPLIT, $0-12 + GO_ARGS MOVQ $__tsan_go_atomic32_load(SB), AX CALL racecallatomic<>(SB) RET -TEXT sync∕atomic·LoadInt64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·LoadInt64(SB), NOSPLIT, $0-16 + GO_ARGS MOVQ $__tsan_go_atomic64_load(SB), AX CALL racecallatomic<>(SB) RET -TEXT sync∕atomic·LoadUint32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·LoadUint32(SB), NOSPLIT, $0-12 + GO_ARGS JMP sync∕atomic·LoadInt32(SB) -TEXT sync∕atomic·LoadUint64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·LoadUint64(SB), NOSPLIT, $0-16 + GO_ARGS JMP sync∕atomic·LoadInt64(SB) -TEXT sync∕atomic·LoadUintptr(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·LoadUintptr(SB), NOSPLIT, $0-16 + GO_ARGS JMP sync∕atomic·LoadInt64(SB) -TEXT sync∕atomic·LoadPointer(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·LoadPointer(SB), NOSPLIT, $0-16 + GO_ARGS JMP sync∕atomic·LoadInt64(SB) // Store -TEXT sync∕atomic·StoreInt32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·StoreInt32(SB), NOSPLIT, $0-12 + GO_ARGS MOVQ $__tsan_go_atomic32_store(SB), AX CALL racecallatomic<>(SB) RET -TEXT sync∕atomic·StoreInt64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·StoreInt64(SB), NOSPLIT, $0-16 + GO_ARGS MOVQ $__tsan_go_atomic64_store(SB), AX CALL racecallatomic<>(SB) RET -TEXT sync∕atomic·StoreUint32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·StoreUint32(SB), NOSPLIT, $0-12 + GO_ARGS JMP sync∕atomic·StoreInt32(SB) -TEXT sync∕atomic·StoreUint64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·StoreUint64(SB), NOSPLIT, $0-16 + GO_ARGS JMP sync∕atomic·StoreInt64(SB) -TEXT sync∕atomic·StoreUintptr(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·StoreUintptr(SB), NOSPLIT, $0-16 + GO_ARGS JMP sync∕atomic·StoreInt64(SB) // Swap -TEXT sync∕atomic·SwapInt32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·SwapInt32(SB), NOSPLIT, $0-20 + GO_ARGS MOVQ $__tsan_go_atomic32_exchange(SB), AX CALL racecallatomic<>(SB) RET -TEXT sync∕atomic·SwapInt64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·SwapInt64(SB), NOSPLIT, $0-24 + GO_ARGS MOVQ $__tsan_go_atomic64_exchange(SB), AX CALL racecallatomic<>(SB) RET -TEXT sync∕atomic·SwapUint32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·SwapUint32(SB), NOSPLIT, $0-20 + GO_ARGS JMP sync∕atomic·SwapInt32(SB) -TEXT sync∕atomic·SwapUint64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·SwapUint64(SB), NOSPLIT, $0-24 + GO_ARGS JMP sync∕atomic·SwapInt64(SB) -TEXT sync∕atomic·SwapUintptr(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·SwapUintptr(SB), NOSPLIT, $0-24 + GO_ARGS JMP sync∕atomic·SwapInt64(SB) // Add -TEXT sync∕atomic·AddInt32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·AddInt32(SB), NOSPLIT, $0-20 + GO_ARGS MOVQ $__tsan_go_atomic32_fetch_add(SB), AX CALL racecallatomic<>(SB) MOVL add+8(FP), AX // convert fetch_add to add_fetch ADDL AX, ret+16(FP) RET -TEXT sync∕atomic·AddInt64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·AddInt64(SB), NOSPLIT, $0-24 + GO_ARGS MOVQ $__tsan_go_atomic64_fetch_add(SB), AX CALL racecallatomic<>(SB) MOVQ add+8(FP), AX // convert fetch_add to add_fetch ADDQ AX, ret+16(FP) RET -TEXT sync∕atomic·AddUint32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·AddUint32(SB), NOSPLIT, $0-20 + GO_ARGS JMP sync∕atomic·AddInt32(SB) -TEXT sync∕atomic·AddUint64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·AddUint64(SB), NOSPLIT, $0-24 + GO_ARGS JMP sync∕atomic·AddInt64(SB) -TEXT sync∕atomic·AddUintptr(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·AddUintptr(SB), NOSPLIT, $0-24 + GO_ARGS JMP sync∕atomic·AddInt64(SB) // CompareAndSwap -TEXT sync∕atomic·CompareAndSwapInt32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·CompareAndSwapInt32(SB), NOSPLIT, $0-17 + GO_ARGS MOVQ $__tsan_go_atomic32_compare_exchange(SB), AX CALL racecallatomic<>(SB) RET -TEXT sync∕atomic·CompareAndSwapInt64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·CompareAndSwapInt64(SB), NOSPLIT, $0-25 + GO_ARGS MOVQ $__tsan_go_atomic64_compare_exchange(SB), AX CALL racecallatomic<>(SB) RET -TEXT sync∕atomic·CompareAndSwapUint32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·CompareAndSwapUint32(SB), NOSPLIT, $0-17 + GO_ARGS JMP sync∕atomic·CompareAndSwapInt32(SB) -TEXT sync∕atomic·CompareAndSwapUint64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·CompareAndSwapUint64(SB), NOSPLIT, $0-25 + GO_ARGS JMP sync∕atomic·CompareAndSwapInt64(SB) -TEXT sync∕atomic·CompareAndSwapUintptr(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·CompareAndSwapUintptr(SB), NOSPLIT, $0-25 + GO_ARGS JMP sync∕atomic·CompareAndSwapInt64(SB) // Generic atomic operation implementation. @@ -331,8 +363,10 @@ racecallatomic_data: JAE racecallatomic_ignore racecallatomic_ok: // Addr is within the good range, call the atomic function. +#ifndef GOEXPERIMENT_REGABI get_tls(R12) MOVQ g(R12), R14 +#endif MOVQ g_racectx(R14), RARG0 // goroutine context MOVQ 8(SP), RARG1 // caller pc MOVQ (SP), RARG2 // pc @@ -344,8 +378,10 @@ racecallatomic_ignore: // An attempt to synchronize on the address would cause crash. MOVQ AX, R15 // remember the original function MOVQ $__tsan_go_ignore_sync_begin(SB), AX +#ifndef GOEXPERIMENT_REGABI get_tls(R12) MOVQ g(R12), R14 +#endif MOVQ g_racectx(R14), RARG0 // goroutine context CALL racecall<>(SB) MOVQ R15, AX // restore the original function @@ -373,8 +409,10 @@ TEXT runtime·racecall(SB), NOSPLIT, $0-0 // Switches SP to g0 stack and calls (AX). Arguments already set. TEXT racecall<>(SB), NOSPLIT, $0-0 +#ifndef GOEXPERIMENT_REGABI get_tls(R12) MOVQ g(R12), R14 +#endif MOVQ g_m(R14), R13 // Switch to g0 stack. MOVQ SP, R12 // callee-saved, preserved across the CALL @@ -386,6 +424,9 @@ call: ANDQ $~15, SP // alignment for gcc ABI CALL AX MOVQ R12, SP + // Back to Go world, set special registers. + // The g register (R14) is preserved in C. + XORPS X15, X15 RET // C->Go callback thunk that allows to call runtime·racesymbolize from C code. @@ -393,7 +434,9 @@ call: // The overall effect of Go->C->Go call chain is similar to that of mcall. // RARG0 contains command code. RARG1 contains command-specific context. // See racecallback for command codes. -TEXT runtime·racecallbackthunk(SB), NOSPLIT, $56-8 +// Defined as ABIInternal so as to avoid introducing a wrapper, +// because its address is passed to C via funcPC. +TEXT runtime·racecallbackthunk<ABIInternal>(SB), NOSPLIT, $56-8 // Handle command raceGetProcCmd (0) here. // First, code below assumes that we are on curg, while raceGetProcCmd // can be executed on g0. Second, it is called frequently, so will @@ -421,12 +464,13 @@ rest: PUSHQ R15 // Set g = g0. get_tls(R12) - MOVQ g(R12), R13 - MOVQ g_m(R13), R14 - MOVQ m_g0(R14), R15 + MOVQ g(R12), R14 + MOVQ g_m(R14), R13 + MOVQ m_g0(R13), R15 CMPQ R13, R15 JEQ noswitch // branch if already on g0 MOVQ R15, g(R12) // g = m->g0 + MOVQ R15, R14 // set g register PUSHQ RARG1 // func arg PUSHQ RARG0 // func arg CALL runtime·racecallback(SB) diff --git a/src/runtime/race_arm64.s b/src/runtime/race_arm64.s index 6bc389f69f..8aa17742b8 100644 --- a/src/runtime/race_arm64.s +++ b/src/runtime/race_arm64.s @@ -200,86 +200,86 @@ TEXT runtime·racefuncexit(SB), NOSPLIT, $0-0 // R0, R1, R2 set in racecallatomic // Load -TEXT sync∕atomic·LoadInt32(SB), NOSPLIT, $0 +TEXT sync∕atomic·LoadInt32(SB), NOSPLIT, $0-12 GO_ARGS MOVD $__tsan_go_atomic32_load(SB), R9 BL racecallatomic<>(SB) RET -TEXT sync∕atomic·LoadInt64(SB), NOSPLIT, $0 +TEXT sync∕atomic·LoadInt64(SB), NOSPLIT, $0-16 GO_ARGS MOVD $__tsan_go_atomic64_load(SB), R9 BL racecallatomic<>(SB) RET -TEXT sync∕atomic·LoadUint32(SB), NOSPLIT, $0 +TEXT sync∕atomic·LoadUint32(SB), NOSPLIT, $0-12 GO_ARGS JMP sync∕atomic·LoadInt32(SB) -TEXT sync∕atomic·LoadUint64(SB), NOSPLIT, $0 +TEXT sync∕atomic·LoadUint64(SB), NOSPLIT, $0-16 GO_ARGS JMP sync∕atomic·LoadInt64(SB) -TEXT sync∕atomic·LoadUintptr(SB), NOSPLIT, $0 +TEXT sync∕atomic·LoadUintptr(SB), NOSPLIT, $0-16 GO_ARGS JMP sync∕atomic·LoadInt64(SB) -TEXT sync∕atomic·LoadPointer(SB), NOSPLIT, $0 +TEXT sync∕atomic·LoadPointer(SB), NOSPLIT, $0-16 GO_ARGS JMP sync∕atomic·LoadInt64(SB) // Store -TEXT sync∕atomic·StoreInt32(SB), NOSPLIT, $0 +TEXT sync∕atomic·StoreInt32(SB), NOSPLIT, $0-12 GO_ARGS MOVD $__tsan_go_atomic32_store(SB), R9 BL racecallatomic<>(SB) RET -TEXT sync∕atomic·StoreInt64(SB), NOSPLIT, $0 +TEXT sync∕atomic·StoreInt64(SB), NOSPLIT, $0-16 GO_ARGS MOVD $__tsan_go_atomic64_store(SB), R9 BL racecallatomic<>(SB) RET -TEXT sync∕atomic·StoreUint32(SB), NOSPLIT, $0 +TEXT sync∕atomic·StoreUint32(SB), NOSPLIT, $0-12 GO_ARGS JMP sync∕atomic·StoreInt32(SB) -TEXT sync∕atomic·StoreUint64(SB), NOSPLIT, $0 +TEXT sync∕atomic·StoreUint64(SB), NOSPLIT, $0-16 GO_ARGS JMP sync∕atomic·StoreInt64(SB) -TEXT sync∕atomic·StoreUintptr(SB), NOSPLIT, $0 +TEXT sync∕atomic·StoreUintptr(SB), NOSPLIT, $0-16 GO_ARGS JMP sync∕atomic·StoreInt64(SB) // Swap -TEXT sync∕atomic·SwapInt32(SB), NOSPLIT, $0 +TEXT sync∕atomic·SwapInt32(SB), NOSPLIT, $0-20 GO_ARGS MOVD $__tsan_go_atomic32_exchange(SB), R9 BL racecallatomic<>(SB) RET -TEXT sync∕atomic·SwapInt64(SB), NOSPLIT, $0 +TEXT sync∕atomic·SwapInt64(SB), NOSPLIT, $0-24 GO_ARGS MOVD $__tsan_go_atomic64_exchange(SB), R9 BL racecallatomic<>(SB) RET -TEXT sync∕atomic·SwapUint32(SB), NOSPLIT, $0 +TEXT sync∕atomic·SwapUint32(SB), NOSPLIT, $0-20 GO_ARGS JMP sync∕atomic·SwapInt32(SB) -TEXT sync∕atomic·SwapUint64(SB), NOSPLIT, $0 +TEXT sync∕atomic·SwapUint64(SB), NOSPLIT, $0-24 GO_ARGS JMP sync∕atomic·SwapInt64(SB) -TEXT sync∕atomic·SwapUintptr(SB), NOSPLIT, $0 +TEXT sync∕atomic·SwapUintptr(SB), NOSPLIT, $0-24 GO_ARGS JMP sync∕atomic·SwapInt64(SB) // Add -TEXT sync∕atomic·AddInt32(SB), NOSPLIT, $0 +TEXT sync∕atomic·AddInt32(SB), NOSPLIT, $0-20 GO_ARGS MOVD $__tsan_go_atomic32_fetch_add(SB), R9 BL racecallatomic<>(SB) @@ -289,7 +289,7 @@ TEXT sync∕atomic·AddInt32(SB), NOSPLIT, $0 MOVW R0, ret+16(FP) RET -TEXT sync∕atomic·AddInt64(SB), NOSPLIT, $0 +TEXT sync∕atomic·AddInt64(SB), NOSPLIT, $0-24 GO_ARGS MOVD $__tsan_go_atomic64_fetch_add(SB), R9 BL racecallatomic<>(SB) @@ -299,40 +299,40 @@ TEXT sync∕atomic·AddInt64(SB), NOSPLIT, $0 MOVD R0, ret+16(FP) RET -TEXT sync∕atomic·AddUint32(SB), NOSPLIT, $0 +TEXT sync∕atomic·AddUint32(SB), NOSPLIT, $0-20 GO_ARGS JMP sync∕atomic·AddInt32(SB) -TEXT sync∕atomic·AddUint64(SB), NOSPLIT, $0 +TEXT sync∕atomic·AddUint64(SB), NOSPLIT, $0-24 GO_ARGS JMP sync∕atomic·AddInt64(SB) -TEXT sync∕atomic·AddUintptr(SB), NOSPLIT, $0 +TEXT sync∕atomic·AddUintptr(SB), NOSPLIT, $0-24 GO_ARGS JMP sync∕atomic·AddInt64(SB) // CompareAndSwap -TEXT sync∕atomic·CompareAndSwapInt32(SB), NOSPLIT, $0 +TEXT sync∕atomic·CompareAndSwapInt32(SB), NOSPLIT, $0-17 GO_ARGS MOVD $__tsan_go_atomic32_compare_exchange(SB), R9 BL racecallatomic<>(SB) RET -TEXT sync∕atomic·CompareAndSwapInt64(SB), NOSPLIT, $0 +TEXT sync∕atomic·CompareAndSwapInt64(SB), NOSPLIT, $0-25 GO_ARGS MOVD $__tsan_go_atomic64_compare_exchange(SB), R9 BL racecallatomic<>(SB) RET -TEXT sync∕atomic·CompareAndSwapUint32(SB), NOSPLIT, $0 +TEXT sync∕atomic·CompareAndSwapUint32(SB), NOSPLIT, $0-17 GO_ARGS JMP sync∕atomic·CompareAndSwapInt32(SB) -TEXT sync∕atomic·CompareAndSwapUint64(SB), NOSPLIT, $0 +TEXT sync∕atomic·CompareAndSwapUint64(SB), NOSPLIT, $0-25 GO_ARGS JMP sync∕atomic·CompareAndSwapInt64(SB) -TEXT sync∕atomic·CompareAndSwapUintptr(SB), NOSPLIT, $0 +TEXT sync∕atomic·CompareAndSwapUintptr(SB), NOSPLIT, $0-25 GO_ARGS JMP sync∕atomic·CompareAndSwapInt64(SB) diff --git a/src/runtime/race_ppc64le.s b/src/runtime/race_ppc64le.s index 7421d539ca..8961254ea6 100644 --- a/src/runtime/race_ppc64le.s +++ b/src/runtime/race_ppc64le.s @@ -207,78 +207,95 @@ TEXT runtime·racefuncexit(SB), NOSPLIT, $0-0 // R3, R4, R5 set in racecallatomic // Load atomic in tsan -TEXT sync∕atomic·LoadInt32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·LoadInt32(SB), NOSPLIT, $0-12 + GO_ARGS // void __tsan_go_atomic32_load(ThreadState *thr, uptr cpc, uptr pc, u8 *a); MOVD $__tsan_go_atomic32_load(SB), R8 ADD $32, R1, R6 // addr of caller's 1st arg BR racecallatomic<>(SB) RET -TEXT sync∕atomic·LoadInt64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·LoadInt64(SB), NOSPLIT, $0-16 + GO_ARGS // void __tsan_go_atomic64_load(ThreadState *thr, uptr cpc, uptr pc, u8 *a); MOVD $__tsan_go_atomic64_load(SB), R8 ADD $32, R1, R6 // addr of caller's 1st arg BR racecallatomic<>(SB) RET -TEXT sync∕atomic·LoadUint32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·LoadUint32(SB), NOSPLIT, $0-12 + GO_ARGS BR sync∕atomic·LoadInt32(SB) -TEXT sync∕atomic·LoadUint64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·LoadUint64(SB), NOSPLIT, $0-16 + GO_ARGS BR sync∕atomic·LoadInt64(SB) -TEXT sync∕atomic·LoadUintptr(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·LoadUintptr(SB), NOSPLIT, $0-16 + GO_ARGS BR sync∕atomic·LoadInt64(SB) -TEXT sync∕atomic·LoadPointer(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·LoadPointer(SB), NOSPLIT, $0-16 + GO_ARGS BR sync∕atomic·LoadInt64(SB) // Store atomic in tsan -TEXT sync∕atomic·StoreInt32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·StoreInt32(SB), NOSPLIT, $0-12 + GO_ARGS // void __tsan_go_atomic32_store(ThreadState *thr, uptr cpc, uptr pc, u8 *a); MOVD $__tsan_go_atomic32_store(SB), R8 ADD $32, R1, R6 // addr of caller's 1st arg BR racecallatomic<>(SB) -TEXT sync∕atomic·StoreInt64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·StoreInt64(SB), NOSPLIT, $0-16 + GO_ARGS // void __tsan_go_atomic64_store(ThreadState *thr, uptr cpc, uptr pc, u8 *a); MOVD $__tsan_go_atomic64_store(SB), R8 ADD $32, R1, R6 // addr of caller's 1st arg BR racecallatomic<>(SB) -TEXT sync∕atomic·StoreUint32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·StoreUint32(SB), NOSPLIT, $0-12 + GO_ARGS BR sync∕atomic·StoreInt32(SB) -TEXT sync∕atomic·StoreUint64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·StoreUint64(SB), NOSPLIT, $0-16 + GO_ARGS BR sync∕atomic·StoreInt64(SB) -TEXT sync∕atomic·StoreUintptr(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·StoreUintptr(SB), NOSPLIT, $0-16 + GO_ARGS BR sync∕atomic·StoreInt64(SB) // Swap in tsan -TEXT sync∕atomic·SwapInt32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·SwapInt32(SB), NOSPLIT, $0-20 + GO_ARGS // void __tsan_go_atomic32_exchange(ThreadState *thr, uptr cpc, uptr pc, u8 *a); MOVD $__tsan_go_atomic32_exchange(SB), R8 ADD $32, R1, R6 // addr of caller's 1st arg BR racecallatomic<>(SB) -TEXT sync∕atomic·SwapInt64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·SwapInt64(SB), NOSPLIT, $0-24 + GO_ARGS // void __tsan_go_atomic64_exchange(ThreadState *thr, uptr cpc, uptr pc, u8 *a) MOVD $__tsan_go_atomic64_exchange(SB), R8 ADD $32, R1, R6 // addr of caller's 1st arg BR racecallatomic<>(SB) -TEXT sync∕atomic·SwapUint32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·SwapUint32(SB), NOSPLIT, $0-20 + GO_ARGS BR sync∕atomic·SwapInt32(SB) -TEXT sync∕atomic·SwapUint64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·SwapUint64(SB), NOSPLIT, $0-24 + GO_ARGS BR sync∕atomic·SwapInt64(SB) -TEXT sync∕atomic·SwapUintptr(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·SwapUintptr(SB), NOSPLIT, $0-24 + GO_ARGS BR sync∕atomic·SwapInt64(SB) // Add atomic in tsan -TEXT sync∕atomic·AddInt32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·AddInt32(SB), NOSPLIT, $0-20 + GO_ARGS // void __tsan_go_atomic32_fetch_add(ThreadState *thr, uptr cpc, uptr pc, u8 *a); MOVD $__tsan_go_atomic32_fetch_add(SB), R8 ADD $64, R1, R6 // addr of caller's 1st arg @@ -291,7 +308,8 @@ TEXT sync∕atomic·AddInt32(SB), NOSPLIT, $0-0 MOVW R3, ret+16(FP) RET -TEXT sync∕atomic·AddInt64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·AddInt64(SB), NOSPLIT, $0-24 + GO_ARGS // void __tsan_go_atomic64_fetch_add(ThreadState *thr, uptr cpc, uptr pc, u8 *a); MOVD $__tsan_go_atomic64_fetch_add(SB), R8 ADD $64, R1, R6 // addr of caller's 1st arg @@ -304,37 +322,45 @@ TEXT sync∕atomic·AddInt64(SB), NOSPLIT, $0-0 MOVD R3, ret+16(FP) RET -TEXT sync∕atomic·AddUint32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·AddUint32(SB), NOSPLIT, $0-20 + GO_ARGS BR sync∕atomic·AddInt32(SB) -TEXT sync∕atomic·AddUint64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·AddUint64(SB), NOSPLIT, $0-24 + GO_ARGS BR sync∕atomic·AddInt64(SB) -TEXT sync∕atomic·AddUintptr(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·AddUintptr(SB), NOSPLIT, $0-24 + GO_ARGS BR sync∕atomic·AddInt64(SB) // CompareAndSwap in tsan -TEXT sync∕atomic·CompareAndSwapInt32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·CompareAndSwapInt32(SB), NOSPLIT, $0-17 + GO_ARGS // void __tsan_go_atomic32_compare_exchange( // ThreadState *thr, uptr cpc, uptr pc, u8 *a) MOVD $__tsan_go_atomic32_compare_exchange(SB), R8 ADD $32, R1, R6 // addr of caller's 1st arg BR racecallatomic<>(SB) -TEXT sync∕atomic·CompareAndSwapInt64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·CompareAndSwapInt64(SB), NOSPLIT, $0-25 + GO_ARGS // void __tsan_go_atomic32_compare_exchange( // ThreadState *thr, uptr cpc, uptr pc, u8 *a) MOVD $__tsan_go_atomic64_compare_exchange(SB), R8 ADD $32, R1, R6 // addr of caller's 1st arg BR racecallatomic<>(SB) -TEXT sync∕atomic·CompareAndSwapUint32(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·CompareAndSwapUint32(SB), NOSPLIT, $0-17 + GO_ARGS BR sync∕atomic·CompareAndSwapInt32(SB) -TEXT sync∕atomic·CompareAndSwapUint64(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·CompareAndSwapUint64(SB), NOSPLIT, $0-25 + GO_ARGS BR sync∕atomic·CompareAndSwapInt64(SB) -TEXT sync∕atomic·CompareAndSwapUintptr(SB), NOSPLIT, $0-0 +TEXT sync∕atomic·CompareAndSwapUintptr(SB), NOSPLIT, $0-25 + GO_ARGS BR sync∕atomic·CompareAndSwapInt64(SB) // Common function used to call tsan's atomic functions diff --git a/src/runtime/runtime-gdb_test.go b/src/runtime/runtime-gdb_test.go index e52bd1c4c4..5df8c3c745 100644 --- a/src/runtime/runtime-gdb_test.go +++ b/src/runtime/runtime-gdb_test.go @@ -8,7 +8,6 @@ import ( "bytes" "fmt" "internal/testenv" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -170,7 +169,7 @@ func testGdbPython(t *testing.T, cgo bool) { checkGdbVersion(t) checkGdbPython(t) - dir, err := ioutil.TempDir("", "go-build") + dir, err := os.MkdirTemp("", "go-build") if err != nil { t.Fatalf("failed to create temp directory: %v", err) } @@ -195,7 +194,7 @@ func testGdbPython(t *testing.T, cgo bool) { } } - err = ioutil.WriteFile(filepath.Join(dir, "main.go"), src, 0644) + err = os.WriteFile(filepath.Join(dir, "main.go"), src, 0644) if err != nil { t.Fatalf("failed to create file: %v", err) } @@ -404,7 +403,7 @@ func TestGdbBacktrace(t *testing.T) { t.Parallel() checkGdbVersion(t) - dir, err := ioutil.TempDir("", "go-build") + dir, err := os.MkdirTemp("", "go-build") if err != nil { t.Fatalf("failed to create temp directory: %v", err) } @@ -412,7 +411,7 @@ func TestGdbBacktrace(t *testing.T) { // Build the source code. src := filepath.Join(dir, "main.go") - err = ioutil.WriteFile(src, []byte(backtraceSource), 0644) + err = os.WriteFile(src, []byte(backtraceSource), 0644) if err != nil { t.Fatalf("failed to create file: %v", err) } @@ -482,7 +481,7 @@ func TestGdbAutotmpTypes(t *testing.T) { t.Skip("TestGdbAutotmpTypes is too slow on aix/ppc64") } - dir, err := ioutil.TempDir("", "go-build") + dir, err := os.MkdirTemp("", "go-build") if err != nil { t.Fatalf("failed to create temp directory: %v", err) } @@ -490,7 +489,7 @@ func TestGdbAutotmpTypes(t *testing.T) { // Build the source code. src := filepath.Join(dir, "main.go") - err = ioutil.WriteFile(src, []byte(autotmpTypeSource), 0644) + err = os.WriteFile(src, []byte(autotmpTypeSource), 0644) if err != nil { t.Fatalf("failed to create file: %v", err) } @@ -551,7 +550,7 @@ func TestGdbConst(t *testing.T) { t.Parallel() checkGdbVersion(t) - dir, err := ioutil.TempDir("", "go-build") + dir, err := os.MkdirTemp("", "go-build") if err != nil { t.Fatalf("failed to create temp directory: %v", err) } @@ -559,7 +558,7 @@ func TestGdbConst(t *testing.T) { // Build the source code. src := filepath.Join(dir, "main.go") - err = ioutil.WriteFile(src, []byte(constsSource), 0644) + err = os.WriteFile(src, []byte(constsSource), 0644) if err != nil { t.Fatalf("failed to create file: %v", err) } @@ -618,7 +617,7 @@ func TestGdbPanic(t *testing.T) { t.Parallel() checkGdbVersion(t) - dir, err := ioutil.TempDir("", "go-build") + dir, err := os.MkdirTemp("", "go-build") if err != nil { t.Fatalf("failed to create temp directory: %v", err) } @@ -626,7 +625,7 @@ func TestGdbPanic(t *testing.T) { // Build the source code. src := filepath.Join(dir, "main.go") - err = ioutil.WriteFile(src, []byte(panicSource), 0644) + err = os.WriteFile(src, []byte(panicSource), 0644) if err != nil { t.Fatalf("failed to create file: %v", err) } @@ -696,7 +695,7 @@ func TestGdbInfCallstack(t *testing.T) { t.Parallel() checkGdbVersion(t) - dir, err := ioutil.TempDir("", "go-build") + dir, err := os.MkdirTemp("", "go-build") if err != nil { t.Fatalf("failed to create temp directory: %v", err) } @@ -704,7 +703,7 @@ func TestGdbInfCallstack(t *testing.T) { // Build the source code. src := filepath.Join(dir, "main.go") - err = ioutil.WriteFile(src, []byte(InfCallstackSource), 0644) + err = os.WriteFile(src, []byte(InfCallstackSource), 0644) if err != nil { t.Fatalf("failed to create file: %v", err) } diff --git a/src/runtime/runtime-lldb_test.go b/src/runtime/runtime-lldb_test.go index 1e2e5d5be9..c923b872aa 100644 --- a/src/runtime/runtime-lldb_test.go +++ b/src/runtime/runtime-lldb_test.go @@ -6,7 +6,6 @@ package runtime_test import ( "internal/testenv" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -143,20 +142,20 @@ func TestLldbPython(t *testing.T) { checkLldbPython(t) - dir, err := ioutil.TempDir("", "go-build") + dir, err := os.MkdirTemp("", "go-build") if err != nil { t.Fatalf("failed to create temp directory: %v", err) } defer os.RemoveAll(dir) src := filepath.Join(dir, "main.go") - err = ioutil.WriteFile(src, []byte(lldbHelloSource), 0644) + err = os.WriteFile(src, []byte(lldbHelloSource), 0644) if err != nil { t.Fatalf("failed to create src file: %v", err) } mod := filepath.Join(dir, "go.mod") - err = ioutil.WriteFile(mod, []byte("module lldbtest"), 0644) + err = os.WriteFile(mod, []byte("module lldbtest"), 0644) if err != nil { t.Fatalf("failed to create mod file: %v", err) } @@ -172,7 +171,7 @@ func TestLldbPython(t *testing.T) { } src = filepath.Join(dir, "script.py") - err = ioutil.WriteFile(src, []byte(lldbScriptSource), 0755) + err = os.WriteFile(src, []byte(lldbScriptSource), 0755) if err != nil { t.Fatalf("failed to create script: %v", err) } diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index c9376827da..b7c7b4cff2 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -853,7 +853,7 @@ type funcinl struct { // layout of Itab known to compilers // allocated in non-garbage-collected memory // Needs to be in sync with -// ../cmd/compile/internal/gc/reflect.go:/^func.dumptabs. +// ../cmd/compile/internal/gc/reflect.go:/^func.WriteTabs. type itab struct { inter *interfacetype _type *_type @@ -1052,7 +1052,6 @@ func (w waitReason) String() string { } var ( - allglen uintptr allm *m gomaxprocs int32 ncpu int32 diff --git a/src/runtime/select.go b/src/runtime/select.go index 41e68a3746..e72761bfa9 100644 --- a/src/runtime/select.go +++ b/src/runtime/select.go @@ -415,8 +415,7 @@ bufrecv: if cas.elem != nil { raceWriteObjectPC(c.elemtype, cas.elem, casePC(casi), chanrecvpc) } - raceacquire(chanbuf(c, c.recvx)) - racerelease(chanbuf(c, c.recvx)) + racenotify(c, c.recvx, nil) } if msanenabled && cas.elem != nil { msanwrite(cas.elem, c.elemtype.size) @@ -438,8 +437,7 @@ bufrecv: bufsend: // can send to buffer if raceenabled { - raceacquire(chanbuf(c, c.sendx)) - racerelease(chanbuf(c, c.sendx)) + racenotify(c, c.sendx, nil) raceReadObjectPC(c.elemtype, cas.elem, casePC(casi), chansendpc) } if msanenabled { diff --git a/src/runtime/signal_amd64.go b/src/runtime/signal_amd64.go index 6ab1f758c2..3eeb5e044f 100644 --- a/src/runtime/signal_amd64.go +++ b/src/runtime/signal_amd64.go @@ -65,11 +65,14 @@ func (c *sigctxt) preparePanic(sig uint32, gp *g) { pc := uintptr(c.rip()) sp := uintptr(c.rsp()) + // In case we are panicking from external code, we need to initialize + // Go special registers. We inject sigpanic0 (instead of sigpanic), + // which takes care of that. if shouldPushSigpanic(gp, pc, *(*uintptr)(unsafe.Pointer(sp))) { - c.pushCall(funcPC(sigpanic), pc) + c.pushCall(funcPC(sigpanic0), pc) } else { // Not safe to push the call. Just clobber the frame. - c.set_rip(uint64(funcPC(sigpanic))) + c.set_rip(uint64(funcPC(sigpanic0))) } } diff --git a/src/runtime/signal_openbsd.go b/src/runtime/signal_openbsd.go index 99c601ce58..d2c5c5e39a 100644 --- a/src/runtime/signal_openbsd.go +++ b/src/runtime/signal_openbsd.go @@ -37,5 +37,5 @@ var sigtable = [...]sigTabT{ /* 29 */ {_SigNotify, "SIGINFO: status request from keyboard"}, /* 30 */ {_SigNotify, "SIGUSR1: user-defined signal 1"}, /* 31 */ {_SigNotify, "SIGUSR2: user-defined signal 2"}, - /* 32 */ {_SigNotify, "SIGTHR: reserved"}, + /* 32 */ {0, "SIGTHR: reserved"}, // thread AST - cannot be registered. } diff --git a/src/runtime/signal_unix.go b/src/runtime/signal_unix.go index 6aad079f03..3f70707ab4 100644 --- a/src/runtime/signal_unix.go +++ b/src/runtime/signal_unix.go @@ -336,7 +336,7 @@ func doSigPreempt(gp *g, ctxt *sigctxt) { atomic.Xadd(&gp.m.preemptGen, 1) atomic.Store(&gp.m.signalPending, 0) - if GOOS == "darwin" { + if GOOS == "darwin" || GOOS == "ios" { atomic.Xadd(&pendingPreemptSignals, -1) } } @@ -352,12 +352,12 @@ const preemptMSupported = true func preemptM(mp *m) { // On Darwin, don't try to preempt threads during exec. // Issue #41702. - if GOOS == "darwin" { + if GOOS == "darwin" || GOOS == "ios" { execLock.rlock() } if atomic.Cas(&mp.signalPending, 0, 1) { - if GOOS == "darwin" { + if GOOS == "darwin" || GOOS == "ios" { atomic.Xadd(&pendingPreemptSignals, 1) } @@ -369,7 +369,7 @@ func preemptM(mp *m) { signalM(mp, sigPreempt) } - if GOOS == "darwin" { + if GOOS == "darwin" || GOOS == "ios" { execLock.runlock() } } @@ -432,7 +432,7 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) { // no non-Go signal handler for sigPreempt. // The default behavior for sigPreempt is to ignore // the signal, so badsignal will be a no-op anyway. - if GOOS == "darwin" { + if GOOS == "darwin" || GOOS == "ios" { atomic.Xadd(&pendingPreemptSignals, -1) } return @@ -475,6 +475,14 @@ func adjustSignalStack(sig uint32, mp *m, gsigStack *gsignalStack) bool { return false } + var st stackt + sigaltstack(nil, &st) + stsp := uintptr(unsafe.Pointer(st.ss_sp)) + if st.ss_flags&_SS_DISABLE == 0 && sp >= stsp && sp < stsp+st.ss_size { + setGsignalStack(&st, gsigStack) + return true + } + if sp >= mp.g0.stack.lo && sp < mp.g0.stack.hi { // The signal was delivered on the g0 stack. // This can happen when linked with C code @@ -483,29 +491,25 @@ func adjustSignalStack(sig uint32, mp *m, gsigStack *gsignalStack) bool { // the signal handler directly when C code, // including C code called via cgo, calls a // TSAN-intercepted function such as malloc. + // + // We check this condition last as g0.stack.lo + // may be not very accurate (see mstart). st := stackt{ss_size: mp.g0.stack.hi - mp.g0.stack.lo} setSignalstackSP(&st, mp.g0.stack.lo) setGsignalStack(&st, gsigStack) return true } - var st stackt - sigaltstack(nil, &st) + // sp is not within gsignal stack, g0 stack, or sigaltstack. Bad. + setg(nil) + needm() if st.ss_flags&_SS_DISABLE != 0 { - setg(nil) - needm() noSignalStack(sig) - dropm() - } - stsp := uintptr(unsafe.Pointer(st.ss_sp)) - if sp < stsp || sp >= stsp+st.ss_size { - setg(nil) - needm() + } else { sigNotOnStack(sig) - dropm() } - setGsignalStack(&st, gsigStack) - return true + dropm() + return false } // crashing is the number of m's we have waited for when implementing @@ -1042,15 +1046,26 @@ func msigrestore(sigmask sigset) { sigprocmask(_SIG_SETMASK, &sigmask, nil) } -// sigblock blocks all signals in the current thread's signal mask. +// sigsetAllExiting is used by sigblock(true) when a thread is +// exiting. sigset_all is defined in OS specific code, and per GOOS +// behavior may override this default for sigsetAllExiting: see +// osinit(). +var sigsetAllExiting = sigset_all + +// sigblock blocks signals in the current thread's signal mask. // This is used to block signals while setting up and tearing down g -// when a non-Go thread calls a Go function. -// The OS-specific code is expected to define sigset_all. +// when a non-Go thread calls a Go function. When a thread is exiting +// we use the sigsetAllExiting value, otherwise the OS specific +// definition of sigset_all is used. // This is nosplit and nowritebarrierrec because it is called by needm // which may be called on a non-Go thread with no g available. //go:nosplit //go:nowritebarrierrec -func sigblock() { +func sigblock(exiting bool) { + if exiting { + sigprocmask(_SIG_SETMASK, &sigsetAllExiting, nil) + return + } sigprocmask(_SIG_SETMASK, &sigset_all, nil) } diff --git a/src/runtime/signal_windows.go b/src/runtime/signal_windows.go index 6d98d02598..3af2e39b08 100644 --- a/src/runtime/signal_windows.go +++ b/src/runtime/signal_windows.go @@ -43,16 +43,9 @@ func initExceptionHandler() { // //go:nosplit func isAbort(r *context) bool { - switch GOARCH { - case "386", "amd64": - // In the case of an abort, the exception IP is one byte after - // the INT3 (this differs from UNIX OSes). - return isAbortPC(r.ip() - 1) - case "arm": - return isAbortPC(r.ip()) - default: - return false - } + // In the case of an abort, the exception IP is one byte after + // the INT3 (this differs from UNIX OSes). + return isAbortPC(r.ip() - 1) } // isgoexception reports whether this exception should be translated diff --git a/src/runtime/signal_windows_test.go b/src/runtime/signal_windows_test.go index f99857193c..33a9b92ee7 100644 --- a/src/runtime/signal_windows_test.go +++ b/src/runtime/signal_windows_test.go @@ -7,11 +7,11 @@ import ( "bytes" "fmt" "internal/testenv" - "io/ioutil" "os" "os/exec" "path/filepath" "runtime" + "strconv" "strings" "syscall" "testing" @@ -28,7 +28,7 @@ func TestVectoredHandlerDontCrashOnLibrary(t *testing.T) { testenv.MustHaveExecPath(t, "gcc") testprog.Lock() defer testprog.Unlock() - dir, err := ioutil.TempDir("", "go-build") + dir, err := os.MkdirTemp("", "go-build") if err != nil { t.Fatalf("failed to create temp directory: %v", err) } @@ -80,6 +80,69 @@ func sendCtrlBreak(pid int) error { return nil } +// TestCtrlHandler tests that Go can gracefully handle closing the console window. +// See https://golang.org/issues/41884. +func TestCtrlHandler(t *testing.T) { + testenv.MustHaveGoBuild(t) + t.Parallel() + + // build go program + exe := filepath.Join(t.TempDir(), "test.exe") + cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", exe, "testdata/testwinsignal/main.go") + out, err := testenv.CleanCmdEnv(cmd).CombinedOutput() + if err != nil { + t.Fatalf("failed to build go exe: %v\n%s", err, out) + } + + // run test program + cmd = exec.Command(exe) + var stderr bytes.Buffer + cmd.Stderr = &stderr + outPipe, err := cmd.StdoutPipe() + if err != nil { + t.Fatalf("Failed to create stdout pipe: %v", err) + } + outReader := bufio.NewReader(outPipe) + + // in a new command window + const _CREATE_NEW_CONSOLE = 0x00000010 + cmd.SysProcAttr = &syscall.SysProcAttr{ + CreationFlags: _CREATE_NEW_CONSOLE, + HideWindow: true, + } + if err := cmd.Start(); err != nil { + t.Fatalf("Start failed: %v", err) + } + defer func() { + cmd.Process.Kill() + cmd.Wait() + }() + + // wait for child to be ready to receive signals + if line, err := outReader.ReadString('\n'); err != nil { + t.Fatalf("could not read stdout: %v", err) + } else if strings.TrimSpace(line) != "ready" { + t.Fatalf("unexpected message: %s", line) + } + + // gracefully kill pid, this closes the command window + if err := exec.Command("taskkill.exe", "/pid", strconv.Itoa(cmd.Process.Pid)).Run(); err != nil { + t.Fatalf("failed to kill: %v", err) + } + + // check child received, handled SIGTERM + if line, err := outReader.ReadString('\n'); err != nil { + t.Fatalf("could not read stdout: %v", err) + } else if expected, got := syscall.SIGTERM.String(), strings.TrimSpace(line); expected != got { + t.Fatalf("Expected '%s' got: %s", expected, got) + } + + // check child exited gracefully, did not timeout + if err := cmd.Wait(); err != nil { + t.Fatalf("Program exited with error: %v\n%s", err, &stderr) + } +} + // TestLibraryCtrlHandler tests that Go DLL allows calling program to handle console control events. // See https://golang.org/issues/35965. func TestLibraryCtrlHandler(t *testing.T) { @@ -93,7 +156,7 @@ func TestLibraryCtrlHandler(t *testing.T) { testenv.MustHaveExecPath(t, "gcc") testprog.Lock() defer testprog.Unlock() - dir, err := ioutil.TempDir("", "go-build") + dir, err := os.MkdirTemp("", "go-build") if err != nil { t.Fatalf("failed to create temp directory: %v", err) } diff --git a/src/runtime/sigqueue.go b/src/runtime/sigqueue.go index 0605f5da80..28b9e26d0f 100644 --- a/src/runtime/sigqueue.go +++ b/src/runtime/sigqueue.go @@ -12,12 +12,16 @@ // sigsend is called by the signal handler to queue a new signal. // signal_recv is called by the Go program to receive a newly queued signal. // Synchronization between sigsend and signal_recv is based on the sig.state -// variable. It can be in 3 states: sigIdle, sigReceiving and sigSending. +// variable. It can be in 4 states: sigIdle, sigReceiving, sigSending and sigFixup. // sigReceiving means that signal_recv is blocked on sig.Note and there are no // new pending signals. // sigSending means that sig.mask *may* contain new pending signals, // signal_recv can't be blocked in this state. // sigIdle means that there are no new pending signals and signal_recv is not blocked. +// sigFixup is a transient state that can only exist as a short +// transition from sigReceiving and then on to sigIdle: it is +// used to ensure the AllThreadsSyscall()'s mDoFixup() operation +// occurs on the sleeping m, waiting to receive a signal. // Transitions between states are done atomically with CAS. // When signal_recv is unblocked, it resets sig.Note and rechecks sig.mask. // If several sigsends and signal_recv execute concurrently, it can lead to @@ -59,6 +63,7 @@ const ( sigIdle = iota sigReceiving sigSending + sigFixup ) // sigsend delivers a signal from sighandler to the internal signal delivery queue. @@ -112,6 +117,9 @@ Send: notewakeup(&sig.note) break Send } + case sigFixup: + // nothing to do - we need to wait for sigIdle. + osyield() } } @@ -119,6 +127,19 @@ Send: return true } +// sigRecvPrepareForFixup is used to temporarily wake up the +// signal_recv() running thread while it is blocked waiting for the +// arrival of a signal. If it causes the thread to wake up, the +// sig.state travels through this sequence: sigReceiving -> sigFixup +// -> sigIdle -> sigReceiving and resumes. (This is only called while +// GC is disabled.) +//go:nosplit +func sigRecvPrepareForFixup() { + if atomic.Cas(&sig.state, sigReceiving, sigFixup) { + notewakeup(&sig.note) + } +} + // Called to receive the next queued signal. // Must only be called from a single goroutine at a time. //go:linkname signal_recv os/signal.signal_recv @@ -146,7 +167,16 @@ func signal_recv() uint32 { } notetsleepg(&sig.note, -1) noteclear(&sig.note) - break Receive + if !atomic.Cas(&sig.state, sigFixup, sigIdle) { + break Receive + } + // Getting here, the code will + // loop around again to sleep + // in state sigReceiving. This + // path is taken when + // sigRecvPrepareForFixup() + // has been called by another + // thread. } case sigSending: if atomic.Cas(&sig.state, sigSending, sigIdle) { diff --git a/src/runtime/sigqueue_plan9.go b/src/runtime/sigqueue_plan9.go index d5fe8f8b35..aebd2060e7 100644 --- a/src/runtime/sigqueue_plan9.go +++ b/src/runtime/sigqueue_plan9.go @@ -92,6 +92,13 @@ func sendNote(s *byte) bool { return true } +// sigRecvPrepareForFixup is a no-op on plan9. (This would only be +// called while GC is disabled.) +// +//go:nosplit +func sigRecvPrepareForFixup() { +} + // Called to receive the next queued signal. // Must only be called from a single goroutine at a time. //go:linkname signal_recv os/signal.signal_recv diff --git a/src/runtime/stack_test.go b/src/runtime/stack_test.go index adfc65384a..43fc5cac55 100644 --- a/src/runtime/stack_test.go +++ b/src/runtime/stack_test.go @@ -17,6 +17,7 @@ import ( "sync/atomic" "testing" "time" + _ "unsafe" // for go:linkname ) // TestStackMem measures per-thread stack segment cache behavior. @@ -851,3 +852,43 @@ func deferHeapAndStack(n int) (r int) { // Pass a value to escapeMe to force it to escape. var escapeMe = func(x interface{}) {} + +// Test that when F -> G is inlined and F is excluded from stack +// traces, G still appears. +func TestTracebackInlineExcluded(t *testing.T) { + defer func() { + recover() + buf := make([]byte, 4<<10) + stk := string(buf[:Stack(buf, false)]) + + t.Log(stk) + + if not := "tracebackExcluded"; strings.Contains(stk, not) { + t.Errorf("found but did not expect %q", not) + } + if want := "tracebackNotExcluded"; !strings.Contains(stk, want) { + t.Errorf("expected %q in stack", want) + } + }() + tracebackExcluded() +} + +// tracebackExcluded should be excluded from tracebacks. There are +// various ways this could come up. Linking it to a "runtime." name is +// rather synthetic, but it's easy and reliable. See issue #42754 for +// one way this happened in real code. +// +//go:linkname tracebackExcluded runtime.tracebackExcluded +//go:noinline +func tracebackExcluded() { + // Call an inlined function that should not itself be excluded + // from tracebacks. + tracebackNotExcluded() +} + +// tracebackNotExcluded should be inlined into tracebackExcluded, but +// should not itself be excluded from the traceback. +func tracebackNotExcluded() { + var x *int + *x = 0 +} diff --git a/src/runtime/stubs.go b/src/runtime/stubs.go index d77cb4d460..c0cc95ec65 100644 --- a/src/runtime/stubs.go +++ b/src/runtime/stubs.go @@ -4,7 +4,10 @@ package runtime -import "unsafe" +import ( + "internal/abi" + "unsafe" +) // Should be a built-in for unsafe.Pointer? //go:nosplit @@ -73,7 +76,15 @@ func badsystemstack() { // *ptr is uninitialized memory (e.g., memory that's being reused // for a new allocation) and hence contains only "junk". // +// memclrNoHeapPointers ensures that if ptr is pointer-aligned, and n +// is a multiple of the pointer size, then any pointer-aligned, +// pointer-sized portion is cleared atomically. Despite the function +// name, this is necessary because this function is the underlying +// implementation of typedmemclr and memclrHasPointers. See the doc of +// memmove for more details. +// // The (CPU-specific) implementations of this function are in memclr_*.s. +// //go:noescape func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) @@ -133,6 +144,9 @@ func sync_fastrand() uint32 { return fastrand() } //go:linkname net_fastrand net.fastrand func net_fastrand() uint32 { return fastrand() } +//go:linkname os_fastrand os.fastrand +func os_fastrand() uint32 { return fastrand() } + // in internal/bytealg/equal_*.s //go:noescape func memequal(a, b unsafe.Pointer, size uintptr) bool @@ -156,7 +170,6 @@ func noescape(p unsafe.Pointer) unsafe.Pointer { // pointer-declared arguments. func cgocallback(fn, frame, ctxt uintptr) func gogo(buf *gobuf) -func gosave(buf *gobuf) //go:noescape func jmpdefer(fv *funcval, argp uintptr) @@ -164,19 +177,50 @@ func asminit() func setg(gg *g) func breakpoint() -// reflectcall calls fn with a copy of the n argument bytes pointed at by arg. -// After fn returns, reflectcall copies n-retoffset result bytes -// back into arg+retoffset before returning. If copying result bytes back, -// the caller should pass the argument frame type as argtype, so that -// call can execute appropriate write barriers during the copy. +// reflectcall calls fn with arguments described by stackArgs, stackArgsSize, +// frameSize, and regArgs. +// +// Arguments passed on the stack and space for return values passed on the stack +// must be laid out at the space pointed to by stackArgs (with total length +// stackArgsSize) according to the ABI. +// +// stackRetOffset must be some value <= stackArgsSize that indicates the +// offset within stackArgs where the return value space begins. +// +// frameSize is the total size of the argument frame at stackArgs and must +// therefore be >= stackArgsSize. It must include additional space for spilling +// register arguments for stack growth and preemption. +// +// TODO(mknyszek): Once we don't need the additional spill space, remove frameSize, +// since frameSize will be redundant with stackArgsSize. // -// Package reflect always passes a frame type. In package runtime, -// Windows callbacks are the only use of this that copies results -// back, and those cannot have pointers in their results, so runtime -// passes nil for the frame type. +// Arguments passed in registers must be laid out in regArgs according to the ABI. +// regArgs will hold any return values passed in registers after the call. +// +// reflectcall copies stack arguments from stackArgs to the goroutine stack, and +// then copies back stackArgsSize-stackRetOffset bytes back to the return space +// in stackArgs once fn has completed. It also "unspills" argument registers from +// regArgs before calling fn, and spills them back into regArgs immediately +// following the call to fn. If there are results being returned on the stack, +// the caller should pass the argument frame type as stackArgsType so that +// reflectcall can execute appropriate write barriers during the copy. +// +// reflectcall expects regArgs.ReturnIsPtr to be populated indicating which +// registers on the return path will contain Go pointers. It will then store +// these pointers in regArgs.Ptrs such that they are visible to the GC. +// +// Package reflect passes a frame type. In package runtime, there is only +// one call that copies results back, in callbackWrap in syscall_windows.go, and it +// does NOT pass a frame type, meaning there are no write barriers invoked. See that +// call site for justification. // // Package reflect accesses this symbol through a linkname. -func reflectcall(argtype *_type, fn, arg unsafe.Pointer, argsize uint32, retoffset uint32) +// +// Arguments passed through to reflectcall do not escape. The type is used +// only in a very limited callee of reflectcall, the stackArgs are copied, and +// regArgs is only used in the reflectcall frame. +//go:noescape +func reflectcall(stackArgsType *_type, fn, stackArgs unsafe.Pointer, stackArgsSize, stackRetOffset, frameSize uint32, regArgs *abi.RegArgs) func procyield(cycles uint32) @@ -346,3 +390,7 @@ func duffcopy() // Called from linker-generated .initarray; declared for go vet; do NOT call from Go. func addmoduledata() + +// Injected by the signal handler for panicking signals. On many platforms it just +// jumps to sigpanic. +func sigpanic0() diff --git a/src/runtime/stubs2.go b/src/runtime/stubs2.go index 4a1a5cc3d9..85088b3ab9 100644 --- a/src/runtime/stubs2.go +++ b/src/runtime/stubs2.go @@ -2,12 +2,13 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !aix +// +build !darwin +// +build !js +// +build !openbsd // +build !plan9 // +build !solaris // +build !windows -// +build !js -// +build !darwin -// +build !aix package runtime diff --git a/src/runtime/stubs3.go b/src/runtime/stubs3.go index 95eecc7eca..1885d32051 100644 --- a/src/runtime/stubs3.go +++ b/src/runtime/stubs3.go @@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !aix +// +build !darwin +// +build !freebsd +// +build !openbsd // +build !plan9 // +build !solaris -// +build !freebsd -// +build !darwin -// +build !aix package runtime diff --git a/src/runtime/sys_darwin.go b/src/runtime/sys_darwin.go index e4f19bbf41..4a3f2fc453 100644 --- a/src/runtime/sys_darwin.go +++ b/src/runtime/sys_darwin.go @@ -6,50 +6,6 @@ package runtime import "unsafe" -// Call fn with arg as its argument. Return what fn returns. -// fn is the raw pc value of the entry point of the desired function. -// Switches to the system stack, if not already there. -// Preserves the calling point as the location where a profiler traceback will begin. -//go:nosplit -func libcCall(fn, arg unsafe.Pointer) int32 { - // Leave caller's PC/SP/G around for traceback. - gp := getg() - var mp *m - if gp != nil { - mp = gp.m - } - if mp != nil && mp.libcallsp == 0 { - mp.libcallg.set(gp) - mp.libcallpc = getcallerpc() - // sp must be the last, because once async cpu profiler finds - // all three values to be non-zero, it will use them - mp.libcallsp = getcallersp() - } else { - // Make sure we don't reset libcallsp. This makes - // libcCall reentrant; We remember the g/pc/sp for the - // first call on an M, until that libcCall instance - // returns. Reentrance only matters for signals, as - // libc never calls back into Go. The tricky case is - // where we call libcX from an M and record g/pc/sp. - // Before that call returns, a signal arrives on the - // same M and the signal handling code calls another - // libc function. We don't want that second libcCall - // from within the handler to be recorded, and we - // don't want that call's completion to zero - // libcallsp. - // We don't need to set libcall* while we're in a sighandler - // (even if we're not currently in libc) because we block all - // signals while we're handling a signal. That includes the - // profile signal, which is the one that uses the libcall* info. - mp = nil - } - res := asmcgocall(fn, arg) - if mp != nil { - mp.libcallsp = 0 - } - return res -} - // The X versions of syscall expect the libc call to return a 64-bit result. // Otherwise (the non-X version) expects a 32-bit result. // This distinction is required because an error is indicated by returning -1, @@ -228,6 +184,13 @@ func madvise_trampoline() //go:nosplit //go:cgo_unsafe_args +func mlock(addr unsafe.Pointer, n uintptr) { + libcCall(unsafe.Pointer(funcPC(mlock_trampoline)), unsafe.Pointer(&addr)) +} +func mlock_trampoline() + +//go:nosplit +//go:cgo_unsafe_args func read(fd int32, p unsafe.Pointer, n int32) int32 { return libcCall(unsafe.Pointer(funcPC(read_trampoline)), unsafe.Pointer(&fd)) } @@ -303,9 +266,9 @@ func nanotime_trampoline() //go:nosplit //go:cgo_unsafe_args func walltime1() (int64, int32) { - var t timeval + var t timespec libcCall(unsafe.Pointer(funcPC(walltime_trampoline)), unsafe.Pointer(&t)) - return int64(t.tv_sec), 1000 * t.tv_usec + return t.tv_sec, int32(t.tv_nsec) } func walltime_trampoline() @@ -353,13 +316,20 @@ func setitimer_trampoline() //go:nosplit //go:cgo_unsafe_args -func sysctl(mib *uint32, miblen uint32, out *byte, size *uintptr, dst *byte, ndst uintptr) int32 { +func sysctl(mib *uint32, miblen uint32, oldp *byte, oldlenp *uintptr, newp *byte, newlen uintptr) int32 { return libcCall(unsafe.Pointer(funcPC(sysctl_trampoline)), unsafe.Pointer(&mib)) } func sysctl_trampoline() //go:nosplit //go:cgo_unsafe_args +func sysctlbyname(name *byte, oldp *byte, oldlenp *uintptr, newp *byte, newlen uintptr) int32 { + return libcCall(unsafe.Pointer(funcPC(sysctlbyname_trampoline)), unsafe.Pointer(&name)) +} +func sysctlbyname_trampoline() + +//go:nosplit +//go:cgo_unsafe_args func fcntl(fd, cmd, arg int32) int32 { return libcCall(unsafe.Pointer(funcPC(fcntl_trampoline)), unsafe.Pointer(&fd)) } @@ -453,7 +423,7 @@ func setNonblock(fd int32) { //go:cgo_import_dynamic libc_pthread_create pthread_create "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_pthread_self pthread_self "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_pthread_kill pthread_kill "/usr/lib/libSystem.B.dylib" -//go:cgo_import_dynamic libc_exit exit "/usr/lib/libSystem.B.dylib" +//go:cgo_import_dynamic libc_exit _exit "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_raise raise "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_open open "/usr/lib/libSystem.B.dylib" @@ -465,12 +435,13 @@ func setNonblock(fd int32) { //go:cgo_import_dynamic libc_mmap mmap "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_munmap munmap "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_madvise madvise "/usr/lib/libSystem.B.dylib" +//go:cgo_import_dynamic libc_mlock mlock "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_error __error "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_usleep usleep "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_mach_timebase_info mach_timebase_info "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_mach_absolute_time mach_absolute_time "/usr/lib/libSystem.B.dylib" -//go:cgo_import_dynamic libc_gettimeofday gettimeofday "/usr/lib/libSystem.B.dylib" +//go:cgo_import_dynamic libc_clock_gettime clock_gettime "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_sigaction sigaction "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_pthread_sigmask pthread_sigmask "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_sigaltstack sigaltstack "/usr/lib/libSystem.B.dylib" @@ -478,6 +449,7 @@ func setNonblock(fd int32) { //go:cgo_import_dynamic libc_kill kill "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_setitimer setitimer "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_sysctl sysctl "/usr/lib/libSystem.B.dylib" +//go:cgo_import_dynamic libc_sysctlbyname sysctlbyname "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_fcntl fcntl "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_kqueue kqueue "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_kevent kevent "/usr/lib/libSystem.B.dylib" diff --git a/src/runtime/sys_darwin_amd64.s b/src/runtime/sys_darwin_amd64.s index 825852d673..0fe8c7e172 100644 --- a/src/runtime/sys_darwin_amd64.s +++ b/src/runtime/sys_darwin_amd64.s @@ -5,13 +5,17 @@ // System calls and other sys.stuff for AMD64, Darwin // System calls are implemented in libSystem, this file contains // trampolines that convert from Go to C calling convention. +// The trampolines are ABIInternal as they are referenced from +// Go code with funcPC. #include "go_asm.h" #include "go_tls.h" #include "textflag.h" +#define CLOCK_REALTIME 0 + // Exit the entire program (like C exit) -TEXT runtime·exit_trampoline(SB),NOSPLIT,$0 +TEXT runtime·exit_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVL 0(DI), DI // arg 1 exit status @@ -20,7 +24,7 @@ TEXT runtime·exit_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·open_trampoline(SB),NOSPLIT,$0 +TEXT runtime·open_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVL 8(DI), SI // arg 2 flags @@ -31,7 +35,7 @@ TEXT runtime·open_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·close_trampoline(SB),NOSPLIT,$0 +TEXT runtime·close_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVL 0(DI), DI // arg 1 fd @@ -39,7 +43,7 @@ TEXT runtime·close_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·read_trampoline(SB),NOSPLIT,$0 +TEXT runtime·read_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ 8(DI), SI // arg 2 buf @@ -55,7 +59,7 @@ noerr: POPQ BP RET -TEXT runtime·write_trampoline(SB),NOSPLIT,$0 +TEXT runtime·write_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ 8(DI), SI // arg 2 buf @@ -71,7 +75,7 @@ noerr: POPQ BP RET -TEXT runtime·pipe_trampoline(SB),NOSPLIT,$0 +TEXT runtime·pipe_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP CALL libc_pipe(SB) // pointer already in DI @@ -82,7 +86,7 @@ TEXT runtime·pipe_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·setitimer_trampoline(SB),NOSPLIT,$0 +TEXT runtime·setitimer_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ 8(DI), SI // arg 2 new @@ -92,7 +96,7 @@ TEXT runtime·setitimer_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·madvise_trampoline(SB), NOSPLIT, $0 +TEXT runtime·madvise_trampoline<ABIInternal>(SB), NOSPLIT, $0 PUSHQ BP MOVQ SP, BP MOVQ 8(DI), SI // arg 2 len @@ -103,9 +107,12 @@ TEXT runtime·madvise_trampoline(SB), NOSPLIT, $0 POPQ BP RET +TEXT runtime·mlock_trampoline<ABIInternal>(SB), NOSPLIT, $0 + UNDEF // unimplemented + GLOBL timebase<>(SB),NOPTR,$(machTimebaseInfo__size) -TEXT runtime·nanotime_trampoline(SB),NOSPLIT,$0 +TEXT runtime·nanotime_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ DI, BX @@ -134,16 +141,16 @@ initialized: POPQ BP RET -TEXT runtime·walltime_trampoline(SB),NOSPLIT,$0 +TEXT runtime·walltime_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP // make a frame; keep stack aligned MOVQ SP, BP - // DI already has *timeval - XORL SI, SI // no timezone needed - CALL libc_gettimeofday(SB) + MOVQ DI, SI // arg 2 timespec + MOVL $CLOCK_REALTIME, DI // arg 1 clock_id + CALL libc_clock_gettime(SB) POPQ BP RET -TEXT runtime·sigaction_trampoline(SB),NOSPLIT,$0 +TEXT runtime·sigaction_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ 8(DI), SI // arg 2 new @@ -156,7 +163,7 @@ TEXT runtime·sigaction_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·sigprocmask_trampoline(SB),NOSPLIT,$0 +TEXT runtime·sigprocmask_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ 8(DI), SI // arg 2 new @@ -169,7 +176,7 @@ TEXT runtime·sigprocmask_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·sigaltstack_trampoline(SB),NOSPLIT,$0 +TEXT runtime·sigaltstack_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ 8(DI), SI // arg 2 old @@ -181,7 +188,7 @@ TEXT runtime·sigaltstack_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·raiseproc_trampoline(SB),NOSPLIT,$0 +TEXT runtime·raiseproc_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVL 0(DI), BX // signal @@ -207,7 +214,7 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 // This is the function registered during sigaction and is invoked when // a signal is received. It just redirects to the Go function sigtrampgo. -TEXT runtime·sigtramp(SB),NOSPLIT,$0 +TEXT runtime·sigtramp<ABIInternal>(SB),NOSPLIT,$0 // This runs on the signal stack, so we have lots of stack available. // We allocate our own stack space, because if we tell the linker // how much we're using, the NOSPLIT check fails. @@ -241,7 +248,7 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$0 // Used instead of sigtramp in programs that use cgo. // Arguments from kernel are in DI, SI, DX. -TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0 +TEXT runtime·cgoSigtramp<ABIInternal>(SB),NOSPLIT,$0 // If no traceback function, do usual sigtramp. MOVQ runtime·cgoTraceback(SB), AX TESTQ AX, AX @@ -284,12 +291,12 @@ TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0 // The first three arguments, and the fifth, are already in registers. // Set the two remaining arguments now. MOVQ runtime·cgoTraceback(SB), CX - MOVQ $runtime·sigtramp(SB), R9 + MOVQ $runtime·sigtramp<ABIInternal>(SB), R9 MOVQ _cgo_callers(SB), AX JMP AX sigtramp: - JMP runtime·sigtramp(SB) + JMP runtime·sigtramp<ABIInternal>(SB) sigtrampnog: // Signal arrived on a non-Go thread. If this is SIGPROF, get a @@ -315,7 +322,7 @@ sigtrampnog: MOVQ _cgo_callers(SB), AX JMP AX -TEXT runtime·mmap_trampoline(SB),NOSPLIT,$0 +TEXT runtime·mmap_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP // make a frame; keep stack aligned MOVQ SP, BP MOVQ DI, BX @@ -338,7 +345,7 @@ ok: POPQ BP RET -TEXT runtime·munmap_trampoline(SB),NOSPLIT,$0 +TEXT runtime·munmap_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ 8(DI), SI // arg 2 len @@ -350,7 +357,7 @@ TEXT runtime·munmap_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·usleep_trampoline(SB),NOSPLIT,$0 +TEXT runtime·usleep_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVL 0(DI), DI // arg 1 usec @@ -362,27 +369,39 @@ TEXT runtime·settls(SB),NOSPLIT,$32 // Nothing to do on Darwin, pthread already set thread-local storage up. RET -TEXT runtime·sysctl_trampoline(SB),NOSPLIT,$0 +TEXT runtime·sysctl_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVL 8(DI), SI // arg 2 miblen - MOVQ 16(DI), DX // arg 3 out - MOVQ 24(DI), CX // arg 4 size - MOVQ 32(DI), R8 // arg 5 dst - MOVQ 40(DI), R9 // arg 6 ndst + MOVQ 16(DI), DX // arg 3 oldp + MOVQ 24(DI), CX // arg 4 oldlenp + MOVQ 32(DI), R8 // arg 5 newp + MOVQ 40(DI), R9 // arg 6 newlen MOVQ 0(DI), DI // arg 1 mib CALL libc_sysctl(SB) POPQ BP RET -TEXT runtime·kqueue_trampoline(SB),NOSPLIT,$0 +TEXT runtime·sysctlbyname_trampoline<ABIInternal>(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI // arg 2 oldp + MOVQ 16(DI), DX // arg 3 oldlenp + MOVQ 24(DI), CX // arg 4 newp + MOVQ 32(DI), R8 // arg 5 newlen + MOVQ 0(DI), DI // arg 1 name + CALL libc_sysctlbyname(SB) + POPQ BP + RET + +TEXT runtime·kqueue_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP CALL libc_kqueue(SB) POPQ BP RET -TEXT runtime·kevent_trampoline(SB),NOSPLIT,$0 +TEXT runtime·kevent_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ 8(DI), SI // arg 2 keventt @@ -401,7 +420,7 @@ ok: POPQ BP RET -TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$0 +TEXT runtime·fcntl_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVL 4(DI), SI // arg 2 cmd @@ -458,7 +477,7 @@ TEXT runtime·mstart_stub(SB),NOSPLIT,$0 // A pointer to the arguments is passed in DI. // A single int32 result is returned in AX. // (For more results, make an args/results structure.) -TEXT runtime·pthread_attr_init_trampoline(SB),NOSPLIT,$0 +TEXT runtime·pthread_attr_init_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP // make frame, keep stack 16-byte aligned. MOVQ SP, BP MOVQ 0(DI), DI // arg 1 attr @@ -466,7 +485,7 @@ TEXT runtime·pthread_attr_init_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·pthread_attr_getstacksize_trampoline(SB),NOSPLIT,$0 +TEXT runtime·pthread_attr_getstacksize_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ 8(DI), SI // arg 2 size @@ -475,7 +494,7 @@ TEXT runtime·pthread_attr_getstacksize_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·pthread_attr_setdetachstate_trampoline(SB),NOSPLIT,$0 +TEXT runtime·pthread_attr_setdetachstate_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ 8(DI), SI // arg 2 state @@ -484,7 +503,7 @@ TEXT runtime·pthread_attr_setdetachstate_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·pthread_create_trampoline(SB),NOSPLIT,$0 +TEXT runtime·pthread_create_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP SUBQ $16, SP @@ -497,7 +516,7 @@ TEXT runtime·pthread_create_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·raise_trampoline(SB),NOSPLIT,$0 +TEXT runtime·raise_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVL 0(DI), DI // arg 1 signal @@ -505,7 +524,7 @@ TEXT runtime·raise_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·pthread_mutex_init_trampoline(SB),NOSPLIT,$0 +TEXT runtime·pthread_mutex_init_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ 8(DI), SI // arg 2 attr @@ -514,7 +533,7 @@ TEXT runtime·pthread_mutex_init_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·pthread_mutex_lock_trampoline(SB),NOSPLIT,$0 +TEXT runtime·pthread_mutex_lock_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ 0(DI), DI // arg 1 mutex @@ -522,7 +541,7 @@ TEXT runtime·pthread_mutex_lock_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·pthread_mutex_unlock_trampoline(SB),NOSPLIT,$0 +TEXT runtime·pthread_mutex_unlock_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ 0(DI), DI // arg 1 mutex @@ -530,7 +549,7 @@ TEXT runtime·pthread_mutex_unlock_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·pthread_cond_init_trampoline(SB),NOSPLIT,$0 +TEXT runtime·pthread_cond_init_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ 8(DI), SI // arg 2 attr @@ -539,7 +558,7 @@ TEXT runtime·pthread_cond_init_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·pthread_cond_wait_trampoline(SB),NOSPLIT,$0 +TEXT runtime·pthread_cond_wait_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ 8(DI), SI // arg 2 mutex @@ -548,7 +567,7 @@ TEXT runtime·pthread_cond_wait_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·pthread_cond_timedwait_relative_np_trampoline(SB),NOSPLIT,$0 +TEXT runtime·pthread_cond_timedwait_relative_np_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ 8(DI), SI // arg 2 mutex @@ -558,7 +577,7 @@ TEXT runtime·pthread_cond_timedwait_relative_np_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·pthread_cond_signal_trampoline(SB),NOSPLIT,$0 +TEXT runtime·pthread_cond_signal_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ 0(DI), DI // arg 1 cond @@ -566,7 +585,7 @@ TEXT runtime·pthread_cond_signal_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·pthread_self_trampoline(SB),NOSPLIT,$0 +TEXT runtime·pthread_self_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ DI, BX // BX is caller-save @@ -575,7 +594,7 @@ TEXT runtime·pthread_self_trampoline(SB),NOSPLIT,$0 POPQ BP RET -TEXT runtime·pthread_kill_trampoline(SB),NOSPLIT,$0 +TEXT runtime·pthread_kill_trampoline<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP MOVQ 8(DI), SI // arg 2 sig @@ -600,7 +619,7 @@ TEXT runtime·pthread_kill_trampoline(SB),NOSPLIT,$0 // // syscall expects a 32-bit result and tests for 32-bit -1 // to decide there was an error. -TEXT runtime·syscall(SB),NOSPLIT,$0 +TEXT runtime·syscall<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP SUBQ $16, SP @@ -650,7 +669,7 @@ ok: // // syscallX is like syscall but expects a 64-bit result // and tests for 64-bit -1 to decide there was an error. -TEXT runtime·syscallX(SB),NOSPLIT,$0 +TEXT runtime·syscallX<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP SUBQ $16, SP @@ -686,7 +705,7 @@ ok: // syscallPtr is like syscallX except that the libc function reports an // error by returning NULL and setting errno. -TEXT runtime·syscallPtr(SB),NOSPLIT,$0 +TEXT runtime·syscallPtr<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP SUBQ $16, SP @@ -739,7 +758,7 @@ ok: // // syscall6 expects a 32-bit result and tests for 32-bit -1 // to decide there was an error. -TEXT runtime·syscall6(SB),NOSPLIT,$0 +TEXT runtime·syscall6<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP SUBQ $16, SP @@ -792,7 +811,7 @@ ok: // // syscall6X is like syscall6 but expects a 64-bit result // and tests for 64-bit -1 to decide there was an error. -TEXT runtime·syscall6X(SB),NOSPLIT,$0 +TEXT runtime·syscall6X<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP SUBQ $16, SP @@ -828,7 +847,7 @@ ok: // syscallNoErr is like syscall6 but does not check for errors, and // only returns one value, for use with standard C ABI library functions. -TEXT runtime·syscallNoErr(SB),NOSPLIT,$0 +TEXT runtime·syscallNoErr<ABIInternal>(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP SUBQ $16, SP diff --git a/src/runtime/sys_darwin_arm64.s b/src/runtime/sys_darwin_arm64.s index fd713b7902..96d2ed1076 100644 --- a/src/runtime/sys_darwin_arm64.s +++ b/src/runtime/sys_darwin_arm64.s @@ -10,6 +10,8 @@ #include "go_tls.h" #include "textflag.h" +#define CLOCK_REALTIME 0 + TEXT notok<>(SB),NOSPLIT,$0 MOVD $0, R8 MOVD R8, (R8) @@ -118,6 +120,12 @@ TEXT runtime·madvise_trampoline(SB),NOSPLIT,$0 BL libc_madvise(SB) RET +TEXT runtime·mlock_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 // arg 2 len + MOVD 0(R0), R0 // arg 1 addr + BL libc_mlock(SB) + RET + TEXT runtime·setitimer_trampoline(SB),NOSPLIT,$0 MOVD 8(R0), R1 // arg 2 new MOVD 16(R0), R2 // arg 3 old @@ -126,9 +134,9 @@ TEXT runtime·setitimer_trampoline(SB),NOSPLIT,$0 RET TEXT runtime·walltime_trampoline(SB),NOSPLIT,$0 - // R0 already has *timeval - MOVD $0, R1 // no timezone needed - BL libc_gettimeofday(SB) + MOVD R0, R1 // arg 2 timespec + MOVW $CLOCK_REALTIME, R0 // arg 1 clock_id + BL libc_clock_gettime(SB) RET GLOBL timebase<>(SB),NOPTR,$(machTimebaseInfo__size) @@ -293,14 +301,24 @@ TEXT runtime·usleep_trampoline(SB),NOSPLIT,$0 TEXT runtime·sysctl_trampoline(SB),NOSPLIT,$0 MOVW 8(R0), R1 // arg 2 miblen - MOVD 16(R0), R2 // arg 3 out - MOVD 24(R0), R3 // arg 4 size - MOVD 32(R0), R4 // arg 5 dst - MOVD 40(R0), R5 // arg 6 ndst + MOVD 16(R0), R2 // arg 3 oldp + MOVD 24(R0), R3 // arg 4 oldlenp + MOVD 32(R0), R4 // arg 5 newp + MOVD 40(R0), R5 // arg 6 newlen MOVD 0(R0), R0 // arg 1 mib BL libc_sysctl(SB) RET +TEXT runtime·sysctlbyname_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 // arg 2 oldp + MOVD 16(R0), R2 // arg 3 oldlenp + MOVD 24(R0), R3 // arg 4 newp + MOVD 32(R0), R4 // arg 5 newlen + MOVD 0(R0), R0 // arg 1 name + BL libc_sysctlbyname(SB) + RET + + TEXT runtime·kqueue_trampoline(SB),NOSPLIT,$0 BL libc_kqueue(SB) RET diff --git a/src/runtime/sys_freebsd_386.s b/src/runtime/sys_freebsd_386.s index c346e719e1..97e6d9ab36 100644 --- a/src/runtime/sys_freebsd_386.s +++ b/src/runtime/sys_freebsd_386.s @@ -13,12 +13,16 @@ TEXT runtime·sys_umtx_op(SB),NOSPLIT,$-4 MOVL $454, AX INT $0x80 + JAE 2(PC) + NEGL AX MOVL AX, ret+20(FP) RET TEXT runtime·thr_new(SB),NOSPLIT,$-4 MOVL $455, AX INT $0x80 + JAE 2(PC) + NEGL AX MOVL AX, ret+8(FP) RET @@ -120,6 +124,8 @@ TEXT runtime·pipe2(SB),NOSPLIT,$12-16 MOVL flags+0(FP), BX MOVL BX, 8(SP) INT $0x80 + JAE 2(PC) + NEGL AX MOVL AX, errno+12(FP) RET diff --git a/src/runtime/sys_freebsd_amd64.s b/src/runtime/sys_freebsd_amd64.s index 010b2ec4d4..07734b0d7d 100644 --- a/src/runtime/sys_freebsd_amd64.s +++ b/src/runtime/sys_freebsd_amd64.s @@ -18,6 +18,8 @@ TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0 MOVQ ut+24(FP), R8 MOVL $454, AX SYSCALL + JCC 2(PC) + NEGQ AX MOVL AX, ret+32(FP) RET @@ -26,6 +28,8 @@ TEXT runtime·thr_new(SB),NOSPLIT,$0 MOVL size+8(FP), SI MOVL $455, AX SYSCALL + JCC 2(PC) + NEGQ AX MOVL AX, ret+16(FP) RET @@ -118,6 +122,8 @@ TEXT runtime·pipe2(SB),NOSPLIT,$0-20 MOVL flags+0(FP), SI MOVL $542, AX SYSCALL + JCC 2(PC) + NEGQ AX MOVL AX, errno+16(FP) RET diff --git a/src/runtime/sys_freebsd_arm.s b/src/runtime/sys_freebsd_arm.s index 1e12f9cfcb..b12e47c576 100644 --- a/src/runtime/sys_freebsd_arm.s +++ b/src/runtime/sys_freebsd_arm.s @@ -51,6 +51,7 @@ TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0 ADD $20, R13 // arg 5 is passed on stack MOVW $SYS__umtx_op, R7 SWI $0 + RSB.CS $0, R0 SUB $20, R13 // BCS error MOVW R0, ret+20(FP) @@ -61,6 +62,7 @@ TEXT runtime·thr_new(SB),NOSPLIT,$0 MOVW size+4(FP), R1 MOVW $SYS_thr_new, R7 SWI $0 + RSB.CS $0, R0 MOVW R0, ret+8(FP) RET @@ -144,6 +146,7 @@ TEXT runtime·pipe2(SB),NOSPLIT,$0-16 MOVW flags+0(FP), R1 MOVW $SYS_pipe2, R7 SWI $0 + RSB.CS $0, R0 MOVW R0, errno+12(FP) RET diff --git a/src/runtime/sys_freebsd_arm64.s b/src/runtime/sys_freebsd_arm64.s index 8a4f9b7fa1..1aa09e87ca 100644 --- a/src/runtime/sys_freebsd_arm64.s +++ b/src/runtime/sys_freebsd_arm64.s @@ -60,6 +60,9 @@ TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0 MOVD ut+24(FP), R4 MOVD $SYS__umtx_op, R8 SVC + BCC ok + NEG R0, R0 +ok: MOVW R0, ret+32(FP) RET @@ -69,6 +72,9 @@ TEXT runtime·thr_new(SB),NOSPLIT,$0 MOVW size+8(FP), R1 MOVD $SYS_thr_new, R8 SVC + BCC ok + NEG R0, R0 +ok: MOVW R0, ret+16(FP) RET diff --git a/src/runtime/sys_libc.go b/src/runtime/sys_libc.go new file mode 100644 index 0000000000..996c032105 --- /dev/null +++ b/src/runtime/sys_libc.go @@ -0,0 +1,53 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build darwin openbsd,amd64 openbsd,arm64 + +package runtime + +import "unsafe" + +// Call fn with arg as its argument. Return what fn returns. +// fn is the raw pc value of the entry point of the desired function. +// Switches to the system stack, if not already there. +// Preserves the calling point as the location where a profiler traceback will begin. +//go:nosplit +func libcCall(fn, arg unsafe.Pointer) int32 { + // Leave caller's PC/SP/G around for traceback. + gp := getg() + var mp *m + if gp != nil { + mp = gp.m + } + if mp != nil && mp.libcallsp == 0 { + mp.libcallg.set(gp) + mp.libcallpc = getcallerpc() + // sp must be the last, because once async cpu profiler finds + // all three values to be non-zero, it will use them + mp.libcallsp = getcallersp() + } else { + // Make sure we don't reset libcallsp. This makes + // libcCall reentrant; We remember the g/pc/sp for the + // first call on an M, until that libcCall instance + // returns. Reentrance only matters for signals, as + // libc never calls back into Go. The tricky case is + // where we call libcX from an M and record g/pc/sp. + // Before that call returns, a signal arrives on the + // same M and the signal handling code calls another + // libc function. We don't want that second libcCall + // from within the handler to be recorded, and we + // don't want that call's completion to zero + // libcallsp. + // We don't need to set libcall* while we're in a sighandler + // (even if we're not currently in libc) because we block all + // signals while we're handling a signal. That includes the + // profile signal, which is the one that uses the libcall* info. + mp = nil + } + res := asmcgocall(fn, arg) + if mp != nil { + mp.libcallsp = 0 + } + return res +} diff --git a/src/runtime/sys_linux_amd64.s b/src/runtime/sys_linux_amd64.s index 37cb8dad03..d48573c2c5 100644 --- a/src/runtime/sys_linux_amd64.s +++ b/src/runtime/sys_linux_amd64.s @@ -215,9 +215,13 @@ TEXT runtime·walltime1(SB),NOSPLIT,$16-12 MOVQ SP, R12 // Save old SP; R12 unchanged by C code. +#ifdef GOEXPERIMENT_REGABI + MOVQ g_m(R14), BX // BX unchanged by C code. +#else get_tls(CX) MOVQ g(CX), AX MOVQ g_m(AX), BX // BX unchanged by C code. +#endif // Set vdsoPC and vdsoSP for SIGPROF traceback. // Save the old values on stack and restore them on exit, @@ -232,7 +236,11 @@ TEXT runtime·walltime1(SB),NOSPLIT,$16-12 MOVQ CX, m_vdsoPC(BX) MOVQ DX, m_vdsoSP(BX) +#ifdef GOEXPERIMENT_REGABI + CMPQ R14, m_curg(BX) // Only switch if on curg. +#else CMPQ AX, m_curg(BX) // Only switch if on curg. +#endif JNE noswitch MOVQ m_g0(BX), DX @@ -275,9 +283,13 @@ TEXT runtime·nanotime1(SB),NOSPLIT,$16-8 MOVQ SP, R12 // Save old SP; R12 unchanged by C code. +#ifdef GOEXPERIMENT_REGABI + MOVQ g_m(R14), BX // BX unchanged by C code. +#else get_tls(CX) MOVQ g(CX), AX MOVQ g_m(AX), BX // BX unchanged by C code. +#endif // Set vdsoPC and vdsoSP for SIGPROF traceback. // Save the old values on stack and restore them on exit, @@ -292,7 +304,11 @@ TEXT runtime·nanotime1(SB),NOSPLIT,$16-8 MOVQ CX, m_vdsoPC(BX) MOVQ DX, m_vdsoSP(BX) +#ifdef GOEXPERIMENT_REGABI + CMPQ R14, m_curg(BX) // Only switch if on curg. +#else CMPQ AX, m_curg(BX) // Only switch if on curg. +#endif JNE noswitch MOVQ m_g0(BX), DX @@ -632,6 +648,7 @@ nog1: get_tls(CX) MOVQ R13, g_m(R9) MOVQ R9, g(CX) + MOVQ R9, R14 // set g register CALL runtime·stackcheck(SB) nog2: diff --git a/src/runtime/sys_linux_mips64x.s b/src/runtime/sys_linux_mips64x.s index afad056d06..c3e9f37694 100644 --- a/src/runtime/sys_linux_mips64x.s +++ b/src/runtime/sys_linux_mips64x.s @@ -250,6 +250,14 @@ noswitch: BEQ R25, fallback JAL (R25) + // check on vdso call return for kernel compatibility + // see https://golang.org/issues/39046 + // if we get any error make fallback permanent. + BEQ R2, R0, finish + MOVV R0, runtime·vdsoClockgettimeSym(SB) + MOVW $0, R4 // CLOCK_REALTIME + MOVV $0(R29), R5 + JMP fallback finish: MOVV 0(R29), R3 // sec @@ -311,6 +319,12 @@ noswitch: BEQ R25, fallback JAL (R25) + // see walltime1 for detail + BEQ R2, R0, finish + MOVV R0, runtime·vdsoClockgettimeSym(SB) + MOVW $1, R4 // CLOCK_MONOTONIC + MOVV $0(R29), R5 + JMP fallback finish: MOVV 0(R29), R3 // sec diff --git a/src/runtime/sys_openbsd.go b/src/runtime/sys_openbsd.go new file mode 100644 index 0000000000..fcddf4d6a5 --- /dev/null +++ b/src/runtime/sys_openbsd.go @@ -0,0 +1,60 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build openbsd,amd64 openbsd,arm64 + +package runtime + +import "unsafe" + +// The *_trampoline functions convert from the Go calling convention to the C calling convention +// and then call the underlying libc function. These are defined in sys_openbsd_$ARCH.s. + +//go:nosplit +//go:cgo_unsafe_args +func pthread_attr_init(attr *pthreadattr) int32 { + return libcCall(unsafe.Pointer(funcPC(pthread_attr_init_trampoline)), unsafe.Pointer(&attr)) +} +func pthread_attr_init_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func pthread_attr_destroy(attr *pthreadattr) int32 { + return libcCall(unsafe.Pointer(funcPC(pthread_attr_destroy_trampoline)), unsafe.Pointer(&attr)) +} +func pthread_attr_destroy_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func pthread_attr_getstacksize(attr *pthreadattr, size *uintptr) int32 { + return libcCall(unsafe.Pointer(funcPC(pthread_attr_getstacksize_trampoline)), unsafe.Pointer(&attr)) +} +func pthread_attr_getstacksize_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func pthread_attr_setdetachstate(attr *pthreadattr, state int) int32 { + return libcCall(unsafe.Pointer(funcPC(pthread_attr_setdetachstate_trampoline)), unsafe.Pointer(&attr)) +} +func pthread_attr_setdetachstate_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func pthread_create(attr *pthreadattr, start uintptr, arg unsafe.Pointer) int32 { + return libcCall(unsafe.Pointer(funcPC(pthread_create_trampoline)), unsafe.Pointer(&attr)) +} +func pthread_create_trampoline() + +// Tell the linker that the libc_* functions are to be found +// in a system library, with the libc_ prefix missing. + +//go:cgo_import_dynamic libc_pthread_attr_init pthread_attr_init "libpthread.so" +//go:cgo_import_dynamic libc_pthread_attr_destroy pthread_attr_destroy "libpthread.so" +//go:cgo_import_dynamic libc_pthread_attr_getstacksize pthread_attr_getstacksize "libpthread.so" +//go:cgo_import_dynamic libc_pthread_attr_setdetachstate pthread_attr_setdetachstate "libpthread.so" +//go:cgo_import_dynamic libc_pthread_create pthread_create "libpthread.so" +//go:cgo_import_dynamic libc_pthread_sigmask pthread_sigmask "libpthread.so" + +//go:cgo_import_dynamic _ _ "libpthread.so" +//go:cgo_import_dynamic _ _ "libc.so" diff --git a/src/runtime/sys_openbsd1.go b/src/runtime/sys_openbsd1.go new file mode 100644 index 0000000000..e2886218db --- /dev/null +++ b/src/runtime/sys_openbsd1.go @@ -0,0 +1,34 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build openbsd,amd64 openbsd,arm64 + +package runtime + +import "unsafe" + +//go:nosplit +//go:cgo_unsafe_args +func thrsleep(ident uintptr, clock_id int32, tsp *timespec, lock uintptr, abort *uint32) int32 { + return libcCall(unsafe.Pointer(funcPC(thrsleep_trampoline)), unsafe.Pointer(&ident)) +} +func thrsleep_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func thrwakeup(ident uintptr, n int32) int32 { + return libcCall(unsafe.Pointer(funcPC(thrwakeup_trampoline)), unsafe.Pointer(&ident)) +} +func thrwakeup_trampoline() + +func osyield() { + libcCall(unsafe.Pointer(funcPC(sched_yield_trampoline)), unsafe.Pointer(nil)) +} +func sched_yield_trampoline() + +//go:cgo_import_dynamic libc_thrsleep __thrsleep "libc.so" +//go:cgo_import_dynamic libc_thrwakeup __thrwakeup "libc.so" +//go:cgo_import_dynamic libc_sched_yield sched_yield "libc.so" + +//go:cgo_import_dynamic _ _ "libc.so" diff --git a/src/runtime/sys_openbsd2.go b/src/runtime/sys_openbsd2.go new file mode 100644 index 0000000000..474e7145e7 --- /dev/null +++ b/src/runtime/sys_openbsd2.go @@ -0,0 +1,250 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build openbsd,amd64 openbsd,arm64 + +package runtime + +import "unsafe" + +// This is exported via linkname to assembly in runtime/cgo. +//go:linkname exit +//go:nosplit +//go:cgo_unsafe_args +func exit(code int32) { + libcCall(unsafe.Pointer(funcPC(exit_trampoline)), unsafe.Pointer(&code)) +} +func exit_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func getthrid() (tid int32) { + libcCall(unsafe.Pointer(funcPC(getthrid_trampoline)), unsafe.Pointer(&tid)) + return +} +func getthrid_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func raiseproc(sig uint32) { + libcCall(unsafe.Pointer(funcPC(raiseproc_trampoline)), unsafe.Pointer(&sig)) +} +func raiseproc_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func thrkill(tid int32, sig int) { + libcCall(unsafe.Pointer(funcPC(thrkill_trampoline)), unsafe.Pointer(&tid)) +} +func thrkill_trampoline() + +// mmap is used to do low-level memory allocation via mmap. Don't allow stack +// splits, since this function (used by sysAlloc) is called in a lot of low-level +// parts of the runtime and callers often assume it won't acquire any locks. +// go:nosplit +func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) (unsafe.Pointer, int) { + args := struct { + addr unsafe.Pointer + n uintptr + prot, flags, fd int32 + off uint32 + ret1 unsafe.Pointer + ret2 int + }{addr, n, prot, flags, fd, off, nil, 0} + libcCall(unsafe.Pointer(funcPC(mmap_trampoline)), unsafe.Pointer(&args)) + return args.ret1, args.ret2 +} +func mmap_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func munmap(addr unsafe.Pointer, n uintptr) { + libcCall(unsafe.Pointer(funcPC(munmap_trampoline)), unsafe.Pointer(&addr)) +} +func munmap_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func madvise(addr unsafe.Pointer, n uintptr, flags int32) { + libcCall(unsafe.Pointer(funcPC(madvise_trampoline)), unsafe.Pointer(&addr)) +} +func madvise_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func open(name *byte, mode, perm int32) (ret int32) { + return libcCall(unsafe.Pointer(funcPC(open_trampoline)), unsafe.Pointer(&name)) +} +func open_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func closefd(fd int32) int32 { + return libcCall(unsafe.Pointer(funcPC(close_trampoline)), unsafe.Pointer(&fd)) +} +func close_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func read(fd int32, p unsafe.Pointer, n int32) int32 { + return libcCall(unsafe.Pointer(funcPC(read_trampoline)), unsafe.Pointer(&fd)) +} +func read_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func write1(fd uintptr, p unsafe.Pointer, n int32) int32 { + return libcCall(unsafe.Pointer(funcPC(write_trampoline)), unsafe.Pointer(&fd)) +} +func write_trampoline() + +func pipe() (r, w int32, errno int32) { + return pipe2(0) +} + +func pipe2(flags int32) (r, w int32, errno int32) { + var p [2]int32 + args := struct { + p unsafe.Pointer + flags int32 + }{noescape(unsafe.Pointer(&p)), flags} + errno = libcCall(unsafe.Pointer(funcPC(pipe2_trampoline)), unsafe.Pointer(&args)) + return p[0], p[1], errno +} +func pipe2_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func setitimer(mode int32, new, old *itimerval) { + libcCall(unsafe.Pointer(funcPC(setitimer_trampoline)), unsafe.Pointer(&mode)) +} +func setitimer_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func usleep(usec uint32) { + libcCall(unsafe.Pointer(funcPC(usleep_trampoline)), unsafe.Pointer(&usec)) +} +func usleep_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func sysctl(mib *uint32, miblen uint32, out *byte, size *uintptr, dst *byte, ndst uintptr) int32 { + return libcCall(unsafe.Pointer(funcPC(sysctl_trampoline)), unsafe.Pointer(&mib)) +} +func sysctl_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func fcntl(fd, cmd, arg int32) int32 { + return libcCall(unsafe.Pointer(funcPC(fcntl_trampoline)), unsafe.Pointer(&fd)) +} +func fcntl_trampoline() + +//go:nosplit +func nanotime1() int64 { + var ts timespec + args := struct { + clock_id int32 + tp unsafe.Pointer + }{_CLOCK_MONOTONIC, unsafe.Pointer(&ts)} + libcCall(unsafe.Pointer(funcPC(clock_gettime_trampoline)), unsafe.Pointer(&args)) + return ts.tv_sec*1e9 + int64(ts.tv_nsec) +} +func clock_gettime_trampoline() + +//go:nosplit +func walltime1() (int64, int32) { + var ts timespec + args := struct { + clock_id int32 + tp unsafe.Pointer + }{_CLOCK_REALTIME, unsafe.Pointer(&ts)} + libcCall(unsafe.Pointer(funcPC(clock_gettime_trampoline)), unsafe.Pointer(&args)) + return ts.tv_sec, int32(ts.tv_nsec) +} + +//go:nosplit +//go:cgo_unsafe_args +func kqueue() int32 { + return libcCall(unsafe.Pointer(funcPC(kqueue_trampoline)), nil) +} +func kqueue_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32 { + return libcCall(unsafe.Pointer(funcPC(kevent_trampoline)), unsafe.Pointer(&kq)) +} +func kevent_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func sigaction(sig uint32, new *sigactiont, old *sigactiont) { + libcCall(unsafe.Pointer(funcPC(sigaction_trampoline)), unsafe.Pointer(&sig)) +} +func sigaction_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func sigprocmask(how uint32, new *sigset, old *sigset) { + libcCall(unsafe.Pointer(funcPC(sigprocmask_trampoline)), unsafe.Pointer(&how)) +} +func sigprocmask_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func sigaltstack(new *stackt, old *stackt) { + libcCall(unsafe.Pointer(funcPC(sigaltstack_trampoline)), unsafe.Pointer(&new)) +} +func sigaltstack_trampoline() + +// Not used on OpenBSD, but must be defined. +func exitThread(wait *uint32) { +} + +//go:nosplit +func closeonexec(fd int32) { + fcntl(fd, _F_SETFD, _FD_CLOEXEC) +} + +//go:nosplit +func setNonblock(fd int32) { + flags := fcntl(fd, _F_GETFL, 0) + fcntl(fd, _F_SETFL, flags|_O_NONBLOCK) +} + +// Tell the linker that the libc_* functions are to be found +// in a system library, with the libc_ prefix missing. + +//go:cgo_import_dynamic libc_errno __errno "libc.so" +//go:cgo_import_dynamic libc_exit exit "libc.so" +//go:cgo_import_dynamic libc_getthrid getthrid "libc.so" +//go:cgo_import_dynamic libc_sched_yield sched_yield "libc.so" +//go:cgo_import_dynamic libc_thrkill thrkill "libc.so" + +//go:cgo_import_dynamic libc_mmap mmap "libc.so" +//go:cgo_import_dynamic libc_munmap munmap "libc.so" +//go:cgo_import_dynamic libc_madvise madvise "libc.so" + +//go:cgo_import_dynamic libc_open open "libc.so" +//go:cgo_import_dynamic libc_close close "libc.so" +//go:cgo_import_dynamic libc_read read "libc.so" +//go:cgo_import_dynamic libc_write write "libc.so" +//go:cgo_import_dynamic libc_pipe2 pipe2 "libc.so" + +//go:cgo_import_dynamic libc_clock_gettime clock_gettime "libc.so" +//go:cgo_import_dynamic libc_setitimer setitimer "libc.so" +//go:cgo_import_dynamic libc_usleep usleep "libc.so" +//go:cgo_import_dynamic libc_sysctl sysctl "libc.so" +//go:cgo_import_dynamic libc_fcntl fcntl "libc.so" +//go:cgo_import_dynamic libc_getpid getpid "libc.so" +//go:cgo_import_dynamic libc_kill kill "libc.so" +//go:cgo_import_dynamic libc_kqueue kqueue "libc.so" +//go:cgo_import_dynamic libc_kevent kevent "libc.so" + +//go:cgo_import_dynamic libc_sigaction sigaction "libc.so" +//go:cgo_import_dynamic libc_sigaltstack sigaltstack "libc.so" + +//go:cgo_import_dynamic _ _ "libc.so" diff --git a/src/runtime/sys_openbsd3.go b/src/runtime/sys_openbsd3.go new file mode 100644 index 0000000000..4d4c88e3ac --- /dev/null +++ b/src/runtime/sys_openbsd3.go @@ -0,0 +1,113 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build openbsd,amd64 openbsd,arm64 + +package runtime + +import "unsafe" + +// The X versions of syscall expect the libc call to return a 64-bit result. +// Otherwise (the non-X version) expects a 32-bit result. +// This distinction is required because an error is indicated by returning -1, +// and we need to know whether to check 32 or 64 bits of the result. +// (Some libc functions that return 32 bits put junk in the upper 32 bits of AX.) + +//go:linkname syscall_syscall syscall.syscall +//go:nosplit +//go:cgo_unsafe_args +func syscall_syscall(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) { + entersyscall() + libcCall(unsafe.Pointer(funcPC(syscall)), unsafe.Pointer(&fn)) + exitsyscall() + return +} +func syscall() + +//go:linkname syscall_syscallX syscall.syscallX +//go:nosplit +//go:cgo_unsafe_args +func syscall_syscallX(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) { + entersyscall() + libcCall(unsafe.Pointer(funcPC(syscallX)), unsafe.Pointer(&fn)) + exitsyscall() + return +} +func syscallX() + +//go:linkname syscall_syscall6 syscall.syscall6 +//go:nosplit +//go:cgo_unsafe_args +func syscall_syscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) { + entersyscall() + libcCall(unsafe.Pointer(funcPC(syscall6)), unsafe.Pointer(&fn)) + exitsyscall() + return +} +func syscall6() + +//go:linkname syscall_syscall6X syscall.syscall6X +//go:nosplit +//go:cgo_unsafe_args +func syscall_syscall6X(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) { + entersyscall() + libcCall(unsafe.Pointer(funcPC(syscall6X)), unsafe.Pointer(&fn)) + exitsyscall() + return +} +func syscall6X() + +//go:linkname syscall_syscall10 syscall.syscall10 +//go:nosplit +//go:cgo_unsafe_args +func syscall_syscall10(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 uintptr) (r1, r2, err uintptr) { + entersyscall() + libcCall(unsafe.Pointer(funcPC(syscall10)), unsafe.Pointer(&fn)) + exitsyscall() + return +} +func syscall10() + +//go:linkname syscall_syscall10X syscall.syscall10X +//go:nosplit +//go:cgo_unsafe_args +func syscall_syscall10X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 uintptr) (r1, r2, err uintptr) { + entersyscall() + libcCall(unsafe.Pointer(funcPC(syscall10X)), unsafe.Pointer(&fn)) + exitsyscall() + return +} +func syscall10X() + +//go:linkname syscall_rawSyscall syscall.rawSyscall +//go:nosplit +//go:cgo_unsafe_args +func syscall_rawSyscall(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) { + libcCall(unsafe.Pointer(funcPC(syscall)), unsafe.Pointer(&fn)) + return +} + +//go:linkname syscall_rawSyscall6 syscall.rawSyscall6 +//go:nosplit +//go:cgo_unsafe_args +func syscall_rawSyscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) { + libcCall(unsafe.Pointer(funcPC(syscall6)), unsafe.Pointer(&fn)) + return +} + +//go:linkname syscall_rawSyscall6X syscall.rawSyscall6X +//go:nosplit +//go:cgo_unsafe_args +func syscall_rawSyscall6X(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) { + libcCall(unsafe.Pointer(funcPC(syscall6X)), unsafe.Pointer(&fn)) + return +} + +//go:linkname syscall_rawSyscall10X syscall.rawSyscall10X +//go:nosplit +//go:cgo_unsafe_args +func syscall_rawSyscall10X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 uintptr) (r1, r2, err uintptr) { + libcCall(unsafe.Pointer(funcPC(syscall10X)), unsafe.Pointer(&fn)) + return +} diff --git a/src/runtime/sys_openbsd_amd64.s b/src/runtime/sys_openbsd_amd64.s index 37d70ab9aa..b3a76b57a3 100644 --- a/src/runtime/sys_openbsd_amd64.s +++ b/src/runtime/sys_openbsd_amd64.s @@ -2,8 +2,10 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // -// System calls and other sys.stuff for AMD64, OpenBSD -// /usr/src/sys/kern/syscalls.master for syscall numbers. +// System calls and other sys.stuff for AMD64, OpenBSD. +// System calls are implemented in libc/libpthread, this file +// contains trampolines that convert from Go to C calling convention. +// Some direct system call implementations currently remain. // #include "go_asm.h" @@ -12,405 +14,775 @@ #define CLOCK_MONOTONIC $3 -// int32 tfork(void *param, uintptr psize, M *mp, G *gp, void (*fn)(void)); -TEXT runtime·tfork(SB),NOSPLIT,$32 - - // Copy mp, gp and fn off parent stack for use by child. - MOVQ mm+16(FP), R8 - MOVQ gg+24(FP), R9 - MOVQ fn+32(FP), R12 +TEXT runtime·settls(SB),NOSPLIT,$0 + // Nothing to do, pthread already set thread-local storage up. + RET - MOVQ param+0(FP), DI - MOVQ psize+8(FP), SI - MOVL $8, AX // sys___tfork - SYSCALL +// mstart_stub is the first function executed on a new thread started by pthread_create. +// It just does some low-level setup and then calls mstart. +// Note: called with the C calling convention. +TEXT runtime·mstart_stub(SB),NOSPLIT,$0 + // DI points to the m. + // We are already on m's g0 stack. - // Return if tfork syscall failed. - JCC 4(PC) - NEGQ AX - MOVL AX, ret+40(FP) - RET + // Save callee-save registers. + SUBQ $48, SP + MOVQ BX, 0(SP) + MOVQ BP, 8(SP) + MOVQ R12, 16(SP) + MOVQ R13, 24(SP) + MOVQ R14, 32(SP) + MOVQ R15, 40(SP) - // In parent, return. - CMPL AX, $0 - JEQ 3(PC) - MOVL AX, ret+40(FP) - RET + // Load g and save to TLS entry. + // See cmd/link/internal/ld/sym.go:computeTLSOffset. + MOVQ m_g0(DI), DX // g + MOVQ DX, -8(FS) - // Set FS to point at m->tls. - LEAQ m_tls(R8), DI - CALL runtime·settls(SB) + // Someday the convention will be D is always cleared. + CLD - // In child, set up new stack. - get_tls(CX) - MOVQ R8, g_m(R9) - MOVQ R9, g(CX) - CALL runtime·stackcheck(SB) + CALL runtime·mstart(SB) - // Call fn - CALL R12 + // Restore callee-save registers. + MOVQ 0(SP), BX + MOVQ 8(SP), BP + MOVQ 16(SP), R12 + MOVQ 24(SP), R13 + MOVQ 32(SP), R14 + MOVQ 40(SP), R15 - // It shouldn't return. If it does, exit - MOVQ $0, DI // arg 1 - notdead - MOVL $302, AX // sys___threxit - SYSCALL - JMP -3(PC) // keep exiting + // Go is all done with this OS thread. + // Tell pthread everything is ok (we never join with this thread, so + // the value here doesn't really matter). + XORL AX, AX -TEXT runtime·osyield(SB),NOSPLIT,$0 - MOVL $298, AX // sys_sched_yield - SYSCALL + ADDQ $48, SP RET -TEXT runtime·thrsleep(SB),NOSPLIT,$0 - MOVQ ident+0(FP), DI // arg 1 - ident - MOVL clock_id+8(FP), SI // arg 2 - clock_id - MOVQ tsp+16(FP), DX // arg 3 - tp - MOVQ lock+24(FP), R10 // arg 4 - lock - MOVQ abort+32(FP), R8 // arg 5 - abort - MOVL $94, AX // sys___thrsleep - SYSCALL - MOVL AX, ret+40(FP) +TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 + MOVQ fn+0(FP), AX + MOVL sig+8(FP), DI + MOVQ info+16(FP), SI + MOVQ ctx+24(FP), DX + PUSHQ BP + MOVQ SP, BP + ANDQ $~15, SP // alignment for x86_64 ABI + CALL AX + MOVQ BP, SP + POPQ BP RET -TEXT runtime·thrwakeup(SB),NOSPLIT,$0 - MOVQ ident+0(FP), DI // arg 1 - ident - MOVL n+8(FP), SI // arg 2 - n - MOVL $301, AX // sys___thrwakeup - SYSCALL - MOVL AX, ret+16(FP) - RET +TEXT runtime·sigtramp(SB),NOSPLIT,$72 + // Save callee-saved C registers, since the caller may be a C signal handler. + MOVQ BX, bx-8(SP) + MOVQ BP, bp-16(SP) // save in case GOEXPERIMENT=noframepointer is set + MOVQ R12, r12-24(SP) + MOVQ R13, r13-32(SP) + MOVQ R14, r14-40(SP) + MOVQ R15, r15-48(SP) + // We don't save mxcsr or the x87 control word because sigtrampgo doesn't + // modify them. -// Exit the entire program (like C exit) -TEXT runtime·exit(SB),NOSPLIT,$-8 - MOVL code+0(FP), DI // arg 1 - exit status - MOVL $1, AX // sys_exit - SYSCALL - MOVL $0xf1, 0xf1 // crash + MOVQ DX, ctx-56(SP) + MOVQ SI, info-64(SP) + MOVQ DI, signum-72(SP) + CALL runtime·sigtrampgo(SB) + + MOVQ r15-48(SP), R15 + MOVQ r14-40(SP), R14 + MOVQ r13-32(SP), R13 + MOVQ r12-24(SP), R12 + MOVQ bp-16(SP), BP + MOVQ bx-8(SP), BX RET -// func exitThread(wait *uint32) -TEXT runtime·exitThread(SB),NOSPLIT,$0-8 - MOVQ wait+0(FP), DI // arg 1 - notdead - MOVL $302, AX // sys___threxit - SYSCALL - MOVL $0xf1, 0xf1 // crash - JMP 0(PC) +// +// These trampolines help convert from Go calling convention to C calling convention. +// They should be called with asmcgocall. +// A pointer to the arguments is passed in DI. +// A single int32 result is returned in AX. +// (For more results, make an args/results structure.) +TEXT runtime·pthread_attr_init_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 0(DI), DI // arg 1 - attr + CALL libc_pthread_attr_init(SB) + POPQ BP + RET -TEXT runtime·open(SB),NOSPLIT,$-8 - MOVQ name+0(FP), DI // arg 1 pathname - MOVL mode+8(FP), SI // arg 2 flags - MOVL perm+12(FP), DX // arg 3 mode - MOVL $5, AX - SYSCALL - JCC 2(PC) - MOVL $-1, AX - MOVL AX, ret+16(FP) +TEXT runtime·pthread_attr_destroy_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 0(DI), DI // arg 1 - attr + CALL libc_pthread_attr_destroy(SB) + POPQ BP RET -TEXT runtime·closefd(SB),NOSPLIT,$-8 - MOVL fd+0(FP), DI // arg 1 fd - MOVL $6, AX - SYSCALL - JCC 2(PC) - MOVL $-1, AX - MOVL AX, ret+8(FP) +TEXT runtime·pthread_attr_getstacksize_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI // arg 2 - stacksize + MOVQ 0(DI), DI // arg 1 - attr + CALL libc_pthread_attr_getstacksize(SB) + POPQ BP RET -TEXT runtime·read(SB),NOSPLIT,$-8 - MOVL fd+0(FP), DI // arg 1 fd - MOVQ p+8(FP), SI // arg 2 buf - MOVL n+16(FP), DX // arg 3 count - MOVL $3, AX - SYSCALL - JCC 2(PC) - NEGQ AX // caller expects negative errno - MOVL AX, ret+24(FP) +TEXT runtime·pthread_attr_setdetachstate_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI // arg 2 - detachstate + MOVQ 0(DI), DI // arg 1 - attr + CALL libc_pthread_attr_setdetachstate(SB) + POPQ BP RET -// func pipe() (r, w int32, errno int32) -TEXT runtime·pipe(SB),NOSPLIT,$0-12 - LEAQ r+0(FP), DI - MOVL $263, AX - SYSCALL - MOVL AX, errno+8(FP) +TEXT runtime·pthread_create_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + SUBQ $16, SP + MOVQ 0(DI), SI // arg 2 - attr + MOVQ 8(DI), DX // arg 3 - start + MOVQ 16(DI), CX // arg 4 - arg + MOVQ SP, DI // arg 1 - &thread (discarded) + CALL libc_pthread_create(SB) + MOVQ BP, SP + POPQ BP RET -// func pipe2(flags int32) (r, w int32, errno int32) -TEXT runtime·pipe2(SB),NOSPLIT,$0-20 - LEAQ r+8(FP), DI - MOVL flags+0(FP), SI - MOVL $101, AX - SYSCALL - MOVL AX, errno+16(FP) +TEXT runtime·thrkill_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVL 8(DI), SI // arg 2 - signal + MOVQ $0, DX // arg 3 - tcb + MOVL 0(DI), DI // arg 1 - tid + CALL libc_thrkill(SB) + POPQ BP RET -TEXT runtime·write1(SB),NOSPLIT,$-8 - MOVQ fd+0(FP), DI // arg 1 - fd - MOVQ p+8(FP), SI // arg 2 - buf - MOVL n+16(FP), DX // arg 3 - nbyte - MOVL $4, AX // sys_write - SYSCALL - JCC 2(PC) - NEGQ AX // caller expects negative errno - MOVL AX, ret+24(FP) +TEXT runtime·thrsleep_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVL 8(DI), SI // arg 2 - clock_id + MOVQ 16(DI), DX // arg 3 - abstime + MOVQ 24(DI), CX // arg 4 - lock + MOVQ 32(DI), R8 // arg 5 - abort + MOVQ 0(DI), DI // arg 1 - id + CALL libc_thrsleep(SB) + POPQ BP RET -TEXT runtime·usleep(SB),NOSPLIT,$16 - MOVL $0, DX - MOVL usec+0(FP), AX - MOVL $1000000, CX - DIVL CX - MOVQ AX, 0(SP) // tv_sec - MOVL $1000, AX - MULL DX - MOVQ AX, 8(SP) // tv_nsec +TEXT runtime·thrwakeup_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVL 8(DI), SI // arg 2 - count + MOVQ 0(DI), DI // arg 1 - id + CALL libc_thrwakeup(SB) + POPQ BP + RET - MOVQ SP, DI // arg 1 - rqtp - MOVQ $0, SI // arg 2 - rmtp - MOVL $91, AX // sys_nanosleep - SYSCALL +TEXT runtime·exit_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVL 0(DI), DI // arg 1 exit status + CALL libc_exit(SB) + MOVL $0xf1, 0xf1 // crash + POPQ BP RET -TEXT runtime·getthrid(SB),NOSPLIT,$0-4 - MOVL $299, AX // sys_getthrid - SYSCALL - MOVL AX, ret+0(FP) +TEXT runtime·getthrid_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ DI, BX // BX is caller-save + CALL libc_getthrid(SB) + MOVL AX, 0(BX) // return value + POPQ BP RET -TEXT runtime·thrkill(SB),NOSPLIT,$0-16 - MOVL tid+0(FP), DI // arg 1 - tid - MOVQ sig+8(FP), SI // arg 2 - signum - MOVQ $0, DX // arg 3 - tcb - MOVL $119, AX // sys_thrkill - SYSCALL +TEXT runtime·raiseproc_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVL 0(DI), BX // signal + CALL libc_getpid(SB) + MOVL AX, DI // arg 1 pid + MOVL BX, SI // arg 2 signal + CALL libc_kill(SB) + POPQ BP RET -TEXT runtime·raiseproc(SB),NOSPLIT,$16 - MOVL $20, AX // sys_getpid - SYSCALL - MOVQ AX, DI // arg 1 - pid - MOVL sig+0(FP), SI // arg 2 - signum - MOVL $122, AX // sys_kill - SYSCALL +TEXT runtime·sched_yield_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + CALL libc_sched_yield(SB) + POPQ BP RET -TEXT runtime·setitimer(SB),NOSPLIT,$-8 - MOVL mode+0(FP), DI // arg 1 - which - MOVQ new+8(FP), SI // arg 2 - itv - MOVQ old+16(FP), DX // arg 3 - oitv - MOVL $69, AX // sys_setitimer - SYSCALL +TEXT runtime·mmap_trampoline(SB),NOSPLIT,$0 + PUSHQ BP // make a frame; keep stack aligned + MOVQ SP, BP + MOVQ DI, BX + MOVQ 0(BX), DI // arg 1 addr + MOVQ 8(BX), SI // arg 2 len + MOVL 16(BX), DX // arg 3 prot + MOVL 20(BX), CX // arg 4 flags + MOVL 24(BX), R8 // arg 5 fid + MOVL 28(BX), R9 // arg 6 offset + CALL libc_mmap(SB) + XORL DX, DX + CMPQ AX, $-1 + JNE ok + CALL libc_errno(SB) + MOVLQSX (AX), DX // errno + XORQ AX, AX +ok: + MOVQ AX, 32(BX) + MOVQ DX, 40(BX) + POPQ BP RET -// func walltime1() (sec int64, nsec int32) -TEXT runtime·walltime1(SB), NOSPLIT, $32 - MOVQ $0, DI // arg 1 - clock_id - LEAQ 8(SP), SI // arg 2 - tp - MOVL $87, AX // sys_clock_gettime - SYSCALL - MOVQ 8(SP), AX // sec - MOVQ 16(SP), DX // nsec +TEXT runtime·munmap_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI // arg 2 len + MOVQ 0(DI), DI // arg 1 addr + CALL libc_munmap(SB) + TESTQ AX, AX + JEQ 2(PC) + MOVL $0xf1, 0xf1 // crash + POPQ BP + RET - // sec is in AX, nsec in DX - MOVQ AX, sec+0(FP) - MOVL DX, nsec+8(FP) +TEXT runtime·madvise_trampoline(SB), NOSPLIT, $0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI // arg 2 len + MOVL 16(DI), DX // arg 3 advice + MOVQ 0(DI), DI // arg 1 addr + CALL libc_madvise(SB) + // ignore failure - maybe pages are locked + POPQ BP RET -TEXT runtime·nanotime1(SB),NOSPLIT,$24 - MOVQ CLOCK_MONOTONIC, DI // arg 1 - clock_id - LEAQ 8(SP), SI // arg 2 - tp - MOVL $87, AX // sys_clock_gettime - SYSCALL - MOVQ 8(SP), AX // sec - MOVQ 16(SP), DX // nsec +TEXT runtime·open_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVL 8(DI), SI // arg 2 - flags + MOVL 12(DI), DX // arg 3 - mode + MOVQ 0(DI), DI // arg 1 - path + XORL AX, AX // vararg: say "no float args" + CALL libc_open(SB) + POPQ BP + RET - // sec is in AX, nsec in DX - // return nsec in AX - IMULQ $1000000000, AX - ADDQ DX, AX - MOVQ AX, ret+0(FP) +TEXT runtime·close_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVL 0(DI), DI // arg 1 - fd + CALL libc_close(SB) + POPQ BP RET -TEXT runtime·sigaction(SB),NOSPLIT,$-8 - MOVL sig+0(FP), DI // arg 1 - signum - MOVQ new+8(FP), SI // arg 2 - nsa - MOVQ old+16(FP), DX // arg 3 - osa - MOVL $46, AX - SYSCALL - JCC 2(PC) - MOVL $0xf1, 0xf1 // crash +TEXT runtime·read_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI // arg 2 - buf + MOVL 16(DI), DX // arg 3 - count + MOVL 0(DI), DI // arg 1 - fd + CALL libc_read(SB) + TESTL AX, AX + JGE noerr + CALL libc_errno(SB) + MOVL (AX), AX // errno + NEGL AX // caller expects negative errno value +noerr: + POPQ BP RET -TEXT runtime·obsdsigprocmask(SB),NOSPLIT,$0 - MOVL how+0(FP), DI // arg 1 - how - MOVL new+4(FP), SI // arg 2 - set - MOVL $48, AX // sys_sigprocmask - SYSCALL - JCC 2(PC) - MOVL $0xf1, 0xf1 // crash - MOVL AX, ret+8(FP) +TEXT runtime·write_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI // arg 2 buf + MOVL 16(DI), DX // arg 3 count + MOVL 0(DI), DI // arg 1 fd + CALL libc_write(SB) + TESTL AX, AX + JGE noerr + CALL libc_errno(SB) + MOVL (AX), AX // errno + NEGL AX // caller expects negative errno value +noerr: + POPQ BP RET -TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 - MOVQ fn+0(FP), AX - MOVL sig+8(FP), DI - MOVQ info+16(FP), SI - MOVQ ctx+24(FP), DX +TEXT runtime·pipe2_trampoline(SB),NOSPLIT,$0 PUSHQ BP MOVQ SP, BP - ANDQ $~15, SP // alignment for x86_64 ABI - CALL AX - MOVQ BP, SP + MOVL 8(DI), SI // arg 2 flags + MOVQ 0(DI), DI // arg 1 filedes + CALL libc_pipe2(SB) + TESTL AX, AX + JEQ 3(PC) + CALL libc_errno(SB) + MOVL (AX), AX // errno + NEGL AX // caller expects negative errno value POPQ BP RET -TEXT runtime·sigtramp(SB),NOSPLIT,$72 - // Save callee-saved C registers, since the caller may be a C signal handler. - MOVQ BX, bx-8(SP) - MOVQ BP, bp-16(SP) // save in case GOEXPERIMENT=noframepointer is set - MOVQ R12, r12-24(SP) - MOVQ R13, r13-32(SP) - MOVQ R14, r14-40(SP) - MOVQ R15, r15-48(SP) - // We don't save mxcsr or the x87 control word because sigtrampgo doesn't - // modify them. +TEXT runtime·setitimer_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI // arg 2 new + MOVQ 16(DI), DX // arg 3 old + MOVL 0(DI), DI // arg 1 which + CALL libc_setitimer(SB) + POPQ BP + RET - MOVQ DX, ctx-56(SP) - MOVQ SI, info-64(SP) - MOVQ DI, signum-72(SP) - CALL runtime·sigtrampgo(SB) +TEXT runtime·usleep_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVL 0(DI), DI // arg 1 usec + CALL libc_usleep(SB) + POPQ BP + RET - MOVQ r15-48(SP), R15 - MOVQ r14-40(SP), R14 - MOVQ r13-32(SP), R13 - MOVQ r12-24(SP), R12 - MOVQ bp-16(SP), BP - MOVQ bx-8(SP), BX +TEXT runtime·sysctl_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVL 8(DI), SI // arg 2 miblen + MOVQ 16(DI), DX // arg 3 out + MOVQ 24(DI), CX // arg 4 size + MOVQ 32(DI), R8 // arg 5 dst + MOVQ 40(DI), R9 // arg 6 ndst + MOVQ 0(DI), DI // arg 1 mib + CALL libc_sysctl(SB) + POPQ BP RET -TEXT runtime·mmap(SB),NOSPLIT,$0 - MOVQ addr+0(FP), DI // arg 1 - addr - MOVQ n+8(FP), SI // arg 2 - len - MOVL prot+16(FP), DX // arg 3 - prot - MOVL flags+20(FP), R10 // arg 4 - flags - MOVL fd+24(FP), R8 // arg 5 - fd - MOVL off+28(FP), R9 - SUBQ $16, SP - MOVQ R9, 8(SP) // arg 7 - offset (passed on stack) - MOVQ $0, R9 // arg 6 - pad - MOVL $197, AX - SYSCALL - JCC ok - ADDQ $16, SP - MOVQ $0, p+32(FP) - MOVQ AX, err+40(FP) +TEXT runtime·kqueue_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + CALL libc_kqueue(SB) + POPQ BP RET + +TEXT runtime·kevent_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI // arg 2 keventt + MOVL 16(DI), DX // arg 3 nch + MOVQ 24(DI), CX // arg 4 ev + MOVL 32(DI), R8 // arg 5 nev + MOVQ 40(DI), R9 // arg 6 ts + MOVL 0(DI), DI // arg 1 kq + CALL libc_kevent(SB) + CMPL AX, $-1 + JNE ok + CALL libc_errno(SB) + MOVL (AX), AX // errno + NEGL AX // caller expects negative errno value ok: - ADDQ $16, SP - MOVQ AX, p+32(FP) - MOVQ $0, err+40(FP) + POPQ BP RET -TEXT runtime·munmap(SB),NOSPLIT,$0 - MOVQ addr+0(FP), DI // arg 1 - addr - MOVQ n+8(FP), SI // arg 2 - len - MOVL $73, AX // sys_munmap - SYSCALL - JCC 2(PC) - MOVL $0xf1, 0xf1 // crash +TEXT runtime·clock_gettime_trampoline(SB),NOSPLIT,$0 + PUSHQ BP // make a frame; keep stack aligned + MOVQ SP, BP + MOVQ 8(DI), SI // arg 2 tp + MOVL 0(DI), DI // arg 1 clock_id + CALL libc_clock_gettime(SB) + TESTL AX, AX + JEQ 2(PC) + MOVL $0xf1, 0xf1 // crash + POPQ BP RET -TEXT runtime·madvise(SB),NOSPLIT,$0 - MOVQ addr+0(FP), DI // arg 1 - addr - MOVQ n+8(FP), SI // arg 2 - len - MOVL flags+16(FP), DX // arg 3 - behav - MOVQ $75, AX // sys_madvise - SYSCALL - JCC 2(PC) - MOVL $-1, AX - MOVL AX, ret+24(FP) +TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVL 4(DI), SI // arg 2 cmd + MOVL 8(DI), DX // arg 3 arg + MOVL 0(DI), DI // arg 1 fd + XORL AX, AX // vararg: say "no float args" + CALL libc_fcntl(SB) + POPQ BP RET -TEXT runtime·sigaltstack(SB),NOSPLIT,$-8 - MOVQ new+0(FP), DI // arg 1 - nss - MOVQ old+8(FP), SI // arg 2 - oss - MOVQ $288, AX // sys_sigaltstack - SYSCALL - JCC 2(PC) - MOVL $0xf1, 0xf1 // crash +TEXT runtime·sigaction_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI // arg 2 new + MOVQ 16(DI), DX // arg 3 old + MOVL 0(DI), DI // arg 1 sig + CALL libc_sigaction(SB) + TESTL AX, AX + JEQ 2(PC) + MOVL $0xf1, 0xf1 // crash + POPQ BP RET -// set tls base to DI -TEXT runtime·settls(SB),NOSPLIT,$0 - // adjust for ELF: wants to use -8(FS) for g - ADDQ $8, DI - MOVQ $329, AX // sys___settcb - SYSCALL - JCC 2(PC) - MOVL $0xf1, 0xf1 // crash +TEXT runtime·sigprocmask_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI // arg 2 new + MOVQ 16(DI), DX // arg 3 old + MOVL 0(DI), DI // arg 1 how + CALL libc_pthread_sigmask(SB) + TESTL AX, AX + JEQ 2(PC) + MOVL $0xf1, 0xf1 // crash + POPQ BP RET -TEXT runtime·sysctl(SB),NOSPLIT,$0 - MOVQ mib+0(FP), DI // arg 1 - name - MOVL miblen+8(FP), SI // arg 2 - namelen - MOVQ out+16(FP), DX // arg 3 - oldp - MOVQ size+24(FP), R10 // arg 4 - oldlenp - MOVQ dst+32(FP), R8 // arg 5 - newp - MOVQ ndst+40(FP), R9 // arg 6 - newlen - MOVQ $202, AX // sys___sysctl - SYSCALL - JCC 4(PC) - NEGQ AX - MOVL AX, ret+48(FP) +TEXT runtime·sigaltstack_trampoline(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI // arg 2 old + MOVQ 0(DI), DI // arg 1 new + CALL libc_sigaltstack(SB) + TESTQ AX, AX + JEQ 2(PC) + MOVL $0xf1, 0xf1 // crash + POPQ BP RET - MOVL $0, AX - MOVL AX, ret+48(FP) + +// syscall calls a function in libc on behalf of the syscall package. +// syscall takes a pointer to a struct like: +// struct { +// fn uintptr +// a1 uintptr +// a2 uintptr +// a3 uintptr +// r1 uintptr +// r2 uintptr +// err uintptr +// } +// syscall must be called on the g0 stack with the +// C calling convention (use libcCall). +// +// syscall expects a 32-bit result and tests for 32-bit -1 +// to decide there was an error. +TEXT runtime·syscall(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + SUBQ $16, SP + MOVQ (0*8)(DI), CX // fn + MOVQ (2*8)(DI), SI // a2 + MOVQ (3*8)(DI), DX // a3 + MOVQ DI, (SP) + MOVQ (1*8)(DI), DI // a1 + XORL AX, AX // vararg: say "no float args" + + CALL CX + + MOVQ (SP), DI + MOVQ AX, (4*8)(DI) // r1 + MOVQ DX, (5*8)(DI) // r2 + + // Standard libc functions return -1 on error + // and set errno. + CMPL AX, $-1 // Note: high 32 bits are junk + JNE ok + + // Get error code from libc. + CALL libc_errno(SB) + MOVLQSX (AX), AX + MOVQ (SP), DI + MOVQ AX, (6*8)(DI) // err + +ok: + XORL AX, AX // no error (it's ignored anyway) + MOVQ BP, SP + POPQ BP RET -// int32 runtime·kqueue(void); -TEXT runtime·kqueue(SB),NOSPLIT,$0 - MOVL $269, AX - SYSCALL - JCC 2(PC) - NEGQ AX - MOVL AX, ret+0(FP) +// syscallX calls a function in libc on behalf of the syscall package. +// syscallX takes a pointer to a struct like: +// struct { +// fn uintptr +// a1 uintptr +// a2 uintptr +// a3 uintptr +// r1 uintptr +// r2 uintptr +// err uintptr +// } +// syscallX must be called on the g0 stack with the +// C calling convention (use libcCall). +// +// syscallX is like syscall but expects a 64-bit result +// and tests for 64-bit -1 to decide there was an error. +TEXT runtime·syscallX(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + SUBQ $16, SP + MOVQ (0*8)(DI), CX // fn + MOVQ (2*8)(DI), SI // a2 + MOVQ (3*8)(DI), DX // a3 + MOVQ DI, (SP) + MOVQ (1*8)(DI), DI // a1 + XORL AX, AX // vararg: say "no float args" + + CALL CX + + MOVQ (SP), DI + MOVQ AX, (4*8)(DI) // r1 + MOVQ DX, (5*8)(DI) // r2 + + // Standard libc functions return -1 on error + // and set errno. + CMPQ AX, $-1 + JNE ok + + // Get error code from libc. + CALL libc_errno(SB) + MOVLQSX (AX), AX + MOVQ (SP), DI + MOVQ AX, (6*8)(DI) // err + +ok: + XORL AX, AX // no error (it's ignored anyway) + MOVQ BP, SP + POPQ BP + RET + +// syscall6 calls a function in libc on behalf of the syscall package. +// syscall6 takes a pointer to a struct like: +// struct { +// fn uintptr +// a1 uintptr +// a2 uintptr +// a3 uintptr +// a4 uintptr +// a5 uintptr +// a6 uintptr +// r1 uintptr +// r2 uintptr +// err uintptr +// } +// syscall6 must be called on the g0 stack with the +// C calling convention (use libcCall). +// +// syscall6 expects a 32-bit result and tests for 32-bit -1 +// to decide there was an error. +TEXT runtime·syscall6(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + SUBQ $16, SP + MOVQ (0*8)(DI), R11// fn + MOVQ (2*8)(DI), SI // a2 + MOVQ (3*8)(DI), DX // a3 + MOVQ (4*8)(DI), CX // a4 + MOVQ (5*8)(DI), R8 // a5 + MOVQ (6*8)(DI), R9 // a6 + MOVQ DI, (SP) + MOVQ (1*8)(DI), DI // a1 + XORL AX, AX // vararg: say "no float args" + + CALL R11 + + MOVQ (SP), DI + MOVQ AX, (7*8)(DI) // r1 + MOVQ DX, (8*8)(DI) // r2 + + CMPL AX, $-1 + JNE ok + + CALL libc_errno(SB) + MOVLQSX (AX), AX + MOVQ (SP), DI + MOVQ AX, (9*8)(DI) // err + +ok: + XORL AX, AX // no error (it's ignored anyway) + MOVQ BP, SP + POPQ BP RET -// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout); -TEXT runtime·kevent(SB),NOSPLIT,$0 - MOVL kq+0(FP), DI - MOVQ ch+8(FP), SI - MOVL nch+16(FP), DX - MOVQ ev+24(FP), R10 - MOVL nev+32(FP), R8 - MOVQ ts+40(FP), R9 - MOVL $72, AX - SYSCALL - JCC 2(PC) - NEGQ AX - MOVL AX, ret+48(FP) +// syscall6X calls a function in libc on behalf of the syscall package. +// syscall6X takes a pointer to a struct like: +// struct { +// fn uintptr +// a1 uintptr +// a2 uintptr +// a3 uintptr +// a4 uintptr +// a5 uintptr +// a6 uintptr +// r1 uintptr +// r2 uintptr +// err uintptr +// } +// syscall6X must be called on the g0 stack with the +// C calling convention (use libcCall). +// +// syscall6X is like syscall6 but expects a 64-bit result +// and tests for 64-bit -1 to decide there was an error. +TEXT runtime·syscall6X(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + SUBQ $16, SP + MOVQ (0*8)(DI), R11// fn + MOVQ (2*8)(DI), SI // a2 + MOVQ (3*8)(DI), DX // a3 + MOVQ (4*8)(DI), CX // a4 + MOVQ (5*8)(DI), R8 // a5 + MOVQ (6*8)(DI), R9 // a6 + MOVQ DI, (SP) + MOVQ (1*8)(DI), DI // a1 + XORL AX, AX // vararg: say "no float args" + + CALL R11 + + MOVQ (SP), DI + MOVQ AX, (7*8)(DI) // r1 + MOVQ DX, (8*8)(DI) // r2 + + CMPQ AX, $-1 + JNE ok + + CALL libc_errno(SB) + MOVLQSX (AX), AX + MOVQ (SP), DI + MOVQ AX, (9*8)(DI) // err + +ok: + XORL AX, AX // no error (it's ignored anyway) + MOVQ BP, SP + POPQ BP RET -// void runtime·closeonexec(int32 fd); -TEXT runtime·closeonexec(SB),NOSPLIT,$0 - MOVL fd+0(FP), DI // fd - MOVQ $2, SI // F_SETFD - MOVQ $1, DX // FD_CLOEXEC - MOVL $92, AX // fcntl - SYSCALL +// syscall10 calls a function in libc on behalf of the syscall package. +// syscall10 takes a pointer to a struct like: +// struct { +// fn uintptr +// a1 uintptr +// a2 uintptr +// a3 uintptr +// a4 uintptr +// a5 uintptr +// a6 uintptr +// a7 uintptr +// a8 uintptr +// a9 uintptr +// a10 uintptr +// r1 uintptr +// r2 uintptr +// err uintptr +// } +// syscall10 must be called on the g0 stack with the +// C calling convention (use libcCall). +TEXT runtime·syscall10(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + SUBQ $48, SP + + // Arguments a1 to a6 get passed in registers, with a7 onwards being + // passed via the stack per the x86-64 System V ABI + // (https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdf). + MOVQ (7*8)(DI), R10 // a7 + MOVQ (8*8)(DI), R11 // a8 + MOVQ (9*8)(DI), R12 // a9 + MOVQ (10*8)(DI), R13 // a10 + MOVQ R10, (0*8)(SP) // a7 + MOVQ R11, (1*8)(SP) // a8 + MOVQ R12, (2*8)(SP) // a9 + MOVQ R13, (3*8)(SP) // a10 + MOVQ (0*8)(DI), R11 // fn + MOVQ (2*8)(DI), SI // a2 + MOVQ (3*8)(DI), DX // a3 + MOVQ (4*8)(DI), CX // a4 + MOVQ (5*8)(DI), R8 // a5 + MOVQ (6*8)(DI), R9 // a6 + MOVQ DI, (4*8)(SP) + MOVQ (1*8)(DI), DI // a1 + XORL AX, AX // vararg: say "no float args" + + CALL R11 + + MOVQ (4*8)(SP), DI + MOVQ AX, (11*8)(DI) // r1 + MOVQ DX, (12*8)(DI) // r2 + + CMPL AX, $-1 + JNE ok + + CALL libc_errno(SB) + MOVLQSX (AX), AX + MOVQ (4*8)(SP), DI + MOVQ AX, (13*8)(DI) // err + +ok: + XORL AX, AX // no error (it's ignored anyway) + MOVQ BP, SP + POPQ BP RET -// func runtime·setNonblock(int32 fd) -TEXT runtime·setNonblock(SB),NOSPLIT,$0-4 - MOVL fd+0(FP), DI // fd - MOVQ $3, SI // F_GETFL - MOVQ $0, DX - MOVL $92, AX // fcntl - SYSCALL - MOVL fd+0(FP), DI // fd - MOVQ $4, SI // F_SETFL - MOVQ $4, DX // O_NONBLOCK - ORL AX, DX - MOVL $92, AX // fcntl - SYSCALL +// syscall10X calls a function in libc on behalf of the syscall package. +// syscall10X takes a pointer to a struct like: +// struct { +// fn uintptr +// a1 uintptr +// a2 uintptr +// a3 uintptr +// a4 uintptr +// a5 uintptr +// a6 uintptr +// a7 uintptr +// a8 uintptr +// a9 uintptr +// a10 uintptr +// r1 uintptr +// r2 uintptr +// err uintptr +// } +// syscall10X must be called on the g0 stack with the +// C calling convention (use libcCall). +// +// syscall10X is like syscall10 but expects a 64-bit result +// and tests for 64-bit -1 to decide there was an error. +TEXT runtime·syscall10X(SB),NOSPLIT,$0 + PUSHQ BP + MOVQ SP, BP + SUBQ $48, SP + + // Arguments a1 to a6 get passed in registers, with a7 onwards being + // passed via the stack per the x86-64 System V ABI + // (https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdf). + MOVQ (7*8)(DI), R10 // a7 + MOVQ (8*8)(DI), R11 // a8 + MOVQ (9*8)(DI), R12 // a9 + MOVQ (10*8)(DI), R13 // a10 + MOVQ R10, (0*8)(SP) // a7 + MOVQ R11, (1*8)(SP) // a8 + MOVQ R12, (2*8)(SP) // a9 + MOVQ R13, (3*8)(SP) // a10 + MOVQ (0*8)(DI), R11 // fn + MOVQ (2*8)(DI), SI // a2 + MOVQ (3*8)(DI), DX // a3 + MOVQ (4*8)(DI), CX // a4 + MOVQ (5*8)(DI), R8 // a5 + MOVQ (6*8)(DI), R9 // a6 + MOVQ DI, (4*8)(SP) + MOVQ (1*8)(DI), DI // a1 + XORL AX, AX // vararg: say "no float args" + + CALL R11 + + MOVQ (4*8)(SP), DI + MOVQ AX, (11*8)(DI) // r1 + MOVQ DX, (12*8)(DI) // r2 + + CMPQ AX, $-1 + JNE ok + + CALL libc_errno(SB) + MOVLQSX (AX), AX + MOVQ (4*8)(SP), DI + MOVQ AX, (13*8)(DI) // err + +ok: + XORL AX, AX // no error (it's ignored anyway) + MOVQ BP, SP + POPQ BP RET diff --git a/src/runtime/sys_openbsd_arm64.s b/src/runtime/sys_openbsd_arm64.s index 621b1b1a42..9b4acc90a5 100644 --- a/src/runtime/sys_openbsd_arm64.s +++ b/src/runtime/sys_openbsd_arm64.s @@ -3,7 +3,9 @@ // license that can be found in the LICENSE file. // // System calls and other sys.stuff for arm64, OpenBSD -// /usr/src/sys/kern/syscalls.master for syscall numbers. +// System calls are implemented in libc/libpthread, this file +// contains trampolines that convert from Go to C calling convention. +// Some direct system call implementations currently remain. // #include "go_asm.h" @@ -13,239 +15,65 @@ #define CLOCK_REALTIME $0 #define CLOCK_MONOTONIC $3 -// With OpenBSD 6.7 onwards, an arm64 syscall returns two instructions -// after the SVC instruction, to allow for a speculative execution -// barrier to be placed after the SVC without impacting performance. -// For now use hardware no-ops as this works with both older and newer -// kernels. After OpenBSD 6.8 is released this should be changed to -// speculation barriers. -#define INVOKE_SYSCALL \ - SVC; \ - NOOP; \ - NOOP +// mstart_stub is the first function executed on a new thread started by pthread_create. +// It just does some low-level setup and then calls mstart. +// Note: called with the C calling convention. +TEXT runtime·mstart_stub(SB),NOSPLIT,$160 + // R0 points to the m. + // We are already on m's g0 stack. -// Exit the entire program (like C exit) -TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0 - MOVW code+0(FP), R0 // arg 1 - status - MOVD $1, R8 // sys_exit - INVOKE_SYSCALL - BCC 3(PC) - MOVD $0, R0 // crash on syscall failure - MOVD R0, (R0) - RET - -// func exitThread(wait *uint32) -TEXT runtime·exitThread(SB),NOSPLIT,$0 - MOVD wait+0(FP), R0 // arg 1 - notdead - MOVD $302, R8 // sys___threxit - INVOKE_SYSCALL - MOVD $0, R0 // crash on syscall failure - MOVD R0, (R0) - JMP 0(PC) - -TEXT runtime·open(SB),NOSPLIT|NOFRAME,$0 - MOVD name+0(FP), R0 // arg 1 - path - MOVW mode+8(FP), R1 // arg 2 - mode - MOVW perm+12(FP), R2 // arg 3 - perm - MOVD $5, R8 // sys_open - INVOKE_SYSCALL - BCC 2(PC) - MOVW $-1, R0 - MOVW R0, ret+16(FP) - RET - -TEXT runtime·closefd(SB),NOSPLIT|NOFRAME,$0 - MOVW fd+0(FP), R0 // arg 1 - fd - MOVD $6, R8 // sys_close - INVOKE_SYSCALL - BCC 2(PC) - MOVW $-1, R0 - MOVW R0, ret+8(FP) - RET - -TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0 - MOVW fd+0(FP), R0 // arg 1 - fd - MOVD p+8(FP), R1 // arg 2 - buf - MOVW n+16(FP), R2 // arg 3 - nbyte - MOVD $3, R8 // sys_read - INVOKE_SYSCALL - BCC 2(PC) - NEG R0, R0 - MOVW R0, ret+24(FP) - RET - -// func pipe() (r, w int32, errno int32) -TEXT runtime·pipe(SB),NOSPLIT|NOFRAME,$0-12 - MOVD $r+0(FP), R0 - MOVW $0, R1 - MOVD $101, R8 // sys_pipe2 - INVOKE_SYSCALL - BCC 2(PC) - NEG R0, R0 - MOVW R0, errno+8(FP) - RET - -// func pipe2(flags int32) (r, w int32, errno int32) -TEXT runtime·pipe2(SB),NOSPLIT|NOFRAME,$0-20 - MOVD $r+8(FP), R0 - MOVW flags+0(FP), R1 - MOVD $101, R8 // sys_pipe2 - INVOKE_SYSCALL - BCC 2(PC) - NEG R0, R0 - MOVW R0, errno+16(FP) - RET - -TEXT runtime·write1(SB),NOSPLIT|NOFRAME,$0 - MOVD fd+0(FP), R0 // arg 1 - fd - MOVD p+8(FP), R1 // arg 2 - buf - MOVW n+16(FP), R2 // arg 3 - nbyte - MOVD $4, R8 // sys_write - INVOKE_SYSCALL - BCC 2(PC) - NEG R0, R0 - MOVW R0, ret+24(FP) - RET + // Save callee-save registers. + MOVD R19, 8(RSP) + MOVD R20, 16(RSP) + MOVD R21, 24(RSP) + MOVD R22, 32(RSP) + MOVD R23, 40(RSP) + MOVD R24, 48(RSP) + MOVD R25, 56(RSP) + MOVD R26, 64(RSP) + MOVD R27, 72(RSP) + MOVD g, 80(RSP) + MOVD R29, 88(RSP) + FMOVD F8, 96(RSP) + FMOVD F9, 104(RSP) + FMOVD F10, 112(RSP) + FMOVD F11, 120(RSP) + FMOVD F12, 128(RSP) + FMOVD F13, 136(RSP) + FMOVD F14, 144(RSP) + FMOVD F15, 152(RSP) -TEXT runtime·usleep(SB),NOSPLIT,$24-4 - MOVWU usec+0(FP), R3 - MOVD R3, R5 - MOVW $1000000, R4 - UDIV R4, R3 - MOVD R3, 8(RSP) // tv_sec - MUL R3, R4 - SUB R4, R5 - MOVW $1000, R4 - MUL R4, R5 - MOVD R5, 16(RSP) // tv_nsec + MOVD m_g0(R0), g + BL runtime·save_g(SB) - ADD $8, RSP, R0 // arg 1 - rqtp - MOVD $0, R1 // arg 2 - rmtp - MOVD $91, R8 // sys_nanosleep - INVOKE_SYSCALL - RET - -TEXT runtime·getthrid(SB),NOSPLIT,$0-4 - MOVD $299, R8 // sys_getthrid - INVOKE_SYSCALL - MOVW R0, ret+0(FP) - RET - -TEXT runtime·thrkill(SB),NOSPLIT,$0-16 - MOVW tid+0(FP), R0 // arg 1 - tid - MOVD sig+8(FP), R1 // arg 2 - signum - MOVW $0, R2 // arg 3 - tcb - MOVD $119, R8 // sys_thrkill - INVOKE_SYSCALL - RET + BL runtime·mstart(SB) -TEXT runtime·raiseproc(SB),NOSPLIT,$0 - MOVD $20, R8 // sys_getpid - INVOKE_SYSCALL - // arg 1 - pid, already in R0 - MOVW sig+0(FP), R1 // arg 2 - signum - MOVD $122, R8 // sys_kill - INVOKE_SYSCALL - RET + // Restore callee-save registers. + MOVD 8(RSP), R19 + MOVD 16(RSP), R20 + MOVD 24(RSP), R21 + MOVD 32(RSP), R22 + MOVD 40(RSP), R23 + MOVD 48(RSP), R24 + MOVD 56(RSP), R25 + MOVD 64(RSP), R26 + MOVD 72(RSP), R27 + MOVD 80(RSP), g + MOVD 88(RSP), R29 + FMOVD 96(RSP), F8 + FMOVD 104(RSP), F9 + FMOVD 112(RSP), F10 + FMOVD 120(RSP), F11 + FMOVD 128(RSP), F12 + FMOVD 136(RSP), F13 + FMOVD 144(RSP), F14 + FMOVD 152(RSP), F15 -TEXT runtime·mmap(SB),NOSPLIT,$0 - MOVD addr+0(FP), R0 // arg 1 - addr - MOVD n+8(FP), R1 // arg 2 - len - MOVW prot+16(FP), R2 // arg 3 - prot - MOVW flags+20(FP), R3 // arg 4 - flags - MOVW fd+24(FP), R4 // arg 5 - fd - MOVW $0, R5 // arg 6 - pad - MOVW off+28(FP), R6 // arg 7 - offset - MOVD $197, R8 // sys_mmap - INVOKE_SYSCALL - MOVD $0, R1 - BCC 3(PC) - MOVD R0, R1 // if error, move to R1 + // Go is all done with this OS thread. + // Tell pthread everything is ok (we never join with this thread, so + // the value here doesn't really matter). MOVD $0, R0 - MOVD R0, p+32(FP) - MOVD R1, err+40(FP) - RET -TEXT runtime·munmap(SB),NOSPLIT,$0 - MOVD addr+0(FP), R0 // arg 1 - addr - MOVD n+8(FP), R1 // arg 2 - len - MOVD $73, R8 // sys_munmap - INVOKE_SYSCALL - BCC 3(PC) - MOVD $0, R0 // crash on syscall failure - MOVD R0, (R0) - RET - -TEXT runtime·madvise(SB),NOSPLIT,$0 - MOVD addr+0(FP), R0 // arg 1 - addr - MOVD n+8(FP), R1 // arg 2 - len - MOVW flags+16(FP), R2 // arg 2 - flags - MOVD $75, R8 // sys_madvise - INVOKE_SYSCALL - BCC 2(PC) - MOVW $-1, R0 - MOVW R0, ret+24(FP) - RET - -TEXT runtime·setitimer(SB),NOSPLIT,$0 - MOVW mode+0(FP), R0 // arg 1 - mode - MOVD new+8(FP), R1 // arg 2 - new value - MOVD old+16(FP), R2 // arg 3 - old value - MOVD $69, R8 // sys_setitimer - INVOKE_SYSCALL - RET - -// func walltime1() (sec int64, nsec int32) -TEXT runtime·walltime1(SB), NOSPLIT, $32 - MOVW CLOCK_REALTIME, R0 // arg 1 - clock_id - MOVD $8(RSP), R1 // arg 2 - tp - MOVD $87, R8 // sys_clock_gettime - INVOKE_SYSCALL - - MOVD 8(RSP), R0 // sec - MOVD 16(RSP), R1 // nsec - MOVD R0, sec+0(FP) - MOVW R1, nsec+8(FP) - - RET - -// int64 nanotime1(void) so really -// void nanotime1(int64 *nsec) -TEXT runtime·nanotime1(SB),NOSPLIT,$32 - MOVW CLOCK_MONOTONIC, R0 // arg 1 - clock_id - MOVD $8(RSP), R1 // arg 2 - tp - MOVD $87, R8 // sys_clock_gettime - INVOKE_SYSCALL - - MOVW 8(RSP), R3 // sec - MOVW 16(RSP), R5 // nsec - - MOVD $1000000000, R4 - MUL R4, R3 - ADD R5, R3 - MOVD R3, ret+0(FP) - RET - -TEXT runtime·sigaction(SB),NOSPLIT,$0 - MOVW sig+0(FP), R0 // arg 1 - signum - MOVD new+8(FP), R1 // arg 2 - new sigaction - MOVD old+16(FP), R2 // arg 3 - old sigaction - MOVD $46, R8 // sys_sigaction - INVOKE_SYSCALL - BCC 3(PC) - MOVD $3, R0 // crash on syscall failure - MOVD R0, (R0) - RET - -TEXT runtime·obsdsigprocmask(SB),NOSPLIT,$0 - MOVW how+0(FP), R0 // arg 1 - mode - MOVW new+4(FP), R1 // arg 2 - new - MOVD $48, R8 // sys_sigprocmask - INVOKE_SYSCALL - BCC 3(PC) - MOVD $3, R8 // crash on syscall failure - MOVD R8, (R8) - MOVW R0, ret+8(FP) RET TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 @@ -282,9 +110,6 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$192 // If called from an external code context, g will not be set. // Save R0, since runtime·load_g will clobber it. MOVW R0, 8(RSP) // signum - MOVB runtime·iscgo(SB), R0 - CMP $0, R0 - BEQ 2(PC) BL runtime·load_g(SB) MOVD R1, 16(RSP) @@ -314,135 +139,562 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$192 RET -// int32 tfork(void *param, uintptr psize, M *mp, G *gp, void (*fn)(void)); -TEXT runtime·tfork(SB),NOSPLIT,$0 +// +// These trampolines help convert from Go calling convention to C calling convention. +// They should be called with asmcgocall. +// A pointer to the arguments is passed in R0. +// A single int32 result is returned in R0. +// (For more results, make an args/results structure.) +TEXT runtime·pthread_attr_init_trampoline(SB),NOSPLIT,$0 + MOVD 0(R0), R0 // arg 1 - attr + CALL libc_pthread_attr_init(SB) + RET + +TEXT runtime·pthread_attr_destroy_trampoline(SB),NOSPLIT,$0 + MOVD 0(R0), R0 // arg 1 - attr + CALL libc_pthread_attr_destroy(SB) + RET + +TEXT runtime·pthread_attr_getstacksize_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 // arg 2 - size + MOVD 0(R0), R0 // arg 1 - attr + CALL libc_pthread_attr_getstacksize(SB) + RET + +TEXT runtime·pthread_attr_setdetachstate_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 // arg 2 - state + MOVD 0(R0), R0 // arg 1 - attr + CALL libc_pthread_attr_setdetachstate(SB) + RET + +TEXT runtime·pthread_create_trampoline(SB),NOSPLIT,$0 + MOVD 0(R0), R1 // arg 2 - attr + MOVD 8(R0), R2 // arg 3 - start + MOVD 16(R0), R3 // arg 4 - arg + SUB $16, RSP + MOVD RSP, R0 // arg 1 - &threadid (discard) + CALL libc_pthread_create(SB) + ADD $16, RSP + RET + +TEXT runtime·thrkill_trampoline(SB),NOSPLIT,$0 + MOVW 8(R0), R1 // arg 2 - signal + MOVD $0, R2 // arg 3 - tcb + MOVW 0(R0), R0 // arg 1 - tid + CALL libc_thrkill(SB) + RET + +TEXT runtime·thrsleep_trampoline(SB),NOSPLIT,$0 + MOVW 8(R0), R1 // arg 2 - clock_id + MOVD 16(R0), R2 // arg 3 - abstime + MOVD 24(R0), R3 // arg 4 - lock + MOVD 32(R0), R4 // arg 5 - abort + MOVD 0(R0), R0 // arg 1 - id + CALL libc_thrsleep(SB) + RET + +TEXT runtime·thrwakeup_trampoline(SB),NOSPLIT,$0 + MOVW 8(R0), R1 // arg 2 - count + MOVD 0(R0), R0 // arg 1 - id + CALL libc_thrwakeup(SB) + RET + +TEXT runtime·exit_trampoline(SB),NOSPLIT,$0 + MOVW 0(R0), R0 // arg 1 - status + CALL libc_exit(SB) + MOVD $0, R0 // crash on failure + MOVD R0, (R0) + RET + +TEXT runtime·getthrid_trampoline(SB),NOSPLIT,$0 + MOVD R0, R19 // pointer to args + CALL libc_getthrid(SB) + MOVW R0, 0(R19) // return value + RET + +TEXT runtime·raiseproc_trampoline(SB),NOSPLIT,$0 + MOVD R0, R19 // pointer to args + CALL libc_getpid(SB) // arg 1 - pid + MOVW 0(R19), R1 // arg 2 - signal + CALL libc_kill(SB) + RET + +TEXT runtime·sched_yield_trampoline(SB),NOSPLIT,$0 + CALL libc_sched_yield(SB) + RET + +TEXT runtime·mmap_trampoline(SB),NOSPLIT,$0 + MOVD R0, R19 // pointer to args + MOVD 0(R19), R0 // arg 1 - addr + MOVD 8(R19), R1 // arg 2 - len + MOVW 16(R19), R2 // arg 3 - prot + MOVW 20(R19), R3 // arg 4 - flags + MOVW 24(R19), R4 // arg 5 - fid + MOVW 28(R19), R5 // arg 6 - offset + CALL libc_mmap(SB) + MOVD $0, R1 + CMP $-1, R0 + BNE noerr + CALL libc_errno(SB) + MOVW (R0), R1 // errno + MOVD $0, R0 +noerr: + MOVD R0, 32(R19) + MOVD R1, 40(R19) + RET + +TEXT runtime·munmap_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 // arg 2 - len + MOVD 0(R0), R0 // arg 1 - addr + CALL libc_munmap(SB) + CMP $-1, R0 + BNE 3(PC) + MOVD $0, R0 // crash on failure + MOVD R0, (R0) + RET + +TEXT runtime·madvise_trampoline(SB), NOSPLIT, $0 + MOVD 8(R0), R1 // arg 2 - len + MOVW 16(R0), R2 // arg 3 - advice + MOVD 0(R0), R0 // arg 1 - addr + CALL libc_madvise(SB) + // ignore failure - maybe pages are locked + RET + +TEXT runtime·open_trampoline(SB),NOSPLIT,$0 + MOVW 8(R0), R1 // arg 2 - flags + MOVW 12(R0), R2 // arg 3 - mode + MOVD 0(R0), R0 // arg 1 - path + MOVD $0, R3 // varargs + CALL libc_open(SB) + RET - // Copy mp, gp and fn off parent stack for use by child. - MOVD mm+16(FP), R4 - MOVD gg+24(FP), R5 - MOVD fn+32(FP), R6 +TEXT runtime·close_trampoline(SB),NOSPLIT,$0 + MOVD 0(R0), R0 // arg 1 - fd + CALL libc_close(SB) + RET - MOVD param+0(FP), R0 // arg 1 - param - MOVD psize+8(FP), R1 // arg 2 - psize - MOVD $8, R8 // sys___tfork - INVOKE_SYSCALL +TEXT runtime·read_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 // arg 2 - buf + MOVW 16(R0), R2 // arg 3 - count + MOVW 0(R0), R0 // arg 1 - fd + CALL libc_read(SB) + CMP $-1, R0 + BNE noerr + CALL libc_errno(SB) + MOVW (R0), R0 // errno + NEG R0, R0 // caller expects negative errno value +noerr: + RET - // Return if syscall failed. - BCC 4(PC) - NEG R0, R0 - MOVW R0, ret+40(FP) +TEXT runtime·write_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 // arg 2 - buf + MOVW 16(R0), R2 // arg 3 - count + MOVW 0(R0), R0 // arg 1 - fd + CALL libc_write(SB) + CMP $-1, R0 + BNE noerr + CALL libc_errno(SB) + MOVW (R0), R0 // errno + NEG R0, R0 // caller expects negative errno value +noerr: RET - // In parent, return. - CMP $0, R0 - BEQ 3(PC) - MOVW R0, ret+40(FP) +TEXT runtime·pipe2_trampoline(SB),NOSPLIT,$0 + MOVW 8(R0), R1 // arg 2 - flags + MOVD 0(R0), R0 // arg 1 - filedes + CALL libc_pipe2(SB) + CMP $-1, R0 + BNE noerr + CALL libc_errno(SB) + MOVW (R0), R0 // errno + NEG R0, R0 // caller expects negative errno value +noerr: RET - // Initialise m, g. - MOVD R5, g - MOVD R4, g_m(g) +TEXT runtime·setitimer_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 // arg 2 - new + MOVD 16(R0), R2 // arg 3 - old + MOVW 0(R0), R0 // arg 1 - which + CALL libc_setitimer(SB) + RET - // Call fn. - BL (R6) +TEXT runtime·usleep_trampoline(SB),NOSPLIT,$0 + MOVD 0(R0), R0 // arg 1 - usec + CALL libc_usleep(SB) + RET - // fn should never return. - MOVD $2, R8 // crash if reached - MOVD R8, (R8) +TEXT runtime·sysctl_trampoline(SB),NOSPLIT,$0 + MOVW 8(R0), R1 // arg 2 - miblen + MOVD 16(R0), R2 // arg 3 - out + MOVD 24(R0), R3 // arg 4 - size + MOVD 32(R0), R4 // arg 5 - dst + MOVD 40(R0), R5 // arg 6 - ndst + MOVD 0(R0), R0 // arg 1 - mib + CALL libc_sysctl(SB) RET -TEXT runtime·sigaltstack(SB),NOSPLIT,$0 - MOVD new+0(FP), R0 // arg 1 - new sigaltstack - MOVD old+8(FP), R1 // arg 2 - old sigaltstack - MOVD $288, R8 // sys_sigaltstack - INVOKE_SYSCALL - BCC 3(PC) - MOVD $0, R8 // crash on syscall failure - MOVD R8, (R8) +TEXT runtime·kqueue_trampoline(SB),NOSPLIT,$0 + CALL libc_kqueue(SB) RET -TEXT runtime·osyield(SB),NOSPLIT,$0 - MOVD $298, R8 // sys_sched_yield - INVOKE_SYSCALL +TEXT runtime·kevent_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 // arg 2 - keventt + MOVW 16(R0), R2 // arg 3 - nch + MOVD 24(R0), R3 // arg 4 - ev + MOVW 32(R0), R4 // arg 5 - nev + MOVD 40(R0), R5 // arg 6 - ts + MOVW 0(R0), R0 // arg 1 - kq + CALL libc_kevent(SB) + CMP $-1, R0 + BNE noerr + CALL libc_errno(SB) + MOVW (R0), R0 // errno + NEG R0, R0 // caller expects negative errno value +noerr: RET -TEXT runtime·thrsleep(SB),NOSPLIT,$0 - MOVD ident+0(FP), R0 // arg 1 - ident - MOVW clock_id+8(FP), R1 // arg 2 - clock_id - MOVD tsp+16(FP), R2 // arg 3 - tsp - MOVD lock+24(FP), R3 // arg 4 - lock - MOVD abort+32(FP), R4 // arg 5 - abort - MOVD $94, R8 // sys___thrsleep - INVOKE_SYSCALL - MOVW R0, ret+40(FP) +TEXT runtime·clock_gettime_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 // arg 2 - tp + MOVD 0(R0), R0 // arg 1 - clock_id + CALL libc_clock_gettime(SB) + CMP $-1, R0 + BNE 3(PC) + MOVD $0, R0 // crash on failure + MOVD R0, (R0) RET -TEXT runtime·thrwakeup(SB),NOSPLIT,$0 - MOVD ident+0(FP), R0 // arg 1 - ident - MOVW n+8(FP), R1 // arg 2 - n - MOVD $301, R8 // sys___thrwakeup - INVOKE_SYSCALL - MOVW R0, ret+16(FP) +TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$0 + MOVW 4(R0), R1 // arg 2 - cmd + MOVW 8(R0), R2 // arg 3 - arg + MOVW 0(R0), R0 // arg 1 - fd + MOVD $0, R3 // vararg + CALL libc_fcntl(SB) RET -TEXT runtime·sysctl(SB),NOSPLIT,$0 - MOVD mib+0(FP), R0 // arg 1 - mib - MOVW miblen+8(FP), R1 // arg 2 - miblen - MOVD out+16(FP), R2 // arg 3 - out - MOVD size+24(FP), R3 // arg 4 - size - MOVD dst+32(FP), R4 // arg 5 - dest - MOVD ndst+40(FP), R5 // arg 6 - newlen - MOVD $202, R8 // sys___sysctl - INVOKE_SYSCALL - BCC 2(PC) - NEG R0, R0 - MOVW R0, ret+48(FP) +TEXT runtime·sigaction_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 // arg 2 - new + MOVD 16(R0), R2 // arg 3 - old + MOVW 0(R0), R0 // arg 1 - sig + CALL libc_sigaction(SB) + CMP $-1, R0 + BNE 3(PC) + MOVD $0, R0 // crash on syscall failure + MOVD R0, (R0) RET -// int32 runtime·kqueue(void); -TEXT runtime·kqueue(SB),NOSPLIT,$0 - MOVD $269, R8 // sys_kqueue - INVOKE_SYSCALL - BCC 2(PC) - NEG R0, R0 - MOVW R0, ret+0(FP) +TEXT runtime·sigprocmask_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 // arg 2 - new + MOVD 16(R0), R2 // arg 3 - old + MOVW 0(R0), R0 // arg 1 - how + CALL libc_pthread_sigmask(SB) + CMP $-1, R0 + BNE 3(PC) + MOVD $0, R0 // crash on syscall failure + MOVD R0, (R0) RET -// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout); -TEXT runtime·kevent(SB),NOSPLIT,$0 - MOVW kq+0(FP), R0 // arg 1 - kq - MOVD ch+8(FP), R1 // arg 2 - changelist - MOVW nch+16(FP), R2 // arg 3 - nchanges - MOVD ev+24(FP), R3 // arg 4 - eventlist - MOVW nev+32(FP), R4 // arg 5 - nevents - MOVD ts+40(FP), R5 // arg 6 - timeout - MOVD $72, R8 // sys_kevent - INVOKE_SYSCALL - BCC 2(PC) - NEG R0, R0 - MOVW R0, ret+48(FP) +TEXT runtime·sigaltstack_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 // arg 2 - old + MOVD 0(R0), R0 // arg 1 - new + CALL libc_sigaltstack(SB) + CMP $-1, R0 + BNE 3(PC) + MOVD $0, R0 // crash on syscall failure + MOVD R0, (R0) RET -// func closeonexec(fd int32) -TEXT runtime·closeonexec(SB),NOSPLIT,$0 - MOVW fd+0(FP), R0 // arg 1 - fd - MOVD $2, R1 // arg 2 - cmd (F_SETFD) - MOVD $1, R2 // arg 3 - arg (FD_CLOEXEC) - MOVD $92, R8 // sys_fcntl - INVOKE_SYSCALL +// syscall calls a function in libc on behalf of the syscall package. +// syscall takes a pointer to a struct like: +// struct { +// fn uintptr +// a1 uintptr +// a2 uintptr +// a3 uintptr +// r1 uintptr +// r2 uintptr +// err uintptr +// } +// syscall must be called on the g0 stack with the +// C calling convention (use libcCall). +// +// syscall expects a 32-bit result and tests for 32-bit -1 +// to decide there was an error. +TEXT runtime·syscall(SB),NOSPLIT,$0 + MOVD R0, R19 // pointer to args + + MOVD (0*8)(R19), R11 // fn + MOVD (1*8)(R19), R0 // a1 + MOVD (2*8)(R19), R1 // a2 + MOVD (3*8)(R19), R2 // a3 + MOVD $0, R3 // vararg + + CALL R11 + + MOVD R0, (4*8)(R19) // r1 + MOVD R1, (5*8)(R19) // r2 + + // Standard libc functions return -1 on error + // and set errno. + CMPW $-1, R0 + BNE ok + + // Get error code from libc. + CALL libc_errno(SB) + MOVW (R0), R0 + MOVD R0, (6*8)(R19) // err + +ok: RET -// func runtime·setNonblock(int32 fd) -TEXT runtime·setNonblock(SB),NOSPLIT|NOFRAME,$0-4 - MOVW fd+0(FP), R0 // arg 1 - fd - MOVD $3, R1 // arg 2 - cmd (F_GETFL) - MOVD $0, R2 // arg 3 - MOVD $92, R8 // sys_fcntl - INVOKE_SYSCALL - MOVD $4, R2 // O_NONBLOCK - ORR R0, R2 // arg 3 - flags - MOVW fd+0(FP), R0 // arg 1 - fd - MOVD $4, R1 // arg 2 - cmd (F_SETFL) - MOVD $92, R8 // sys_fcntl - INVOKE_SYSCALL +// syscallX calls a function in libc on behalf of the syscall package. +// syscallX takes a pointer to a struct like: +// struct { +// fn uintptr +// a1 uintptr +// a2 uintptr +// a3 uintptr +// r1 uintptr +// r2 uintptr +// err uintptr +// } +// syscallX must be called on the g0 stack with the +// C calling convention (use libcCall). +// +// syscallX is like syscall but expects a 64-bit result +// and tests for 64-bit -1 to decide there was an error. +TEXT runtime·syscallX(SB),NOSPLIT,$0 + MOVD R0, R19 // pointer to args + + MOVD (0*8)(R19), R11 // fn + MOVD (1*8)(R19), R0 // a1 + MOVD (2*8)(R19), R1 // a2 + MOVD (3*8)(R19), R2 // a3 + MOVD $0, R3 // vararg + + CALL R11 + + MOVD R0, (4*8)(R19) // r1 + MOVD R1, (5*8)(R19) // r2 + + // Standard libc functions return -1 on error + // and set errno. + CMP $-1, R0 + BNE ok + + // Get error code from libc. + CALL libc_errno(SB) + MOVW (R0), R0 + MOVD R0, (6*8)(R19) // err + +ok: + RET + +// syscall6 calls a function in libc on behalf of the syscall package. +// syscall6 takes a pointer to a struct like: +// struct { +// fn uintptr +// a1 uintptr +// a2 uintptr +// a3 uintptr +// a4 uintptr +// a5 uintptr +// a6 uintptr +// r1 uintptr +// r2 uintptr +// err uintptr +// } +// syscall6 must be called on the g0 stack with the +// C calling convention (use libcCall). +// +// syscall6 expects a 32-bit result and tests for 32-bit -1 +// to decide there was an error. +TEXT runtime·syscall6(SB),NOSPLIT,$0 + MOVD R0, R19 // pointer to args + + MOVD (0*8)(R19), R11 // fn + MOVD (1*8)(R19), R0 // a1 + MOVD (2*8)(R19), R1 // a2 + MOVD (3*8)(R19), R2 // a3 + MOVD (4*8)(R19), R3 // a4 + MOVD (5*8)(R19), R4 // a5 + MOVD (6*8)(R19), R5 // a6 + MOVD $0, R6 // vararg + + CALL R11 + + MOVD R0, (7*8)(R19) // r1 + MOVD R1, (8*8)(R19) // r2 + + // Standard libc functions return -1 on error + // and set errno. + CMPW $-1, R0 + BNE ok + + // Get error code from libc. + CALL libc_errno(SB) + MOVW (R0), R0 + MOVD R0, (9*8)(R19) // err + +ok: + RET + +// syscall6X calls a function in libc on behalf of the syscall package. +// syscall6X takes a pointer to a struct like: +// struct { +// fn uintptr +// a1 uintptr +// a2 uintptr +// a3 uintptr +// a4 uintptr +// a5 uintptr +// a6 uintptr +// r1 uintptr +// r2 uintptr +// err uintptr +// } +// syscall6X must be called on the g0 stack with the +// C calling convention (use libcCall). +// +// syscall6X is like syscall6 but expects a 64-bit result +// and tests for 64-bit -1 to decide there was an error. +TEXT runtime·syscall6X(SB),NOSPLIT,$0 + MOVD R0, R19 // pointer to args + + MOVD (0*8)(R19), R11 // fn + MOVD (1*8)(R19), R0 // a1 + MOVD (2*8)(R19), R1 // a2 + MOVD (3*8)(R19), R2 // a3 + MOVD (4*8)(R19), R3 // a4 + MOVD (5*8)(R19), R4 // a5 + MOVD (6*8)(R19), R5 // a6 + MOVD $0, R6 // vararg + + CALL R11 + + MOVD R0, (7*8)(R19) // r1 + MOVD R1, (8*8)(R19) // r2 + + // Standard libc functions return -1 on error + // and set errno. + CMP $-1, R0 + BNE ok + + // Get error code from libc. + CALL libc_errno(SB) + MOVW (R0), R0 + MOVD R0, (9*8)(R19) // err + +ok: + RET + +// syscall10 calls a function in libc on behalf of the syscall package. +// syscall10 takes a pointer to a struct like: +// struct { +// fn uintptr +// a1 uintptr +// a2 uintptr +// a3 uintptr +// a4 uintptr +// a5 uintptr +// a6 uintptr +// a7 uintptr +// a8 uintptr +// a9 uintptr +// a10 uintptr +// r1 uintptr +// r2 uintptr +// err uintptr +// } +// syscall10 must be called on the g0 stack with the +// C calling convention (use libcCall). +TEXT runtime·syscall10(SB),NOSPLIT,$0 + MOVD R0, R19 // pointer to args + + MOVD (0*8)(R19), R11 // fn + MOVD (1*8)(R19), R0 // a1 + MOVD (2*8)(R19), R1 // a2 + MOVD (3*8)(R19), R2 // a3 + MOVD (4*8)(R19), R3 // a4 + MOVD (5*8)(R19), R4 // a5 + MOVD (6*8)(R19), R5 // a6 + MOVD (7*8)(R19), R6 // a7 + MOVD (8*8)(R19), R7 // a8 + MOVD (9*8)(R19), R8 // a9 + MOVD (10*8)(R19), R9 // a10 + MOVD $0, R10 // vararg + + CALL R11 + + MOVD R0, (11*8)(R19) // r1 + MOVD R1, (12*8)(R19) // r2 + + // Standard libc functions return -1 on error + // and set errno. + CMPW $-1, R0 + BNE ok + + // Get error code from libc. + CALL libc_errno(SB) + MOVW (R0), R0 + MOVD R0, (13*8)(R19) // err + +ok: + RET + +// syscall10X calls a function in libc on behalf of the syscall package. +// syscall10X takes a pointer to a struct like: +// struct { +// fn uintptr +// a1 uintptr +// a2 uintptr +// a3 uintptr +// a4 uintptr +// a5 uintptr +// a6 uintptr +// a7 uintptr +// a8 uintptr +// a9 uintptr +// a10 uintptr +// r1 uintptr +// r2 uintptr +// err uintptr +// } +// syscall10X must be called on the g0 stack with the +// C calling convention (use libcCall). +// +// syscall10X is like syscall10 but expects a 64-bit result +// and tests for 64-bit -1 to decide there was an error. +TEXT runtime·syscall10X(SB),NOSPLIT,$0 + MOVD R0, R19 // pointer to args + + MOVD (0*8)(R19), R11 // fn + MOVD (1*8)(R19), R0 // a1 + MOVD (2*8)(R19), R1 // a2 + MOVD (3*8)(R19), R2 // a3 + MOVD (4*8)(R19), R3 // a4 + MOVD (5*8)(R19), R4 // a5 + MOVD (6*8)(R19), R5 // a6 + MOVD (7*8)(R19), R6 // a7 + MOVD (8*8)(R19), R7 // a8 + MOVD (9*8)(R19), R8 // a9 + MOVD (10*8)(R19), R9 // a10 + MOVD $0, R10 // vararg + + CALL R11 + + MOVD R0, (11*8)(R19) // r1 + MOVD R1, (12*8)(R19) // r2 + + // Standard libc functions return -1 on error + // and set errno. + CMP $-1, R0 + BNE ok + + // Get error code from libc. + CALL libc_errno(SB) + MOVW (R0), R0 + MOVD R0, (13*8)(R19) // err + +ok: RET diff --git a/src/runtime/sys_openbsd_mips64.s b/src/runtime/sys_openbsd_mips64.s index 57a5dbd40e..3e4d209081 100644 --- a/src/runtime/sys_openbsd_mips64.s +++ b/src/runtime/sys_openbsd_mips64.s @@ -244,8 +244,8 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 MOVW sig+8(FP), R4 MOVV info+16(FP), R5 MOVV ctx+24(FP), R6 - MOVV fn+0(FP), R7 - CALL (R7) // Alignment for ELF ABI? + MOVV fn+0(FP), R25 // Must use R25, needed for PIC code. + CALL (R25) RET TEXT runtime·sigtramp(SB),NOSPLIT,$192 diff --git a/src/runtime/sys_windows_386.s b/src/runtime/sys_windows_386.s index 2e5e82879c..ef8a3dd3c2 100644 --- a/src/runtime/sys_windows_386.s +++ b/src/runtime/sys_windows_386.s @@ -415,12 +415,15 @@ TEXT runtime·usleep2(SB),NOSPLIT,$20 // Runs on OS stack. duration (in 100ns units) is in BX. TEXT runtime·usleep2HighRes(SB),NOSPLIT,$36 + get_tls(CX) + CMPL CX, $0 + JE gisnotset + // Want negative 100ns units. NEGL BX MOVL $-1, hi-4(SP) MOVL BX, lo-8(SP) - get_tls(CX) MOVL g(CX), CX MOVL g_m(CX), CX MOVL (m_mOS+mOS_highResTimer)(CX), CX @@ -449,6 +452,12 @@ TEXT runtime·usleep2HighRes(SB),NOSPLIT,$36 RET +gisnotset: + // TLS is not configured. Call usleep2 instead. + MOVL $runtime·usleep2(SB), AX + CALL AX + RET + // Runs on OS stack. TEXT runtime·switchtothread(SB),NOSPLIT,$0 MOVL SP, BP diff --git a/src/runtime/sys_windows_amd64.s b/src/runtime/sys_windows_amd64.s index e9ec99a51d..d1690cad58 100644 --- a/src/runtime/sys_windows_amd64.s +++ b/src/runtime/sys_windows_amd64.s @@ -454,11 +454,14 @@ TEXT runtime·usleep2(SB),NOSPLIT|NOFRAME,$48 // Runs on OS stack. duration (in 100ns units) is in BX. TEXT runtime·usleep2HighRes(SB),NOSPLIT|NOFRAME,$72 + get_tls(CX) + CMPQ CX, $0 + JE gisnotset + MOVQ SP, AX ANDQ $~15, SP // alignment as per Windows requirement MOVQ AX, 64(SP) - get_tls(CX) MOVQ g(CX), CX MOVQ g_m(CX), CX MOVQ (m_mOS+mOS_highResTimer)(CX), CX // hTimer @@ -484,6 +487,12 @@ TEXT runtime·usleep2HighRes(SB),NOSPLIT|NOFRAME,$72 MOVQ 64(SP), SP RET +gisnotset: + // TLS is not configured. Call usleep2 instead. + MOVQ $runtime·usleep2(SB), AX + CALL AX + RET + // Runs on OS stack. TEXT runtime·switchtothread(SB),NOSPLIT|NOFRAME,$0 MOVQ SP, AX diff --git a/src/runtime/sys_windows_arm.s b/src/runtime/sys_windows_arm.s index 3fc6d27cb0..fe267080cc 100644 --- a/src/runtime/sys_windows_arm.s +++ b/src/runtime/sys_windows_arm.s @@ -314,48 +314,42 @@ TEXT runtime·externalthreadhandler(SB),NOSPLIT|NOFRAME,$0 GLOBL runtime·cbctxts(SB), NOPTR, $4 TEXT runtime·callbackasm1(SB),NOSPLIT|NOFRAME,$0 - // TODO(austin): This needs to be converted to match changes - // in cgocallback, but I have no way to test. See CL 258938, - // and callbackasm1 on amd64 and 386. - MOVM.DB.W [R4-R11, R14], (R13) // push {r4-r11, lr} - SUB $36, R13 // space for locals + // On entry, the trampoline in zcallback_windows_arm.s left + // the callback index in R12 (which is volatile in the C ABI). - // save callback arguments to stack. We currently support up to 4 arguments - ADD $16, R13, R4 - MOVM.IA [R0-R3], (R4) + // Push callback register arguments r0-r3. We do this first so + // they're contiguous with stack arguments. + MOVM.DB.W [R0-R3], (R13) + // Push C callee-save registers r4-r11 and lr. + MOVM.DB.W [R4-R11, R14], (R13) + SUB $(16 + callbackArgs__size), R13 // space for locals - // load cbctxts[i]. The trampoline in zcallback_windows.s puts the callback - // index in R12 - MOVW runtime·cbctxts(SB), R4 - MOVW R12<<2(R4), R4 // R4 holds pointer to wincallbackcontext structure - - // extract callback context - MOVW wincallbackcontext_argsize(R4), R5 - MOVW wincallbackcontext_gobody(R4), R4 - - // we currently support up to 4 arguments - CMP $(4 * 4), R5 - BL.GT runtime·abort(SB) - - // extend argsize by size of return value - ADD $4, R5 - - // Build 'type args struct' - MOVW R4, 4(R13) // fn - ADD $16, R13, R0 // arg (points to r0-r3, ret on stack) - MOVW R0, 8(R13) - MOVW R5, 12(R13) // argsize + // Create a struct callbackArgs on our stack. + MOVW R12, (16+callbackArgs_index)(R13) // callback index + MOVW $(16+callbackArgs__size+4*9)(R13), R0 + MOVW R0, (16+callbackArgs_args)(R13) // address of args vector + MOVW $0, R0 + MOVW R0, (16+callbackArgs_result)(R13) // result + // Prepare for entry to Go. BL runtime·load_g(SB) - BL runtime·cgocallback_gofunc(SB) - ADD $16, R13, R0 // load arg - MOVW 12(R13), R1 // load argsize - SUB $4, R1 // offset to return value - MOVW R1<<0(R0), R0 // load return value + // Call cgocallback, which will call callbackWrap(frame). + MOVW $0, R0 + MOVW R0, 12(R13) // context + MOVW $16(R13), R1 // R1 = &callbackArgs{...} + MOVW R1, 8(R13) // frame (address of callbackArgs) + MOVW $·callbackWrap(SB), R1 + MOVW R1, 4(R13) // PC of function to call + BL runtime·cgocallback(SB) + + // Get callback result. + MOVW (16+callbackArgs_result)(R13), R0 - ADD $36, R13 // free locals - MOVM.IA.W (R13), [R4-R11, R15] // pop {r4-r11, pc} + ADD $(16 + callbackArgs__size), R13 // free locals + MOVM.IA.W (R13), [R4-R11, R12] // pop {r4-r11, lr=>r12} + ADD $(4*4), R13 // skip r0-r3 + B (R12) // return // uint32 tstart_stdcall(M *newm); TEXT runtime·tstart_stdcall(SB),NOSPLIT|NOFRAME,$0 diff --git a/src/runtime/syscall2_solaris.go b/src/runtime/syscall2_solaris.go index e098e8006a..3310489202 100644 --- a/src/runtime/syscall2_solaris.go +++ b/src/runtime/syscall2_solaris.go @@ -15,7 +15,6 @@ import _ "unsafe" // for go:linkname //go:cgo_import_dynamic libc_gethostname gethostname "libc.so" //go:cgo_import_dynamic libc_getpid getpid "libc.so" //go:cgo_import_dynamic libc_ioctl ioctl "libc.so" -//go:cgo_import_dynamic libc_pipe pipe "libc.so" //go:cgo_import_dynamic libc_setgid setgid "libc.so" //go:cgo_import_dynamic libc_setgroups setgroups "libc.so" //go:cgo_import_dynamic libc_setsid setsid "libc.so" @@ -33,7 +32,6 @@ import _ "unsafe" // for go:linkname //go:linkname libc_gethostname libc_gethostname //go:linkname libc_getpid libc_getpid //go:linkname libc_ioctl libc_ioctl -//go:linkname libc_pipe libc_pipe //go:linkname libc_setgid libc_setgid //go:linkname libc_setgroups libc_setgroups //go:linkname libc_setsid libc_setsid diff --git a/src/runtime/syscall_windows.go b/src/runtime/syscall_windows.go index 21f2452b5a..add40bb0b3 100644 --- a/src/runtime/syscall_windows.go +++ b/src/runtime/syscall_windows.go @@ -5,6 +5,7 @@ package runtime import ( + "internal/abi" "runtime/internal/sys" "unsafe" ) @@ -109,14 +110,19 @@ func compileCallback(fn eface, cdecl bool) (code uintptr) { // passed as two words (little endian); and // structs are pushed on the stack. In // fastcall, arguments larger than the word - // size are passed by reference. + // size are passed by reference. On arm, + // 8-byte aligned arguments round up to the + // next even register and can be split across + // registers and the stack. panic("compileCallback: argument size is larger than uintptr") } - if k := t.kind & kindMask; GOARCH == "amd64" && (k == kindFloat32 || k == kindFloat64) { + if k := t.kind & kindMask; (GOARCH == "amd64" || GOARCH == "arm") && (k == kindFloat32 || k == kindFloat64) { // In fastcall, floating-point arguments in // the first four positions are passed in // floating-point registers, which we don't - // currently spill. + // currently spill. arm passes floating-point + // arguments in VFP registers, which we also + // don't support. panic("compileCallback: float arguments not supported") } @@ -128,6 +134,7 @@ func compileCallback(fn eface, cdecl bool) (code uintptr) { // argument word and all supported Windows // architectures are little endian, so src is already // pointing to the right place for smaller arguments. + // The same is true on arm. // Copy just the size of the argument. Note that this // could be a small by-value struct, but C and Go @@ -139,7 +146,7 @@ func compileCallback(fn eface, cdecl bool) (code uintptr) { abiMap = append(abiMap, part) } - // cdecl, stdcall, and fastcall pad arguments to word size. + // cdecl, stdcall, fastcall, and arm pad arguments to word size. src += sys.PtrSize // The Go ABI packs arguments. dst += t.size @@ -205,7 +212,18 @@ func compileCallback(fn eface, cdecl bool) (code uintptr) { type callbackArgs struct { index uintptr - args unsafe.Pointer // Arguments in stdcall/cdecl convention, with registers spilled + // args points to the argument block. + // + // For cdecl and stdcall, all arguments are on the stack. + // + // For fastcall, the trampoline spills register arguments to + // the reserved spill slots below the stack arguments, + // resulting in a layout equivalent to stdcall. + // + // For arm, the trampoline stores the register arguments just + // below the stack arguments, so again we can treat it as one + // big stack arguments frame. + args unsafe.Pointer // Below are out-args from callbackWrap result uintptr retPop uintptr // For 386 cdecl, how many bytes to pop on return @@ -216,7 +234,7 @@ func callbackWrap(a *callbackArgs) { c := cbs.ctxt[a.index] a.retPop = c.retPop - // Convert from stdcall to Go ABI. + // Convert from C to Go ABI. var frame [callbackMaxFrame]byte goArgs := unsafe.Pointer(&frame) for _, part := range c.abiMap { @@ -225,7 +243,11 @@ func callbackWrap(a *callbackArgs) { // Even though this is copying back results, we can pass a nil // type because those results must not require write barriers. - reflectcall(nil, unsafe.Pointer(c.fn), noescape(goArgs), uint32(c.retOffset)+sys.PtrSize, uint32(c.retOffset)) + // + // Pass a dummy RegArgs for now. + // TODO(mknyszek): Pass arguments in registers. + var regs abi.RegArgs + reflectcall(nil, unsafe.Pointer(c.fn), noescape(goArgs), uint32(c.retOffset)+sys.PtrSize, uint32(c.retOffset), uint32(c.retOffset)+sys.PtrSize, ®s) // Extract the result. a.result = *(*uintptr)(unsafe.Pointer(&frame[c.retOffset])) diff --git a/src/runtime/syscall_windows_test.go b/src/runtime/syscall_windows_test.go index 3827c6ed83..fb215b3c31 100644 --- a/src/runtime/syscall_windows_test.go +++ b/src/runtime/syscall_windows_test.go @@ -10,7 +10,6 @@ import ( "internal/syscall/windows/sysdll" "internal/testenv" "io" - "io/ioutil" "math" "os" "os/exec" @@ -446,7 +445,7 @@ func TestStdcallAndCDeclCallbacks(t *testing.T) { if _, err := exec.LookPath("gcc"); err != nil { t.Skip("skipping test: gcc is missing") } - tmp, err := ioutil.TempDir("", "TestCDeclCallback") + tmp, err := os.MkdirTemp("", "TestCDeclCallback") if err != nil { t.Fatal("TempDir failed: ", err) } @@ -602,14 +601,14 @@ uintptr_t cfunc(callback f, uintptr_t n) { return r; } ` - tmpdir, err := ioutil.TempDir("", "TestReturnAfterStackGrowInCallback") + tmpdir, err := os.MkdirTemp("", "TestReturnAfterStackGrowInCallback") if err != nil { t.Fatal("TempDir failed: ", err) } defer os.RemoveAll(tmpdir) srcname := "mydll.c" - err = ioutil.WriteFile(filepath.Join(tmpdir, srcname), []byte(src), 0) + err = os.WriteFile(filepath.Join(tmpdir, srcname), []byte(src), 0) if err != nil { t.Fatal(err) } @@ -671,14 +670,14 @@ uintptr_t cfunc(uintptr_t a, double b, float c, double d) { return 0; } ` - tmpdir, err := ioutil.TempDir("", "TestFloatArgs") + tmpdir, err := os.MkdirTemp("", "TestFloatArgs") if err != nil { t.Fatal("TempDir failed: ", err) } defer os.RemoveAll(tmpdir) srcname := "mydll.c" - err = ioutil.WriteFile(filepath.Join(tmpdir, srcname), []byte(src), 0) + err = os.WriteFile(filepath.Join(tmpdir, srcname), []byte(src), 0) if err != nil { t.Fatal(err) } @@ -733,14 +732,14 @@ double cfuncDouble(uintptr_t a, double b, float c, double d) { return 0; } ` - tmpdir, err := ioutil.TempDir("", "TestFloatReturn") + tmpdir, err := os.MkdirTemp("", "TestFloatReturn") if err != nil { t.Fatal("TempDir failed: ", err) } defer os.RemoveAll(tmpdir) srcname := "mydll.c" - err = ioutil.WriteFile(filepath.Join(tmpdir, srcname), []byte(src), 0) + err = os.WriteFile(filepath.Join(tmpdir, srcname), []byte(src), 0) if err != nil { t.Fatal(err) } @@ -948,7 +947,7 @@ func TestDLLPreloadMitigation(t *testing.T) { t.Skip("skipping test: gcc is missing") } - tmpdir, err := ioutil.TempDir("", "TestDLLPreloadMitigation") + tmpdir, err := os.MkdirTemp("", "TestDLLPreloadMitigation") if err != nil { t.Fatal("TempDir failed: ", err) } @@ -969,12 +968,13 @@ func TestDLLPreloadMitigation(t *testing.T) { #include <stdint.h> #include <windows.h> -uintptr_t cfunc() { +uintptr_t cfunc(void) { SetLastError(123); + return 0; } ` srcname := "nojack.c" - err = ioutil.WriteFile(filepath.Join(tmpdir, srcname), []byte(src), 0) + err = os.WriteFile(filepath.Join(tmpdir, srcname), []byte(src), 0) if err != nil { t.Fatal(err) } @@ -1034,7 +1034,7 @@ func TestBigStackCallbackSyscall(t *testing.T) { t.Fatal("Abs failed: ", err) } - tmpdir, err := ioutil.TempDir("", "TestBigStackCallback") + tmpdir, err := os.MkdirTemp("", "TestBigStackCallback") if err != nil { t.Fatal("TempDir failed: ", err) } @@ -1183,14 +1183,14 @@ func BenchmarkOsYield(b *testing.B) { } func BenchmarkRunningGoProgram(b *testing.B) { - tmpdir, err := ioutil.TempDir("", "BenchmarkRunningGoProgram") + tmpdir, err := os.MkdirTemp("", "BenchmarkRunningGoProgram") if err != nil { b.Fatal(err) } defer os.RemoveAll(tmpdir) src := filepath.Join(tmpdir, "main.go") - err = ioutil.WriteFile(src, []byte(benchmarkRunningGoProgram), 0666) + err = os.WriteFile(src, []byte(benchmarkRunningGoProgram), 0666) if err != nil { b.Fatal(err) } diff --git a/src/runtime/testdata/testprog/deadlock.go b/src/runtime/testdata/testprog/deadlock.go index 105d6a5faa..781acbd770 100644 --- a/src/runtime/testdata/testprog/deadlock.go +++ b/src/runtime/testdata/testprog/deadlock.go @@ -25,6 +25,7 @@ func init() { register("RecursivePanic2", RecursivePanic2) register("RecursivePanic3", RecursivePanic3) register("RecursivePanic4", RecursivePanic4) + register("RecursivePanic5", RecursivePanic5) register("GoexitExit", GoexitExit) register("GoNil", GoNil) register("MainGoroutineID", MainGoroutineID) @@ -160,6 +161,44 @@ func RecursivePanic4() { panic("first panic") } +// Test case where we have an open-coded defer higher up the stack (in two), and +// in the current function (three) we recover in a defer while we still have +// another defer to be processed. +func RecursivePanic5() { + one() + panic("third panic") +} + +//go:noinline +func one() { + two() +} + +//go:noinline +func two() { + defer func() { + }() + + three() +} + +//go:noinline +func three() { + defer func() { + }() + + defer func() { + fmt.Println(recover()) + }() + + defer func() { + fmt.Println(recover()) + panic("second panic") + }() + + panic("first panic") +} + func GoexitExit() { println("t1") go func() { diff --git a/src/runtime/testdata/testprog/memprof.go b/src/runtime/testdata/testprog/memprof.go index 7b134bc078..0392e60f84 100644 --- a/src/runtime/testdata/testprog/memprof.go +++ b/src/runtime/testdata/testprog/memprof.go @@ -7,7 +7,6 @@ package main import ( "bytes" "fmt" - "io/ioutil" "os" "runtime" "runtime/pprof" @@ -31,7 +30,7 @@ func MemProf() { runtime.GC() - f, err := ioutil.TempFile("", "memprof") + f, err := os.CreateTemp("", "memprof") if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(2) diff --git a/src/runtime/testdata/testprog/syscalls_linux.go b/src/runtime/testdata/testprog/syscalls_linux.go index b8ac087626..48f8014237 100644 --- a/src/runtime/testdata/testprog/syscalls_linux.go +++ b/src/runtime/testdata/testprog/syscalls_linux.go @@ -7,7 +7,6 @@ package main import ( "bytes" "fmt" - "io/ioutil" "os" "syscall" ) @@ -17,7 +16,7 @@ func gettid() int { } func tidExists(tid int) (exists, supported bool) { - stat, err := ioutil.ReadFile(fmt.Sprintf("/proc/self/task/%d/stat", tid)) + stat, err := os.ReadFile(fmt.Sprintf("/proc/self/task/%d/stat", tid)) if os.IsNotExist(err) { return false, true } diff --git a/src/runtime/testdata/testprog/timeprof.go b/src/runtime/testdata/testprog/timeprof.go index 0702885369..1e90af4033 100644 --- a/src/runtime/testdata/testprog/timeprof.go +++ b/src/runtime/testdata/testprog/timeprof.go @@ -6,7 +6,6 @@ package main import ( "fmt" - "io/ioutil" "os" "runtime/pprof" "time" @@ -17,7 +16,7 @@ func init() { } func TimeProf() { - f, err := ioutil.TempFile("", "timeprof") + f, err := os.CreateTemp("", "timeprof") if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(2) diff --git a/src/runtime/testdata/testprog/vdso.go b/src/runtime/testdata/testprog/vdso.go index ef92f48758..d2a300d8f2 100644 --- a/src/runtime/testdata/testprog/vdso.go +++ b/src/runtime/testdata/testprog/vdso.go @@ -8,7 +8,6 @@ package main import ( "fmt" - "io/ioutil" "os" "runtime/pprof" "time" @@ -19,7 +18,7 @@ func init() { } func signalInVDSO() { - f, err := ioutil.TempFile("", "timeprofnow") + f, err := os.CreateTemp("", "timeprofnow") if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(2) diff --git a/src/runtime/testdata/testprogcgo/pprof.go b/src/runtime/testdata/testprogcgo/pprof.go index 00f2c42e93..3b73fa0bdd 100644 --- a/src/runtime/testdata/testprogcgo/pprof.go +++ b/src/runtime/testdata/testprogcgo/pprof.go @@ -60,7 +60,6 @@ import "C" import ( "fmt" - "io/ioutil" "os" "runtime" "runtime/pprof" @@ -75,7 +74,7 @@ func init() { func CgoPprof() { runtime.SetCgoTraceback(0, unsafe.Pointer(C.pprofCgoTraceback), nil, nil) - f, err := ioutil.TempFile("", "prof") + f, err := os.CreateTemp("", "prof") if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(2) diff --git a/src/runtime/testdata/testprogcgo/threadpprof.go b/src/runtime/testdata/testprogcgo/threadpprof.go index 37a2a1ab65..feb774ba59 100644 --- a/src/runtime/testdata/testprogcgo/threadpprof.go +++ b/src/runtime/testdata/testprogcgo/threadpprof.go @@ -74,7 +74,6 @@ import "C" import ( "fmt" - "io/ioutil" "os" "runtime" "runtime/pprof" @@ -97,7 +96,7 @@ func CgoPprofThreadNoTraceback() { } func pprofThread() { - f, err := ioutil.TempFile("", "prof") + f, err := os.CreateTemp("", "prof") if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(2) diff --git a/src/runtime/testdata/testprogcgo/traceback.go b/src/runtime/testdata/testprogcgo/traceback.go index 2a023f66ca..e2d7599131 100644 --- a/src/runtime/testdata/testprogcgo/traceback.go +++ b/src/runtime/testdata/testprogcgo/traceback.go @@ -11,58 +11,11 @@ package main /* #cgo CFLAGS: -g -O0 -#include <stdint.h> - -char *p; - -static int f3(void) { - *p = 0; - return 0; -} - -static int f2(void) { - return f3(); -} - -static int f1(void) { - return f2(); -} - -struct cgoTracebackArg { - uintptr_t context; - uintptr_t sigContext; - uintptr_t* buf; - uintptr_t max; -}; - -struct cgoSymbolizerArg { - uintptr_t pc; - const char* file; - uintptr_t lineno; - const char* func; - uintptr_t entry; - uintptr_t more; - uintptr_t data; -}; - -void cgoTraceback(void* parg) { - struct cgoTracebackArg* arg = (struct cgoTracebackArg*)(parg); - arg->buf[0] = 1; - arg->buf[1] = 2; - arg->buf[2] = 3; - arg->buf[3] = 0; -} - -void cgoSymbolizer(void* parg) { - struct cgoSymbolizerArg* arg = (struct cgoSymbolizerArg*)(parg); - if (arg->pc != arg->data + 1) { - arg->file = "unexpected data"; - } else { - arg->file = "cgo symbolizer"; - } - arg->lineno = arg->data + 1; - arg->data++; -} +// Defined in traceback_c.c. +extern int crashInGo; +int tracebackF1(void); +void cgoTraceback(void* parg); +void cgoSymbolizer(void* parg); */ import "C" @@ -73,9 +26,29 @@ import ( func init() { register("CrashTraceback", CrashTraceback) + register("CrashTracebackGo", CrashTracebackGo) } func CrashTraceback() { runtime.SetCgoTraceback(0, unsafe.Pointer(C.cgoTraceback), nil, unsafe.Pointer(C.cgoSymbolizer)) - C.f1() + C.tracebackF1() +} + +func CrashTracebackGo() { + C.crashInGo = 1 + CrashTraceback() +} + +//export h1 +func h1() { + h2() +} + +func h2() { + h3() +} + +func h3() { + var x *int + *x = 0 } diff --git a/src/runtime/testdata/testprogcgo/traceback_c.c b/src/runtime/testdata/testprogcgo/traceback_c.c new file mode 100644 index 0000000000..56eda8fa8c --- /dev/null +++ b/src/runtime/testdata/testprogcgo/traceback_c.c @@ -0,0 +1,65 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// The C definitions for traceback.go. That file uses //export so +// it can't put function definitions in the "C" import comment. + +#include <stdint.h> + +char *p; + +int crashInGo; +extern void h1(void); + +int tracebackF3(void) { + if (crashInGo) + h1(); + else + *p = 0; + return 0; +} + +int tracebackF2(void) { + return tracebackF3(); +} + +int tracebackF1(void) { + return tracebackF2(); +} + +struct cgoTracebackArg { + uintptr_t context; + uintptr_t sigContext; + uintptr_t* buf; + uintptr_t max; +}; + +struct cgoSymbolizerArg { + uintptr_t pc; + const char* file; + uintptr_t lineno; + const char* func; + uintptr_t entry; + uintptr_t more; + uintptr_t data; +}; + +void cgoTraceback(void* parg) { + struct cgoTracebackArg* arg = (struct cgoTracebackArg*)(parg); + arg->buf[0] = 1; + arg->buf[1] = 2; + arg->buf[2] = 3; + arg->buf[3] = 0; +} + +void cgoSymbolizer(void* parg) { + struct cgoSymbolizerArg* arg = (struct cgoSymbolizerArg*)(parg); + if (arg->pc != arg->data + 1) { + arg->file = "unexpected data"; + } else { + arg->file = "cgo symbolizer"; + } + arg->lineno = arg->data + 1; + arg->data++; +} diff --git a/src/runtime/testdata/testwinsignal/main.go b/src/runtime/testdata/testwinsignal/main.go new file mode 100644 index 0000000000..d8cd884ffa --- /dev/null +++ b/src/runtime/testdata/testwinsignal/main.go @@ -0,0 +1,19 @@ +package main
+
+import (
+ "fmt"
+ "os"
+ "os/signal"
+ "time"
+)
+
+func main() {
+ c := make(chan os.Signal, 1)
+ signal.Notify(c)
+
+ fmt.Println("ready")
+ sig := <-c
+
+ time.Sleep(time.Second)
+ fmt.Println(sig)
+}
diff --git a/src/runtime/textflag.h b/src/runtime/textflag.h index daca36d948..e727208cd0 100644 --- a/src/runtime/textflag.h +++ b/src/runtime/textflag.h @@ -35,3 +35,5 @@ // Function is the top of the call stack. Call stack unwinders should stop // at this function. #define TOPFRAME 2048 +// Function is an ABI wrapper. +#define ABIWRAPPER 4096 diff --git a/src/runtime/time.go b/src/runtime/time.go index 75b66f8492..8ab2a03430 100644 --- a/src/runtime/time.go +++ b/src/runtime/time.go @@ -23,6 +23,8 @@ type timer struct { // Timer wakes up at when, and then at when+period, ... (period > 0 only) // each time calling f(arg, now) in the timer goroutine, so f must be // a well-behaved function and not block. + // + // when must be positive on an active timer. when int64 period int64 f func(interface{}, uintptr) @@ -185,6 +187,9 @@ func timeSleep(ns int64) { t.f = goroutineReady t.arg = gp t.nextwhen = nanotime() + ns + if t.nextwhen < 0 { // check for overflow. + t.nextwhen = maxWhen + } gopark(resetForSleep, unsafe.Pointer(t), waitReasonSleep, traceEvGoSleep, 1) } @@ -242,10 +247,14 @@ func goroutineReady(arg interface{}, seq uintptr) { // That avoids the risk of changing the when field of a timer in some P's heap, // which could cause the heap to become unsorted. func addtimer(t *timer) { - // when must never be negative; otherwise runtimer will overflow - // during its delta calculation and never expire other runtime timers. - if t.when < 0 { - t.when = maxWhen + // when must be positive. A negative value will cause runtimer to + // overflow during its delta calculation and never expire other runtime + // timers. Zero will cause checkTimers to fail to notice the timer. + if t.when <= 0 { + throw("timer when must be positive") + } + if t.period < 0 { + throw("timer period must be non-negative") } if t.status != timerNoStatus { throw("addtimer called with initialized timer") @@ -406,8 +415,11 @@ func dodeltimer0(pp *p) { // This is called by the netpoll code or time.Ticker.Reset or time.Timer.Reset. // Reports whether the timer was modified before it was run. func modtimer(t *timer, when, period int64, f func(interface{}, uintptr), arg interface{}, seq uintptr) bool { - if when < 0 { - when = maxWhen + if when <= 0 { + throw("timer when must be positive") + } + if period < 0 { + throw("timer period must be non-negative") } status := uint32(timerNoStatus) @@ -597,8 +609,14 @@ func moveTimers(pp *p, timers []*timer) { for { switch s := atomic.Load(&t.status); s { case timerWaiting: + if !atomic.Cas(&t.status, s, timerMoving) { + continue + } t.pp = 0 doaddtimer(pp, t) + if !atomic.Cas(&t.status, timerMoving, timerWaiting) { + badTimer() + } break loop case timerModifiedEarlier, timerModifiedLater: if !atomic.Cas(&t.status, s, timerMoving) { @@ -846,6 +864,9 @@ func runOneTimer(pp *p, t *timer, now int64) { // Leave in heap but adjust next time to fire. delta := t.when - now t.when += t.period * (1 + -delta/t.period) + if t.when < 0 { // check for overflow. + t.when = maxWhen + } siftdownTimer(pp.timers, 0) if !atomic.Cas(&t.status, timerRunning, timerWaiting) { badTimer() @@ -1064,6 +1085,9 @@ func siftupTimer(t []*timer, i int) { badTimer() } when := t[i].when + if when <= 0 { + badTimer() + } tmp := t[i] for i > 0 { p := (i - 1) / 4 // parent @@ -1084,6 +1108,9 @@ func siftdownTimer(t []*timer, i int) { badTimer() } when := t[i].when + if when <= 0 { + badTimer() + } tmp := t[i] for { c := i*4 + 1 // left child diff --git a/src/runtime/timestub2.go b/src/runtime/timestub2.go index 6d73aabc35..68777ee4a9 100644 --- a/src/runtime/timestub2.go +++ b/src/runtime/timestub2.go @@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !aix // +build !darwin -// +build !windows // +build !freebsd -// +build !aix +// +build !openbsd // +build !solaris +// +build !windows package runtime diff --git a/src/runtime/tls_arm64.s b/src/runtime/tls_arm64.s index 3f02974d5b..085012f791 100644 --- a/src/runtime/tls_arm64.s +++ b/src/runtime/tls_arm64.s @@ -10,9 +10,11 @@ TEXT runtime·load_g(SB),NOSPLIT,$0 #ifndef TLS_darwin +#ifndef GOOS_openbsd MOVB runtime·iscgo(SB), R0 CBZ R0, nocgo #endif +#endif MRS_TPIDR_R0 #ifdef TLS_darwin @@ -27,9 +29,11 @@ nocgo: TEXT runtime·save_g(SB),NOSPLIT,$0 #ifndef TLS_darwin +#ifndef GOOS_openbsd MOVB runtime·iscgo(SB), R0 CBZ R0, nocgo #endif +#endif MRS_TPIDR_R0 #ifdef TLS_darwin diff --git a/src/runtime/trace/trace_test.go b/src/runtime/trace/trace_test.go index 235845df4e..b316eafe4c 100644 --- a/src/runtime/trace/trace_test.go +++ b/src/runtime/trace/trace_test.go @@ -10,7 +10,6 @@ import ( "internal/race" "internal/trace" "io" - "io/ioutil" "net" "os" "runtime" @@ -586,7 +585,7 @@ func saveTrace(t *testing.T, buf *bytes.Buffer, name string) { if !*saveTraces { return } - if err := ioutil.WriteFile(name+".trace", buf.Bytes(), 0600); err != nil { + if err := os.WriteFile(name+".trace", buf.Bytes(), 0600); err != nil { t.Errorf("failed to write trace file: %s", err) } } diff --git a/src/runtime/traceback.go b/src/runtime/traceback.go index f3df152535..2601cd697f 100644 --- a/src/runtime/traceback.go +++ b/src/runtime/traceback.go @@ -396,13 +396,21 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in // If there is inlining info, print the inner frames. if inldata := funcdata(f, _FUNCDATA_InlTree); inldata != nil { inltree := (*[1 << 20]inlinedCall)(inldata) + var inlFunc _func + inlFuncInfo := funcInfo{&inlFunc, f.datap} for { ix := pcdatavalue(f, _PCDATA_InlTreeIndex, tracepc, nil) if ix < 0 { break } - if (flags&_TraceRuntimeFrames) != 0 || showframe(f, gp, nprint == 0, inltree[ix].funcID, lastFuncID) { - name := funcnameFromNameoff(f, inltree[ix].func_) + + // Create a fake _func for the + // inlined function. + inlFunc.nameoff = inltree[ix].func_ + inlFunc.funcID = inltree[ix].funcID + + if (flags&_TraceRuntimeFrames) != 0 || showframe(inlFuncInfo, gp, nprint == 0, inlFuncInfo.funcID, lastFuncID) { + name := funcname(inlFuncInfo) file, line := funcline(f, tracepc) print(name, "(...)\n") print("\t", file, ":", line, "\n") @@ -811,6 +819,9 @@ func showframe(f funcInfo, gp *g, firstFrame bool, funcID, childID funcID) bool // showfuncinfo reports whether a function with the given characteristics should // be printed during a traceback. func showfuncinfo(f funcInfo, firstFrame bool, funcID, childID funcID) bool { + // Note that f may be a synthesized funcInfo for an inlined + // function, in which case only nameoff and funcID are set. + level, _, _ := gotraceback() if level > 1 { // Show all frames. @@ -906,17 +917,25 @@ func tracebackothers(me *g) { level, _, _ := gotraceback() // Show the current goroutine first, if we haven't already. - g := getg() - gp := g.m.curg - if gp != nil && gp != me { + curgp := getg().m.curg + if curgp != nil && curgp != me { print("\n") - goroutineheader(gp) - traceback(^uintptr(0), ^uintptr(0), 0, gp) + goroutineheader(curgp) + traceback(^uintptr(0), ^uintptr(0), 0, curgp) } - lock(&allglock) - for _, gp := range allgs { - if gp == me || gp == g.m.curg || readgstatus(gp) == _Gdead || isSystemGoroutine(gp, false) && level < 2 { + // We can't take allglock here because this may be during fatal + // throw/panic, where locking allglock could be out-of-order or a + // direct deadlock. + // + // Instead, use atomic access to allgs which requires no locking. We + // don't lock against concurrent creation of new Gs, but even with + // allglock we may miss Gs created after this loop. + ptr, length := atomicAllG() + for i := uintptr(0); i < length; i++ { + gp := atomicAllGIndex(ptr, i) + + if gp == me || gp == curgp || readgstatus(gp) == _Gdead || isSystemGoroutine(gp, false) && level < 2 { continue } print("\n") @@ -925,14 +944,13 @@ func tracebackothers(me *g) { // called from a signal handler initiated during a // systemstack call. The original G is still in the // running state, and we want to print its stack. - if gp.m != g.m && readgstatus(gp)&^_Gscan == _Grunning { + if gp.m != getg().m && readgstatus(gp)&^_Gscan == _Grunning { print("\tgoroutine running on other thread; stack unavailable\n") printcreatedby(gp) } else { traceback(^uintptr(0), ^uintptr(0), 0, gp) } } - unlock(&allglock) } // tracebackHexdump hexdumps part of stk around frame.sp and frame.fp diff --git a/src/runtime/type.go b/src/runtime/type.go index 81455f3532..18fc4bbfad 100644 --- a/src/runtime/type.go +++ b/src/runtime/type.go @@ -383,7 +383,7 @@ type maptype struct { } // Note: flag values must match those used in the TMAP case -// in ../cmd/compile/internal/gc/reflect.go:dtypesym. +// in ../cmd/compile/internal/gc/reflect.go:writeType. func (mt *maptype) indirectkey() bool { // store ptr to key instead of key itself return mt.flags&1 != 0 } diff --git a/src/runtime/wincallback.go b/src/runtime/wincallback.go index c022916422..fb452222da 100644 --- a/src/runtime/wincallback.go +++ b/src/runtime/wincallback.go @@ -11,7 +11,6 @@ package main import ( "bytes" "fmt" - "io/ioutil" "os" ) @@ -38,7 +37,7 @@ TEXT runtime·callbackasm(SB),7,$0 } filename := fmt.Sprintf("zcallback_windows.s") - err := ioutil.WriteFile(filename, buf.Bytes(), 0666) + err := os.WriteFile(filename, buf.Bytes(), 0666) if err != nil { fmt.Fprintf(os.Stderr, "wincallback: %s\n", err) os.Exit(2) @@ -66,7 +65,7 @@ TEXT runtime·callbackasm(SB),NOSPLIT|NOFRAME,$0 buf.WriteString("\tB\truntime·callbackasm1(SB)\n") } - err := ioutil.WriteFile("zcallback_windows_arm.s", buf.Bytes(), 0666) + err := os.WriteFile("zcallback_windows_arm.s", buf.Bytes(), 0666) if err != nil { fmt.Fprintf(os.Stderr, "wincallback: %s\n", err) os.Exit(2) @@ -82,7 +81,7 @@ package runtime const cb_max = %d // maximum number of windows callbacks allowed `, maxCallback)) - err := ioutil.WriteFile("zcallback_windows.go", buf.Bytes(), 0666) + err := os.WriteFile("zcallback_windows.go", buf.Bytes(), 0666) if err != nil { fmt.Fprintf(os.Stderr, "wincallback: %s\n", err) os.Exit(2) |
