Source file test/fixedbugs/issue9355.go

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

View as plain text