mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.link] cmd/link: add a test for trampoline insertion
Now that we have converted pclntab pass to using the loader, trampoline insertion should work again. Add a test. Change-Id: Ia9a0485456ac75cc6e706218a359f109cd8fce43 Reviewed-on: https://go-review.googlesource.com/c/go/+/228141 Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
d4a70b97dc
commit
4a0bca37d2
1 changed files with 48 additions and 0 deletions
|
|
@ -628,3 +628,51 @@ func TestFuncAlign(t *testing.T) {
|
|||
t.Errorf("unexpected output: %s\n", out)
|
||||
}
|
||||
}
|
||||
|
||||
const helloSrc = `
|
||||
package main
|
||||
import "fmt"
|
||||
func main() { fmt.Println("hello") }
|
||||
`
|
||||
|
||||
func TestTrampoline(t *testing.T) {
|
||||
// Test that trampoline insertion works as expected.
|
||||
// For stress test, we set -debugtramp=2 flag, which sets a very low
|
||||
// threshold for trampoline generation, and essentially all cross-package
|
||||
// calls will use trampolines.
|
||||
switch runtime.GOARCH {
|
||||
case "arm", "ppc64", "ppc64le":
|
||||
default:
|
||||
t.Skipf("trampoline insertion is not implemented on %s", runtime.GOARCH)
|
||||
}
|
||||
|
||||
testenv.MustHaveGoBuild(t)
|
||||
|
||||
tmpdir, err := ioutil.TempDir("", "TestTrampoline")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
src := filepath.Join(tmpdir, "hello.go")
|
||||
err = ioutil.WriteFile(src, []byte(helloSrc), 0666)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
exe := filepath.Join(tmpdir, "hello.exe")
|
||||
|
||||
// Build and run with old object file format.
|
||||
cmd := exec.Command(testenv.GoToolPath(t), "build", "-ldflags=-debugtramp=2", "-o", exe, src)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("build failed: %v\n%s", err, out)
|
||||
}
|
||||
cmd = exec.Command(exe)
|
||||
out, err = cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Errorf("executable failed to run: %v\n%s", err, out)
|
||||
}
|
||||
if string(out) != "hello\n" {
|
||||
t.Errorf("unexpected output:\n%s", out)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue