]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/dwarf: fix bug in inlined func DIE range DWARF 5 info
authorThan McIntosh <thanm@golang.org>
Wed, 12 Mar 2025 16:05:11 +0000 (12:05 -0400)
committerThan McIntosh <thanm@golang.org>
Wed, 12 Mar 2025 17:15:52 +0000 (10:15 -0700)
This patch changes the strategy we use in the compiler for handling
range information for inlined subroutine bodies, fixing a bug in how
this was handled for DWARF 5.  The high and lo PC values being emitted
for DW_TAG_inlined_subroutine DIEs were incorrect, pointing to the
start of functions instead of the proper location. The fix in this
patch is to move to unconditionally using 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.

Updates #26379.
Fixes #72821.

Change-Id: Ifb65ecc6221601bad2ca3939f9b69964c1fafc7c
Reviewed-on: https://go-review.googlesource.com/c/go/+/657175
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alessandro Arzilli <alessandro.arzilli@gmail.com>
src/cmd/internal/dwarf/dwarf.go

index 88dac10c1b74eaa525d85832bd8677fa64b3ca4a..7673c3f6ba43c4c50838239140a6a443fc16427e 100644 (file)
@@ -1295,8 +1295,11 @@ func putInlinedFunc(ctxt Context, s *FnState, callIdx int) error {
        ic := s.InlCalls.Calls[callIdx]
        callee := ic.AbsFunSym
 
+       // For DWARF 5, we always use the ranges form of the abbrev, since
+       // it is more compact than using explicit hi/lo PC attrs.  See
+       // issue #72821 for more on why this makes sense.
        abbrev := DW_ABRV_INLINED_SUBROUTINE_RANGES
-       if len(ic.Ranges) == 1 {
+       if len(ic.Ranges) == 1 && !buildcfg.Experiment.Dwarf5 {
                abbrev = DW_ABRV_INLINED_SUBROUTINE
        }
        Uleb128put(ctxt, s.Info, int64(abbrev))