mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
Following the previous CLs, do the same for aux symbols. This has some small speedup: (linking cmd/compile) Dostkcheck 41.0ms ± 1% 38.6ms ± 1% -6.00% (p=0.008 n=5+5) Change-Id: Id62b2fc9e4ef1be92e60e4c03faec0a953eee94e Reviewed-on: https://go-review.googlesource.com/c/go/+/222303 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
39 lines
874 B
Go
39 lines
874 B
Go
// Copyright 2020 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package goobj2
|
|
|
|
import (
|
|
"bufio"
|
|
"bytes"
|
|
"cmd/internal/bio"
|
|
"testing"
|
|
)
|
|
|
|
func dummyWriter() *Writer {
|
|
var buf bytes.Buffer
|
|
wr := &bio.Writer{Writer: bufio.NewWriter(&buf)} // hacky: no file, so cannot seek
|
|
return NewWriter(wr)
|
|
}
|
|
|
|
func TestSize(t *testing.T) {
|
|
// This test checks that hard-coded sizes match the actual sizes
|
|
// in the object file format.
|
|
tests := []struct {
|
|
x interface{ Write(*Writer) }
|
|
want uint32
|
|
}{
|
|
{&Reloc{}, RelocSize},
|
|
{&Aux{}, AuxSize},
|
|
}
|
|
w := dummyWriter()
|
|
for _, test := range tests {
|
|
off0 := w.off
|
|
test.x.Write(w)
|
|
got := w.off - off0
|
|
if got != test.want {
|
|
t.Errorf("size(%T) mismatch: %d bytes written, but size=%d", test.x, got, test.want)
|
|
}
|
|
}
|
|
}
|