]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/compile, cmd/asm: use bio.Writer for object file writing
authorCherry Zhang <cherryyz@google.com>
Wed, 11 Sep 2019 20:11:31 +0000 (16:11 -0400)
committerCherry Zhang <cherryyz@google.com>
Tue, 1 Oct 2019 20:28:45 +0000 (20:28 +0000)
It is convenient to have a seekable writer. A later CL will make
use of Seek.

Change-Id: Iba0107ce2975d9a451d97f16aa91a318dd4c90e2
Reviewed-on: https://go-review.googlesource.com/c/go/+/196028
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
src/cmd/asm/main.go
src/cmd/compile/internal/gc/obj.go
src/cmd/internal/obj/objfile.go

index fc6acc74c05180c2f115e17ec14345bad6f7bae0..91b48975d290ffe0859706d1d3537460a02fff14 100644 (file)
@@ -46,12 +46,11 @@ func main() {
        architecture.Init(ctxt)
 
        // Create object file, write header.
-       out, err := os.Create(*flags.OutputFile)
+       buf, err := bio.Create(*flags.OutputFile)
        if err != nil {
                log.Fatal(err)
        }
-       defer bio.MustClose(out)
-       buf := bufio.NewWriter(bio.MustWriter(out))
+       defer buf.Close()
 
        if !*flags.SymABIs {
                fmt.Fprintf(buf, "go object %s %s %s\n", objabi.GOOS, objabi.GOARCH, objabi.Version)
@@ -91,9 +90,8 @@ func main() {
                } else {
                        log.Print("assembly failed")
                }
-               out.Close()
+               buf.Close()
                os.Remove(*flags.OutputFile)
                os.Exit(1)
        }
-       buf.Flush()
 }
index e703e8a3022e55832db838ba219b027bb3197551..ae0fc1dbc121adf8145a0e3415d9c30a8dfa5548 100644 (file)
@@ -166,7 +166,7 @@ func dumpLinkerObj(bout *bio.Writer) {
 
        fmt.Fprintf(bout, "\n!\n")
 
-       obj.WriteObjFile(Ctxt, bout.Writer, myimportpath)
+       obj.WriteObjFile(Ctxt, bout, myimportpath)
 }
 
 func addptabs() {
index ab5627c0dd14504bb14c0406fac1125f244a2c0c..c51a11c51f8b80641999dcba70c826222a3c5eec 100644 (file)
@@ -8,6 +8,7 @@ package obj
 
 import (
        "bufio"
+       "cmd/internal/bio"
        "cmd/internal/dwarf"
        "cmd/internal/objabi"
        "cmd/internal/sys"
@@ -80,7 +81,8 @@ func newObjWriter(ctxt *Link, b *bufio.Writer, pkgpath string) *objWriter {
        }
 }
 
-func WriteObjFile(ctxt *Link, b *bufio.Writer, pkgpath string) {
+func WriteObjFile(ctxt *Link, bout *bio.Writer, pkgpath string) {
+       b := bout.Writer
        w := newObjWriter(ctxt, b, pkgpath)
 
        // Magic header