Skip to content

Commit 951143c

Browse files
cmd/link: increase the function call limit in stkcheck
There is real (albeit generated) code that exceeds the limit. Fixes #33555 Change-Id: I668e85825d3d2a471970e869abe63f3492213cc1 Reviewed-on: https://go-review.googlesource.com/c/go/+/189697 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent 3626252 commit 951143c

2 files changed

Lines changed: 82 additions & 1 deletion

File tree

src/cmd/link/internal/ld/lib.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2066,7 +2066,7 @@ func stkcheck(ctxt *Link, up *chain, depth int) int {
20662066
s.Attr |= sym.AttrStackCheck
20672067
}
20682068

2069-
if depth > 100 {
2069+
if depth > 500 {
20702070
Errorf(s, "nosplit stack check too deep")
20712071
stkbroke(ctxt, up, 0)
20722072
return -1

test/fixedbugs/issue33555.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// +build !nacl,!js
2+
// run
3+
4+
// Copyright 2019 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+
// Test that the linker permits long call sequences.
9+
package main
10+
11+
import (
12+
"bytes"
13+
"fmt"
14+
"io/ioutil"
15+
"os"
16+
"os/exec"
17+
"path/filepath"
18+
"strconv"
19+
)
20+
21+
const start = `
22+
package main
23+
24+
func main() {
25+
println(f0() + 1)
26+
}
27+
`
28+
29+
const fn = `
30+
//go:noinline
31+
func f%d() int {
32+
return f%d() + 1
33+
}`
34+
35+
const fnlast = `
36+
//go:noinline
37+
func f%d() int {
38+
return 0
39+
}
40+
`
41+
42+
const count = 400
43+
44+
func main() {
45+
if err := test(); err != nil {
46+
fmt.Fprintln(os.Stderr, err)
47+
os.Exit(1)
48+
}
49+
}
50+
51+
func test() error {
52+
var buf bytes.Buffer
53+
buf.WriteString(start)
54+
for i := 0; i < count; i++ {
55+
fmt.Fprintf(&buf, fn, i, i + 1)
56+
}
57+
fmt.Fprintf(&buf, fnlast, count)
58+
59+
dir, err := ioutil.TempDir("", "issue33555")
60+
if err != nil {
61+
return err
62+
}
63+
defer os.RemoveAll(dir)
64+
65+
fn := filepath.Join(dir, "x.go")
66+
if err := ioutil.WriteFile(fn, buf.Bytes(), 0644); err != nil {
67+
return err
68+
}
69+
70+
out, err := exec.Command("go", "run", fn).CombinedOutput()
71+
if err != nil {
72+
return err
73+
}
74+
75+
want := strconv.Itoa(count + 1)
76+
if got := string(bytes.TrimSpace(out)); got != want {
77+
return fmt.Errorf("got %q want %q", got, want)
78+
}
79+
80+
return nil
81+
}

0 commit comments

Comments
 (0)