if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f asmb\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
if ld.Iself {
ld.Asmbelfsetup()
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f rodatblk\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
ld.Cseek(int64(ld.Segrodata.Fileoff))
ld.Datblk(int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f datblk\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
ld.Cseek(int64(ld.Segdata.Fileoff))
ld.Datblk(int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f sym\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
switch ld.HEADTYPE {
default:
if ld.Iself {
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f header\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
ld.Cseek(0)
switch ld.HEADTYPE {
default:
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f asmb\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f codeblk\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
if ld.Iself {
ld.Asmbelfsetup()
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f rodatblk\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
ld.Cseek(int64(ld.Segrodata.Fileoff))
ld.Datblk(int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f datblk\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
ld.Cseek(int64(ld.Segdata.Fileoff))
ld.Datblk(int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f sym\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
switch ld.HEADTYPE {
default:
case obj.Hplan9,
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f headr\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
ld.Cseek(0)
switch ld.HEADTYPE {
default:
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f asmb\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
if ld.Iself {
ld.Asmbelfsetup()
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f rodatblk\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
ld.Cseek(int64(ld.Segrodata.Fileoff))
ld.Datblk(int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f datblk\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
ld.Cseek(int64(ld.Segdata.Fileoff))
ld.Datblk(int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f sym\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
switch ld.HEADTYPE {
default:
if ld.Iself {
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f header\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
ld.Cseek(0)
switch ld.HEADTYPE {
default:
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f asmb\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
if ld.Iself {
ld.Asmbelfsetup()
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f rodatblk\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
ld.Cseek(int64(ld.Segrodata.Fileoff))
ld.Datblk(int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f datblk\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
ld.Cseek(int64(ld.Segdata.Fileoff))
ld.Datblk(int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f sym\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
switch ld.HEADTYPE {
default:
if ld.Iself {
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f headr\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
ld.Cseek(0)
switch ld.HEADTYPE {
default:
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f asmb\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
if ld.Iself {
ld.Asmbelfsetup()
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f rodatblk\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
ld.Cseek(int64(ld.Segrodata.Fileoff))
ld.Datblk(int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f datblk\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
ld.Cseek(int64(ld.Segdata.Fileoff))
ld.Datblk(int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f sym\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
switch ld.HEADTYPE {
default:
if ld.Iself {
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f header\n", obj.Cputime())
}
- ld.Bflush(&ld.Bso)
+ ld.Bso.Flush()
ld.Cseek(0)
switch ld.HEADTYPE {
default:
if Debug['v'] != 0 {
fmt.Fprintf(&Bso, "%5.2f reloc\n", obj.Cputime())
}
- Bflush(&Bso)
+ Bso.Flush()
for s := Ctxt.Textp; s != nil; s = s.Next {
relocsym(s)
if Debug['v'] != 0 {
fmt.Fprintf(&Bso, "%5.2f reloc\n", obj.Cputime())
}
- Bflush(&Bso)
+ Bso.Flush()
for s := Ctxt.Textp; s != nil; s = s.Next {
dynrelocsym(s)
}
}
- Bflush(&Bso)
+ Bso.Flush()
}
func Datblk(addr int64, size int64) {
if Debug['v'] != 0 {
fmt.Fprintf(&Bso, "%5.2f dodata\n", obj.Cputime())
}
- Bflush(&Bso)
+ Bso.Flush()
var last *LSym
datap = nil
return x
}
-func ldpkg(f *Biobuf, pkg string, length int64, filename string, whence int) {
+func ldpkg(f *obj.Biobuf, pkg string, length int64, filename string, whence int) {
var p0, p1 int
if Debug['g'] != 0 {
}
bdata := make([]byte, length)
- if int64(Bread(f, bdata)) != length {
+ if int64(obj.Bread(f, bdata)) != length {
fmt.Fprintf(os.Stderr, "%s: short pkg read %s\n", os.Args[0], filename)
if Debug['u'] != 0 {
errorexit()
}
type ElfObj struct {
- f *Biobuf
+ f *obj.Biobuf
base int64 // offset in f where ELF begins
length int64 // length of ELF
is64 int
return 0
}
-func ldelf(f *Biobuf, pkg string, length int64, pn string) {
+func ldelf(f *obj.Biobuf, pkg string, length int64, pn string) {
if Debug['v'] != 0 {
fmt.Fprintf(&Bso, "%5.2f ldelf %s\n", obj.Cputime(), pn)
}
Ctxt.Version++
- base := int32(Boffset(f))
+ base := int32(obj.Boffset(f))
var add uint64
var e binary.ByteOrder
var sect *ElfSect
var sym ElfSym
var symbols []*LSym
- if Bread(f, hdrbuf[:]) != len(hdrbuf) {
+ if obj.Bread(f, hdrbuf[:]) != len(hdrbuf) {
goto bad
}
hdr = new(ElfHdrBytes)
elfobj.nsect = uint(elfobj.shnum)
for i := 0; uint(i) < elfobj.nsect; i++ {
- if Bseek(f, int64(uint64(base)+elfobj.shoff+uint64(int64(i)*int64(elfobj.shentsize))), 0) < 0 {
+ if obj.Bseek(f, int64(uint64(base)+elfobj.shoff+uint64(int64(i)*int64(elfobj.shentsize))), 0) < 0 {
goto bad
}
sect = &elfobj.sect[i]
sect.base = make([]byte, sect.size)
err = fmt.Errorf("short read")
- if Bseek(elfobj.f, int64(uint64(elfobj.base)+sect.off), 0) < 0 || Bread(elfobj.f, sect.base) != len(sect.base) {
+ if obj.Bseek(elfobj.f, int64(uint64(elfobj.base)+sect.off), 0) < 0 || obj.Bread(elfobj.f, sect.base) != len(sect.base) {
return err
}
)
type LdMachoObj struct {
- f *Biobuf
+ f *obj.Biobuf
base int64 // off in f where Mach-O begins
length int64 // length of Mach-O
is64 bool
rel := make([]LdMachoRel, sect.nreloc)
n := int(sect.nreloc * 8)
buf := make([]byte, n)
- if Bseek(m.f, m.base+int64(sect.reloff), 0) < 0 || Bread(m.f, buf) != n {
+ if obj.Bseek(m.f, m.base+int64(sect.reloff), 0) < 0 || obj.Bread(m.f, buf) != n {
return -1
}
var p []byte
n := int(d.nindirectsyms)
p := make([]byte, n*4)
- if Bseek(m.f, m.base+int64(d.indirectsymoff), 0) < 0 || Bread(m.f, p) != len(p) {
+ if obj.Bseek(m.f, m.base+int64(d.indirectsymoff), 0) < 0 || obj.Bread(m.f, p) != len(p) {
return -1
}
}
strbuf := make([]byte, symtab.strsize)
- if Bseek(m.f, m.base+int64(symtab.stroff), 0) < 0 || Bread(m.f, strbuf) != len(strbuf) {
+ if obj.Bseek(m.f, m.base+int64(symtab.stroff), 0) < 0 || obj.Bread(m.f, strbuf) != len(strbuf) {
return -1
}
}
n := int(symtab.nsym * uint32(symsize))
symbuf := make([]byte, n)
- if Bseek(m.f, m.base+int64(symtab.symoff), 0) < 0 || Bread(m.f, symbuf) != len(symbuf) {
+ if obj.Bseek(m.f, m.base+int64(symtab.symoff), 0) < 0 || obj.Bread(m.f, symbuf) != len(symbuf) {
return -1
}
sym := make([]LdMachoSym, symtab.nsym)
return 0
}
-func ldmacho(f *Biobuf, pkg string, length int64, pn string) {
+func ldmacho(f *obj.Biobuf, pkg string, length int64, pn string) {
var err error
var j int
var is64 bool
var name string
Ctxt.Version++
- base := Boffset(f)
- if Bread(f, hdr[:]) != len(hdr) {
+ base := obj.Boffset(f)
+ if obj.Bread(f, hdr[:]) != len(hdr) {
goto bad
}
if is64 {
var tmp [4]uint8
- Bread(f, tmp[:4]) // skip reserved word in header
+ obj.Bread(f, tmp[:4]) // skip reserved word in header
}
m = new(LdMachoObj)
m.cmd = make([]LdMachoCmd, ncmd)
off = uint32(len(hdr))
cmdp = make([]byte, cmdsz)
- if Bread(f, cmdp) != len(cmdp) {
+ if obj.Bread(f, cmdp) != len(cmdp) {
err = fmt.Errorf("reading cmds: %v", err)
goto bad
}
}
dat = make([]byte, c.seg.filesz)
- if Bseek(f, m.base+int64(c.seg.fileoff), 0) < 0 || Bread(f, dat) != len(dat) {
+ if obj.Bseek(f, m.base+int64(c.seg.fileoff), 0) < 0 || obj.Bread(f, dat) != len(dat) {
err = fmt.Errorf("cannot load object data: %v", err)
goto bad
}
}
type PeObj struct {
- f *Biobuf
+ f *obj.Biobuf
name string
base uint32
sect []PeSect
snames []byte
}
-func ldpe(f *Biobuf, pkg string, length int64, pn string) {
+func ldpe(f *obj.Biobuf, pkg string, length int64, pn string) {
if Debug['v'] != 0 {
fmt.Fprintf(&Bso, "%5.2f ldpe %s\n", obj.Cputime(), pn)
}
var sect *PeSect
Ctxt.Version++
- base := int32(Boffset(f))
+ base := int32(obj.Boffset(f))
peobj := new(PeObj)
peobj.f = f
// TODO return error if found .cormeta
// load string table
- Bseek(f, int64(base)+int64(peobj.fh.PointerToSymbolTable)+int64(len(symbuf))*int64(peobj.fh.NumberOfSymbols), 0)
+ obj.Bseek(f, int64(base)+int64(peobj.fh.PointerToSymbolTable)+int64(len(symbuf))*int64(peobj.fh.NumberOfSymbols), 0)
- if Bread(f, symbuf[:4]) != 4 {
+ if obj.Bread(f, symbuf[:4]) != 4 {
goto bad
}
l = Le32(symbuf[:])
peobj.snames = make([]byte, l)
- Bseek(f, int64(base)+int64(peobj.fh.PointerToSymbolTable)+int64(len(symbuf))*int64(peobj.fh.NumberOfSymbols), 0)
- if Bread(f, peobj.snames) != len(peobj.snames) {
+ obj.Bseek(f, int64(base)+int64(peobj.fh.PointerToSymbolTable)+int64(len(symbuf))*int64(peobj.fh.NumberOfSymbols), 0)
+ if obj.Bread(f, peobj.snames) != len(peobj.snames) {
goto bad
}
peobj.pesym = make([]PeSym, peobj.fh.NumberOfSymbols)
peobj.npesym = uint(peobj.fh.NumberOfSymbols)
- Bseek(f, int64(base)+int64(peobj.fh.PointerToSymbolTable), 0)
+ obj.Bseek(f, int64(base)+int64(peobj.fh.PointerToSymbolTable), 0)
for i := 0; uint32(i) < peobj.fh.NumberOfSymbols; i += numaux + 1 {
- Bseek(f, int64(base)+int64(peobj.fh.PointerToSymbolTable)+int64(len(symbuf))*int64(i), 0)
- if Bread(f, symbuf[:]) != len(symbuf) {
+ obj.Bseek(f, int64(base)+int64(peobj.fh.PointerToSymbolTable)+int64(len(symbuf))*int64(i), 0)
+ if obj.Bread(f, symbuf[:]) != len(symbuf) {
goto bad
}
}
r = make([]Reloc, rsect.sh.NumberOfRelocations)
- Bseek(f, int64(peobj.base)+int64(rsect.sh.PointerToRelocations), 0)
+ obj.Bseek(f, int64(peobj.base)+int64(rsect.sh.PointerToRelocations), 0)
for j = 0; j < int(rsect.sh.NumberOfRelocations); j++ {
rp = &r[j]
- if Bread(f, symbuf[:10]) != 10 {
+ if obj.Bread(f, symbuf[:10]) != 10 {
goto bad
}
rva := Le32(symbuf[0:])
if sect.sh.PointerToRawData == 0 { // .bss doesn't have data in object file
return 0
}
- if Bseek(peobj.f, int64(peobj.base)+int64(sect.sh.PointerToRawData), 0) < 0 || Bread(peobj.f, sect.base) != len(sect.base) {
+ if obj.Bseek(peobj.f, int64(peobj.base)+int64(sect.sh.PointerToRawData), 0) < 0 || obj.Bread(peobj.f, sect.base) != len(sect.base) {
return -1
}
var (
headstring string
// buffered output
- Bso Biobuf
+ Bso obj.Biobuf
)
var coutbuf struct {
* look for the next file in an archive.
* adapted from libmach.
*/
-func nextar(bp *Biobuf, off int64, a *ArHdr) int64 {
+func nextar(bp *obj.Biobuf, off int64, a *ArHdr) int64 {
if off&1 != 0 {
off++
}
- Bseek(bp, off, 0)
+ obj.Bseek(bp, off, 0)
buf := make([]byte, SAR_HDR)
- if n := Bread(bp, buf); n < len(buf) {
+ if n := obj.Bread(bp, buf); n < len(buf) {
if n >= 0 {
return 0
}
if Debug['v'] > 1 {
fmt.Fprintf(&Bso, "%5.2f ldobj: %s (%s)\n", obj.Cputime(), file, pkg)
}
- Bflush(&Bso)
+ Bso.Flush()
var err error
- var f *Biobuf
- f, err = Bopenr(file)
+ var f *obj.Biobuf
+ f, err = obj.Bopenr(file)
if err != nil {
Exitf("cannot open file %s: %v", file, err)
}
magbuf := make([]byte, len(ARMAG))
- if Bread(f, magbuf) != len(magbuf) || !strings.HasPrefix(string(magbuf), ARMAG) {
+ if obj.Bread(f, magbuf) != len(magbuf) || !strings.HasPrefix(string(magbuf), ARMAG) {
/* load it as a regular file */
- l := Bseek(f, 0, 2)
+ l := obj.Bseek(f, 0, 2)
- Bseek(f, 0, 0)
+ obj.Bseek(f, 0, 0)
ldobj(f, pkg, l, file, file, FileObj)
- Bterm(f)
+ obj.Bterm(f)
return
}
/* skip over optional __.GOSYMDEF and process __.PKGDEF */
- off := Boffset(f)
+ off := obj.Boffset(f)
var arhdr ArHdr
l := nextar(f, off, &arhdr)
}
out:
- Bterm(f)
+ obj.Bterm(f)
}
type Hostobj struct {
- ld func(*Biobuf, string, int64, string)
+ ld func(*obj.Biobuf, string, int64, string)
pkg string
pn string
file string
"runtime/race",
}
-func ldhostobj(ld func(*Biobuf, string, int64, string), f *Biobuf, pkg string, length int64, pn string, file string) {
+func ldhostobj(ld func(*obj.Biobuf, string, int64, string), f *obj.Biobuf, pkg string, length int64, pn string, file string) {
isinternal := false
for i := 0; i < len(internalpkg); i++ {
if pkg == internalpkg[i] {
h.pkg = pkg
h.pn = pn
h.file = file
- h.off = Boffset(f)
+ h.off = obj.Boffset(f)
h.length = length
}
func hostobjs() {
- var f *Biobuf
+ var f *obj.Biobuf
var h *Hostobj
for i := 0; i < len(hostobj); i++ {
h = &hostobj[i]
var err error
- f, err = Bopenr(h.file)
+ f, err = obj.Bopenr(h.file)
if f == nil {
Exitf("cannot reopen %s: %v", h.pn, err)
}
- Bseek(f, h.off, 0)
+ obj.Bseek(f, h.off, 0)
h.ld(f, h.pkg, h.length, h.pn)
- Bterm(f)
+ obj.Bterm(f)
}
}
if Debug['v'] != 0 {
fmt.Fprintf(&Bso, "archive: %s\n", strings.Join(argv, " "))
- Bflush(&Bso)
+ Bso.Flush()
}
if out, err := exec.Command(argv[0], argv[1:]...).CombinedOutput(); err != nil {
fmt.Fprintf(&Bso, " %q", v)
}
fmt.Fprintf(&Bso, "\n")
- Bflush(&Bso)
+ Bso.Flush()
}
if out, err := exec.Command(argv[0], argv[1:]...).CombinedOutput(); err != nil {
}
}
-func ldobj(f *Biobuf, pkg string, length int64, pn string, file string, whence int) {
- eof := Boffset(f) + length
+func ldobj(f *obj.Biobuf, pkg string, length int64, pn string, file string, whence int) {
+ eof := obj.Boffset(f) + length
- start := Boffset(f)
- c1 := Bgetc(f)
- c2 := Bgetc(f)
- c3 := Bgetc(f)
- c4 := Bgetc(f)
- Bseek(f, start, 0)
+ start := obj.Boffset(f)
+ c1 := obj.Bgetc(f)
+ c2 := obj.Bgetc(f)
+ c3 := obj.Bgetc(f)
+ c4 := obj.Bgetc(f)
+ obj.Bseek(f, start, 0)
magic := uint32(c1)<<24 | uint32(c2)<<16 | uint32(c3)<<8 | uint32(c4)
if magic == 0x7f454c46 { // \x7F E L F
}
/* check the header */
- line := Brdline(f, '\n')
+ line := obj.Brdline(f, '\n')
if line == "" {
- if Blinelen(f) > 0 {
+ if obj.Blinelen(f) > 0 {
Diag("%s: not an object file", pn)
return
}
}
/* skip over exports and other info -- ends with \n!\n */
- import0 := Boffset(f)
+ import0 := obj.Boffset(f)
c1 = '\n' // the last line ended in \n
- c2 = Bgetc(f)
- c3 = Bgetc(f)
+ c2 = obj.Bgetc(f)
+ c3 = obj.Bgetc(f)
for c1 != '\n' || c2 != '!' || c3 != '\n' {
c1 = c2
c2 = c3
- c3 = Bgetc(f)
- if c3 == Beof {
+ c3 = obj.Bgetc(f)
+ if c3 == obj.Beof {
Diag("truncated object file: %s", pn)
return
}
}
- import1 := Boffset(f)
+ import1 := obj.Boffset(f)
- Bseek(f, import0, 0)
+ obj.Bseek(f, import0, 0)
ldpkg(f, pkg, import1-import0-2, pn, whence) // -2 for !\n
- Bseek(f, import1, 0)
+ obj.Bseek(f, import1, 0)
- ldobjfile(Ctxt, f, pkg, eof-Boffset(f), pn)
+ ldobjfile(Ctxt, f, pkg, eof-obj.Boffset(f), pn)
}
func ldshlibsyms(shlib string) {
}
if Ctxt.Debugvlog > 1 && Ctxt.Bso != nil {
fmt.Fprintf(Ctxt.Bso, "%5.2f ldshlibsyms: found library with name %s at %s\n", obj.Cputime(), shlib, libpath)
- Bflush(Ctxt.Bso)
+ Ctxt.Bso.Flush()
}
f, err := elf.Open(libpath)
if Debug['v'] != 0 || Debug['n'] != 0 {
fmt.Fprintf(&Bso, "%5.2f symsize = %d\n", obj.Cputime(), uint32(Symsize))
}
- Bflush(&Bso)
+ Bso.Flush()
}
func Symaddr(s *LSym) int64 {
package ld
-import "encoding/binary"
+import (
+ "cmd/internal/obj"
+ "encoding/binary"
+)
type LSym struct {
Name string
Arch *LinkArch
Debugasm int32
Debugvlog int32
- Bso *Biobuf
+ Bso *obj.Biobuf
Windows int32
Goroot string
Hash map[symVer]*LSym
endmagic = "\xff\xffgo13ld"
)
-func ldobjfile(ctxt *Link, f *Biobuf, pkg string, length int64, pn string) {
- start := Boffset(f)
+func ldobjfile(ctxt *Link, f *obj.Biobuf, pkg string, length int64, pn string) {
+ start := obj.Boffset(f)
ctxt.Version++
var buf [8]uint8
- Bread(f, buf[:])
+ obj.Bread(f, buf[:])
if string(buf[:]) != startmagic {
log.Fatalf("%s: invalid file start %x %x %x %x %x %x %x %x", pn, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7])
}
- c := Bgetc(f)
+ c := obj.Bgetc(f)
if c != 1 {
log.Fatalf("%s: invalid file version number %d", pn, c)
}
}
for {
- c, err := f.r.Peek(1)
+ c, err := f.Peek(1)
if err != nil {
log.Fatalf("%s: peeking: %v", pn, err)
}
}
buf = [8]uint8{}
- Bread(f, buf[:])
+ obj.Bread(f, buf[:])
if string(buf[:]) != endmagic {
log.Fatalf("%s: invalid file end", pn)
}
- if Boffset(f) != start+length {
- log.Fatalf("%s: unexpected end at %d, want %d", pn, int64(Boffset(f)), int64(start+length))
+ if obj.Boffset(f) != start+length {
+ log.Fatalf("%s: unexpected end at %d, want %d", pn, int64(obj.Boffset(f)), int64(start+length))
}
}
var readsym_ndup int
-func readsym(ctxt *Link, f *Biobuf, pkg string, pn string) {
- if Bgetc(f) != 0xfe {
+func readsym(ctxt *Link, f *obj.Biobuf, pkg string, pn string) {
+ if obj.Bgetc(f) != 0xfe {
log.Fatalf("readsym out of sync")
}
t := int(rdint(f))
}
}
-func rdint(f *Biobuf) int64 {
+func rdint(f *obj.Biobuf) int64 {
var c int
uv := uint64(0)
if shift >= 64 {
log.Fatalf("corrupt input")
}
- c = Bgetc(f)
+ c = obj.Bgetc(f)
uv |= uint64(c&0x7F) << uint(shift)
if c&0x80 == 0 {
break
return int64(uv>>1) ^ (int64(uint64(uv)<<63) >> 63)
}
-func rdstring(f *Biobuf) string {
+func rdstring(f *obj.Biobuf) string {
n := rdint(f)
p := make([]byte, n)
- Bread(f, p)
+ obj.Bread(f, p)
return string(p)
}
-func rddata(f *Biobuf) []byte {
+func rddata(f *obj.Biobuf) []byte {
n := rdint(f)
p := make([]byte, n)
- Bread(f, p)
+ obj.Bread(f, p)
return p
}
var symbuf []byte
-func rdsym(ctxt *Link, f *Biobuf, pkg string) *LSym {
+func rdsym(ctxt *Link, f *obj.Biobuf, pkg string) *LSym {
n := int(rdint(f))
if n == 0 {
rdint(f)
if len(symbuf) < n {
symbuf = make([]byte, n)
}
- Bread(f, symbuf[:n])
+ obj.Bread(f, symbuf[:n])
p := string(symbuf[:n])
v := int(rdint(f))
if v != 0 {
Ctxt.Diag = Diag
Ctxt.Bso = &Bso
- Bso = *Binitw(os.Stdout)
+ Bso = *obj.Binitw(os.Stdout)
Debug = [128]int{}
nerrors = 0
outfile = ""
if Debug['v'] != 0 {
fmt.Fprintf(&Bso, "HEADER = -H%d -T0x%x -D0x%x -R0x%x\n", HEADTYPE, uint64(INITTEXT), uint64(INITDAT), uint32(INITRND))
}
- Bflush(&Bso)
+ Bso.Flush()
if Buildmode == BuildmodeShared {
for i := 0; i < flag.NArg(); i++ {
fmt.Fprintf(&Bso, "%d liveness data\n", liveness)
}
- Bflush(&Bso)
+ Bso.Flush()
errorexit()
}
package ld
import (
- "bufio"
"bytes"
"encoding/binary"
- "io"
"log"
"os"
"runtime"
return s
}
-type Biobuf struct {
- f *os.File
- r *bufio.Reader
- w *bufio.Writer
- linelen int
-}
-
-func Bopenw(name string) (*Biobuf, error) {
- f, err := os.Create(name)
- if err != nil {
- return nil, err
- }
- return &Biobuf{f: f, w: bufio.NewWriter(f)}, nil
-}
-
-func Bopenr(name string) (*Biobuf, error) {
- f, err := os.Open(name)
- if err != nil {
- return nil, err
- }
- return &Biobuf{f: f, r: bufio.NewReader(f)}, nil
-}
-
-func Binitw(w *os.File) *Biobuf {
- return &Biobuf{w: bufio.NewWriter(w), f: w}
-}
-
-func (b *Biobuf) Write(p []byte) (int, error) {
- return b.w.Write(p)
-}
-
-func Bwritestring(b *Biobuf, p string) (int, error) {
- return b.w.WriteString(p)
-}
-
-func Bseek(b *Biobuf, offset int64, whence int) int64 {
- if b.w != nil {
- if err := b.w.Flush(); err != nil {
- log.Fatalf("writing output: %v", err)
- }
- } else if b.r != nil {
- if whence == 1 {
- offset -= int64(b.r.Buffered())
- }
- }
- off, err := b.f.Seek(offset, whence)
- if err != nil {
- log.Panicf("seeking in output [%d %d %p]: %v", offset, whence, b.f, err)
- }
- if b.r != nil {
- b.r.Reset(b.f)
- }
- return off
-}
-
-func Boffset(b *Biobuf) int64 {
- if b.w != nil {
- if err := b.w.Flush(); err != nil {
- log.Fatalf("writing output: %v", err)
- }
- }
- off, err := b.f.Seek(0, 1)
- if err != nil {
- log.Fatalf("seeking in output [0, 1]: %v", err)
- }
- if b.r != nil {
- off -= int64(b.r.Buffered())
- }
- return off
-}
-
-func (b *Biobuf) Flush() error {
- return b.w.Flush()
-}
-
-func Bwrite(b *Biobuf, p []byte) (int, error) {
- return b.w.Write(p)
-}
-
-func Bputc(b *Biobuf, c byte) {
- b.w.WriteByte(c)
-}
-
-const Beof = -1
-
-func Bread(b *Biobuf, p []byte) int {
- n, err := io.ReadFull(b.r, p)
- if n == 0 {
- if err != nil && err != io.EOF {
- n = -1
- }
- }
- return n
-}
-
-func Bgetc(b *Biobuf) int {
- c, err := b.r.ReadByte()
- if err != nil {
- return -1
- }
- return int(c)
-}
-
-func Bgetrune(b *Biobuf) int {
- r, _, err := b.r.ReadRune()
- if err != nil {
- return -1
- }
- return int(r)
-}
-
-func (b *Biobuf) Read(p []byte) (int, error) {
- return b.r.Read(p)
-}
-
-func Brdline(b *Biobuf, delim int) string {
- s, err := b.r.ReadBytes(byte(delim))
- if err != nil {
- log.Fatalf("reading input: %v", err)
- }
- b.linelen = len(s)
- return string(s)
-}
-
-func Brdstr(b *Biobuf, delim int, cut int) string {
- s, err := b.r.ReadString(byte(delim))
- if err != nil {
- log.Fatalf("reading input: %v", err)
- }
- if len(s) > 0 && cut > 0 {
- s = s[:len(s)-1]
- }
- return s
-}
-
func Access(name string, mode int) int {
if mode != 0 {
panic("bad access")
return 0
}
-func Blinelen(b *Biobuf) int {
- return b.linelen
-}
-
-func Bflush(b *Biobuf) error {
- return b.w.Flush()
-}
-
-func Bterm(b *Biobuf) error {
- var err error
- if b.w != nil {
- err = b.w.Flush()
- }
- err1 := b.f.Close()
- if err == nil {
- err = err1
- }
- return err
-}
-
// strings.Compare, introduced in Go 1.5.
func stringsCompare(a, b string) int {
if a == b {
}
func Boffset(b *Biobuf) int64 {
- if err := b.w.Flush(); err != nil {
- log.Fatalf("writing output: %v", err)
+ if b.w != nil {
+ if err := b.w.Flush(); err != nil {
+ log.Fatalf("writing output: %v", err)
+ }
}
off, err := b.f.Seek(0, 1)
if err != nil {
- log.Fatalf("seeking in output: %v", err)
+ log.Fatalf("seeking in output [0, 1]: %v", err)
+ }
+ if b.r != nil {
+ off -= int64(b.r.Buffered())
}
return off
}