go/src/internal
Than McIntosh 39957b5d89 coverage: fix count vs emit discrepancy in coverage counter data writing
This patch revises the way coverage counter data writing takes place
to avoid problems where useful counter data (for user-written functions)
is skipped in favor of counter data from stdlib functions that are
executed "late in the game", during the counter writing process itself.

Reading counter values from a running "--coverpkg=all" program is an
inherently racy operation; while the the code that scans the coverage
counter segment is reading values, the program is still executing,
potentially updating those values, and updates can include execution
of previously un-executed functions. The existing counter data writing
code was using a two-pass model (initial sweep over the counter
segment to count live functions, second sweep to actually write data),
and wasn't properly accounting for the fact that the second pass could
see more functions than the first.

In the bug in question, the first pass discovered an initial set of
1240 functions, but by the time the second pass kicked in, several
additional new functions were also live. The second pass scanned the
counter segment again to write out exactly 1240 functions, but since
some of the counters for the newly executed functions were earlier in
the segment (due to linker layout quirks) than the user's selected
function, the sweep terminated before writing out counters for the
function of interest.

The fix rewrites the counter data file encoder to make a single sweep
over the counter segment instead of using a two-pass scheme.

Fixes #59563.

Change-Id: I5e908e226bb224adb90a2fb783013e52deb341da
Reviewed-on: https://go-review.googlesource.com/c/go/+/484535
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Than McIntosh <thanm@google.com>
2023-04-26 12:44:34 +00:00
..
abi runtime, cmd: rationalize StackLimit and StackGuard 2023-04-21 19:28:56 +00:00
buildcfg all: replace fmt.Sprintf("%d") with strconv.Itoa 2023-03-31 18:41:24 +00:00
bytealg cmd/internal/obj/ppc64: modify PCALIGN to ensure alignment 2023-04-21 16:47:45 +00:00
cfg cmd/go: change toolchain based on $GOTOOLCHAIN 2023-04-18 13:19:02 +00:00
coverage coverage: fix count vs emit discrepancy in coverage counter data writing 2023-04-26 12:44:34 +00:00
cpu internal/cpu: add a detection for Neoverse(N2, V2) cores 2023-04-25 14:08:20 +00:00
dag runtime: generate the lock ranking from a DAG description 2022-08-04 15:31:44 +00:00
diff all: gofmt main repo 2022-05-19 15:49:05 +00:00
fmtsort all: remove unnecessary allocations from w.WriteString(fmt.Sprint*(...)) by fmt.Fprint*(w, ...) 2022-09-14 16:11:21 +00:00
fuzz cmd/go: add check for unknown godebug setting 2023-04-18 13:19:19 +00:00
goarch internal/goarch, internal/goos: update generators for syslist.go 2022-06-15 21:31:23 +00:00
godebug cmd/go: add check for unknown godebug setting 2023-04-18 13:19:19 +00:00
godebugs src/internal/godebugs: add a skip for missing godebug.md 2023-04-18 16:58:25 +00:00
goexperiment cmd/compile: experimental loop iterator capture semantics change 2023-03-06 18:34:24 +00:00
goos all: add wasip1 definitions 2023-03-30 18:50:57 +00:00
goroot internal/testenv: avoid rebuilding all of std in WriteImportcfg 2023-02-02 19:27:33 +00:00
goversion internal/goversion: update Version to 1.21 2023-01-17 19:47:10 +00:00
intern cmd/go: add check for unknown godebug setting 2023-04-18 13:19:19 +00:00
itoa
lazyregexp
lazytemplate
nettrace all: gofmt main repo 2022-04-11 16:34:30 +00:00
obscuretestdata crypto/x509: allow BoringCrypto to use 4096-bit keys 2022-11-09 14:47:58 +00:00
oserror
pkgbits all: re-run stringer 2023-04-11 20:24:07 +00:00
platform cmd/dist: refactor generated cgo-support logic 2023-04-20 17:26:46 +00:00
poll internal/poll: add GetsockoptInt 2023-04-18 13:44:49 +00:00
profile internal/profile: use internal/lazyregexp for the legacy parser 2023-01-20 09:27:47 +00:00
race
reflectlite internal/reflectlite: use unsafe.String in name.name and name.tag 2022-11-10 18:42:48 +00:00
safefilepath internal/safefilepath: fix TestFromFS on Plan 9 2022-12-07 23:52:46 +00:00
saferio internal/saferio: handle potential total size overflow in SliceCap 2022-09-26 20:36:02 +00:00
singleflight internal/singleflight: move Done call in TestForgetUnshared 2023-03-29 22:21:50 +00:00
syscall runtime: filter i/o async entries using completion key on windows 2023-04-11 19:08:56 +00:00
sysinfo
testdir internal/testdir: simplify and clean up 2023-02-28 01:11:40 +00:00
testenv internal/testenv: actually try to exec on ios and wasm 2023-04-24 20:39:25 +00:00
testlog
testpty internal/testpty: fix error handling 2023-01-25 18:38:54 +00:00
trace runtime/trace: update outdated Task and Region documentation 2023-03-09 19:10:52 +00:00
txtar all: replace package ioutil with os and io in src 2022-09-20 02:13:02 +00:00
types go/types: add test case for CL 486398 2023-04-21 14:43:28 +00:00
unsafeheader
xcoff all: fix misuses of "a" vs "an" 2023-04-04 14:20:53 +00:00
zstd internal/zstd: new internal package for zstd decompression 2023-04-18 20:34:13 +00:00