runtime: support valgrind (but not asan) in specialized malloc functions

We're adding this so that the compiler doesn't need to know about
valgrind since it's just implemented using a build tag.

Change-Id: I6a6a696452b0379caceca2ae4e49195016f7a90d
Reviewed-on: https://go-review.googlesource.com/c/go/+/708296
Reviewed-by: Michael Matloob <matloob@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Matloob <matloob@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
matloob 2025-10-01 12:06:14 -04:00 committed by Gopher Robot
parent a7917eed70
commit c54dc1418b
2 changed files with 333 additions and 0 deletions

View file

@ -50,6 +50,8 @@ func mallocPanic(size uintptr, typ *_type, needzero bool) unsafe.Pointer {
panic("not defined for sizeclass")
}
// WARNING: mallocStub does not do any work for sanitizers so callers need
// to steer out of this codepath early if sanitizers are enabled.
func mallocStub(size uintptr, typ *_type, needzero bool) unsafe.Pointer {
if doubleCheckMalloc {
if gcphase == _GCmarktermination {
@ -77,6 +79,13 @@ func mallocStub(size uintptr, typ *_type, needzero bool) unsafe.Pointer {
// Actually do the allocation.
x, elemsize := inlinedMalloc(size, typ, needzero)
// Notify valgrind, if enabled.
// To allow the compiler to not know about valgrind, we do valgrind instrumentation
// unlike the other sanitizers.
if valgrindenabled {
valgrindMalloc(x, size)
}
// Adjust our GC assist debt to account for internal fragmentation.
if gcBlackenEnabled != 0 && elemsize != 0 {
if assistG := getg().m.curg; assistG != nil {