r := &ls.R[len(ls.R)-1]
r.Type = objabi.R_DWARFSECREF
}
+
func (c dwCtxt) AddFileRef(s dwarf.Sym, f interface{}) {
ls := s.(*LSym)
rsym := f.(*LSym)
- ls.WriteAddr(c.Link, ls.Size, 4, rsym, 0)
- r := &ls.R[len(ls.R)-1]
- r.Type = objabi.R_DWARFFILEREF
+ fidx := c.Link.PosTable.FileIndex(rsym.Name)
+ // Note the +1 here -- the value we're writing is going to be an
+ // index into the DWARF line table file section, whose entries
+ // are numbered starting at 1, not 0.
+ ls.WriteInt(c.Link, ls.Size, 4, int64(fidx+1))
}
func (c dwCtxt) CurrentOffset(s dwarf.Sym) int64 {
lsu.AddUint8(0) // standard_opcode_lengths[10]
lsu.AddUint8(0) // include_directories (empty)
- // Maps loader.Sym for file symbol to expanded filename.
- expandedFiles := make(map[loader.Sym]string)
-
// Copy over the file table.
fileNums := make(map[string]int)
lsDwsym := dwSym(ls)
// Output the state machine for each function remaining.
var lastAddr int64
- rslice := []loader.Reloc{}
for _, s := range unit.Textp2 {
fnSym := loader.Sym(s)
lsu.SetUint32(d.arch, unitLengthOffset, uint32(lsu.Size()-unitstart))
lsu.SetUint32(d.arch, headerLengthOffset, uint32(headerend-headerstart))
}
-
- // Process any R_DWARFFILEREF relocations, since we now know the
- // line table file indices for this compilation unit. Note that
- // this loop visits only subprogram DIEs: if the compiler is
- // changed to generate DW_AT_decl_file attributes for other
- // DIE flavors (ex: variables) then those DIEs would need to
- // be included below.
- missing := make(map[int]interface{})
- for _, f := range unit.FuncDIEs2 {
- fnSym := loader.Sym(f)
-
- // Create a symbol updater prior to looking at the relocations
- // on the DWARF subprogram DIE symbol. We need to do this here
- // so that any modifications to the reloc slice will get
- // stored in loader payload for the symbol (as opposed to a
- // temporary slice of relocs read from the object file). Copy
- // back relocations with updated addends.
- fnu := d.ldr.MakeSymbolUpdater(fnSym)
-
- relocs := d.ldr.Relocs(fnSym)
- rslice = relocs.ReadAll(rslice)
-
- for ri := range rslice {
- r := &rslice[ri]
- if r.Type != objabi.R_DWARFFILEREF {
- continue
- }
-
- fname, ok := expandedFiles[r.Sym]
- if !ok {
- fname = expandFileSym(d.ldr, r.Sym)
- expandedFiles[r.Sym] = fname
- }
-
- idx, ok := fileNums[fname]
- if ok {
- if int(int32(idx)) != idx {
- d.linkctxt.Errorf(fnSym, "bad R_DWARFFILEREF relocation: file index overflow")
- }
- if r.Size != 4 {
- d.linkctxt.Errorf(fnSym, "bad R_DWARFFILEREF relocation: has size %d, expected 4", r.Size)
- }
- if r.Add != 0 {
- d.linkctxt.Errorf(fnSym, "bad R_DWARFFILEREF relocation: addend not zero")
- }
- if r.Off < 0 || r.Off+4 > int32(len(fnu.Data())) {
- d.linkctxt.Errorf(fnSym, "bad R_DWARFFILEREF relocation offset %d + 4 would write past length %d", r.Off, len(fnu.Data()))
- continue
- }
-
- d.ldr.SetAttrReachable(r.Sym, true)
- d.ldr.SetAttrNotInSymbolTable(r.Sym, true)
- r.Add = int64(idx) // record the index in r.Add, we'll apply it in the reloc phase.
- } else {
- sv := d.ldr.SymValue(r.Sym)
- _, found := missing[int(sv)]
- if !found {
- d.linkctxt.Errorf(fnSym, "R_DWARFFILEREF relocation file missing: %s idx %d symVal %d", d.ldr.SymName(r.Sym), r.Sym, sv)
- missing[int(sv)] = nil
- }
- }
- }
- fnu.WriteRelocs(rslice)
- }
}
// writepcranges generates the DW_AT_ranges table for compilation unit cu.
}
}
- // If this symbol has any DWARF file relocations, we need to
- // make sure that the relocations are copied back over, since
- // DWARF-gen alters the offset values for these relocs. Also:
- // if this is an info symbol and it refers to a previously
- // unseen range/loc symbol, we'll need to fix up relocations
- // for it as well.
- relocs := l.Relocs(cand)
- rslice = relocs.ReadSyms(rslice)
- for ri := range rslice {
- if rslice[ri].Type == objabi.R_DWARFFILEREF {
- relfix = true
- break
- }
- if st != sym.SDWARFINFO {
- continue
- }
- rst := l.SymType(rslice[ri].Sym)
- if rst == sym.SDWARFRANGE || rst == sym.SDWARFLOC {
- relfix = true
- break
- }
- }
-
if relfix {
relocfixup = append(relocfixup, cand)
}