mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/link: remove coutbuf global variable
Begin passing coutbuf by as a parameter. To make the initial plumbing pass easier, it is also a field in the standard ctxt parameter. Consolidate the byte writing functions into the OutBuf object. The result is less architecture-dependent initialization. To avoid plumbing out everywhere we want to report an error, move handling of out file deletion to an AtExit function. For #22095 Change-Id: I0863695241562e0662ae3669666c7922b8c846f9 Reviewed-on: https://go-review.googlesource.com/67318 Run-TryBot: David Crawshaw <crawshaw@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
5d95de2072
commit
5fe9bbcf63
27 changed files with 794 additions and 874 deletions
|
|
@ -849,7 +849,7 @@ func Codeblk(ctxt *Link, addr int64, size int64) {
|
|||
}
|
||||
func CodeblkPad(ctxt *Link, addr int64, size int64, pad []byte) {
|
||||
if *flagA {
|
||||
ctxt.Logf("codeblk [%#x,%#x) at offset %#x\n", addr, addr+size, coutbuf.Offset())
|
||||
ctxt.Logf("codeblk [%#x,%#x) at offset %#x\n", addr, addr+size, ctxt.Out.Offset())
|
||||
}
|
||||
|
||||
blk(ctxt, ctxt.Textp, addr, size, pad)
|
||||
|
|
@ -932,13 +932,13 @@ func blk(ctxt *Link, syms []*Symbol, addr, size int64, pad []byte) {
|
|||
errorexit()
|
||||
}
|
||||
if addr < s.Value {
|
||||
strnputPad("", int(s.Value-addr), pad)
|
||||
ctxt.Out.WriteStringPad("", int(s.Value-addr), pad)
|
||||
addr = s.Value
|
||||
}
|
||||
Cwrite(s.P)
|
||||
ctxt.Out.Write(s.P)
|
||||
addr += int64(len(s.P))
|
||||
if addr < s.Value+s.Size {
|
||||
strnputPad("", int(s.Value+s.Size-addr), pad)
|
||||
ctxt.Out.WriteStringPad("", int(s.Value+s.Size-addr), pad)
|
||||
addr = s.Value + s.Size
|
||||
}
|
||||
if addr != s.Value+s.Size {
|
||||
|
|
@ -951,14 +951,14 @@ func blk(ctxt *Link, syms []*Symbol, addr, size int64, pad []byte) {
|
|||
}
|
||||
|
||||
if addr < eaddr {
|
||||
strnputPad("", int(eaddr-addr), pad)
|
||||
ctxt.Out.WriteStringPad("", int(eaddr-addr), pad)
|
||||
}
|
||||
Cflush()
|
||||
ctxt.Out.Flush()
|
||||
}
|
||||
|
||||
func Datblk(ctxt *Link, addr int64, size int64) {
|
||||
if *flagA {
|
||||
ctxt.Logf("datblk [%#x,%#x) at offset %#x\n", addr, addr+size, coutbuf.Offset())
|
||||
ctxt.Logf("datblk [%#x,%#x) at offset %#x\n", addr, addr+size, ctxt.Out.Offset())
|
||||
}
|
||||
|
||||
blk(ctxt, datap, addr, size, zeros[:])
|
||||
|
|
@ -1029,7 +1029,7 @@ func Datblk(ctxt *Link, addr int64, size int64) {
|
|||
|
||||
func Dwarfblk(ctxt *Link, addr int64, size int64) {
|
||||
if *flagA {
|
||||
ctxt.Logf("dwarfblk [%#x,%#x) at offset %#x\n", addr, addr+size, coutbuf.Offset())
|
||||
ctxt.Logf("dwarfblk [%#x,%#x) at offset %#x\n", addr, addr+size, ctxt.Out.Offset())
|
||||
}
|
||||
|
||||
blk(ctxt, dwarfp, addr, size, zeros[:])
|
||||
|
|
@ -1037,31 +1037,6 @@ func Dwarfblk(ctxt *Link, addr int64, size int64) {
|
|||
|
||||
var zeros [512]byte
|
||||
|
||||
// strnput writes the first n bytes of s.
|
||||
// If n is larger than len(s),
|
||||
// it is padded with NUL bytes.
|
||||
func strnput(s string, n int) {
|
||||
strnputPad(s, n, zeros[:])
|
||||
}
|
||||
|
||||
// strnput writes the first n bytes of s.
|
||||
// If n is larger than len(s),
|
||||
// it is padded with the bytes in pad (repeated as needed).
|
||||
func strnputPad(s string, n int, pad []byte) {
|
||||
if len(s) >= n {
|
||||
Cwritestring(s[:n])
|
||||
} else {
|
||||
Cwritestring(s)
|
||||
n -= len(s)
|
||||
for n > len(pad) {
|
||||
Cwrite(pad)
|
||||
n -= len(pad)
|
||||
|
||||
}
|
||||
Cwrite(pad[:n])
|
||||
}
|
||||
}
|
||||
|
||||
var strdata []*Symbol
|
||||
|
||||
func addstrdata1(ctxt *Link, arg string) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue