]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/dwarf: always use AT_ranges for scopes with DWARF 5
authorThan McIntosh <thanm@golang.org>
Wed, 12 Mar 2025 18:08:21 +0000 (14:08 -0400)
committerThan McIntosh <thanm@golang.org>
Thu, 13 Mar 2025 12:16:59 +0000 (05:16 -0700)
This patch extends the change in CL 657175 to apply the same abbrev
selection strategy to single-range lexical scopes that we're now using
for inlined routine bodies, when DWARF 5 is in effect. Ranges are more
compact and use fewer relocation than explicit hi/lo PC values, so we
might as well always use them.

Updates #26379.

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

index 7673c3f6ba43c4c50838239140a6a443fc16427e..6e06f139b03d31f06e96784a1aabe57968d34cab 100644 (file)
@@ -600,12 +600,8 @@ var abbrevs = []dwAbbrev{
                DW_TAG_lexical_block,
                DW_CHILDREN_yes,
                []dwAttrForm{
-                       // Note: we can't take advantage of DW_FORM_addrx here,
-                       // since there is no way (at least at the moment) to
-                       // have an encoding for low_pc of the form "addrx + constant"
-                       // in DWARF5. If we wanted to use addrx, we'd need to create
-                       // a whole new entry in .debug_addr for the block start,
-                       // which would kind of defeat the point.
+                       // Note: unused if we are generating DWARF 5, we
+                       // use the ranges form even if there is a singleton range.
                        {DW_AT_low_pc, DW_FORM_addr},
                        {DW_AT_high_pc, DW_FORM_addr},
                },
@@ -1526,7 +1522,10 @@ func putscope(ctxt Context, s *FnState, scopes []Scope, curscope int32, fnabbrev
                        continue
                }
 
-               if len(scope.Ranges) == 1 {
+               // 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.
+               if len(scope.Ranges) == 1 && !buildcfg.Experiment.Dwarf5 {
                        Uleb128put(ctxt, s.Info, DW_ABRV_LEXICAL_BLOCK_SIMPLE)
                        putattr(ctxt, s.Info, DW_ABRV_LEXICAL_BLOCK_SIMPLE, DW_FORM_addr, DW_CLS_ADDRESS, scope.Ranges[0].Start, s.StartPC)
                        putattr(ctxt, s.Info, DW_ABRV_LEXICAL_BLOCK_SIMPLE, DW_FORM_addr, DW_CLS_ADDRESS, scope.Ranges[0].End, s.StartPC)