github.com/zach-klippenstein/go@v0.0.0-20150108044943-fcfbeb3adf58/test/fixedbugs/issue9355.go (about) 1 // run 2 3 // Copyright 2014 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 package main 8 9 import ( 10 "fmt" 11 "go/build" 12 "os" 13 "os/exec" 14 "path/filepath" 15 "regexp" 16 "runtime" 17 ) 18 19 func main() { 20 if runtime.Compiler != "gc" || runtime.GOOS == "nacl" { 21 return 22 } 23 a, err := build.ArchChar(runtime.GOARCH) 24 if err != nil { 25 fmt.Println("BUG:", err) 26 os.Exit(1) 27 } 28 out := run("go", "tool", a+"g", "-S", filepath.Join("fixedbugs", "issue9355.dir", "a.go")) 29 // 6g/8g print the offset as dec, but 5g/9g print the offset as hex. 30 patterns := []string{ 31 `rel 0\+\d t=1 \"\"\.x\+8\r?\n`, // y = &x.b 32 `rel 0\+\d t=1 \"\"\.x\+(28|1c)\r?\n`, // z = &x.d.q 33 `rel 0\+\d t=1 \"\"\.b\+5\r?\n`, // c = &b[5] 34 `rel 0\+\d t=1 \"\"\.x\+(88|58)\r?\n`, // w = &x.f[3].r 35 } 36 for _, p := range patterns { 37 if ok, err := regexp.Match(p, out); !ok || err != nil { 38 println(string(out)) 39 panic("can't find pattern " + p) 40 } 41 } 42 } 43 44 func run(cmd string, args ...string) []byte { 45 out, err := exec.Command(cmd, args...).CombinedOutput() 46 if err != nil { 47 fmt.Println(string(out)) 48 fmt.Println(err) 49 os.Exit(1) 50 } 51 return out 52 }