本文整理匯總了Golang中cmd/internal/bio.Reader類的典型用法代碼示例。如果您正苦於以下問題:Golang Reader類的具體用法?Golang Reader怎麽用?Golang Reader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Reader類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: LoadObjFile
func LoadObjFile(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
start := f.Offset()
r := &objReader{
rd: f.Reader,
pkg: pkg,
ctxt: ctxt,
pn: pn,
dupSym: &Symbol{Name: ".dup"},
}
r.loadObjFile()
if f.Offset() != start+length {
log.Fatalf("%s: unexpected end at %d, want %d", pn, f.Offset(), start+length)
}
}
示例2: LoadObjFile
func LoadObjFile(ctxt *Link, f *bio.Reader, lib *Library, length int64, pn string) {
start := f.Offset()
r := &objReader{
rd: f.Reader,
lib: lib,
ctxt: ctxt,
pn: pn,
dupSym: &Symbol{Name: ".dup"},
localSymVersion: ctxt.Syms.IncVersion(),
}
r.loadObjFile()
if f.Offset() != start+length {
log.Fatalf("%s: unexpected end at %d, want %d", pn, f.Offset(), start+length)
}
}
示例3: ldelf
func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
if ctxt.Debugvlog != 0 {
ctxt.Logf("%5.2f ldelf %s\n", obj.Cputime(), pn)
}
localSymVersion := ctxt.Syms.IncVersion()
base := f.Offset()
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 *Symbol
var sect *ElfSect
var sym ElfSym
var symbols []*Symbol
if _, err := io.ReadFull(f, hdrbuf[:]); err != nil {
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 = 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 {
Errorf(nil, "%s: elf but not elf relocatable object", pn)
return
}
//.........這裏部分代碼省略.........
示例4: ldpeError
func ldpeError(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) error {
if ctxt.Debugvlog != 0 {
ctxt.Logf("%5.2f ldpe %s\n", obj.Cputime(), pn)
}
localSymVersion := ctxt.Syms.IncVersion()
sectsyms := make(map[*pe.Section]*Symbol)
sectdata := make(map[*pe.Section][]byte)
// Some input files are archives containing multiple of
// object files, and pe.NewFile seeks to the start of
// input file and get confused. Create section reader
// to stop pe.NewFile looking before current position.
sr := io.NewSectionReader((*peBiobuf)(input), input.Offset(), 1<<63-1)
// TODO: replace pe.NewFile with pe.Load (grep for "add Load function" in debug/pe for details)
f, err := pe.NewFile(sr)
if err != nil {
return err
}
defer f.Close()
// TODO return error if found .cormeta
// create symbols for mapped sections
for _, sect := range f.Sections {
if sect.Characteristics&IMAGE_SCN_MEM_DISCARDABLE != 0 {
continue
}
if sect.Characteristics&(IMAGE_SCN_CNT_CODE|IMAGE_SCN_CNT_INITIALIZED_DATA|IMAGE_SCN_CNT_UNINITIALIZED_DATA) == 0 {
// This has been seen for .idata sections, which we
// want to ignore. See issues 5106 and 5273.
continue
}
data, err := sect.Data()
if err != nil {
return err
}
sectdata[sect] = data
name := fmt.Sprintf("%s(%s)", pkg, sect.Name)
s := ctxt.Syms.Lookup(name, localSymVersion)
switch sect.Characteristics & (IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE) {
case IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ: //.rdata
s.Type = obj.SRODATA
case IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE: //.bss
s.Type = obj.SNOPTRBSS
case IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE: //.data
s.Type = obj.SNOPTRDATA
case IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ: //.text
s.Type = obj.STEXT
default:
return fmt.Errorf("unexpected flags %#06x for PE section %s", sect.Characteristics, sect.Name)
}
s.P = data
s.Size = int64(len(data))
sectsyms[sect] = s
if sect.Name == ".rsrc" {
setpersrc(ctxt, s)
}
}
// load relocations
for _, rsect := range f.Sections {
if _, found := sectsyms[rsect]; !found {
continue
}
if rsect.NumberOfRelocations == 0 {
continue
}
if rsect.Characteristics&IMAGE_SCN_MEM_DISCARDABLE != 0 {
continue
}
if rsect.Characteristics&(IMAGE_SCN_CNT_CODE|IMAGE_SCN_CNT_INITIALIZED_DATA|IMAGE_SCN_CNT_UNINITIALIZED_DATA) == 0 {
// This has been seen for .idata sections, which we
// want to ignore. See issues 5106 and 5273.
continue
}
rs := make([]Reloc, rsect.NumberOfRelocations)
for j, r := range rsect.Relocs {
rp := &rs[j]
if int(r.SymbolTableIndex) >= len(f.COFFSymbols) {
return fmt.Errorf("relocation number %d symbol index idx=%d cannot be large then number of symbols %d", j, r.SymbolTableIndex, len(f.COFFSymbols))
}
pesym := &f.COFFSymbols[r.SymbolTableIndex]
gosym, err := readpesym(ctxt, f, pesym, sectsyms, localSymVersion)
if err != nil {
return err
}
if gosym == nil {
//.........這裏部分代碼省略.........
示例5: ldmacho
func ldmacho(f *bio.Reader, 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.IncVersion()
base := f.Offset()
if _, err := io.ReadFull(f, hdr[:]); err != nil {
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(hdr[4*4:])
cmdsz = e.Uint32(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 {
f.Seek(4, 1) // skip reserved word in header
}
m = new(LdMachoObj)
m.f = f
m.e = e
m.cputype = uint(e.Uint32(hdr[1*4:]))
m.subcputype = uint(e.Uint32(hdr[2*4:]))
m.filetype = e.Uint32(hdr[3*4:])
m.ncmd = uint(ncmd)
m.flags = e.Uint32(hdr[6*4:])
m.is64 = is64
m.base = base
m.length = length
m.name = pn
switch SysArch.Family {
default:
Diag("%s: mach-o %s unimplemented", pn, SysArch.Name)
return
case sys.AMD64:
if e != binary.LittleEndian || m.cputype != LdMachoCpuAmd64 {
Diag("%s: mach-o object but not amd64", pn)
return
}
case sys.I386:
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 _, err2 := io.ReadFull(f, cmdp); err2 != nil {
err = fmt.Errorf("reading cmds: %v", err)
goto bad
}
// read and parse load commands
c = nil
symtab = nil
//.........這裏部分代碼省略.........
示例6: ldpe
func ldpe(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f ldpe %s\n", obj.Cputime(), pn)
}
var sect *PeSect
ctxt.IncVersion()
base := f.Offset()
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 *Symbol
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
f.Seek(base+int64(peobj.fh.PointerToSymbolTable)+int64(len(symbuf))*int64(peobj.fh.NumberOfSymbols), 0)
if _, err := io.ReadFull(f, symbuf[:4]); err != nil {
goto bad
}
l = Le32(symbuf[:])
peobj.snames = make([]byte, l)
f.Seek(base+int64(peobj.fh.PointerToSymbolTable)+int64(len(symbuf))*int64(peobj.fh.NumberOfSymbols), 0)
if _, err := io.ReadFull(f, peobj.snames); err != nil {
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)
f.Seek(base+int64(peobj.fh.PointerToSymbolTable), 0)
for i := 0; uint32(i) < peobj.fh.NumberOfSymbols; i += numaux + 1 {
f.Seek(base+int64(peobj.fh.PointerToSymbolTable)+int64(len(symbuf))*int64(i), 0)
if _, err := io.ReadFull(f, symbuf[:]); err != nil {
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++ {
//.........這裏部分代碼省略.........