go/src/cmd/link
Cherry Mui 82c14346d8 cmd/link: don't disable memory profiling when pprof.WriteHeapProfile is used
We have an optimization that if the memory profile is not consumed
anywhere, we set the memory profiling rate to 0 to disable the
"background" low-rate profiling. We detect whether the memory
profile is used by checking whether the runtime.MemProfile function
is reachable at link time. Previously, all APIs that access the
memory profile go through runtime.MemProfile. But the code was
refactored in CL 572396, and now the legacy entry point
WriteHeapProfile uses pprof_memProfileInternal without going
through runtime.MemProfile. In fact, even with the recommended
runtime/pprof.Profile API (pprof.Lookup or pprof.Profiles),
runtime.MemProfile is only (happen to be) reachable through
countHeap.

Change the linker to check runtime.memProfileInternal instead,
which is on all code paths that retrieve the memory profile. Add
a test case for WriteHeapProfile, so we cover all entry points.

Fixes #68136.

Change-Id: I075c8d45c95c81825a1822f032e23107aea4303c
Reviewed-on: https://go-review.googlesource.com/c/go/+/596538
Reviewed-by: Than McIntosh <thanm@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-07-03 22:43:11 +00:00
..
internal cmd/link: don't disable memory profiling when pprof.WriteHeapProfile is used 2024-07-03 22:43:11 +00:00
testdata all: add push linknames to allow legacy pull linknames 2024-05-17 16:48:00 +00:00
cgo_test.go cmd/link: use only the configured C compiler in TestCGOLTO 2023-03-09 22:13:02 +00:00
doc.go cmd/link: document -checklinkname option 2024-07-03 00:14:52 +00:00
dwarf_test.go cmd/compile,cmd/link: skip tests that require DWARF symbols on ios 2023-05-03 17:05:14 +00:00
elf_test.go cmd/link: allow deriving GNU build ID from Go build ID ID 2023-09-18 16:34:01 +00:00
link_test.go cmd/link: print the seed in TestRandLayout 2024-05-24 20:26:02 +00:00
linkbig_test.go cmd/link: use testenv.Command instead of exec.Command in tests 2022-11-15 20:22:14 +00:00
main.go cmd/link: support linker for linux/loong64 2022-05-17 17:54:33 +00:00