Skip to content

Commit bdfa604

Browse files
committed
cmd/internal/dwarf: always use AT_ranges for scopes with DWARF 5
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 <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent d7f5883 commit bdfa604

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/cmd/internal/dwarf/dwarf.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -600,12 +600,8 @@ var abbrevs = []dwAbbrev{
600600
DW_TAG_lexical_block,
601601
DW_CHILDREN_yes,
602602
[]dwAttrForm{
603-
// Note: we can't take advantage of DW_FORM_addrx here,
604-
// since there is no way (at least at the moment) to
605-
// have an encoding for low_pc of the form "addrx + constant"
606-
// in DWARF5. If we wanted to use addrx, we'd need to create
607-
// a whole new entry in .debug_addr for the block start,
608-
// which would kind of defeat the point.
603+
// Note: unused if we are generating DWARF 5, we
604+
// use the ranges form even if there is a singleton range.
609605
{DW_AT_low_pc, DW_FORM_addr},
610606
{DW_AT_high_pc, DW_FORM_addr},
611607
},
@@ -1526,7 +1522,10 @@ func putscope(ctxt Context, s *FnState, scopes []Scope, curscope int32, fnabbrev
15261522
continue
15271523
}
15281524

1529-
if len(scope.Ranges) == 1 {
1525+
// For DWARF 5, we always use the ranges form of the abbrev, since
1526+
// it is more compact than using explicit hi/lo PC attrs. See
1527+
// issue #72821 for more on why this makes sense.
1528+
if len(scope.Ranges) == 1 && !buildcfg.Experiment.Dwarf5 {
15301529
Uleb128put(ctxt, s.Info, DW_ABRV_LEXICAL_BLOCK_SIMPLE)
15311530
putattr(ctxt, s.Info, DW_ABRV_LEXICAL_BLOCK_SIMPLE, DW_FORM_addr, DW_CLS_ADDRESS, scope.Ranges[0].Start, s.StartPC)
15321531
putattr(ctxt, s.Info, DW_ABRV_LEXICAL_BLOCK_SIMPLE, DW_FORM_addr, DW_CLS_ADDRESS, scope.Ranges[0].End, s.StartPC)

0 commit comments

Comments
 (0)