mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/link/internal/ld: move ld.Cpos to coutbuf.Offset
This change moves the ld.Cpos function to a method on coutbuf. This is part of a larger change that makes ld.outbuf look more like a bio.Buf in an effort to eventually replace the former with the latter. Change-Id: I506f7131935a2aa903fa302a0fab0c5be50220fd Reviewed-on: https://go-review.googlesource.com/27578 Run-TryBot: Dave Cheney <dave@cheney.net> Reviewed-by: David Crawshaw <crawshaw@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
61d5daea0a
commit
5f94ff4c87
5 changed files with 34 additions and 35 deletions
|
|
@ -746,7 +746,7 @@ func Codeblk(ctxt *Link, addr int64, size int64) {
|
|||
}
|
||||
func CodeblkPad(ctxt *Link, addr int64, size int64, pad []byte) {
|
||||
if *flagA {
|
||||
fmt.Fprintf(ctxt.Bso, "codeblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos())
|
||||
fmt.Fprintf(ctxt.Bso, "codeblk [%#x,%#x) at offset %#x\n", addr, addr+size, coutbuf.Offset())
|
||||
}
|
||||
|
||||
blk(ctxt, ctxt.Textp, addr, size, pad)
|
||||
|
|
@ -857,7 +857,7 @@ func blk(ctxt *Link, syms []*Symbol, addr, size int64, pad []byte) {
|
|||
|
||||
func Datblk(ctxt *Link, addr int64, size int64) {
|
||||
if *flagA {
|
||||
fmt.Fprintf(ctxt.Bso, "datblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos())
|
||||
fmt.Fprintf(ctxt.Bso, "datblk [%#x,%#x) at offset %#x\n", addr, addr+size, coutbuf.Offset())
|
||||
}
|
||||
|
||||
blk(ctxt, datap, addr, size, zeros[:])
|
||||
|
|
@ -928,7 +928,7 @@ func Datblk(ctxt *Link, addr int64, size int64) {
|
|||
|
||||
func Dwarfblk(ctxt *Link, addr int64, size int64) {
|
||||
if *flagA {
|
||||
fmt.Fprintf(ctxt.Bso, "dwarfblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos())
|
||||
fmt.Fprintf(ctxt.Bso, "dwarfblk [%#x,%#x) at offset %#x\n", addr, addr+size, coutbuf.Offset())
|
||||
}
|
||||
|
||||
blk(ctxt, dwarfp, addr, size, zeros[:])
|
||||
|
|
|
|||
|
|
@ -1729,7 +1729,7 @@ func elfrelocsect(ctxt *Link, sect *Section, syms []*Symbol) {
|
|||
return
|
||||
}
|
||||
|
||||
sect.Reloff = uint64(Cpos())
|
||||
sect.Reloff = uint64(coutbuf.Offset())
|
||||
for i, s := range syms {
|
||||
if !s.Attr.Reachable() {
|
||||
continue
|
||||
|
|
@ -1768,11 +1768,11 @@ func elfrelocsect(ctxt *Link, sect *Section, syms []*Symbol) {
|
|||
}
|
||||
}
|
||||
|
||||
sect.Rellen = uint64(Cpos()) - sect.Reloff
|
||||
sect.Rellen = uint64(coutbuf.Offset()) - sect.Reloff
|
||||
}
|
||||
|
||||
func Elfemitreloc(ctxt *Link) {
|
||||
for Cpos()&7 != 0 {
|
||||
for coutbuf.Offset()&7 != 0 {
|
||||
Cput(0)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -229,6 +229,10 @@ func (w *outBuf) WriteString(s string) (n int, err error) {
|
|||
return n, err
|
||||
}
|
||||
|
||||
func (w *outBuf) Offset() int64 {
|
||||
return w.off
|
||||
}
|
||||
|
||||
var coutbuf outBuf
|
||||
|
||||
const pkgname = "__.PKGDEF"
|
||||
|
|
@ -1771,10 +1775,6 @@ func Cflush() {
|
|||
}
|
||||
}
|
||||
|
||||
func Cpos() int64 {
|
||||
return coutbuf.off
|
||||
}
|
||||
|
||||
func Cseek(p int64) {
|
||||
if p == coutbuf.off {
|
||||
return
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ var dylib []string
|
|||
var linkoff int64
|
||||
|
||||
func machowrite() int {
|
||||
o1 := Cpos()
|
||||
o1 := coutbuf.Offset()
|
||||
|
||||
loadsize := 4 * 4 * ndebug
|
||||
for i := 0; i < len(load); i++ {
|
||||
|
|
@ -291,7 +291,7 @@ func machowrite() int {
|
|||
}
|
||||
}
|
||||
|
||||
return int(Cpos() - o1)
|
||||
return int(coutbuf.Offset() - o1)
|
||||
}
|
||||
|
||||
func (ctxt *Link) domacho() {
|
||||
|
|
@ -815,7 +815,7 @@ func machorelocsect(ctxt *Link, sect *Section, syms []*Symbol) {
|
|||
return
|
||||
}
|
||||
|
||||
sect.Reloff = uint64(Cpos())
|
||||
sect.Reloff = uint64(coutbuf.Offset())
|
||||
for i, s := range syms {
|
||||
if !s.Attr.Reachable() {
|
||||
continue
|
||||
|
|
@ -847,11 +847,11 @@ func machorelocsect(ctxt *Link, sect *Section, syms []*Symbol) {
|
|||
}
|
||||
}
|
||||
|
||||
sect.Rellen = uint64(Cpos()) - sect.Reloff
|
||||
sect.Rellen = uint64(coutbuf.Offset()) - sect.Reloff
|
||||
}
|
||||
|
||||
func Machoemitreloc(ctxt *Link) {
|
||||
for Cpos()&7 != 0 {
|
||||
for coutbuf.Offset()&7 != 0 {
|
||||
Cput(0)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -570,7 +570,7 @@ func peimporteddlls() []string {
|
|||
}
|
||||
|
||||
func addimports(ctxt *Link, datsect *IMAGE_SECTION_HEADER) {
|
||||
startoff := Cpos()
|
||||
startoff := coutbuf.Offset()
|
||||
dynamic := Linklookup(ctxt, ".windynamic", 0)
|
||||
|
||||
// skip import descriptor table (will write it later)
|
||||
|
|
@ -583,7 +583,7 @@ func addimports(ctxt *Link, datsect *IMAGE_SECTION_HEADER) {
|
|||
|
||||
// write dll names
|
||||
for d := dr; d != nil; d = d.next {
|
||||
d.nameoff = uint64(Cpos()) - uint64(startoff)
|
||||
d.nameoff = uint64(coutbuf.Offset()) - uint64(startoff)
|
||||
strput(d.name)
|
||||
}
|
||||
|
||||
|
|
@ -591,18 +591,18 @@ func addimports(ctxt *Link, datsect *IMAGE_SECTION_HEADER) {
|
|||
var m *Imp
|
||||
for d := dr; d != nil; d = d.next {
|
||||
for m = d.ms; m != nil; m = m.next {
|
||||
m.off = uint64(nextsectoff) + uint64(Cpos()) - uint64(startoff)
|
||||
m.off = uint64(nextsectoff) + uint64(coutbuf.Offset()) - uint64(startoff)
|
||||
Wputl(0) // hint
|
||||
strput(m.s.Extname)
|
||||
}
|
||||
}
|
||||
|
||||
// write OriginalFirstThunks
|
||||
oftbase := uint64(Cpos()) - uint64(startoff)
|
||||
oftbase := uint64(coutbuf.Offset()) - uint64(startoff)
|
||||
|
||||
n = uint64(Cpos())
|
||||
n = uint64(coutbuf.Offset())
|
||||
for d := dr; d != nil; d = d.next {
|
||||
d.thunkoff = uint64(Cpos()) - n
|
||||
d.thunkoff = uint64(coutbuf.Offset()) - n
|
||||
for m = d.ms; m != nil; m = m.next {
|
||||
if pe64 != 0 {
|
||||
Vputl(m.off)
|
||||
|
|
@ -619,13 +619,13 @@ func addimports(ctxt *Link, datsect *IMAGE_SECTION_HEADER) {
|
|||
}
|
||||
|
||||
// add pe section and pad it at the end
|
||||
n = uint64(Cpos()) - uint64(startoff)
|
||||
n = uint64(coutbuf.Offset()) - uint64(startoff)
|
||||
|
||||
isect := addpesection(ctxt, ".idata", int(n), int(n))
|
||||
isect.Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE
|
||||
chksectoff(ctxt, isect, startoff)
|
||||
strnput("", int(uint64(isect.SizeOfRawData)-n))
|
||||
endoff := Cpos()
|
||||
endoff := coutbuf.Offset()
|
||||
|
||||
// write FirstThunks (allocated in .data section)
|
||||
ftbase := uint64(dynamic.Value) - uint64(datsect.VirtualAddress) - PEBASE
|
||||
|
|
@ -666,7 +666,6 @@ func addimports(ctxt *Link, datsect *IMAGE_SECTION_HEADER) {
|
|||
|
||||
// update data directory
|
||||
dd[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress = isect.VirtualAddress
|
||||
|
||||
dd[IMAGE_DIRECTORY_ENTRY_IMPORT].Size = isect.VirtualSize
|
||||
dd[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress = uint32(dynamic.Value - PEBASE)
|
||||
dd[IMAGE_DIRECTORY_ENTRY_IAT].Size = uint32(dynamic.Size)
|
||||
|
|
@ -712,7 +711,7 @@ func addexports(ctxt *Link) {
|
|||
|
||||
sect := addpesection(ctxt, ".edata", size, size)
|
||||
sect.Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
|
||||
chksectoff(ctxt, sect, Cpos())
|
||||
chksectoff(ctxt, sect, coutbuf.Offset())
|
||||
va := int(sect.VirtualAddress)
|
||||
dd[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress = uint32(va)
|
||||
dd[IMAGE_DIRECTORY_ENTRY_EXPORT].Size = sect.VirtualSize
|
||||
|
|
@ -772,7 +771,7 @@ func perelocsect(ctxt *Link, sect *Section, syms []*Symbol) int {
|
|||
|
||||
relocs := 0
|
||||
|
||||
sect.Reloff = uint64(Cpos())
|
||||
sect.Reloff = uint64(coutbuf.Offset())
|
||||
for i, s := range syms {
|
||||
if !s.Attr.Reachable() {
|
||||
continue
|
||||
|
|
@ -814,18 +813,18 @@ func perelocsect(ctxt *Link, sect *Section, syms []*Symbol) int {
|
|||
}
|
||||
}
|
||||
|
||||
sect.Rellen = uint64(Cpos()) - sect.Reloff
|
||||
sect.Rellen = uint64(coutbuf.Offset()) - sect.Reloff
|
||||
|
||||
return relocs
|
||||
}
|
||||
|
||||
// peemitreloc emits relocation entries for go.o in external linking.
|
||||
func peemitreloc(ctxt *Link, text, data, ctors *IMAGE_SECTION_HEADER) {
|
||||
for Cpos()&7 != 0 {
|
||||
for coutbuf.Offset()&7 != 0 {
|
||||
Cput(0)
|
||||
}
|
||||
|
||||
text.PointerToRelocations = uint32(Cpos())
|
||||
text.PointerToRelocations = uint32(coutbuf.Offset())
|
||||
// first entry: extended relocs
|
||||
Lputl(0) // placeholder for number of relocation + 1
|
||||
Lputl(0)
|
||||
|
|
@ -836,7 +835,7 @@ func peemitreloc(ctxt *Link, text, data, ctors *IMAGE_SECTION_HEADER) {
|
|||
n += perelocsect(ctxt, sect, datap)
|
||||
}
|
||||
|
||||
cpos := Cpos()
|
||||
cpos := coutbuf.Offset()
|
||||
Cseek(int64(text.PointerToRelocations))
|
||||
Lputl(uint32(n))
|
||||
Cseek(cpos)
|
||||
|
|
@ -859,7 +858,7 @@ func peemitreloc(ctxt *Link, text, data, ctors *IMAGE_SECTION_HEADER) {
|
|||
n += perelocsect(ctxt, sect, datap)
|
||||
}
|
||||
|
||||
cpos = Cpos()
|
||||
cpos = coutbuf.Offset()
|
||||
Cseek(int64(data.PointerToRelocations))
|
||||
Lputl(uint32(n))
|
||||
Cseek(cpos)
|
||||
|
|
@ -873,7 +872,7 @@ func peemitreloc(ctxt *Link, text, data, ctors *IMAGE_SECTION_HEADER) {
|
|||
|
||||
dottext := Linklookup(ctxt, ".text", 0)
|
||||
ctors.NumberOfRelocations = 1
|
||||
ctors.PointerToRelocations = uint32(Cpos())
|
||||
ctors.PointerToRelocations = uint32(coutbuf.Offset())
|
||||
sectoff := ctors.VirtualAddress
|
||||
Lputl(sectoff)
|
||||
Lputl(uint32(dottext.Dynid))
|
||||
|
|
@ -1017,7 +1016,7 @@ func writePESymTableRecords(ctxt *Link) int {
|
|||
}
|
||||
|
||||
func addpesymtable(ctxt *Link) {
|
||||
symtabStartPos := Cpos()
|
||||
symtabStartPos := coutbuf.Offset()
|
||||
|
||||
// write COFF symbol table
|
||||
var symcnt int
|
||||
|
|
@ -1063,7 +1062,7 @@ func addpersrc(ctxt *Link) {
|
|||
|
||||
h := addpesection(ctxt, ".rsrc", int(rsrcsym.Size), int(rsrcsym.Size))
|
||||
h.Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_CNT_INITIALIZED_DATA
|
||||
chksectoff(ctxt, h, Cpos())
|
||||
chksectoff(ctxt, h, coutbuf.Offset())
|
||||
|
||||
// relocation
|
||||
var p []byte
|
||||
|
|
@ -1113,7 +1112,7 @@ func addinitarray(ctxt *Link) (c *IMAGE_SECTION_HEADER) {
|
|||
c.SizeOfRawData = uint32(size)
|
||||
|
||||
Cseek(int64(c.PointerToRawData))
|
||||
chksectoff(ctxt, c, Cpos())
|
||||
chksectoff(ctxt, c, coutbuf.Offset())
|
||||
init_entry := Linklookup(ctxt, *flagEntrySymbol, 0)
|
||||
addr := uint64(init_entry.Value) - init_entry.Sect.Vaddr
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue