]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: rework reporting of oversized stack frames
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 30 Mar 2017 18:46:45 +0000 (11:46 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Fri, 31 Mar 2017 16:31:09 +0000 (16:31 +0000)
We don't support stack frames over 2GB.
Rather than detect this during backend compilation,
check for it at the end of compilation.
This is arguably a more accurate check anyway,
since it takes into account the full frame,
including local stack, arguments, and arch-specific
rounding, although it's unlikely anyone would ever notice.

Also, rather than reporting the error right away,
take note of it and report it later, at the top level.
This is not relevant now, but it will help with making
the backend concurrent, as the append to the list of
oversized functions can be cheaply protected by a plain mutex.

Updates #15756
Updates #19250

Change-Id: Id3fa21906616d62e9dc66e27a17fd5f83304e96e
Reviewed-on: https://go-review.googlesource.com/38972
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/gc/pgen.go
src/cmd/compile/internal/gc/subr.go

index f59d3cd41da2b465f02be3adff67653f26524090..a0d5170a46bb2a7c6468f6e6d54404745e4d14fd 100644 (file)
@@ -523,6 +523,9 @@ func Main(archInit func(*Arch)) {
                if compiling_runtime {
                        checknowritebarrierrec()
                }
+               for _, largePos := range largeStackFrames {
+                       yyerrorl(largePos, "stack frame too large (>2GB)")
+               }
        }
 
        // Phase 9: Check external declarations.
index 283a8e616072b82e273b68e3455995d0e8de3fed..02cabc4a0258a2307847d48c4ac51af7ba379a0a 100644 (file)
@@ -235,10 +235,6 @@ func (s *ssafn) AllocFrame(f *ssa.Func) {
                if thearch.LinkArch.InFamily(sys.MIPS, sys.MIPS64, sys.ARM, sys.ARM64, sys.PPC64, sys.S390X) {
                        s.stksize = Rnd(s.stksize, int64(Widthptr))
                }
-               if s.stksize >= 1<<31 {
-                       yyerrorl(s.curfn.Pos, "stack frame too large (>2GB)")
-               }
-
                n.Xoffset = -s.stksize
        }
 
@@ -289,6 +285,10 @@ func compile(fn *Node) {
        pp := newProgs(fn)
        genssa(ssafn, pp)
        fieldtrack(pp.Text.From.Sym, fn.Func.FieldTrack)
+       if pp.Text.To.Offset >= 1<<31 {
+               largeStackFrames = append(largeStackFrames, fn.Pos)
+               return
+       }
        pp.Flush()
 }
 
index 7e6a2a287fe64c0850757e4cd274f62c759fae9d..fb56d4eb3a47bc4a4b15386238daa8e5964548ed 100644 (file)
@@ -27,6 +27,8 @@ type Error struct {
 
 var errors []Error
 
+var largeStackFrames []src.XPos // positions of functions whose stack frames are too large (rare)
+
 func errorexit() {
        flusherrors()
        if outfile != "" {