Commit b74f01d7 authored by Heschi Kreinick's avatar Heschi Kreinick

cmd/internal/dwarf: update to DWARF4, emit frame_base

In preparation for CL 41770, upgrade .debug_info to DWARF4, and emit
DW_AT_frame_base on subprograms. This should make no semantic
difference.

Also fix a long-standing bug/inconsistency in puttattr: it didn't
add the addend to ref_addrs. Previously this didn't matter because it
was only used for types, but now it's used for section offsets into
symbols that have multiple entries.

RELNOTE=yes

Change-Id: Ib10654ac92edfa29c5167c44133648151d70cf76
Reviewed-on: https://go-review.googlesource.com/44210Reviewed-by: default avatarHyang-Ah Hana Kim <hyangah@gmail.com>
parent 11ab865d
...@@ -255,7 +255,7 @@ var abbrevs = [DW_NABRV]dwAbbrev{ ...@@ -255,7 +255,7 @@ var abbrevs = [DW_NABRV]dwAbbrev{
{DW_AT_language, DW_FORM_data1}, {DW_AT_language, DW_FORM_data1},
{DW_AT_low_pc, DW_FORM_addr}, {DW_AT_low_pc, DW_FORM_addr},
{DW_AT_high_pc, DW_FORM_addr}, {DW_AT_high_pc, DW_FORM_addr},
{DW_AT_stmt_list, DW_FORM_data4}, {DW_AT_stmt_list, DW_FORM_sec_offset},
{DW_AT_comp_dir, DW_FORM_string}, {DW_AT_comp_dir, DW_FORM_string},
{DW_AT_producer, DW_FORM_string}, {DW_AT_producer, DW_FORM_string},
}, },
...@@ -269,6 +269,7 @@ var abbrevs = [DW_NABRV]dwAbbrev{ ...@@ -269,6 +269,7 @@ var abbrevs = [DW_NABRV]dwAbbrev{
{DW_AT_name, DW_FORM_string}, {DW_AT_name, DW_FORM_string},
{DW_AT_low_pc, DW_FORM_addr}, {DW_AT_low_pc, DW_FORM_addr},
{DW_AT_high_pc, DW_FORM_addr}, {DW_AT_high_pc, DW_FORM_addr},
{DW_AT_frame_base, DW_FORM_block1},
{DW_AT_external, DW_FORM_flag}, {DW_AT_external, DW_FORM_flag},
}, },
}, },
...@@ -306,13 +307,12 @@ var abbrevs = [DW_NABRV]dwAbbrev{ ...@@ -306,13 +307,12 @@ var abbrevs = [DW_NABRV]dwAbbrev{
{DW_AT_type, DW_FORM_ref_addr}, {DW_AT_type, DW_FORM_ref_addr},
}, },
}, },
/* LEXICAL_BLOCK_RANGES */ /* LEXICAL_BLOCK_RANGES */
{ {
DW_TAG_lexical_block, DW_TAG_lexical_block,
DW_CHILDREN_yes, DW_CHILDREN_yes,
[]dwAttrForm{ []dwAttrForm{
{DW_AT_ranges, DW_FORM_data4}, // replace with DW_FORM_sec_offset in DWARFv4. {DW_AT_ranges, DW_FORM_sec_offset},
}, },
}, },
...@@ -634,14 +634,15 @@ func putattr(ctxt Context, s Sym, abbrev int, form int, cls int, value int64, da ...@@ -634,14 +634,15 @@ func putattr(ctxt Context, s Sym, abbrev int, form int, cls int, value int64, da
ctxt.AddInt(s, 1, 0) ctxt.AddInt(s, 1, 0)
} }
// In DWARF 3 the ref_addr is always 32 bits, unless emitting a large // As of DWARF 3 the ref_addr is always 32 bits, unless emitting a large
// (> 4 GB of debug info aka "64-bit") unit, which we don't implement. // (> 4 GB of debug info aka "64-bit") unit, which we don't implement.
case DW_FORM_ref_addr: // reference to a DIE in the .info section case DW_FORM_ref_addr: // reference to a DIE in the .info section
fallthrough
case DW_FORM_sec_offset: // offset into a DWARF section other than .info
if data == nil { if data == nil {
return fmt.Errorf("dwarf: null reference in %d", abbrev) return fmt.Errorf("dwarf: null reference in %d", abbrev)
} else {
ctxt.AddSectionOffset(s, 4, data, 0)
} }
ctxt.AddSectionOffset(s, 4, data, value)
case DW_FORM_ref1, // reference within the compilation unit case DW_FORM_ref1, // reference within the compilation unit
DW_FORM_ref2, // reference DW_FORM_ref2, // reference
...@@ -687,7 +688,8 @@ func PutFunc(ctxt Context, s, ranges Sym, name string, external bool, startPC Sy ...@@ -687,7 +688,8 @@ func PutFunc(ctxt Context, s, ranges Sym, name string, external bool, startPC Sy
Uleb128put(ctxt, s, DW_ABRV_FUNCTION) Uleb128put(ctxt, s, DW_ABRV_FUNCTION)
putattr(ctxt, s, DW_ABRV_FUNCTION, DW_FORM_string, DW_CLS_STRING, int64(len(name)), name) putattr(ctxt, s, DW_ABRV_FUNCTION, DW_FORM_string, DW_CLS_STRING, int64(len(name)), name)
putattr(ctxt, s, DW_ABRV_FUNCTION, DW_FORM_addr, DW_CLS_ADDRESS, 0, startPC) putattr(ctxt, s, DW_ABRV_FUNCTION, DW_FORM_addr, DW_CLS_ADDRESS, 0, startPC)
putattr(ctxt, s, DW_ABRV_FUNCTION, DW_FORM_addr, DW_CLS_ADDRESS, size+ctxt.SymValue(startPC), startPC) putattr(ctxt, s, DW_ABRV_FUNCTION, DW_FORM_addr, DW_CLS_ADDRESS, size, startPC)
putattr(ctxt, s, DW_ABRV_FUNCTION, DW_FORM_block1, DW_CLS_BLOCK, 1, []byte{DW_OP_call_frame_cfa})
var ev int64 var ev int64
if external { if external {
ev = 1 ev = 1
...@@ -722,7 +724,7 @@ func putscope(ctxt Context, s, ranges Sym, startPC Sym, curscope int32, scopes [ ...@@ -722,7 +724,7 @@ func putscope(ctxt Context, s, ranges Sym, startPC Sym, curscope int32, scopes [
putattr(ctxt, s, DW_ABRV_LEXICAL_BLOCK_SIMPLE, DW_FORM_addr, DW_CLS_ADDRESS, scope.Ranges[0].End, startPC) putattr(ctxt, s, DW_ABRV_LEXICAL_BLOCK_SIMPLE, DW_FORM_addr, DW_CLS_ADDRESS, scope.Ranges[0].End, startPC)
} else { } else {
Uleb128put(ctxt, s, DW_ABRV_LEXICAL_BLOCK_RANGES) Uleb128put(ctxt, s, DW_ABRV_LEXICAL_BLOCK_RANGES)
putattr(ctxt, s, DW_ABRV_LEXICAL_BLOCK_RANGES, DW_FORM_data4, DW_CLS_PTR, ranges.Len(), ranges) putattr(ctxt, s, DW_ABRV_LEXICAL_BLOCK_RANGES, DW_FORM_sec_offset, DW_CLS_PTR, ranges.Len(), ranges)
ctxt.AddAddress(ranges, nil, -1) ctxt.AddAddress(ranges, nil, -1)
ctxt.AddAddress(ranges, startPC, 0) ctxt.AddAddress(ranges, startPC, 0)
......
...@@ -212,6 +212,11 @@ const ( ...@@ -212,6 +212,11 @@ const (
DW_FORM_ref8 = 0x14 // reference DW_FORM_ref8 = 0x14 // reference
DW_FORM_ref_udata = 0x15 // reference DW_FORM_ref_udata = 0x15 // reference
DW_FORM_indirect = 0x16 // (see Section 7.5.3) DW_FORM_indirect = 0x16 // (see Section 7.5.3)
// Dwarf4
DW_FORM_sec_offset = 0x17 // lineptr, loclistptr, macptr, rangelistptr
DW_FORM_exprloc = 0x18 // exprloc
DW_FORM_flag_present = 0x19 // flag
DW_FORM_ref_sig8 = 0x20 // reference
) )
// Table 24 (#operands, notes) // Table 24 (#operands, notes)
......
...@@ -1348,7 +1348,7 @@ func writeinfo(ctxt *Link, syms []*Symbol, funcs []*Symbol) []*Symbol { ...@@ -1348,7 +1348,7 @@ func writeinfo(ctxt *Link, syms []*Symbol, funcs []*Symbol) []*Symbol {
// Fields marked with (*) must be changed for 64-bit dwarf // Fields marked with (*) must be changed for 64-bit dwarf
// This must match COMPUNITHEADERSIZE above. // This must match COMPUNITHEADERSIZE above.
Adduint32(ctxt, s, 0) // unit_length (*), will be filled in later. Adduint32(ctxt, s, 0) // unit_length (*), will be filled in later.
Adduint16(ctxt, s, 3) // dwarf version (appendix F) Adduint16(ctxt, s, 4) // dwarf version (appendix F)
// debug_abbrev_offset (*) // debug_abbrev_offset (*)
adddwarfref(ctxt, s, abbrevsym, 4) adddwarfref(ctxt, s, abbrevsym, 4)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment