1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Writing Go object files.
13 "cmd/internal/notsha256"
26 const UnlinkablePkg = "<unlinkable>" // invalid package path, used when compiled without -p flag
28 // Entry point of writing new object file.
29 func WriteObjFile(ctxt *Link, b *bio.Writer) {
36 Writer: goobj.NewWriter(b),
38 pkgpath: objabi.PathToPrefix(ctxt.Pkgpath),
45 // We just reserve the space. We'll fill in the offsets later.
48 flags |= goobj.ObjFlagShared
50 if w.pkgpath == UnlinkablePkg {
51 flags |= goobj.ObjFlagUnlinkable
54 log.Fatal("empty package path")
57 flags |= goobj.ObjFlagFromAssembly
61 Fingerprint: ctxt.Fingerprint,
70 h.Offsets[goobj.BlkAutolib] = w.Offset()
71 for i := range ctxt.Imports {
72 ctxt.Imports[i].Write(w.Writer)
76 h.Offsets[goobj.BlkPkgIdx] = w.Offset()
77 for _, pkg := range w.pkglist {
81 // File table (for DWARF and pcln generation).
82 h.Offsets[goobj.BlkFile] = w.Offset()
83 for _, f := range ctxt.PosTable.FileTable() {
84 w.StringRef(filepath.ToSlash(f))
88 h.Offsets[goobj.BlkSymdef] = w.Offset()
89 for _, s := range ctxt.defs {
93 // Short hashed symbol definitions
94 h.Offsets[goobj.BlkHashed64def] = w.Offset()
95 for _, s := range ctxt.hashed64defs {
99 // Hashed symbol definitions
100 h.Offsets[goobj.BlkHasheddef] = w.Offset()
101 for _, s := range ctxt.hasheddefs {
105 // Non-pkg symbol definitions
106 h.Offsets[goobj.BlkNonpkgdef] = w.Offset()
107 for _, s := range ctxt.nonpkgdefs {
111 // Non-pkg symbol references
112 h.Offsets[goobj.BlkNonpkgref] = w.Offset()
113 for _, s := range ctxt.nonpkgrefs {
117 // Referenced package symbol flags
118 h.Offsets[goobj.BlkRefFlags] = w.Offset()
122 h.Offsets[goobj.BlkHash64] = w.Offset()
123 for _, s := range ctxt.hashed64defs {
126 h.Offsets[goobj.BlkHash] = w.Offset()
127 for _, s := range ctxt.hasheddefs {
130 // TODO: hashedrefs unused/unsupported for now
133 h.Offsets[goobj.BlkRelocIdx] = w.Offset()
135 lists := [][]*LSym{ctxt.defs, ctxt.hashed64defs, ctxt.hasheddefs, ctxt.nonpkgdefs}
136 for _, list := range lists {
137 for _, s := range list {
139 nreloc += uint32(len(s.R))
144 // Symbol Info indexes
145 h.Offsets[goobj.BlkAuxIdx] = w.Offset()
147 for _, list := range lists {
148 for _, s := range list {
150 naux += uint32(nAuxSym(s))
156 h.Offsets[goobj.BlkDataIdx] = w.Offset()
158 for _, list := range lists {
159 for _, s := range list {
160 w.Uint32(uint32(dataOff))
161 dataOff += int64(len(s.P))
162 if file := s.File(); file != nil {
163 dataOff += int64(file.Size)
167 if int64(uint32(dataOff)) != dataOff {
168 log.Fatalf("data too large")
170 w.Uint32(uint32(dataOff))
173 h.Offsets[goobj.BlkReloc] = w.Offset()
174 for _, list := range lists {
175 for _, s := range list {
176 sort.Sort(relocByOff(s.R)) // some platforms (e.g. PE) requires relocations in address order
184 h.Offsets[goobj.BlkAux] = w.Offset()
185 for _, list := range lists {
186 for _, s := range list {
192 h.Offsets[goobj.BlkData] = w.Offset()
193 for _, list := range lists {
194 for _, s := range list {
196 if file := s.File(); file != nil {
197 w.writeFile(ctxt, file)
202 // Blocks used only by tools (objdump, nm).
204 // Referenced symbol names from other packages
205 h.Offsets[goobj.BlkRefName] = w.Offset()
208 h.Offsets[goobj.BlkEnd] = w.Offset()
210 // Fix up block offsets in the header
211 end := start + int64(w.Offset())
221 pkgpath string // the package import path (escaped), "" if unknown
222 pkglist []string // list of packages referenced, indexed by ctxt.pkgIdx
224 // scratch space for writing (the Write methods escape
225 // as they are interface calls)
229 tmpHash64 goobj.Hash64Type
230 tmpHash goobj.HashType
231 tmpRefFlags goobj.RefFlags
232 tmpRefName goobj.RefName
235 // prepare package index list
236 func (w *writer) init() {
237 w.pkglist = make([]string, len(w.ctxt.pkgIdx)+1)
238 w.pkglist[0] = "" // dummy invalid package for index 0
239 for pkg, i := range w.ctxt.pkgIdx {
244 func (w *writer) writeFile(ctxt *Link, file *FileInfo) {
245 f, err := os.Open(file.Name)
251 if w.filebuf == nil {
252 w.filebuf = make([]byte, 1024)
257 n, err := f.Read(buf)
268 if written != file.Size {
269 ctxt.Diag("copy %s: unexpected length %d != %d", file.Name, written, file.Size)
273 func (w *writer) StringTable() {
275 for _, p := range w.ctxt.Imports {
278 for _, pkg := range w.pkglist {
281 w.ctxt.traverseSyms(traverseAll, func(s *LSym) {
282 // Don't put names of builtins into the string table (to save
284 if s.PkgIdx == goobj.PkgIdxBuiltin {
287 // TODO: this includes references of indexed symbols from other packages,
288 // for which the linker doesn't need the name. Consider moving them to
289 // a separate block (for tools only).
290 if w.ctxt.Flag_noRefName && s.PkgIdx < goobj.PkgIdxSpecial {
291 // Don't include them if Flag_noRefName
295 s.Name = strings.Replace(s.Name, "\"\".", w.pkgpath+".", -1)
300 // All filenames are in the postable.
301 for _, f := range w.ctxt.PosTable.FileTable() {
302 w.AddString(filepath.ToSlash(f))
306 // cutoff is the maximum data section size permitted by the linker
307 // (see issue #9862).
308 const cutoff = int64(2e9) // 2 GB (or so; looks better in errors than 2^31)
310 func (w *writer) Sym(s *LSym) {
311 abi := uint16(s.ABI())
313 abi = goobj.SymABIstatic
317 flag |= goobj.SymFlagDupok
320 flag |= goobj.SymFlagLocal
322 if s.MakeTypelink() {
323 flag |= goobj.SymFlagTypelink
326 flag |= goobj.SymFlagLeaf
329 flag |= goobj.SymFlagNoSplit
331 if s.ReflectMethod() {
332 flag |= goobj.SymFlagReflectMethod
334 if strings.HasPrefix(s.Name, "type:") && s.Name[5] != '.' && s.Type == objabi.SRODATA {
335 flag |= goobj.SymFlagGoType
339 flag2 |= goobj.SymFlagUsedInIface
341 if strings.HasPrefix(s.Name, "go:itab.") && s.Type == objabi.SRODATA {
342 flag2 |= goobj.SymFlagItab
344 if strings.HasPrefix(s.Name, w.ctxt.Pkgpath) && strings.HasPrefix(s.Name[len(w.ctxt.Pkgpath):], ".") && strings.HasPrefix(s.Name[len(w.ctxt.Pkgpath)+1:], objabi.GlobalDictPrefix) {
345 flag2 |= goobj.SymFlagDict
348 flag2 |= goobj.SymFlagPkgInit
351 if strings.HasPrefix(name, "gofile..") {
352 name = filepath.ToSlash(name)
355 if fn := s.Func(); fn != nil {
356 align = uint32(fn.Align)
358 if s.ContentAddressable() && s.Size != 0 {
359 // We generally assume data symbols are naturally aligned
360 // (e.g. integer constants), except for strings and a few
361 // compiler-emitted funcdata. If we dedup a string symbol and
362 // a non-string symbol with the same content, we should keep
363 // the largest alignment.
364 // TODO: maybe the compiler could set the alignment for all
365 // data symbols more carefully.
367 case strings.HasPrefix(s.Name, "go:string."),
368 strings.HasPrefix(name, "type:.namedata."),
369 strings.HasPrefix(name, "type:.importpath."),
370 strings.HasSuffix(name, ".opendefer"),
371 strings.HasSuffix(name, ".arginfo0"),
372 strings.HasSuffix(name, ".arginfo1"),
373 strings.HasSuffix(name, ".argliveinfo"):
374 // These are just bytes, or varints.
376 case strings.HasPrefix(name, "gclocals·"):
377 // It has 32-bit fields.
381 case w.ctxt.Arch.PtrSize == 8 && s.Size%8 == 0:
393 w.ctxt.Diag("%s: symbol too large (%d bytes > %d bytes)", s.Name, s.Size, cutoff)
396 o.SetName(name, w.Writer)
398 o.SetType(uint8(s.Type))
401 o.SetSiz(uint32(s.Size))
406 func (w *writer) Hash64(s *LSym) {
407 if !s.ContentAddressable() || len(s.R) != 0 {
408 panic("Hash of non-content-addressable symbol")
410 w.tmpHash64 = contentHash64(s)
411 w.Bytes(w.tmpHash64[:])
414 func (w *writer) Hash(s *LSym) {
415 if !s.ContentAddressable() {
416 panic("Hash of non-content-addressable symbol")
418 w.tmpHash = w.contentHash(s)
419 w.Bytes(w.tmpHash[:])
422 // contentHashSection returns a mnemonic for s's section.
423 // The goal is to prevent content-addressability from moving symbols between sections.
424 // contentHashSection only distinguishes between sets of sections for which this matters.
425 // Allowing flexibility increases the effectiveness of content-addressibility.
426 // But in some cases, such as doing addressing based on a base symbol,
427 // we need to ensure that a symbol is always in a particular section.
428 // Some of these conditions are duplicated in cmd/link/internal/ld.(*Link).symtab.
429 // TODO: instead of duplicating them, have the compiler decide where symbols go.
430 func contentHashSection(s *LSym) byte {
435 if strings.HasPrefix(name, "gcargs.") ||
436 strings.HasPrefix(name, "gclocals.") ||
437 strings.HasPrefix(name, "gclocals·") ||
438 strings.HasSuffix(name, ".opendefer") ||
439 strings.HasSuffix(name, ".arginfo0") ||
440 strings.HasSuffix(name, ".arginfo1") ||
441 strings.HasSuffix(name, ".argliveinfo") ||
442 strings.HasSuffix(name, ".wrapinfo") ||
443 strings.HasSuffix(name, ".args_stackmap") ||
444 strings.HasSuffix(name, ".stkobj") {
445 return 'F' // go:func.* or go:funcrel.*
447 if strings.HasPrefix(name, "type:") {
453 func contentHash64(s *LSym) goobj.Hash64Type {
454 if contentHashSection(s) != 0 {
455 panic("short hash of non-default-section sym " + s.Name)
457 var b goobj.Hash64Type
462 // Compute the content hash for a content-addressable symbol.
463 // We build a content hash based on its content and relocations.
464 // Depending on the category of the referenced symbol, we choose
465 // different hash algorithms such that the hash is globally
467 // - For referenced content-addressable symbol, its content hash
468 // is globally consistent.
469 // - For package symbol and builtin symbol, its local index is
470 // globally consistent.
471 // - For non-package symbol, its fully-expanded name is globally
472 // consistent. For now, we require we know the current package
473 // path so we can always expand symbol names. (Otherwise,
474 // symbols with relocations are not considered hashable.)
476 // For now, we assume there is no circular dependencies among
478 func (w *writer) contentHash(s *LSym) goobj.HashType {
482 // Include the size of the symbol in the hash.
483 // This preserves the length of symbols, preventing the following two symbols
484 // from hashing the same:
486 // [2]int{1,2} ≠[10]int{1,2,0,0,0...}
488 // In this case, if the smaller symbol is alive, the larger is not kept unless
490 binary.LittleEndian.PutUint64(tmp[:8], uint64(s.Size))
491 // Some symbols require being in separate sections.
492 tmp[8] = contentHashSection(s)
495 // The compiler trims trailing zeros _sometimes_. We just do
497 h.Write(bytes.TrimRight(s.P, "\x00"))
500 binary.LittleEndian.PutUint32(tmp[:4], uint32(r.Off))
502 tmp[5] = uint8(r.Type)
503 binary.LittleEndian.PutUint64(tmp[6:14], uint64(r.Add))
507 fmt.Printf("symbol: %s\n", s)
508 fmt.Printf("relocation: %#v\n", r)
509 panic("nil symbol target in relocation")
512 case goobj.PkgIdxHashed64:
514 t := contentHash64(rs)
516 case goobj.PkgIdxHashed:
518 t := w.contentHash(rs)
520 case goobj.PkgIdxNone:
522 io.WriteString(h, rs.Name) // name is already expanded at this point
523 case goobj.PkgIdxBuiltin:
525 binary.LittleEndian.PutUint32(tmp[:4], uint32(rs.SymIdx))
527 case goobj.PkgIdxSelf:
528 io.WriteString(h, w.pkgpath)
529 binary.LittleEndian.PutUint32(tmp[:4], uint32(rs.SymIdx))
532 io.WriteString(h, rs.Pkg)
533 binary.LittleEndian.PutUint32(tmp[:4], uint32(rs.SymIdx))
538 copy(b[:], h.Sum(nil))
542 func makeSymRef(s *LSym) goobj.SymRef {
544 return goobj.SymRef{}
546 if s.PkgIdx == 0 || !s.Indexed() {
547 fmt.Printf("unindexed symbol reference: %v\n", s)
548 panic("unindexed symbol reference")
550 return goobj.SymRef{PkgIdx: uint32(s.PkgIdx), SymIdx: uint32(s.SymIdx)}
553 func (w *writer) Reloc(r *Reloc) {
557 o.SetType(uint16(r.Type))
559 o.SetSym(makeSymRef(r.Sym))
563 func (w *writer) aux1(typ uint8, rs *LSym) {
566 o.SetSym(makeSymRef(rs))
570 func (w *writer) Aux(s *LSym) {
572 w.aux1(goobj.AuxGotype, s.Gotype)
574 if fn := s.Func(); fn != nil {
575 w.aux1(goobj.AuxFuncInfo, fn.FuncInfoSym)
577 for _, d := range fn.Pcln.Funcdata {
578 w.aux1(goobj.AuxFuncdata, d)
581 if fn.dwarfInfoSym != nil && fn.dwarfInfoSym.Size != 0 {
582 w.aux1(goobj.AuxDwarfInfo, fn.dwarfInfoSym)
584 if fn.dwarfLocSym != nil && fn.dwarfLocSym.Size != 0 {
585 w.aux1(goobj.AuxDwarfLoc, fn.dwarfLocSym)
587 if fn.dwarfRangesSym != nil && fn.dwarfRangesSym.Size != 0 {
588 w.aux1(goobj.AuxDwarfRanges, fn.dwarfRangesSym)
590 if fn.dwarfDebugLinesSym != nil && fn.dwarfDebugLinesSym.Size != 0 {
591 w.aux1(goobj.AuxDwarfLines, fn.dwarfDebugLinesSym)
593 if fn.Pcln.Pcsp != nil && fn.Pcln.Pcsp.Size != 0 {
594 w.aux1(goobj.AuxPcsp, fn.Pcln.Pcsp)
596 if fn.Pcln.Pcfile != nil && fn.Pcln.Pcfile.Size != 0 {
597 w.aux1(goobj.AuxPcfile, fn.Pcln.Pcfile)
599 if fn.Pcln.Pcline != nil && fn.Pcln.Pcline.Size != 0 {
600 w.aux1(goobj.AuxPcline, fn.Pcln.Pcline)
602 if fn.Pcln.Pcinline != nil && fn.Pcln.Pcinline.Size != 0 {
603 w.aux1(goobj.AuxPcinline, fn.Pcln.Pcinline)
605 for _, pcSym := range fn.Pcln.Pcdata {
606 w.aux1(goobj.AuxPcdata, pcSym)
608 if fn.WasmImportSym != nil {
609 if fn.WasmImportSym.Size == 0 {
610 panic("wasmimport aux sym must have non-zero size")
612 w.aux1(goobj.AuxWasmImport, fn.WasmImportSym)
617 // Emits flags of referenced indexed symbols.
618 func (w *writer) refFlags() {
619 seen := make(map[*LSym]bool)
620 w.ctxt.traverseSyms(traverseRefs, func(rs *LSym) { // only traverse refs, not auxs, as tools don't need auxs
622 case goobj.PkgIdxNone, goobj.PkgIdxHashed64, goobj.PkgIdxHashed, goobj.PkgIdxBuiltin, goobj.PkgIdxSelf: // not an external indexed reference
624 case goobj.PkgIdxInvalid:
625 panic("unindexed symbol reference")
631 symref := makeSymRef(rs)
633 if rs.UsedInIface() {
634 flag2 |= goobj.SymFlagUsedInIface
637 return // no need to write zero flags
646 // Emits names of referenced indexed symbols, used by tools (objdump, nm)
648 func (w *writer) refNames() {
649 if w.ctxt.Flag_noRefName {
652 seen := make(map[*LSym]bool)
653 w.ctxt.traverseSyms(traverseRefs, func(rs *LSym) { // only traverse refs, not auxs, as tools don't need auxs
655 case goobj.PkgIdxNone, goobj.PkgIdxHashed64, goobj.PkgIdxHashed, goobj.PkgIdxBuiltin, goobj.PkgIdxSelf: // not an external indexed reference
657 case goobj.PkgIdxInvalid:
658 panic("unindexed symbol reference")
664 symref := makeSymRef(rs)
667 o.SetName(rs.Name, w.Writer)
670 // TODO: output in sorted order?
671 // Currently tools (cmd/internal/goobj package) doesn't use mmap,
672 // and it just read it into a map in memory upfront. If it uses
673 // mmap, if the output is sorted, it probably could avoid reading
674 // into memory and just do lookups in the mmap'd object file.
677 // return the number of aux symbols s have.
678 func nAuxSym(s *LSym) int {
683 if fn := s.Func(); fn != nil {
684 // FuncInfo is an aux symbol, each Funcdata is an aux symbol
685 n += 1 + len(fn.Pcln.Funcdata)
686 if fn.dwarfInfoSym != nil && fn.dwarfInfoSym.Size != 0 {
689 if fn.dwarfLocSym != nil && fn.dwarfLocSym.Size != 0 {
692 if fn.dwarfRangesSym != nil && fn.dwarfRangesSym.Size != 0 {
695 if fn.dwarfDebugLinesSym != nil && fn.dwarfDebugLinesSym.Size != 0 {
698 if fn.Pcln.Pcsp != nil && fn.Pcln.Pcsp.Size != 0 {
701 if fn.Pcln.Pcfile != nil && fn.Pcln.Pcfile.Size != 0 {
704 if fn.Pcln.Pcline != nil && fn.Pcln.Pcline.Size != 0 {
707 if fn.Pcln.Pcinline != nil && fn.Pcln.Pcinline.Size != 0 {
710 n += len(fn.Pcln.Pcdata)
711 if fn.WasmImport != nil {
712 if fn.WasmImportSym == nil || fn.WasmImportSym.Size == 0 {
713 panic("wasmimport aux sym must exist and have non-zero size")
721 // generate symbols for FuncInfo.
722 func genFuncInfoSyms(ctxt *Link) {
723 infosyms := make([]*LSym, 0, len(ctxt.Text))
725 symidx := int32(len(ctxt.defs))
726 for _, s := range ctxt.Text {
732 Args: uint32(fn.Args),
733 Locals: uint32(fn.Locals),
735 FuncFlag: fn.FuncFlag,
736 StartLine: fn.StartLine,
740 o.File = make([]goobj.CUFileIndex, len(pc.UsedFiles))
741 for f := range pc.UsedFiles {
745 sort.Slice(o.File, func(i, j int) bool { return o.File[i] < o.File[j] })
746 o.InlTree = make([]goobj.InlTreeNode, len(pc.InlTree.nodes))
747 for i, inl := range pc.InlTree.nodes {
748 f, l := ctxt.getFileIndexAndLine(inl.Pos)
749 o.InlTree[i] = goobj.InlTreeNode{
750 Parent: int32(inl.Parent),
751 File: goobj.CUFileIndex(f),
753 Func: makeSymRef(inl.Func),
754 ParentPC: inl.ParentPC,
761 Type: objabi.SDATA, // for now, I don't think it matters
762 PkgIdx: goobj.PkgIdxSelf,
764 P: append([]byte(nil), p...),
767 isym.Set(AttrIndexed, true)
769 infosyms = append(infosyms, isym)
770 fn.FuncInfoSym = isym
773 auxsyms := []*LSym{fn.dwarfRangesSym, fn.dwarfLocSym, fn.dwarfDebugLinesSym, fn.dwarfInfoSym, fn.WasmImportSym}
774 for _, s := range auxsyms {
775 if s == nil || s.Size == 0 {
778 s.PkgIdx = goobj.PkgIdxSelf
780 s.Set(AttrIndexed, true)
782 infosyms = append(infosyms, s)
785 ctxt.defs = append(ctxt.defs, infosyms...)
788 func writeAuxSymDebug(ctxt *Link, par *LSym, aux *LSym) {
789 // Most aux symbols (ex: funcdata) are not interesting--
790 // pick out just the DWARF ones for now.
791 if aux.Type != objabi.SDWARFLOC &&
792 aux.Type != objabi.SDWARFFCN &&
793 aux.Type != objabi.SDWARFABSFCN &&
794 aux.Type != objabi.SDWARFLINES &&
795 aux.Type != objabi.SDWARFRANGE {
798 ctxt.writeSymDebugNamed(aux, "aux for "+par.Name)
801 func debugAsmEmit(ctxt *Link) {
802 if ctxt.Debugasm > 0 {
803 ctxt.traverseSyms(traverseDefs, ctxt.writeSymDebug)
804 if ctxt.Debugasm > 1 {
805 fn := func(par *LSym, aux *LSym) {
806 writeAuxSymDebug(ctxt, par, aux)
808 ctxt.traverseAuxSyms(traverseAux, fn)
813 func (ctxt *Link) writeSymDebug(s *LSym) {
814 ctxt.writeSymDebugNamed(s, s.Name)
817 func (ctxt *Link) writeSymDebugNamed(s *LSym, name string) {
819 if ctxt.Debugasm > 1 {
820 ver = fmt.Sprintf("<%d>", s.ABI())
822 fmt.Fprintf(ctxt.Bso, "%s%s ", name, ver)
824 fmt.Fprintf(ctxt.Bso, "%v ", s.Type)
827 fmt.Fprint(ctxt.Bso, "static ")
830 fmt.Fprintf(ctxt.Bso, "dupok ")
833 fmt.Fprintf(ctxt.Bso, "cfunc ")
836 fmt.Fprintf(ctxt.Bso, "nosplit ")
838 if s.Func() != nil && s.Func().FuncFlag&objabi.FuncFlag_TOPFRAME != 0 {
839 fmt.Fprintf(ctxt.Bso, "topframe ")
841 if s.Func() != nil && s.Func().FuncFlag&objabi.FuncFlag_ASM != 0 {
842 fmt.Fprintf(ctxt.Bso, "asm ")
844 fmt.Fprintf(ctxt.Bso, "size=%d", s.Size)
845 if s.Type == objabi.STEXT {
847 fmt.Fprintf(ctxt.Bso, " args=%#x locals=%#x funcid=%#x align=%#x", uint64(fn.Args), uint64(fn.Locals), uint64(fn.FuncID), uint64(fn.Align))
849 fmt.Fprintf(ctxt.Bso, " leaf")
852 fmt.Fprintf(ctxt.Bso, "\n")
853 if s.Type == objabi.STEXT {
854 for p := s.Func().Text; p != nil; p = p.Link {
855 fmt.Fprintf(ctxt.Bso, "\t%#04x ", uint(int(p.Pc)))
856 if ctxt.Debugasm > 1 {
857 io.WriteString(ctxt.Bso, p.String())
859 p.InnermostString(ctxt.Bso)
861 fmt.Fprintln(ctxt.Bso)
864 for i := 0; i < len(s.P); i += 16 {
865 fmt.Fprintf(ctxt.Bso, "\t%#04x", uint(i))
867 for ; j < i+16 && j < len(s.P); j++ {
868 fmt.Fprintf(ctxt.Bso, " %02x", s.P[j])
870 for ; j < i+16; j++ {
871 fmt.Fprintf(ctxt.Bso, " ")
873 fmt.Fprintf(ctxt.Bso, " ")
874 for j = i; j < i+16 && j < len(s.P); j++ {
877 if ' ' <= c && c <= 0x7e {
880 ctxt.Bso.WriteByte(b)
883 fmt.Fprintf(ctxt.Bso, "\n")
886 sort.Sort(relocByOff(s.R)) // generate stable output
887 for _, r := range s.R {
892 if ctxt.Debugasm > 1 {
893 ver = fmt.Sprintf("<%d>", r.Sym.ABI())
895 } else if r.Type == objabi.R_TLS_LE {
898 if ctxt.Arch.InFamily(sys.ARM, sys.PPC64) {
899 fmt.Fprintf(ctxt.Bso, "\trel %d+%d t=%d %s%s+%x\n", int(r.Off), r.Siz, r.Type, name, ver, uint64(r.Add))
901 fmt.Fprintf(ctxt.Bso, "\trel %d+%d t=%d %s%s+%d\n", int(r.Off), r.Siz, r.Type, name, ver, r.Add)
906 // relocByOff sorts relocations by their offsets.
907 type relocByOff []Reloc
909 func (x relocByOff) Len() int { return len(x) }
910 func (x relocByOff) Less(i, j int) bool { return x[i].Off < x[j].Off }
911 func (x relocByOff) Swap(i, j int) { x[i], x[j] = x[j], x[i] }