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