From 120f445495a573f80b1f0c0acc326c281c01b13e Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 4 Apr 2022 14:51:39 -0400 Subject: [PATCH] test/nosplit: apply stack limit adjustment in the right place The nosplit test was originally written when the stack limit was a mere 128 bytes. Now it's much larger, but rather than rewriting all of the tests, we apply a hack to just add the extra space into the stack frames of the existing tests. Unfortunately, we add it in the wrong place. The extra space should be added just once per chain of nosplit functions, but instead we add it to every frame that appears first on a line in the test's little script language. This means that for tests like start 0 call f1 f1 16 nosplit call f2 f2 16 nosplit call f3 f3 16 nosplit call f4 f4 16 nosplit call f5 f5 16 nosplit call f6 f6 16 nosplit call f7 f7 16 nosplit call f8 f8 16 nosplit call end end 1000 REJECT we add 672 bytes to *every* frame, meaning that we wind up way over the stack limit by the end of the stanza, rather than just a little as originally intended. Fix this by instead adding the extra space to the first nosplit function in a stanza. This isn't perfect either, since we could have a nosplit -> split -> nosplit chain, but it's the best we can do without a graph analysis. Change-Id: Ibf156c68fe3eb1b64a438115f4a17f1a6c7e2bd1 Reviewed-on: https://go-review.googlesource.com/c/go/+/398174 Run-TryBot: Austin Clements Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot --- test/nosplit.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/test/nosplit.go b/test/nosplit.go index 7c7e1bfd99..1d94f6eb91 100644 --- a/test/nosplit.go +++ b/test/nosplit.go @@ -292,12 +292,13 @@ TestCases: fmt.Fprintf(&gobuf, "func main() { main0() }\n") fmt.Fprintf(&buf, "TEXT ·main0(SB),0,$0-0\n\tCALL ·start(SB)\n") + adjusted := false for _, line := range strings.Split(lines, "\n") { line = strings.TrimSpace(line) if line == "" { continue } - for i, subline := range strings.Split(line, ";") { + for _, subline := range strings.Split(line, ";") { subline = strings.TrimSpace(subline) if subline == "" { continue @@ -311,10 +312,19 @@ TestCases: name := m[1] size, _ := strconv.Atoi(m[2]) + if size%ptrSize == 4 { + continue TestCases + } + nosplit := m[3] + body := m[4] + // The limit was originally 128 but is now 800 (928-128). // Instead of rewriting the test cases above, adjust - // the first stack frame to use up the extra bytes. - if i == 0 { + // the first nosplit frame to use up the extra bytes. + // This isn't exactly right because we could have + // nosplit -> split -> nosplit, but it's good enough. + if !adjusted && nosplit != "" { + adjusted = true size += (928 - 128) - 128 // Noopt builds have a larger stackguard. // See ../src/cmd/dist/buildruntime.go:stackGuardMultiplier @@ -326,12 +336,6 @@ TestCases: } } - if size%ptrSize == 4 { - continue TestCases - } - nosplit := m[3] - body := m[4] - if nosplit != "" { nosplit = ",7" } else { -- 2.50.0