Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: .closureptr elided in optimized binaries #69307

Open
aarzilli opened this issue Sep 6, 2024 · 3 comments
Open

cmd/compile: .closureptr elided in optimized binaries #69307

aarzilli opened this issue Sep 6, 2024 · 3 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@aarzilli
Copy link
Contributor

aarzilli commented Sep 6, 2024

$ go version
go version go1.23.0 linux/amd64

(also reproduces on tip)

Given this sample program using range-over-func the DIE emitted for main.PrintAllElements[go.shape.string]-range1 when optimizations are enabled is:

 <1><216c>: Abbrev Number: 3 (DW_TAG_subprogram)
    <216d>   DW_AT_name        : main.PrintAllElements[go.shape.string]-range1
    <219b>   DW_AT_low_pc      : 0x48f520
    <21a3>   DW_AT_high_pc     : 0x48f605
    <21ab>   DW_AT_frame_base  : 1 byte block: 9c       (DW_OP_call_frame_cfa)
    <21ad>   DW_AT_decl_file   : 0x2
    <21b1>   DW_AT_decl_line   : 47
    <21b2>   DW_AT_external    : 1
 <2><21b3>: Abbrev Number: 31 (DW_TAG_typedef)
    <21b4>   DW_AT_name        : .param3
    <21bc>   DW_AT_type        : <0x27e86>
    <21c0>   Unknown AT value: 2906: 3
 <2><21c1>: Abbrev Number: 44 (DW_TAG_formal_parameter)
    <21c2>   DW_AT_name        : v
    <21c4>   DW_AT_variable_parameter: 0
    <21c5>   DW_AT_decl_line   : 47
    <21c6>   DW_AT_type        : <0x21b3>
    <21ca>   DW_AT_location    : 0x1799 (location list)
 <2><21ce>: Abbrev Number: 9 (DW_TAG_inlined_subroutine)
    <21cf>   DW_AT_abstract_origin: <0x1e48>
    <21d3>   DW_AT_ranges      : 0x980
    <21d7>   DW_AT_call_file   : 0x2
    <21db>   DW_AT_call_line   : 49
 <3><21dc>: Abbrev Number: 41 (DW_TAG_formal_parameter)
    <21dd>   DW_AT_abstract_origin: <0x1e59>
    <21e1>   DW_AT_location    : 0 byte block:  ()
 <3><21e2>: Abbrev Number: 0
 <2><21e3>: Abbrev Number: 0

No entries for .closureptr are generated, presumably because all the stores related to .closureptr are optimized away.

Originally reported as go-delve/delve#3806 (where it triggers other related delve bugs).

We could also say that with optimized binaries we do not correlate closure bodies with their parent in the debugger, or that we do a best effort thing and occasionally get it wrong (I suspect actually keeping track of .closureptr could have negative performance effects).

cc @dr2chase

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Sep 6, 2024
@cuonglm
Copy link
Member

cuonglm commented Sep 6, 2024

Maybe related #67918

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 6, 2024
@dmitshur dmitshur added this to the Backlog milestone Sep 6, 2024
@dr2chase
Copy link
Contributor

This is going to be a problem, because in at least one optimized binary where the closureptr is NOT elided, it causes reduced performance compared to foreach call of a plain closure. I'd actually like to get rid of it in optimized binaries completely; I'm not sure what's the best path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Development

No branches or pull requests

6 participants