mirror of
https://github.com/golang/go
synced 2024-11-17 12:34:46 -07:00
08f19bbde1
To improve readability when exported fields are removed, forbid the printer from emitting an empty line before the first comment in a const, var, or type block. Also, when printing the "Has filtered or unexported fields." message, add an empty line before it to separate the message from the struct or interfact contents. Before the change: <<< type NamedArg struct { // Name is the name of the parameter placeholder. // // If empty, the ordinal position in the argument list will be // used. // // Name must omit any symbol prefix. Name string // Value is the value of the parameter. // It may be assigned the same value types as the query // arguments. Value interface{} // contains filtered or unexported fields } >>> After the change: <<< type NamedArg struct { // Name is the name of the parameter placeholder. // // If empty, the ordinal position in the argument list will be // used. // // Name must omit any symbol prefix. Name string // Value is the value of the parameter. // It may be assigned the same value types as the query // arguments. Value interface{} // contains filtered or unexported fields } >>> Fixes #18264 Change-Id: I9fe17ca39cf92fcdfea55064bd2eaa784ce48c88 Reviewed-on: https://go-review.googlesource.com/71990 Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
77 lines
1.6 KiB
Go
77 lines
1.6 KiB
Go
// Copyright 2014 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 cgotest
|
|
|
|
// Test that we have no more than one build ID. In the past we used
|
|
// to generate a separate build ID for each package using cgo, and the
|
|
// linker concatenated them all. We don't want that--we only want
|
|
// one.
|
|
|
|
import (
|
|
"bytes"
|
|
"debug/elf"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func testBuildID(t *testing.T) {
|
|
f, err := elf.Open("/proc/self/exe")
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
t.Skip("no /proc/self/exe")
|
|
}
|
|
t.Fatal("opening /proc/self/exe: ", err)
|
|
}
|
|
defer f.Close()
|
|
|
|
c := 0
|
|
for i, s := range f.Sections {
|
|
if s.Type != elf.SHT_NOTE {
|
|
continue
|
|
}
|
|
|
|
d, err := s.Data()
|
|
if err != nil {
|
|
t.Logf("reading data of note section %d: %v", i, err)
|
|
continue
|
|
}
|
|
|
|
for len(d) > 0 {
|
|
// ELF standards differ as to the sizes in
|
|
// note sections. Both the GNU linker and
|
|
// gold always generate 32-bit sizes, so that
|
|
// is what we assume here.
|
|
|
|
if len(d) < 12 {
|
|
t.Logf("note section %d too short (%d < 12)", i, len(d))
|
|
continue
|
|
}
|
|
|
|
namesz := f.ByteOrder.Uint32(d)
|
|
descsz := f.ByteOrder.Uint32(d[4:])
|
|
typ := f.ByteOrder.Uint32(d[8:])
|
|
|
|
an := (namesz + 3) &^ 3
|
|
ad := (descsz + 3) &^ 3
|
|
|
|
if int(12+an+ad) > len(d) {
|
|
t.Logf("note section %d too short for header (%d < 12 + align(%d,4) + align(%d,4))", i, len(d), namesz, descsz)
|
|
continue
|
|
}
|
|
|
|
// 3 == NT_GNU_BUILD_ID
|
|
if typ == 3 && namesz == 4 && bytes.Equal(d[12:16], []byte("GNU\000")) {
|
|
c++
|
|
}
|
|
|
|
d = d[12+an+ad:]
|
|
}
|
|
}
|
|
|
|
if c > 1 {
|
|
t.Errorf("found %d build ID notes", c)
|
|
}
|
|
}
|