]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/ld: use a simpler cout writer
authorDavid Crawshaw <crawshaw@golang.org>
Wed, 29 Apr 2015 14:59:22 +0000 (10:59 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Wed, 29 Apr 2015 17:13:18 +0000 (17:13 +0000)
Removes the unused *bufio.Reader from the object controlling the
linker's primary output.

Change-Id: If91d9f60752f3dc4b280f35d6eb441f3c47574b2
Reviewed-on: https://go-review.googlesource.com/9362
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/internal/ld/elf.go
src/cmd/internal/ld/lib.go
src/cmd/internal/ld/pe.go

index b56a8072ebcee21246ac64ff79db7da9c45bb5ee..cb4a73a3380ad5f6e4a733c8f0b35a0974b6f016 100644 (file)
@@ -1034,7 +1034,7 @@ func elfinterp(sh *ElfShdr, startva uint64, resoff uint64, p string) int {
 func elfwriteinterp() int {
        sh := elfshname(".interp")
        Cseek(int64(sh.off))
-       coutbuf.w.WriteString(interp)
+       coutbuf.WriteString(interp)
        Cput(0)
        return int(sh.size)
 }
index 3f7b04fbbb2501599a5880fafde9c29853a499db..b14a6c1b50b1f2163d29a1eb1f64e589a6af532f 100644 (file)
@@ -31,6 +31,7 @@
 package ld
 
 import (
+       "bufio"
        "bytes"
        "cmd/internal/obj"
        "debug/elf"
@@ -229,10 +230,14 @@ const (
 var (
        headstring string
        // buffered output
-       Bso     Biobuf
-       coutbuf Biobuf
+       Bso Biobuf
 )
 
+var coutbuf struct {
+       *bufio.Writer
+       f *os.File
+}
+
 const (
        // Whether to assume that the external linker is "gold"
        // (http://sourceware.org/ml/binutils/2008-03/msg00162.html).
@@ -245,7 +250,6 @@ const (
 )
 
 var (
-       cout *os.File
        // Set if we see an object compiled by the host compiler that is not
        // from a package that is known to support internal linking mode.
        externalobj = false
@@ -359,8 +363,8 @@ func libinit() {
                Exitf("cannot create %s: %v", outfile, err)
        }
 
-       cout = f
-       coutbuf = *Binitw(f)
+       coutbuf.Writer = bufio.NewWriter(f)
+       coutbuf.f = f
 
        if INITENTRY == "" {
                switch Buildmode {
@@ -382,21 +386,26 @@ func libinit() {
 
 func Exitf(format string, a ...interface{}) {
        fmt.Fprintf(os.Stderr, os.Args[0]+": "+format+"\n", a...)
-       if cout != nil {
-               cout.Close()
+       if coutbuf.f != nil {
+               coutbuf.f.Close()
                mayberemoveoutfile()
        }
        Exit(2)
 }
 
 func errorexit() {
-       if cout != nil {
+       if coutbuf.f != nil {
+               if nerrors != 0 {
+                       Cflush()
+               }
                // For rmtemp run at atexit time on Windows.
-               cout.Close()
+               if err := coutbuf.f.Close(); err != nil {
+                       Exitf("close: %v", err)
+               }
        }
 
        if nerrors != 0 {
-               if cout != nil {
+               if coutbuf.f != nil {
                        mayberemoveoutfile()
                }
                Exit(2)
@@ -803,16 +812,17 @@ func hostlinksetup() {
        }
 
        // change our output to temporary object file
-       cout.Close()
+       coutbuf.f.Close()
 
        p := fmt.Sprintf("%s/go.o", tmpdir)
        var err error
-       cout, err = os.OpenFile(p, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0775)
+       f, err := os.OpenFile(p, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0775)
        if err != nil {
                Exitf("cannot create %s: %v", p, err)
        }
 
-       coutbuf = *Binitw(cout)
+       coutbuf.Writer = bufio.NewWriter(f)
+       coutbuf.f = f
 }
 
 // hostobjCopy creates a copy of the object files in hostobj in a
@@ -1555,23 +1565,33 @@ func Yconv(s *LSym) string {
 }
 
 func Cflush() {
-       Bflush(&coutbuf)
+       if err := coutbuf.Writer.Flush(); err != nil {
+               Exitf("flushing %s: %v", coutbuf.f.Name(), err)
+       }
 }
 
 func Cpos() int64 {
-       return Boffset(&coutbuf)
+       Cflush()
+       off, err := coutbuf.f.Seek(0, 1)
+       if err != nil {
+               Exitf("seeking in output [0, 1]: %v", err)
+       }
+       return off
 }
 
 func Cseek(p int64) {
-       Bseek(&coutbuf, p, 0)
+       Cflush()
+       if _, err := coutbuf.f.Seek(p, 0); err != nil {
+               Exitf("seeking in output [0, 1]: %v", err)
+       }
 }
 
 func Cwrite(p []byte) {
-       Bwrite(&coutbuf, p)
+       coutbuf.Write(p)
 }
 
 func Cput(c uint8) {
-       Bputc(&coutbuf, c)
+       coutbuf.WriteByte(c)
 }
 
 func usage() {
index f7a45fd3381541c1f25bd1e2cf78248ab4e7d93e..cb82c053d88b9c370f0eed8170911493478ab4a4 100644 (file)
@@ -474,7 +474,7 @@ func pewrite() {
 }
 
 func strput(s string) {
-       coutbuf.w.WriteString(s)
+       coutbuf.WriteString(s)
        Cput(0)
        // string must be padded to even size
        if (len(s)+1)%2 != 0 {