[go] cmd/pprof: respect symbol boundaries during Disasm

7 views
Skip to first unread message

Egon Elbre (Gerrit)

unread,
Jul 19, 2025, 11:36:22 AMJul 19
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Egon Elbre has uploaded the change for review

Commit message

cmd/pprof: respect symbol boundaries during Disasm

When the profile contains locations that incorrectly computed the
disasm would leav to invalid decoding of instructions.
This change ensures that we start decoding from a known location.

Updates #74610
Change-Id: Ic70abff63f1f99f14c4b84a83dfbdbf944517428

Change diff

diff --git a/src/cmd/internal/disasm/disasm.go b/src/cmd/internal/disasm/disasm.go
index 3ae8989..1ee5f48 100644
--- a/src/cmd/internal/disasm/disasm.go
+++ b/src/cmd/internal/disasm/disasm.go
@@ -15,6 +15,7 @@
"encoding/binary"
"fmt"
"io"
+ "iter"
"os"
"path/filepath"
"regexp"
@@ -194,6 +195,29 @@
return cf.Lines[line-1], nil
}

+// TextSyms returns text symbols that overlap the specified range.
+func (d *Disasm) TextSyms(start, end uint64) iter.Seq[objfile.Sym] {
+ if start < d.textStart {
+ start = d.textStart
+ }
+ if end > d.textEnd {
+ end = d.textEnd
+ }
+
+ return func(yield func(objfile.Sym) bool) {
+ for _, sym := range d.syms {
+ symStart := sym.Addr
+ symEnd := sym.Addr + uint64(sym.Size)
+ if sym.Code != 'T' && sym.Code != 't' ||
+ symStart < d.textStart ||
+ symEnd <= start || end <= symStart {
+ continue
+ }
+ yield(sym)
+ }
+ }
+}
+
// Print prints a disassembly of the file to w.
// If filter is non-nil, the disassembly only includes functions with names matching filter.
// If printCode is true, the disassembly includes corresponding source lines.
diff --git a/src/cmd/pprof/pprof.go b/src/cmd/pprof/pprof.go
index bfc2911..474a50c 100644
--- a/src/cmd/pprof/pprof.go
+++ b/src/cmd/pprof/pprof.go
@@ -196,10 +196,17 @@
if err != nil {
return nil, err
}
+
var asm []driver.Inst
- d.Decode(start, end, nil, false, func(pc, size uint64, file string, line int, text string) {
- asm = append(asm, driver.Inst{Addr: pc, File: file, Line: line, Text: text})
- })
+ for sym := range d.TextSyms(start, end) {
+ symStart := sym.Addr
+ symEnd := sym.Addr + uint64(sym.Size)
+ symEnd = min(symEnd, end)
+ d.Decode(symStart, symEnd, sym.Relocs, false, func(pc, size uint64, file string, line int, text string) {
+ asm = append(asm, driver.Inst{Addr: pc, File: file, Line: line, Text: text})
+ })
+ }
+
return asm, nil
}

Change information

Files:
  • M src/cmd/internal/disasm/disasm.go
  • M src/cmd/pprof/pprof.go
Change size: S
Delta: 2 files changed, 34 insertions(+), 3 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ic70abff63f1f99f14c4b84a83dfbdbf944517428
Gerrit-Change-Number: 688955
Gerrit-PatchSet: 1
Gerrit-Owner: Egon Elbre <egon...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Egon Elbre (Gerrit)

unread,
Jul 19, 2025, 12:11:04 PMJul 19
to goph...@pubsubhelper.golang.org, Cherry Mui, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Cherry Mui

Egon Elbre added 1 comment

File src/cmd/pprof/pprof.go
Line 201, Patchset 1 (Latest): for sym := range d.TextSyms(start, end) {
Egon Elbre . unresolved

I'm not sure how often Disasm is called and whether this iteration would cause a performance regression for some use cases.

Open in Gerrit

Related details

Attention is currently required from:
  • Cherry Mui
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ic70abff63f1f99f14c4b84a83dfbdbf944517428
    Gerrit-Change-Number: 688955
    Gerrit-PatchSet: 1
    Gerrit-Owner: Egon Elbre <egon...@gmail.com>
    Gerrit-Reviewer: Cherry Mui <cher...@google.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Cherry Mui <cher...@google.com>
    Gerrit-Comment-Date: Sat, 19 Jul 2025 16:10:55 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    t hepudds (Gerrit)

    unread,
    Jul 19, 2025, 12:20:54 PMJul 19
    to Egon Elbre, goph...@pubsubhelper.golang.org, Cherry Mui, Gopher Robot, golang-co...@googlegroups.com
    Attention needed from Cherry Mui and Egon Elbre

    t hepudds voted Commit-Queue+1

    Commit-Queue+1
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Cherry Mui
    • Egon Elbre
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ic70abff63f1f99f14c4b84a83dfbdbf944517428
    Gerrit-Change-Number: 688955
    Gerrit-PatchSet: 1
    Gerrit-Owner: Egon Elbre <egon...@gmail.com>
    Gerrit-Reviewer: Cherry Mui <cher...@google.com>
    Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Egon Elbre <egon...@gmail.com>
    Gerrit-Attention: Cherry Mui <cher...@google.com>
    Gerrit-Comment-Date: Sat, 19 Jul 2025 16:20:49 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    open
    diffy

    Egon Elbre (Gerrit)

    unread,
    Jul 19, 2025, 1:20:46 PMJul 19
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Cherry Mui and Egon Elbre

    Egon Elbre uploaded new patchset

    Egon Elbre uploaded patch set #2 to this change.
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Cherry Mui
    • Egon Elbre
    Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newpatchset
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ic70abff63f1f99f14c4b84a83dfbdbf944517428
      Gerrit-Change-Number: 688955
      Gerrit-PatchSet: 2
      Gerrit-Owner: Egon Elbre <egon...@gmail.com>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy

      Egon Elbre (Gerrit)

      unread,
      Jul 20, 2025, 6:59:10 AMJul 20
      to goph...@pubsubhelper.golang.org, Go LUCI, t hepudds, Cherry Mui, Gopher Robot, golang-co...@googlegroups.com
      Attention needed from Cherry Mui

      Egon Elbre added 1 comment

      File src/cmd/pprof/pprof.go
      Line 201, Patchset 1: for sym := range d.TextSyms(start, end) {
      Egon Elbre . resolved

      I'm not sure how often Disasm is called and whether this iteration would cause a performance regression for some use cases.

      Egon Elbre

      After thinking about, this overhead should not be a problem, because in https://github.com/google/pprof/blob/6e76a2b096b5fa52e4bb3f7f7a357bd6e6b3b7b1/internal/binutils/binutils.go#L259 it actually invokes a command which would be a significant overhead.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Cherry Mui
      Submit Requirements:
        • requirement is not satisfiedCode-Review
        • requirement satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        • requirement satisfiedTryBots-Pass
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: Ic70abff63f1f99f14c4b84a83dfbdbf944517428
        Gerrit-Change-Number: 688955
        Gerrit-PatchSet: 2
        Gerrit-Owner: Egon Elbre <egon...@gmail.com>
        Gerrit-Reviewer: Cherry Mui <cher...@google.com>
        Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
        Gerrit-CC: Gopher Robot <go...@golang.org>
        Gerrit-Attention: Cherry Mui <cher...@google.com>
        Gerrit-Comment-Date: Sun, 20 Jul 2025 10:59:01 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        Comment-In-Reply-To: Egon Elbre <egon...@gmail.com>
        unsatisfied_requirement
        satisfied_requirement
        open
        diffy

        Egon Elbre (Gerrit)

        unread,
        Oct 1, 2025, 8:54:05 AM (19 hours ago) Oct 1
        to goph...@pubsubhelper.golang.org, Michael Pratt, Go LUCI, t hepudds, Cherry Mui, Gopher Robot, golang-co...@googlegroups.com
        Attention needed from Cherry Mui and Michael Pratt

        Egon Elbre added 1 comment

        Patchset-level comments
        File-level comment, Patchset 2 (Latest):
        Egon Elbre . resolved

        gentle ping for a review

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Cherry Mui
        • Michael Pratt
        Submit Requirements:
        • requirement is not satisfiedCode-Review
        • requirement satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        • requirement satisfiedTryBots-Pass
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: Ic70abff63f1f99f14c4b84a83dfbdbf944517428
        Gerrit-Change-Number: 688955
        Gerrit-PatchSet: 2
        Gerrit-Owner: Egon Elbre <egon...@gmail.com>
        Gerrit-Reviewer: Cherry Mui <cher...@google.com>
        Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
        Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
        Gerrit-CC: Gopher Robot <go...@golang.org>
        Gerrit-Attention: Cherry Mui <cher...@google.com>
        Gerrit-Attention: Michael Pratt <mpr...@google.com>
        Gerrit-Comment-Date: Wed, 01 Oct 2025 12:53:57 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        unsatisfied_requirement
        satisfied_requirement
        open
        diffy

        Cherry Mui (Gerrit)

        unread,
        Oct 1, 2025, 2:31:29 PM (14 hours ago) Oct 1
        to Egon Elbre, goph...@pubsubhelper.golang.org, Michael Pratt, Go LUCI, t hepudds, Gopher Robot, golang-co...@googlegroups.com
        Attention needed from Egon Elbre and Michael Pratt

        Cherry Mui added 1 comment

        Patchset-level comments
        Cherry Mui . unresolved

        This is trying to improve the handling of invalid PCs. There is still a question on the necessity of this. Where do the invalid PCs come from? If the profile is just bad, even we disassemble them correctly it may not actually help, like, is it the right place that the CPU time actually spent?

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Egon Elbre
        • Michael Pratt
        Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: Ic70abff63f1f99f14c4b84a83dfbdbf944517428
          Gerrit-Change-Number: 688955
          Gerrit-PatchSet: 2
          Gerrit-Owner: Egon Elbre <egon...@gmail.com>
          Gerrit-Reviewer: Cherry Mui <cher...@google.com>
          Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
          Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
          Gerrit-CC: Gopher Robot <go...@golang.org>
          Gerrit-Attention: Egon Elbre <egon...@gmail.com>
          Gerrit-Attention: Michael Pratt <mpr...@google.com>
          Gerrit-Comment-Date: Wed, 01 Oct 2025 18:31:26 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: No
          unsatisfied_requirement
          satisfied_requirement
          open
          diffy

          Egon Elbre (Gerrit)

          unread,
          Oct 1, 2025, 5:41:13 PM (11 hours ago) Oct 1
          to goph...@pubsubhelper.golang.org, Michael Pratt, Go LUCI, t hepudds, Cherry Mui, Gopher Robot, golang-co...@googlegroups.com
          Attention needed from Cherry Mui and Michael Pratt

          Egon Elbre added 1 comment

          Patchset-level comments
          Cherry Mui . unresolved

          This is trying to improve the handling of invalid PCs. There is still a question on the necessity of this. Where do the invalid PCs come from? If the profile is just bad, even we disassemble them correctly it may not actually help, like, is it the right place that the CPU time actually spent?

          Egon Elbre

          I agree that this doesn't fix the invalid PC issue and there's still investigation needed on that front.

          However, it does make Disasm func behavior similar to other command line tools used by pprof. From what I can tell gcc objdump, llvm objdump and go tool objdump all do this PC "fixup" to decode.

          For the invalid PC-s, I'm not certain, but it did seem to me like some sort of "off by few bytes" issue. So, even if the profile PCs are wrong, they should be close to the actual corresponding line and still show useful information. So the profile will be still somewhat bad, but at least the disassembly will be correct. Whether this is improvement is worth the cost, I'm not certain, but I'm leaning towards yes... however, I can also see the other side of the argument.

          Open in Gerrit

          Related details

          Attention is currently required from:
          • Cherry Mui
          • Michael Pratt
          Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: Ic70abff63f1f99f14c4b84a83dfbdbf944517428
          Gerrit-Change-Number: 688955
          Gerrit-PatchSet: 2
          Gerrit-Owner: Egon Elbre <egon...@gmail.com>
          Gerrit-Reviewer: Cherry Mui <cher...@google.com>
          Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
          Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
          Gerrit-CC: Gopher Robot <go...@golang.org>
          Gerrit-Attention: Cherry Mui <cher...@google.com>
          Gerrit-Attention: Michael Pratt <mpr...@google.com>
          Gerrit-Comment-Date: Wed, 01 Oct 2025 21:41:04 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: No
          Comment-In-Reply-To: Cherry Mui <cher...@google.com>
          unsatisfied_requirement
          satisfied_requirement
          open
          diffy
          Reply all
          Reply to author
          Forward
          0 new messages