func writeinfo(ctxt *Link, syms []*Symbol, funcs []*Symbol) []*Symbol { if infosec == nil { infosec = Linklookup(ctxt, ".debug_info", 0) } infosec.R = infosec.R[:0] infosec.Type = obj.SDWARFINFO infosec.Attr |= AttrReachable syms = append(syms, infosec) if arangessec == nil { arangessec = Linklookup(ctxt, ".dwarfaranges", 0) } arangessec.R = arangessec.R[:0] var dwarfctxt dwarf.Context = dwctxt{ctxt} for compunit := dwroot.Child; compunit != nil; compunit = compunit.Link { s := dtolsym(compunit.Sym) // Write .debug_info Compilation Unit Header (sec 7.5.1) // Fields marked with (*) must be changed for 64-bit dwarf // This must match COMPUNITHEADERSIZE above. Adduint32(ctxt, s, 0) // unit_length (*), will be filled in later. Adduint16(ctxt, s, 2) // dwarf version (appendix F) // debug_abbrev_offset (*) adddwarfref(ctxt, s, abbrevsym, 4) Adduint8(ctxt, s, uint8(SysArch.PtrSize)) // address_size dwarf.Uleb128put(dwarfctxt, s, int64(compunit.Abbrev)) dwarf.PutAttrs(dwarfctxt, s, compunit.Abbrev, compunit.Attr) cu := []*Symbol{s} if funcs != nil { cu = append(cu, funcs...) funcs = nil } cu = putdies(ctxt, dwarfctxt, cu, compunit.Child) var cusize int64 for _, child := range cu { cusize += child.Size } cusize -= 4 // exclude the length field. setuint32(ctxt, s, 0, uint32(cusize)) newattr(compunit, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, cusize, 0) syms = append(syms, cu...) } return syms }
func putdie(linkctxt *Link, ctxt dwarf.Context, syms []*Symbol, die *dwarf.DWDie) []*Symbol { s := dtolsym(die.Sym) if s == nil { s = syms[len(syms)-1] } else { if s.Attr.OnList() { log.Fatalf("symbol %s listed multiple times", s.Name) } s.Attr |= AttrOnList syms = append(syms, s) } dwarf.Uleb128put(ctxt, s, int64(die.Abbrev)) dwarf.PutAttrs(ctxt, s, die.Abbrev, die.Attr) if dwarf.HasChildren(die) { return putdies(linkctxt, ctxt, syms, die.Child) } return syms }