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: bad inlining informations in debug_info with DWARFv5 on tip #72821

Closed
aarzilli opened this issue Mar 12, 2025 · 6 comments
Closed
Assignees
Labels
BugReport Issues describing a possible bug in the Go implementation. compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@aarzilli
Copy link
Contributor

aarzilli commented Mar 12, 2025

$ go version
go version devel go1.25-644b984027 Tue Mar 11 20:17:59 2025 -0700 linux/amd64

When compiling a simple hello world program the DIE for runtime.main contains the following inlined subroutine entry:

 <2><4bdb7>: Abbrev Number: 8 (DW_TAG_inlined_subroutine)
    <4bdb8>   DW_AT_abstract_origin: <0x26002>
    <4bdbc>   DW_AT_low_pc      : (index: 0x21f): 0x439700
    <4bdbe>   DW_AT_high_pc     : 657
    <4bdc0>   DW_AT_call_file   : 0x28
    <4bdc4>   DW_AT_call_line   : 309

The abstract origin is:

 <1><26002>: Abbrev Number: 5 (DW_TAG_subprogram)
    <26003>   DW_AT_name        : internal/runtime/atomic.(*Uint32).Load
    <2602a>   DW_AT_inline      : 1     (inlined)
    <2602b>   DW_AT_decl_line   : 193
    <2602d>   DW_AT_external    : 1

but according to the inlined subroutine entry this inlining is 657 bytes long and starts at the entry point of runtime.main (neither sounds plausible for atomic.Load).

Calling dwarf.(*Data).Ranges on the same entry returns the same values, so this shouldn't be an GNU objdump bug.

cc @thanm

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Mar 12, 2025
@prattmic
Copy link
Member

cc @golang/compiler

@prattmic prattmic added this to the Go1.25 milestone Mar 12, 2025
@cherrymui
Copy link
Member

cc @thanm

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Mar 12, 2025
@thanm
Copy link
Contributor

thanm commented Mar 12, 2025

Thanks. I see the problem -- fix en route.

@thanm thanm self-assigned this Mar 12, 2025
@thanm
Copy link
Contributor

thanm commented Mar 12, 2025

What's happening in this bug is that we're trying to emit the hi/lo PC values for a given inlined func using FORM_addrx for lo and offset for hi, which is a non-starter, since FORM_addrx at the moment can only be used for addresses corresponding to the start of a func, not the middle of a function.

I am going to fix this bug by changing the compiler to unconditionally use DW_AT_ranges for inlined subroutines, even those with only a single range.

Background: prior to this point, if a given inlined function body had a single contiguous range, we'd pick an abbrev entry for it with explicit DW_AT_low_pc and DW_AT_high_pc attributes. If the extent of the code for the inlined body was not contiguous (which can happen), we'd select an abbrev that used a DW_AT_ranges attribute instead. This strategy (preferring explicit hi/lo PC attrs for a single-range func) made sense for DWARF 4, since in DWARF 4 the representation used in the .debug_ranges section was especially heavyweight (lots of space, lots of relocations), so having explicit hi/lo PC attrs was less expensive.

With DWARF 5, range info is written to the .debug_rnglists section, and the representation here is much more compact. Specifically, a single hi/lo range can be represented using a base address in addrx format (max of 4 bytes, but more likely 2 or 3) followed by start and endpoints of the range in ULEB128 format. This combination is more compact spacewise than the explicit hi/lo values, and has fewer relocations (0 as opposed to 2).

Note: we should at some point consider applying this same strategy to lexical scopes, since we can probably reap some of the same benefits there as well.

@aarzilli please weigh in if you can see any issues with moving in this direction.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/657175 mentions this issue: cmd/internal/dwarf: fix bug in inlined func DIE range DWARF 5 info

@dmitshur dmitshur added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

7 participants