本文整理匯總了Golang中cmd/internal/obj.Boffset函數的典型用法代碼示例。如果您正苦於以下問題:Golang Boffset函數的具體用法?Golang Boffset怎麽用?Golang Boffset使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Boffset函數的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ldobjfile
func ldobjfile(ctxt *Link, f *obj.Biobuf, pkg string, length int64, pn string) {
start := obj.Boffset(f)
ctxt.IncVersion()
var buf [8]uint8
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 := obj.Bgetc(f)
if c != 1 {
log.Fatalf("%s: invalid file version number %d", pn, c)
}
var lib string
for {
lib = rdstring(f)
if lib == "" {
break
}
addlib(ctxt, pkg, pn, lib)
}
ctxt.CurRefs = []*LSym{nil} // zeroth ref is nil
for {
c, err := f.Peek(1)
if err != nil {
log.Fatalf("%s: peeking: %v", pn, err)
}
if c[0] == 0xff {
obj.Bgetc(f)
break
}
readref(ctxt, f, pkg, pn)
}
dataLength := rdint64(f)
data := make([]byte, dataLength)
obj.Bread(f, data)
for {
c, err := f.Peek(1)
if err != nil {
log.Fatalf("%s: peeking: %v", pn, err)
}
if c[0] == 0xff {
break
}
readsym(ctxt, f, &data, pkg, pn)
}
buf = [8]uint8{}
obj.Bread(f, buf[:])
if string(buf[:]) != endmagic {
log.Fatalf("%s: invalid file end", pn)
}
if obj.Boffset(f) != start+length {
log.Fatalf("%s: unexpected end at %d, want %d", pn, int64(obj.Boffset(f)), int64(start+length))
}
}
示例2: ldhostobj
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] {
isinternal = true
break
}
}
// DragonFly declares errno with __thread, which results in a symbol
// type of R_386_TLS_GD or R_X86_64_TLSGD. The Go linker does not
// currently know how to handle TLS relocations, hence we have to
// force external linking for any libraries that link in code that
// uses errno. This can be removed if the Go linker ever supports
// these relocation types.
if HEADTYPE == obj.Hdragonfly {
if pkg == "net" || pkg == "os/user" {
isinternal = false
}
}
if !isinternal {
externalobj = true
}
hostobj = append(hostobj, Hostobj{})
h := &hostobj[len(hostobj)-1]
h.ld = ld
h.pkg = pkg
h.pn = pn
h.file = file
h.off = obj.Boffset(f)
h.length = length
}
示例3: hostArchive
// hostArchive reads an archive file holding host objects and links in
// required objects. The general format is the same as a Go archive
// file, but it has an armap listing symbols and the objects that
// define them. This is used for the compiler support library
// libgcc.a.
func hostArchive(name string) {
f, err := obj.Bopenr(name)
if err != nil {
if os.IsNotExist(err) {
// It's OK if we don't have a libgcc file at all.
return
}
Exitf("cannot open file %s: %v", name, err)
}
defer obj.Bterm(f)
magbuf := make([]byte, len(ARMAG))
if obj.Bread(f, magbuf) != len(magbuf) {
Exitf("file %s too short", name)
}
var arhdr ArHdr
l := nextar(f, obj.Boffset(f), &arhdr)
if l <= 0 {
Exitf("%s missing armap", name)
}
var armap archiveMap
if arhdr.name == "/" || arhdr.name == "/SYM64/" {
armap = readArmap(name, f, arhdr)
} else {
Exitf("%s missing armap", name)
}
loaded := make(map[uint64]bool)
any := true
for any {
var load []uint64
for s := Ctxt.Allsym; s != nil; s = s.Allsym {
for _, r := range s.R {
if r.Sym != nil && r.Sym.Type&obj.SMASK == obj.SXREF {
if off := armap[r.Sym.Name]; off != 0 && !loaded[off] {
load = append(load, off)
loaded[off] = true
}
}
}
}
for _, off := range load {
l := nextar(f, int64(off), &arhdr)
if l <= 0 {
Exitf("%s missing archive entry at offset %d", name, off)
}
pname := fmt.Sprintf("%s(%s)", name, arhdr.name)
l = atolwhex(arhdr.size)
h := ldobj(f, "libgcc", l, pname, name, ArchiveObj)
obj.Bseek(f, h.off, 0)
h.ld(f, h.pkg, h.length, h.pn)
}
any = len(load) > 0
}
}
示例4: ldobjfile
func ldobjfile(ctxt *Link, f *obj.Biobuf, pkg string, length int64, pn string) {
start := obj.Boffset(f)
ctxt.Version++
var buf [8]uint8
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 := obj.Bgetc(f)
if c != 1 {
log.Fatalf("%s: invalid file version number %d", pn, c)
}
var lib string
for {
lib = rdstring(f)
if lib == "" {
break
}
addlib(ctxt, pkg, pn, lib)
}
for {
c, err := f.Peek(1)
if err != nil {
log.Fatalf("%s: peeking: %v", pn, err)
}
if c[0] == 0xff {
break
}
readsym(ctxt, f, pkg, pn)
}
buf = [8]uint8{}
obj.Bread(f, buf[:])
if string(buf[:]) != endmagic {
log.Fatalf("%s: invalid file end", pn)
}
if obj.Boffset(f) != start+length {
log.Fatalf("%s: unexpected end at %d, want %d", pn, int64(obj.Boffset(f)), int64(start+length))
}
}
示例5: dumpobj
func dumpobj() {
var err error
bout, err = obj.Bopenw(outfile)
if err != nil {
Flusherrors()
fmt.Printf("can't create %s: %v\n", outfile, err)
errorexit()
}
startobj := int64(0)
var arhdr [ArhdrSize]byte
if writearchive != 0 {
obj.Bwritestring(bout, "!<arch>\n")
arhdr = [ArhdrSize]byte{}
bout.Write(arhdr[:])
startobj = obj.Boffset(bout)
}
fmt.Fprintf(bout, "go object %s %s %s %s\n", obj.Getgoos(), obj.Getgoarch(), obj.Getgoversion(), obj.Expstring())
dumpexport()
if writearchive != 0 {
bout.Flush()
size := obj.Boffset(bout) - startobj
if size&1 != 0 {
obj.Bputc(bout, 0)
}
obj.Bseek(bout, startobj-ArhdrSize, 0)
formathdr(arhdr[:], "__.PKGDEF", size)
bout.Write(arhdr[:])
bout.Flush()
obj.Bseek(bout, startobj+size+(size&1), 0)
arhdr = [ArhdrSize]byte{}
bout.Write(arhdr[:])
startobj = obj.Boffset(bout)
fmt.Fprintf(bout, "go object %s %s %s %s\n", obj.Getgoos(), obj.Getgoarch(), obj.Getgoversion(), obj.Expstring())
}
if pragcgobuf != "" {
if writearchive != 0 {
// write empty export section; must be before cgo section
fmt.Fprintf(bout, "\n$$\n\n$$\n\n")
}
fmt.Fprintf(bout, "\n$$ // cgo\n")
fmt.Fprintf(bout, "%s\n$$\n\n", pragcgobuf)
}
fmt.Fprintf(bout, "\n!\n")
externs := len(externdcl)
dumpglobls()
dumptypestructs()
// Dump extra globals.
tmp := externdcl
if externdcl != nil {
externdcl = externdcl[externs:]
}
dumpglobls()
externdcl = tmp
dumpdata()
obj.Writeobjdirect(Ctxt, bout)
if writearchive != 0 {
bout.Flush()
size := obj.Boffset(bout) - startobj
if size&1 != 0 {
obj.Bputc(bout, 0)
}
obj.Bseek(bout, startobj-ArhdrSize, 0)
formathdr(arhdr[:], "_go_.o", size)
bout.Write(arhdr[:])
}
obj.Bterm(bout)
}
示例6: objfile
func objfile(lib *Library) {
pkg := pathtoprefix(lib.Pkg)
if Debug['v'] > 1 {
fmt.Fprintf(&Bso, "%5.2f ldobj: %s (%s)\n", obj.Cputime(), lib.File, pkg)
}
Bso.Flush()
var err error
var f *obj.Biobuf
f, err = obj.Bopenr(lib.File)
if err != nil {
Exitf("cannot open file %s: %v", lib.File, err)
}
magbuf := make([]byte, len(ARMAG))
if obj.Bread(f, magbuf) != len(magbuf) || !strings.HasPrefix(string(magbuf), ARMAG) {
/* load it as a regular file */
l := obj.Bseek(f, 0, 2)
obj.Bseek(f, 0, 0)
ldobj(f, pkg, l, lib.File, lib.File, FileObj)
obj.Bterm(f)
return
}
/* skip over optional __.GOSYMDEF and process __.PKGDEF */
off := obj.Boffset(f)
var arhdr ArHdr
l := nextar(f, off, &arhdr)
var pname string
if l <= 0 {
Diag("%s: short read on archive file symbol header", lib.File)
goto out
}
if strings.HasPrefix(arhdr.name, symname) {
off += l
l = nextar(f, off, &arhdr)
if l <= 0 {
Diag("%s: short read on archive file symbol header", lib.File)
goto out
}
}
if !strings.HasPrefix(arhdr.name, pkgname) {
Diag("%s: cannot find package header", lib.File)
goto out
}
if Buildmode == BuildmodeShared {
before := obj.Boffset(f)
pkgdefBytes := make([]byte, atolwhex(arhdr.size))
obj.Bread(f, pkgdefBytes)
hash := sha1.Sum(pkgdefBytes)
lib.hash = hash[:]
obj.Bseek(f, before, 0)
}
off += l
if Debug['u'] != 0 {
ldpkg(f, pkg, atolwhex(arhdr.size), lib.File, Pkgdef)
}
/*
* load all the object files from the archive now.
* this gives us sequential file access and keeps us
* from needing to come back later to pick up more
* objects. it breaks the usual C archive model, but
* this is Go, not C. the common case in Go is that
* we need to load all the objects, and then we throw away
* the individual symbols that are unused.
*
* loading every object will also make it possible to
* load foreign objects not referenced by __.GOSYMDEF.
*/
for {
l = nextar(f, off, &arhdr)
if l == 0 {
break
}
if l < 0 {
Exitf("%s: malformed archive", lib.File)
}
off += l
pname = fmt.Sprintf("%s(%s)", lib.File, arhdr.name)
l = atolwhex(arhdr.size)
ldobj(f, pkg, l, pname, lib.File, ArchiveObj)
}
out:
obj.Bterm(f)
}
示例7: ldobj
func ldobj(f *obj.Biobuf, pkg string, length int64, pn string, file string, whence int) {
eof := obj.Boffset(f) + length
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
ldhostobj(ldelf, f, pkg, length, pn, file)
return
}
if magic&^1 == 0xfeedface || magic&^0x01000000 == 0xcefaedfe {
ldhostobj(ldmacho, f, pkg, length, pn, file)
return
}
if c1 == 0x4c && c2 == 0x01 || c1 == 0x64 && c2 == 0x86 {
ldhostobj(ldpe, f, pkg, length, pn, file)
return
}
/* check the header */
line := obj.Brdline(f, '\n')
if line == "" {
if obj.Blinelen(f) > 0 {
Diag("%s: not an object file", pn)
return
}
Diag("truncated object file: %s", pn)
return
}
if !strings.HasPrefix(line, "go object ") {
if strings.HasSuffix(pn, ".go") {
Exitf("%cl: input %s is not .%c file (use %cg to compile .go files)", Thearch.Thechar, pn, Thearch.Thechar, Thearch.Thechar)
}
if line == Thestring {
// old header format: just $GOOS
Diag("%s: stale object file", pn)
return
}
Diag("%s: not an object file", pn)
return
}
// First, check that the basic goos, goarch, and version match.
t := fmt.Sprintf("%s %s %s ", goos, obj.Getgoarch(), obj.Getgoversion())
line = strings.TrimRight(line, "\n")
if !strings.HasPrefix(line[10:]+" ", t) && Debug['f'] == 0 {
Diag("%s: object is [%s] expected [%s]", pn, line[10:], t)
return
}
// Second, check that longer lines match each other exactly,
// so that the Go compiler and write additional information
// that must be the same from run to run.
if len(line) >= len(t)+10 {
if theline == "" {
theline = line[10:]
} else if theline != line[10:] {
Diag("%s: object is [%s] expected [%s]", pn, line[10:], theline)
return
}
}
/* skip over exports and other info -- ends with \n!\n */
import0 := obj.Boffset(f)
c1 = '\n' // the last line ended in \n
c2 = obj.Bgetc(f)
c3 = obj.Bgetc(f)
for c1 != '\n' || c2 != '!' || c3 != '\n' {
c1 = c2
c2 = c3
c3 = obj.Bgetc(f)
if c3 == obj.Beof {
Diag("truncated object file: %s", pn)
return
}
}
import1 := obj.Boffset(f)
obj.Bseek(f, import0, 0)
ldpkg(f, pkg, import1-import0-2, pn, whence) // -2 for !\n
obj.Bseek(f, import1, 0)
ldobjfile(Ctxt, f, pkg, eof-obj.Boffset(f), pn)
}
示例8: ldelf
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(obj.Boffset(f))
var add uint64
var e binary.ByteOrder
var elfobj *ElfObj
var err error
var flag int
var hdr *ElfHdrBytes
var hdrbuf [64]uint8
var info uint64
var is64 int
var j int
var n int
var name string
var p []byte
var r []Reloc
var rela int
var rp *Reloc
var rsect *ElfSect
var s *LSym
var sect *ElfSect
var sym ElfSym
var symbols []*LSym
if obj.Bread(f, hdrbuf[:]) != len(hdrbuf) {
goto bad
}
hdr = new(ElfHdrBytes)
binary.Read(bytes.NewReader(hdrbuf[:]), binary.BigEndian, hdr) // only byte arrays; byte order doesn't matter
if string(hdr.Ident[:4]) != "\x7FELF" {
goto bad
}
switch hdr.Ident[5] {
case ElfDataLsb:
e = binary.LittleEndian
case ElfDataMsb:
e = binary.BigEndian
default:
goto bad
}
// read header
elfobj = new(ElfObj)
elfobj.e = e
elfobj.f = f
elfobj.base = int64(base)
elfobj.length = length
elfobj.name = pn
is64 = 0
if hdr.Ident[4] == ElfClass64 {
is64 = 1
hdr := new(ElfHdrBytes64)
binary.Read(bytes.NewReader(hdrbuf[:]), binary.BigEndian, hdr) // only byte arrays; byte order doesn't matter
elfobj.type_ = uint32(e.Uint16(hdr.Type[:]))
elfobj.machine = uint32(e.Uint16(hdr.Machine[:]))
elfobj.version = e.Uint32(hdr.Version[:])
elfobj.phoff = e.Uint64(hdr.Phoff[:])
elfobj.shoff = e.Uint64(hdr.Shoff[:])
elfobj.flags = e.Uint32(hdr.Flags[:])
elfobj.ehsize = uint32(e.Uint16(hdr.Ehsize[:]))
elfobj.phentsize = uint32(e.Uint16(hdr.Phentsize[:]))
elfobj.phnum = uint32(e.Uint16(hdr.Phnum[:]))
elfobj.shentsize = uint32(e.Uint16(hdr.Shentsize[:]))
elfobj.shnum = uint32(e.Uint16(hdr.Shnum[:]))
elfobj.shstrndx = uint32(e.Uint16(hdr.Shstrndx[:]))
} else {
elfobj.type_ = uint32(e.Uint16(hdr.Type[:]))
elfobj.machine = uint32(e.Uint16(hdr.Machine[:]))
elfobj.version = e.Uint32(hdr.Version[:])
elfobj.entry = uint64(e.Uint32(hdr.Entry[:]))
elfobj.phoff = uint64(e.Uint32(hdr.Phoff[:]))
elfobj.shoff = uint64(e.Uint32(hdr.Shoff[:]))
elfobj.flags = e.Uint32(hdr.Flags[:])
elfobj.ehsize = uint32(e.Uint16(hdr.Ehsize[:]))
elfobj.phentsize = uint32(e.Uint16(hdr.Phentsize[:]))
elfobj.phnum = uint32(e.Uint16(hdr.Phnum[:]))
elfobj.shentsize = uint32(e.Uint16(hdr.Shentsize[:]))
elfobj.shnum = uint32(e.Uint16(hdr.Shnum[:]))
elfobj.shstrndx = uint32(e.Uint16(hdr.Shstrndx[:]))
}
elfobj.is64 = is64
if uint32(hdr.Ident[6]) != elfobj.version {
goto bad
}
if e.Uint16(hdr.Type[:]) != ElfTypeRelocatable {
Diag("%s: elf but not elf relocatable object", pn)
return
}
//.........這裏部分代碼省略.........
示例9: ldpe
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(obj.Boffset(f))
peobj := new(PeObj)
peobj.f = f
peobj.base = uint32(base)
peobj.name = pn
// read header
var err error
var j int
var l uint32
var name string
var numaux int
var r []Reloc
var rp *Reloc
var rsect *PeSect
var s *LSym
var sym *PeSym
var symbuf [18]uint8
if err = binary.Read(f, binary.LittleEndian, &peobj.fh); err != nil {
goto bad
}
// load section list
peobj.sect = make([]PeSect, peobj.fh.NumberOfSections)
peobj.nsect = uint(peobj.fh.NumberOfSections)
for i := 0; i < int(peobj.fh.NumberOfSections); i++ {
if err = binary.Read(f, binary.LittleEndian, &peobj.sect[i].sh); err != nil {
goto bad
}
peobj.sect[i].size = uint64(peobj.sect[i].sh.SizeOfRawData)
peobj.sect[i].name = cstring(peobj.sect[i].sh.Name[:])
}
// TODO return error if found .cormeta
// load string table
obj.Bseek(f, int64(base)+int64(peobj.fh.PointerToSymbolTable)+int64(len(symbuf))*int64(peobj.fh.NumberOfSymbols), 0)
if obj.Bread(f, symbuf[:4]) != 4 {
goto bad
}
l = Le32(symbuf[:])
peobj.snames = make([]byte, l)
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
}
// rewrite section names if they start with /
for i := 0; i < int(peobj.fh.NumberOfSections); i++ {
if peobj.sect[i].name == "" {
continue
}
if peobj.sect[i].name[0] != '/' {
continue
}
n, _ := strconv.Atoi(peobj.sect[i].name[1:])
peobj.sect[i].name = cstring(peobj.snames[n:])
}
// read symbols
peobj.pesym = make([]PeSym, peobj.fh.NumberOfSymbols)
peobj.npesym = uint(peobj.fh.NumberOfSymbols)
obj.Bseek(f, int64(base)+int64(peobj.fh.PointerToSymbolTable), 0)
for i := 0; uint32(i) < peobj.fh.NumberOfSymbols; i += numaux + 1 {
obj.Bseek(f, int64(base)+int64(peobj.fh.PointerToSymbolTable)+int64(len(symbuf))*int64(i), 0)
if obj.Bread(f, symbuf[:]) != len(symbuf) {
goto bad
}
if (symbuf[0] == 0) && (symbuf[1] == 0) && (symbuf[2] == 0) && (symbuf[3] == 0) {
l = Le32(symbuf[4:])
peobj.pesym[i].name = cstring(peobj.snames[l:]) // sym name length <= 8
} else {
peobj.pesym[i].name = cstring(symbuf[:8])
}
peobj.pesym[i].value = Le32(symbuf[8:])
peobj.pesym[i].sectnum = Le16(symbuf[12:])
peobj.pesym[i].sclass = symbuf[16]
peobj.pesym[i].aux = symbuf[17]
peobj.pesym[i].type_ = Le16(symbuf[14:])
numaux = int(peobj.pesym[i].aux)
if numaux < 0 {
numaux = 0
}
}
// create symbols for mapped sections
for i := 0; uint(i) < peobj.nsect; i++ {
//.........這裏部分代碼省略.........
示例10: ldmacho
func ldmacho(f *obj.Biobuf, pkg string, length int64, pn string) {
var err error
var j int
var is64 bool
var secaddr uint64
var hdr [7 * 4]uint8
var cmdp []byte
var dat []byte
var ncmd uint32
var cmdsz uint32
var ty uint32
var sz uint32
var off uint32
var m *LdMachoObj
var e binary.ByteOrder
var sect *LdMachoSect
var rel *LdMachoRel
var rpi int
var s *LSym
var s1 *LSym
var outer *LSym
var c *LdMachoCmd
var symtab *LdMachoSymtab
var dsymtab *LdMachoDysymtab
var sym *LdMachoSym
var r []Reloc
var rp *Reloc
var name string
Ctxt.Version++
base := obj.Boffset(f)
if obj.Bread(f, hdr[:]) != len(hdr) {
goto bad
}
if binary.BigEndian.Uint32(hdr[:])&^1 == 0xFEEDFACE {
e = binary.BigEndian
} else if binary.LittleEndian.Uint32(hdr[:])&^1 == 0xFEEDFACE {
e = binary.LittleEndian
} else {
err = fmt.Errorf("bad magic - not mach-o file")
goto bad
}
is64 = e.Uint32(hdr[:]) == 0xFEEDFACF
ncmd = e.Uint32([]byte(hdr[4*4:]))
cmdsz = e.Uint32([]byte(hdr[5*4:]))
if ncmd > 0x10000 || cmdsz >= 0x01000000 {
err = fmt.Errorf("implausible mach-o header ncmd=%d cmdsz=%d", ncmd, cmdsz)
goto bad
}
if is64 {
var tmp [4]uint8
obj.Bread(f, tmp[:4]) // skip reserved word in header
}
m = new(LdMachoObj)
m.f = f
m.e = e
m.cputype = uint(e.Uint32([]byte(hdr[1*4:])))
m.subcputype = uint(e.Uint32([]byte(hdr[2*4:])))
m.filetype = e.Uint32([]byte(hdr[3*4:]))
m.ncmd = uint(ncmd)
m.flags = e.Uint32([]byte(hdr[6*4:]))
m.is64 = is64
m.base = base
m.length = length
m.name = pn
switch Thearch.Thechar {
default:
Diag("%s: mach-o %s unimplemented", pn, Thestring)
return
case '6':
if e != binary.LittleEndian || m.cputype != LdMachoCpuAmd64 {
Diag("%s: mach-o object but not amd64", pn)
return
}
case '8':
if e != binary.LittleEndian || m.cputype != LdMachoCpu386 {
Diag("%s: mach-o object but not 386", pn)
return
}
}
m.cmd = make([]LdMachoCmd, ncmd)
off = uint32(len(hdr))
cmdp = make([]byte, cmdsz)
if obj.Bread(f, cmdp) != len(cmdp) {
err = fmt.Errorf("reading cmds: %v", err)
goto bad
}
// read and parse load commands
c = nil
//.........這裏部分代碼省略.........
示例11: dumpobj
func dumpobj() {
var err error
bout, err = obj.Bopenw(outfile)
if err != nil {
Flusherrors()
fmt.Printf("can't create %s: %v\n", outfile, err)
errorexit()
}
startobj := int64(0)
var arhdr [ArhdrSize]byte
if writearchive != 0 {
obj.Bwritestring(bout, "!<arch>\n")
arhdr = [ArhdrSize]byte{}
obj.Bwrite(bout, arhdr[:])
startobj = obj.Boffset(bout)
}
fmt.Fprintf(bout, "go object %s %s %s %s\n", obj.Getgoos(), obj.Getgoarch(), obj.Getgoversion(), obj.Expstring())
dumpexport()
if writearchive != 0 {
obj.Bflush(bout)
size := obj.Boffset(bout) - startobj
if size&1 != 0 {
obj.Bputc(bout, 0)
}
obj.Bseek(bout, startobj-ArhdrSize, 0)
formathdr(arhdr[:], "__.PKGDEF", size)
obj.Bwrite(bout, arhdr[:])
obj.Bflush(bout)
obj.Bseek(bout, startobj+size+(size&1), 0)
arhdr = [ArhdrSize]byte{}
obj.Bwrite(bout, arhdr[:])
startobj = obj.Boffset(bout)
fmt.Fprintf(bout, "go object %s %s %s %s\n", obj.Getgoos(), obj.Getgoarch(), obj.Getgoversion(), obj.Expstring())
}
if pragcgobuf != "" {
if writearchive != 0 {
// write empty export section; must be before cgo section
fmt.Fprintf(bout, "\n$$\n\n$$\n\n")
}
fmt.Fprintf(bout, "\n$$ // cgo\n")
fmt.Fprintf(bout, "%s\n$$\n\n", pragcgobuf)
}
fmt.Fprintf(bout, "\n!\n")
var externs *NodeList
if externdcl != nil {
externs = externdcl.End
}
dumpglobls()
dumptypestructs()
// Dump extra globals.
tmp := externdcl
if externs != nil {
externdcl = externs.Next
}
dumpglobls()
externdcl = tmp
zero := Pkglookup("zerovalue", Runtimepkg)
ggloblsym(zero, int32(zerosize), obj.DUPOK|obj.RODATA)
dumpdata()
obj.Writeobjdirect(Ctxt, bout)
if writearchive != 0 {
obj.Bflush(bout)
size := obj.Boffset(bout) - startobj
if size&1 != 0 {
obj.Bputc(bout, 0)
}
obj.Bseek(bout, startobj-ArhdrSize, 0)
name := fmt.Sprintf("_go_.%c", Thearch.Thechar)
formathdr(arhdr[:], name, size)
obj.Bwrite(bout, arhdr[:])
}
obj.Bterm(bout)
}