From 31ddd8a39d802c073c2bcf4b1f4e74f851fa80c4 Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Tue, 4 Jul 2017 08:32:02 +0200 Subject: [PATCH] cmd/compile: more compact DWARF location for locals and arguments Now that all functions have a DW_AT_frame_base defined we can use DW_OP_fbreg to specify the location of variables and formal parameters, instead of the DW_OP_call_frame_cfa/DW_OP_consts/DW_OP_plus, saving 2 bytes for every variable and 2 bytes for every formal parameter after the first one. Change-Id: I2c7395b67e4a814a0131ab1520df11ca48ff9327 Reviewed-on: https://go-review.googlesource.com/60550 Run-TryBot: Heschi Kreinick TryBot-Result: Gobot Gobot Reviewed-by: Heschi Kreinick --- src/cmd/internal/dwarf/dwarf.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/cmd/internal/dwarf/dwarf.go b/src/cmd/internal/dwarf/dwarf.go index 4beb8c4c61..e963f99e51 100644 --- a/src/cmd/internal/dwarf/dwarf.go +++ b/src/cmd/internal/dwarf/dwarf.go @@ -804,12 +804,14 @@ func putvar(ctxt Context, info, loc Sym, v *Var, startPC Sym, encbuf []byte) { putattr(ctxt, info, v.Abbrev, DW_FORM_sec_offset, DW_CLS_PTR, int64(loc.Len()), loc) addLocList(ctxt, loc, startPC, v, encbuf) } else { - loc := append(encbuf[:0], DW_OP_call_frame_cfa) - if v.StackOffset != 0 { - loc = append(loc, DW_OP_consts) + loc := encbuf[:0] + if v.StackOffset == 0 { + loc = append(loc, DW_OP_call_frame_cfa) + } else { + loc = append(loc, DW_OP_fbreg) loc = AppendSleb128(loc, int64(v.StackOffset)) - loc = append(loc, DW_OP_plus) } + putattr(ctxt, info, v.Abbrev, DW_FORM_block1, DW_CLS_BLOCK, int64(len(loc)), loc) } putattr(ctxt, info, v.Abbrev, DW_FORM_ref_addr, DW_CLS_REFERENCE, 0, v.Type) @@ -826,8 +828,12 @@ func addLocList(ctxt Context, listSym, startPC Sym, v *Var, encbuf []byte) { for _, piece := range entry.Pieces { if !piece.Missing { if piece.OnStack { - locBuf = append(locBuf, DW_OP_fbreg) - locBuf = AppendSleb128(locBuf, int64(piece.StackOffset)) + if piece.StackOffset == 0 { + locBuf = append(locBuf, DW_OP_call_frame_cfa) + } else { + locBuf = append(locBuf, DW_OP_fbreg) + locBuf = AppendSleb128(locBuf, int64(piece.StackOffset)) + } } else { if piece.RegNum < 32 { locBuf = append(locBuf, DW_OP_reg0+byte(piece.RegNum)) -- 2.50.0