"os/exec"
"path/filepath"
"runtime"
+ "strings"
"testing"
)
return nil
}
+// Check that a symbol has a given name, accepting both
+// new and old objects.
+// TODO(go115newobj): remove.
+func matchSymName(symname, want string) bool {
+ return symname == want ||
+ strings.HasPrefix(symname, want+"#") // new style, with index
+}
+
func TestParseGoobj(t *testing.T) {
path := go1obj
}
var found bool
for _, s := range p.Syms {
- if s.Name == "mypkg.go1" {
+ if matchSymName(s.Name, "mypkg.go1") {
found = true
break
}
var found1 bool
var found2 bool
for _, s := range p.Syms {
- if s.Name == "mypkg.go1" {
+ if matchSymName(s.Name, "mypkg.go1") {
found1 = true
}
- if s.Name == "mypkg.go2" {
+ if matchSymName(s.Name, "mypkg.go2") {
found2 = true
}
}
var found1 bool
var found2 bool
for _, s := range p.Syms {
- if s.Name == "mycgo.go1" {
+ if matchSymName(s.Name, "mycgo.go1") {
found1 = true
}
- if s.Name == "mycgo.go2" {
+ if matchSymName(s.Name, "mycgo.go2") {
found2 = true
}
}
case goobj2.PkgIdxSelf:
i = int(s.SymIdx)
default:
+ // Symbol from other package, referenced by index.
+ // We don't know the name. Use index.
pkg := pkglist[p]
- return SymID{fmt.Sprintf("%s.<#%d>", pkg, s.SymIdx), 0}
+ return SymID{fmt.Sprintf("%s.#%d", pkg, s.SymIdx), 0}
}
sym := rr.Sym(i)
return SymID{sym.Name(rr), abiToVer(sym.ABI())}
// Symbols
pcdataBase := start + rr.PcdataBase()
n := rr.NSym() + rr.NNonpkgdef() + rr.NNonpkgref()
+ npkgdef := rr.NSym()
ndef := rr.NSym() + rr.NNonpkgdef()
for i := 0; i < n; i++ {
osym := rr.Sym(i)
// prefix for the package in which the object file has been found.
// Expand it.
name := strings.ReplaceAll(osym.Name(rr), `"".`, r.pkgprefix)
+ if i < npkgdef {
+ // Indexed symbol. Attach index to the name.
+ name += fmt.Sprintf("#%d", i)
+ }
symID := SymID{Name: name, Version: abiToVer(osym.ABI())}
r.p.SymRefs = append(r.p.SymRefs, symID)
}
for i := range syms {
sym := &syms[i]
- if sym.Type == typ && sym.Name == name && sym.CSym == csym {
+ if sym.Type == typ && matchSymName(name, sym.Name) && sym.CSym == csym {
if sym.Found {
t.Fatalf("duplicate symbol %s %s", sym.Type, sym.Name)
}
testGoLib(t, false)
}
+// Check that a symbol has a given name, accepting both
+// new and old objects.
+// TODO(go115newobj): remove.
+func matchSymName(symname, want string) bool {
+ return symname == want ||
+ strings.HasPrefix(symname, want+"#") // new style, with index
+}
+
const testexec = `
package main
"os"
"os/exec"
"path/filepath"
+ "regexp"
"runtime"
"strings"
"testing"
if err != nil {
t.Fatalf("go tool compile fmthello.go: %v\n%s", err, out)
}
+
+ // TODO(go115newobj): drop old object file support.
need := []string{
- "main(SB)",
- "fmthello.go:6",
+ `main(#\d+)?\(SB\)`, // either new or old object file
+ `fmthello\.go:6`,
}
args = []string{
text := string(out)
ok := true
for _, s := range need {
- if !strings.Contains(text, s) {
- t.Errorf("disassembly missing '%s'", s)
+ re := regexp.MustCompile(s)
+ if !re.MatchString(text) {
+ t.Errorf("disassembly missing %q", s)
ok = false
}
}