diff options
| author | David Chase <drchase@google.com> | 2023-05-09 15:03:48 -0400 |
|---|---|---|
| committer | David Chase <drchase@google.com> | 2023-05-09 19:55:24 +0000 |
| commit | 841e99e2830bfdcfcf76accd2b02e0d5dc2ea3e1 (patch) | |
| tree | 55aca90ed0490bc06aefc29d29dd99b9f4e5b54c | |
| parent | fffddce55c8acdf8a834f064f7e8fab9880ecf08 (diff) | |
| download | go-841e99e2830bfdcfcf76accd2b02e0d5dc2ea3e1.tar.xz | |
internal/bisect: adjust stack PCs relative to Callers[2]
This is necessary to make hashes be consistent across runs,
otherwise ASLR messes up search.
Change-Id: Icf668dfe4c2008709f7767397b6700d0d5439287
Reviewed-on: https://go-review.googlesource.com/c/go/+/493857
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: David Chase <drchase@google.com>
| -rw-r--r-- | src/internal/bisect/bisect.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/internal/bisect/bisect.go b/src/internal/bisect/bisect.go index 1a3658a238..21e825eab9 100644 --- a/src/internal/bisect/bisect.go +++ b/src/internal/bisect/bisect.go @@ -412,11 +412,18 @@ func (m *Matcher) Stack(w Writer) bool { func (m *Matcher) stack(w Writer) bool { const maxStack = 16 var stk [maxStack]uintptr - n := runtime.Callers(3, stk[:]) - if n == 0 { + n := runtime.Callers(2, stk[:]) + // caller #2 is not for printing; need it to normalize PCs if ASLR. + if n <= 1 { return false } + base := stk[0] + // normalize PCs + for i := range stk[:n] { + stk[i] -= base + } + h := Hash(stk[:n]) if m.ShouldPrint(h) { var d *dedup @@ -437,7 +444,11 @@ func (m *Matcher) stack(w Writer) bool { } } else { if !d.seen(h) { - printStack(w, h, stk[:n]) + // Restore PCs in stack for printing + for i := range stk[:n] { + stk[i] += base + } + printStack(w, h, stk[1:n]) } } } |
